RTCPeerConnection.h [plain text]
#ifndef RTCPeerConnection_h
#define RTCPeerConnection_h
#if ENABLE(MEDIA_STREAM)
#include "ActiveDOMObject.h"
#include "Dictionary.h"
#include "EventTarget.h"
#include "ExceptionBase.h"
#include "MediaStream.h"
#include "RTCIceCandidate.h"
#include "RTCPeerConnectionHandler.h"
#include "RTCPeerConnectionHandlerClient.h"
#include "ScriptWrappable.h"
#include "Timer.h"
#include <wtf/RefCounted.h>
namespace WebCore {
class MediaStreamTrack;
class RTCConfiguration;
class RTCDTMFSender;
class RTCDataChannel;
class RTCPeerConnectionErrorCallback;
class RTCSessionDescription;
class RTCSessionDescriptionCallback;
class RTCStatsCallback;
class VoidCallback;
class RTCPeerConnection final : public RefCounted<RTCPeerConnection>, public ScriptWrappable, public RTCPeerConnectionHandlerClient, public EventTargetWithInlineData, public ActiveDOMObject, public MediaStream::Observer {
public:
static RefPtr<RTCPeerConnection> create(ScriptExecutionContext&, const Dictionary& rtcConfiguration, ExceptionCode&);
~RTCPeerConnection();
void createOffer(PassRefPtr<RTCSessionDescriptionCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, const Dictionary& offerOptions, ExceptionCode&);
void createAnswer(PassRefPtr<RTCSessionDescriptionCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, const Dictionary& answerOptions, ExceptionCode&);
void setLocalDescription(PassRefPtr<RTCSessionDescription>, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
PassRefPtr<RTCSessionDescription> localDescription(ExceptionCode&);
void setRemoteDescription(PassRefPtr<RTCSessionDescription>, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
PassRefPtr<RTCSessionDescription> remoteDescription(ExceptionCode&);
String signalingState() const;
void updateIce(const Dictionary& rtcConfiguration, ExceptionCode&);
void addIceCandidate(RTCIceCandidate*, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
String iceGatheringState() const;
String iceConnectionState() const;
RTCConfiguration* getConfiguration() const;
Vector<RefPtr<MediaStream>> getLocalStreams() const;
Vector<RefPtr<MediaStream>> getRemoteStreams() const;
MediaStream* getStreamById(const String& streamId);
void addStream(PassRefPtr<MediaStream>, ExceptionCode&);
void removeStream(PassRefPtr<MediaStream>, ExceptionCode&);
void getStats(PassRefPtr<RTCStatsCallback> successCallback, PassRefPtr<RTCPeerConnectionErrorCallback>, PassRefPtr<MediaStreamTrack> selector);
PassRefPtr<RTCDataChannel> createDataChannel(String label, const Dictionary& dataChannelDict, ExceptionCode&);
PassRefPtr<RTCDTMFSender> createDTMFSender(PassRefPtr<MediaStreamTrack>, ExceptionCode&);
void close(ExceptionCode&);
virtual void negotiationNeeded() override;
virtual void didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescriptor>) override;
virtual void didChangeSignalingState(SignalingState) override;
virtual void didChangeIceGatheringState(IceGatheringState) override;
virtual void didChangeIceConnectionState(IceConnectionState) override;
virtual void didAddRemoteStream(PassRefPtr<MediaStreamPrivate>) override;
virtual void didRemoveRemoteStream(MediaStreamPrivate*) override;
virtual void didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler>) override;
virtual EventTargetInterface eventTargetInterface() const override { return RTCPeerConnectionEventTargetInterfaceType; }
virtual ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
virtual void didAddOrRemoveTrack() override;
using RefCounted<RTCPeerConnection>::ref;
using RefCounted<RTCPeerConnection>::deref;
private:
RTCPeerConnection(ScriptExecutionContext&, PassRefPtr<RTCConfiguration>, ExceptionCode&);
static RefPtr<RTCConfiguration> parseConfiguration(const Dictionary& configuration, ExceptionCode&);
void scheduleDispatchEvent(PassRefPtr<Event>);
void scheduledEventTimerFired();
bool hasLocalStreamWithTrackId(const String& trackId);
virtual void refEventTarget() override { ref(); }
virtual void derefEventTarget() override { deref(); }
void stop() override;
const char* activeDOMObjectName() const override;
bool canSuspendForPageCache() const override;
void changeSignalingState(SignalingState);
void changeIceGatheringState(IceGatheringState);
void changeIceConnectionState(IceConnectionState);
bool checkStateForLocalDescription(RTCSessionDescription*);
bool checkStateForRemoteDescription(RTCSessionDescription*);
SignalingState m_signalingState;
IceGatheringState m_iceGatheringState;
IceConnectionState m_iceConnectionState;
Vector<RefPtr<MediaStream>> m_localStreams;
Vector<RefPtr<MediaStream>> m_remoteStreams;
Vector<RefPtr<RTCDataChannel>> m_dataChannels;
std::unique_ptr<RTCPeerConnectionHandler> m_peerHandler;
Timer m_scheduledEventTimer;
Vector<RefPtr<Event>> m_scheduledEvents;
RefPtr<RTCConfiguration> m_configuration;
bool m_stopped;
};
}
#endif // ENABLE(MEDIA_STREAM)
#endif // RTCPeerConnection_h