2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * 3. Neither the name of Google Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef RTCPeerConnection_h
32 #define RTCPeerConnection_h
34 #include "bindings/v8/Dictionary.h"
35 #include "bindings/v8/ScriptWrappable.h"
36 #include "core/dom/ActiveDOMObject.h"
37 #include "core/events/EventTarget.h"
38 #include "modules/mediastream/MediaStream.h"
39 #include "modules/mediastream/RTCIceCandidate.h"
40 #include "platform/AsyncMethodRunner.h"
41 #include "public/platform/WebMediaConstraints.h"
42 #include "public/platform/WebRTCPeerConnectionHandler.h"
43 #include "public/platform/WebRTCPeerConnectionHandlerClient.h"
44 #include "wtf/RefCounted.h"
49 class MediaStreamTrack;
50 class RTCConfiguration;
53 class RTCErrorCallback;
54 class RTCSessionDescription;
55 class RTCSessionDescriptionCallback;
56 class RTCStatsCallback;
59 class RTCPeerConnection FINAL : public RefCounted<RTCPeerConnection>, public ScriptWrappable, public blink::WebRTCPeerConnectionHandlerClient, public EventTargetWithInlineData, public ActiveDOMObject {
60 REFCOUNTED_EVENT_TARGET(RTCPeerConnection);
62 static PassRefPtr<RTCPeerConnection> create(ExecutionContext*, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState&);
63 virtual ~RTCPeerConnection();
65 void createOffer(PassOwnPtr<RTCSessionDescriptionCallback>, PassOwnPtr<RTCErrorCallback>, const Dictionary& mediaConstraints, ExceptionState&);
67 void createAnswer(PassOwnPtr<RTCSessionDescriptionCallback>, PassOwnPtr<RTCErrorCallback>, const Dictionary& mediaConstraints, ExceptionState&);
69 void setLocalDescription(PassRefPtr<RTCSessionDescription>, PassOwnPtr<VoidCallback>, PassOwnPtr<RTCErrorCallback>, ExceptionState&);
70 PassRefPtr<RTCSessionDescription> localDescription(ExceptionState&);
72 void setRemoteDescription(PassRefPtr<RTCSessionDescription>, PassOwnPtr<VoidCallback>, PassOwnPtr<RTCErrorCallback>, ExceptionState&);
73 PassRefPtr<RTCSessionDescription> remoteDescription(ExceptionState&);
75 String signalingState() const;
77 void updateIce(const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState&);
80 void addIceCandidate(RTCIceCandidate*, ExceptionState&);
82 void addIceCandidate(RTCIceCandidate*, PassOwnPtr<VoidCallback>, PassOwnPtr<RTCErrorCallback>, ExceptionState&);
84 String iceGatheringState() const;
86 String iceConnectionState() const;
88 MediaStreamVector getLocalStreams() const;
90 MediaStreamVector getRemoteStreams() const;
92 MediaStream* getStreamById(const String& streamId);
94 void addStream(PassRefPtr<MediaStream>, const Dictionary& mediaConstraints, ExceptionState&);
96 void removeStream(PassRefPtr<MediaStream>, ExceptionState&);
98 void getStats(PassOwnPtr<RTCStatsCallback> successCallback, PassRefPtr<MediaStreamTrack> selector);
100 PassRefPtr<RTCDataChannel> createDataChannel(String label, const Dictionary& dataChannelDict, ExceptionState&);
102 PassRefPtr<RTCDTMFSender> createDTMFSender(PassRefPtr<MediaStreamTrack>, ExceptionState&);
104 void close(ExceptionState&);
106 DEFINE_ATTRIBUTE_EVENT_LISTENER(negotiationneeded);
107 DEFINE_ATTRIBUTE_EVENT_LISTENER(icecandidate);
108 DEFINE_ATTRIBUTE_EVENT_LISTENER(signalingstatechange);
109 DEFINE_ATTRIBUTE_EVENT_LISTENER(addstream);
110 DEFINE_ATTRIBUTE_EVENT_LISTENER(removestream);
111 DEFINE_ATTRIBUTE_EVENT_LISTENER(iceconnectionstatechange);
112 DEFINE_ATTRIBUTE_EVENT_LISTENER(datachannel);
114 // blink::WebRTCPeerConnectionHandlerClient
115 virtual void negotiationNeeded() OVERRIDE;
116 virtual void didGenerateICECandidate(const blink::WebRTCICECandidate&) OVERRIDE;
117 virtual void didChangeSignalingState(SignalingState) OVERRIDE;
118 virtual void didChangeICEGatheringState(ICEGatheringState) OVERRIDE;
119 virtual void didChangeICEConnectionState(ICEConnectionState) OVERRIDE;
120 virtual void didAddRemoteStream(const blink::WebMediaStream&) OVERRIDE;
121 virtual void didRemoveRemoteStream(const blink::WebMediaStream&) OVERRIDE;
122 virtual void didAddRemoteDataChannel(blink::WebRTCDataChannelHandler*) OVERRIDE;
125 virtual const AtomicString& interfaceName() const OVERRIDE;
126 virtual ExecutionContext* executionContext() const OVERRIDE;
129 virtual void suspend() OVERRIDE;
130 virtual void resume() OVERRIDE;
131 virtual void stop() OVERRIDE;
132 virtual bool hasPendingActivity() const OVERRIDE { return !m_stopped; }
135 RTCPeerConnection(ExecutionContext*, PassRefPtr<RTCConfiguration>, blink::WebMediaConstraints, ExceptionState&);
137 static PassRefPtr<RTCConfiguration> parseConfiguration(const Dictionary& configuration, ExceptionState&);
138 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>);
139 void dispatchScheduledEvent();
140 bool hasLocalStreamWithTrackId(const String& trackId);
142 void changeSignalingState(blink::WebRTCPeerConnectionHandlerClient::SignalingState);
143 void changeIceGatheringState(blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState);
144 void changeIceConnectionState(blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState);
146 SignalingState m_signalingState;
147 ICEGatheringState m_iceGatheringState;
148 ICEConnectionState m_iceConnectionState;
150 MediaStreamVector m_localStreams;
151 MediaStreamVector m_remoteStreams;
153 Vector<RefPtr<RTCDataChannel> > m_dataChannels;
155 OwnPtr<blink::WebRTCPeerConnectionHandler> m_peerHandler;
157 AsyncMethodRunner<RTCPeerConnection> m_dispatchScheduledEventRunner;
158 WillBePersistentHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
163 } // namespace WebCore
165 #endif // RTCPeerConnection_h