PeerConnectionBackend.h [plain text]
#pragma once
#if ENABLE(WEB_RTC)
#include "JSDOMPromiseDeferred.h"
#include "RTCRtpParameters.h"
#include "RTCSessionDescription.h"
#include "RTCSignalingState.h"
namespace WebCore {
class MediaStream;
class MediaStreamTrack;
class PeerConnectionBackend;
class RTCDataChannelHandler;
class RTCIceCandidate;
class RTCPeerConnection;
class RTCRtpReceiver;
class RTCRtpSender;
class RTCSessionDescription;
class RTCStatsReport;
struct MediaEndpointConfiguration;
struct RTCAnswerOptions;
struct RTCDataChannelInit;
struct RTCOfferOptions;
namespace PeerConnection {
using SessionDescriptionPromise = DOMPromiseDeferred<IDLDictionary<RTCSessionDescription::Init>>;
using StatsPromise = DOMPromiseDeferred<IDLInterface<RTCStatsReport>>;
}
using CreatePeerConnectionBackend = std::unique_ptr<PeerConnectionBackend> (*)(RTCPeerConnection&);
class PeerConnectionBackend {
public:
WEBCORE_EXPORT static CreatePeerConnectionBackend create;
PeerConnectionBackend(RTCPeerConnection& peerConnection) : m_peerConnection(peerConnection) { }
virtual ~PeerConnectionBackend() { }
void createOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
void createAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
void setLocalDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
void setRemoteDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
void addIceCandidate(RTCIceCandidate*, DOMPromiseDeferred<void>&&);
virtual std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) = 0;
void stop();
virtual RefPtr<RTCSessionDescription> localDescription() const = 0;
virtual RefPtr<RTCSessionDescription> currentLocalDescription() const = 0;
virtual RefPtr<RTCSessionDescription> pendingLocalDescription() const = 0;
virtual RefPtr<RTCSessionDescription> remoteDescription() const = 0;
virtual RefPtr<RTCSessionDescription> currentRemoteDescription() const = 0;
virtual RefPtr<RTCSessionDescription> pendingRemoteDescription() const = 0;
virtual bool setConfiguration(MediaEndpointConfiguration&&) = 0;
virtual void getStats(MediaStreamTrack*, Ref<DeferredPromise>&&) = 0;
virtual Vector<RefPtr<MediaStream>> getRemoteStreams() const = 0;
virtual Ref<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) = 0;
virtual void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) = 0;
virtual void notifyAddedTrack(RTCRtpSender&) { }
virtual void notifyRemovedTrack(RTCRtpSender&) { }
virtual RTCRtpParameters getParameters(RTCRtpSender&) const { return { }; }
void markAsNeedingNegotiation();
bool isNegotiationNeeded() const { return m_negotiationNeeded; };
void clearNegotiationNeededState() { m_negotiationNeeded = false; };
virtual void emulatePlatformEvent(const String& action) = 0;
void newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex);
void disableICECandidateFiltering();
void enableICECandidateFiltering();
virtual void applyRotationForOutgoingVideoSources() { }
protected:
void fireICECandidateEvent(RefPtr<RTCIceCandidate>&&);
void doneGatheringCandidates();
void updateSignalingState(RTCSignalingState);
void createOfferSucceeded(String&&);
void createOfferFailed(Exception&&);
void createAnswerSucceeded(String&&);
void createAnswerFailed(Exception&&);
void setLocalDescriptionSucceeded();
void setLocalDescriptionFailed(Exception&&);
void setRemoteDescriptionSucceeded();
void setRemoteDescriptionFailed(Exception&&);
void addIceCandidateSucceeded();
void addIceCandidateFailed(Exception&&);
String filterSDP(String&&) const;
private:
virtual void doCreateOffer(RTCOfferOptions&&) = 0;
virtual void doCreateAnswer(RTCAnswerOptions&&) = 0;
virtual void doSetLocalDescription(RTCSessionDescription&) = 0;
virtual void doSetRemoteDescription(RTCSessionDescription&) = 0;
virtual void doAddIceCandidate(RTCIceCandidate&) = 0;
virtual void endOfIceCandidates(DOMPromiseDeferred<void>&& promise) { promise.resolve(); }
virtual void doStop() = 0;
protected:
RTCPeerConnection& m_peerConnection;
private:
std::optional<PeerConnection::SessionDescriptionPromise> m_offerAnswerPromise;
std::optional<DOMPromiseDeferred<void>> m_setDescriptionPromise;
std::optional<DOMPromiseDeferred<void>> m_addIceCandidatePromise;
bool m_shouldFilterICECandidates { true };
struct PendingICECandidate {
String sdp;
String mid;
unsigned short sdpMLineIndex;
};
Vector<PendingICECandidate> m_pendingICECandidates;
bool m_negotiationNeeded { false };
};
}
#endif // ENABLE(WEB_RTC)