RTCPeerConnection.h [plain text]
#pragma once
#if ENABLE(WEB_RTC)
#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "MediaStream.h"
#include "RTCConfiguration.h"
#include "RTCDataChannel.h"
#include "RTCIceConnectionState.h"
#include "RTCIceGatheringState.h"
#include "RTCPeerConnectionState.h"
#include "RTCRtpTransceiver.h"
#include "RTCSignalingState.h"
namespace WebCore {
class MediaStreamTrack;
class PeerConnectionBackend;
class RTCController;
class RTCIceCandidate;
class RTCPeerConnectionErrorCallback;
class RTCSessionDescription;
class RTCStatsCallback;
struct RTCAnswerOptions;
struct RTCOfferOptions;
struct RTCRtpParameters;
struct RTCRtpTransceiverInit {
RTCRtpTransceiverDirection direction;
};
class RTCPeerConnection final : public RefCounted<RTCPeerConnection>, public RTCRtpSender::Backend, public EventTargetWithInlineData, public ActiveDOMObject {
public:
static Ref<RTCPeerConnection> create(ScriptExecutionContext&);
virtual ~RTCPeerConnection();
using DataChannelInit = RTCDataChannelInit;
ExceptionOr<void> initializeWith(Document&, RTCConfiguration&&);
void queuedCreateOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
void queuedCreateAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
void queuedSetLocalDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
RefPtr<RTCSessionDescription> localDescription() const;
RefPtr<RTCSessionDescription> currentLocalDescription() const;
RefPtr<RTCSessionDescription> pendingLocalDescription() const;
void queuedSetRemoteDescription(RTCSessionDescription&, DOMPromiseDeferred<void>&&);
RefPtr<RTCSessionDescription> remoteDescription() const;
RefPtr<RTCSessionDescription> currentRemoteDescription() const;
RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
void queuedAddIceCandidate(RTCIceCandidate*, DOMPromiseDeferred<void>&&);
RTCSignalingState signalingState() const { return m_signalingState; }
RTCIceGatheringState iceGatheringState() const { return m_iceGatheringState; }
RTCIceConnectionState iceConnectionState() const { return m_iceConnectionState; }
RTCPeerConnectionState connectionState() const { return m_connectionState; }
const RTCConfiguration& getConfiguration() const { return m_configuration; }
ExceptionOr<void> setConfiguration(RTCConfiguration&&);
void close();
bool isClosed() const { return m_connectionState == RTCPeerConnectionState::Closed; }
const Vector<std::reference_wrapper<RTCRtpSender>>& getSenders() const { return m_transceiverSet->senders(); }
const Vector<std::reference_wrapper<RTCRtpReceiver>>& getReceivers() const { return m_transceiverSet->receivers(); }
const Vector<RefPtr<RTCRtpTransceiver>>& getTransceivers() const { return m_transceiverSet->list(); }
ExceptionOr<Ref<RTCRtpSender>> addTrack(Ref<MediaStreamTrack>&&, const Vector<std::reference_wrapper<MediaStream>>&);
ExceptionOr<void> removeTrack(RTCRtpSender&);
using AddTransceiverTrackOrKind = Variant<RefPtr<MediaStreamTrack>, String>;
ExceptionOr<Ref<RTCRtpTransceiver>> addTransceiver(AddTransceiverTrackOrKind&&, const RTCRtpTransceiverInit&);
ExceptionOr<Ref<RTCDataChannel>> createDataChannel(ScriptExecutionContext&, String&&, RTCDataChannelInit&&);
void getStats(MediaStreamTrack*, Ref<DeferredPromise>&&);
Vector<RefPtr<MediaStream>> getRemoteStreams() const { return m_backend->getRemoteStreams(); }
EventTargetInterface eventTargetInterface() const final { return RTCPeerConnectionEventTargetInterfaceType; }
ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
using RefCounted::ref;
using RefCounted::deref;
WEBCORE_EXPORT void emulatePlatformEvent(const String& action);
void addTransceiver(Ref<RTCRtpTransceiver>&&);
void setSignalingState(RTCSignalingState);
void updateIceGatheringState(RTCIceGatheringState);
void updateIceConnectionState(RTCIceConnectionState);
void scheduleNegotiationNeededEvent();
RTCRtpSender::Backend& senderBackend() { return *this; }
void fireEvent(Event&);
void disableICECandidateFiltering() { m_backend->disableICECandidateFiltering(); }
void enableICECandidateFiltering() { m_backend->enableICECandidateFiltering(); }
void enqueueReplaceTrackTask(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&);
void clearController() { m_controller = nullptr; }
bool hasPendingActivity() const final;
private:
RTCPeerConnection(ScriptExecutionContext&);
ExceptionOr<void> initializeConfiguration(RTCConfiguration&&);
Ref<RTCRtpTransceiver> completeAddTransceiver(Ref<RTCRtpSender>&&, const RTCRtpTransceiverInit&, const String& trackId, const String& trackKind);
void registerToController(RTCController&);
void unregisterFromController();
friend class Internals;
void applyRotationForOutgoingVideoSources() { m_backend->applyRotationForOutgoingVideoSources(); }
void refEventTarget() final { ref(); }
void derefEventTarget() final { deref(); }
WEBCORE_EXPORT void stop() final;
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
RTCRtpParameters getParameters(RTCRtpSender&) const final;
void updateConnectionState();
bool doClose();
void doStop();
bool m_isStopped { false };
RTCSignalingState m_signalingState { RTCSignalingState::Stable };
RTCIceGatheringState m_iceGatheringState { RTCIceGatheringState::New };
RTCIceConnectionState m_iceConnectionState { RTCIceConnectionState::New };
RTCPeerConnectionState m_connectionState { RTCPeerConnectionState::New };
std::unique_ptr<RtpTransceiverSet> m_transceiverSet { std::unique_ptr<RtpTransceiverSet>(new RtpTransceiverSet()) };
std::unique_ptr<PeerConnectionBackend> m_backend;
RTCConfiguration m_configuration;
RTCController* m_controller { nullptr };
};
}
#endif // ENABLE(WEB_RTC)