OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * | |
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 | |
13 * distribution. | |
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. | |
17 * | |
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. | |
29 */ | |
30 | |
31 #ifndef RTCPeerConnection_h | |
32 #define RTCPeerConnection_h | |
33 | |
34 #include "bindings/core/v8/Dictionary.h" | |
35 #include "core/dom/ActiveDOMObject.h" | |
36 #include "modules/EventTargetModules.h" | |
37 #include "modules/mediastream/MediaStream.h" | |
38 #include "modules/mediastream/RTCIceCandidate.h" | |
39 #include "platform/AsyncMethodRunner.h" | |
40 #include "public/platform/WebMediaConstraints.h" | |
41 #include "public/platform/WebRTCPeerConnectionHandler.h" | |
42 #include "public/platform/WebRTCPeerConnectionHandlerClient.h" | |
43 | |
44 namespace blink { | |
45 | |
46 class ExceptionState; | |
47 class MediaStreamTrack; | |
48 class RTCConfiguration; | |
49 class RTCDTMFSender; | |
50 class RTCDataChannel; | |
51 class RTCErrorCallback; | |
52 class RTCOfferOptions; | |
53 class RTCSessionDescription; | |
54 class RTCSessionDescriptionCallback; | |
55 class RTCStatsCallback; | |
56 class VoidCallback; | |
57 | |
58 class RTCPeerConnection final | |
59 : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<RTCPeerCo
nnection> | |
60 , public WebRTCPeerConnectionHandlerClient | |
61 , public EventTargetWithInlineData | |
62 , public ActiveDOMObject { | |
63 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollectedWi
llBeGarbageCollectedFinalized<RTCPeerConnection>); | |
64 DEFINE_WRAPPERTYPEINFO(); | |
65 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RTCPeerConnection); | |
66 public: | |
67 static RTCPeerConnection* create(ExecutionContext*, const Dictionary&, const
Dictionary&, ExceptionState&); | |
68 virtual ~RTCPeerConnection(); | |
69 | |
70 void createOffer(RTCSessionDescriptionCallback*, RTCErrorCallback*, const Di
ctionary&, ExceptionState&); | |
71 | |
72 void createAnswer(RTCSessionDescriptionCallback*, RTCErrorCallback*, const D
ictionary&, ExceptionState&); | |
73 | |
74 void setLocalDescription(RTCSessionDescription*, VoidCallback*, RTCErrorCall
back*, ExceptionState&); | |
75 RTCSessionDescription* localDescription(ExceptionState&); | |
76 | |
77 void setRemoteDescription(RTCSessionDescription*, VoidCallback*, RTCErrorCal
lback*, ExceptionState&); | |
78 RTCSessionDescription* remoteDescription(ExceptionState&); | |
79 | |
80 String signalingState() const; | |
81 | |
82 void updateIce(const Dictionary& rtcConfiguration, const Dictionary& mediaCo
nstraints, ExceptionState&); | |
83 | |
84 // DEPRECATED | |
85 void addIceCandidate(RTCIceCandidate*, ExceptionState&); | |
86 | |
87 void addIceCandidate(RTCIceCandidate*, VoidCallback*, RTCErrorCallback*, Exc
eptionState&); | |
88 | |
89 String iceGatheringState() const; | |
90 | |
91 String iceConnectionState() const; | |
92 | |
93 MediaStreamVector getLocalStreams() const; | |
94 | |
95 MediaStreamVector getRemoteStreams() const; | |
96 | |
97 MediaStream* getStreamById(const String& streamId); | |
98 | |
99 void addStream(MediaStream*, const Dictionary& mediaConstraints, ExceptionSt
ate&); | |
100 | |
101 void removeStream(MediaStream*, ExceptionState&); | |
102 | |
103 void getStats(RTCStatsCallback* successCallback, MediaStreamTrack* selector)
; | |
104 | |
105 RTCDataChannel* createDataChannel(String label, const Dictionary& dataChanne
lDict, ExceptionState&); | |
106 | |
107 RTCDTMFSender* createDTMFSender(MediaStreamTrack*, ExceptionState&); | |
108 | |
109 void close(ExceptionState&); | |
110 | |
111 // We allow getStats after close, but not other calls or callbacks. | |
112 bool shouldFireDefaultCallbacks() { return !m_closed && !m_stopped; } | |
113 bool shouldFireGetStatsCallback() { return !m_stopped; } | |
114 | |
115 DEFINE_ATTRIBUTE_EVENT_LISTENER(negotiationneeded); | |
116 DEFINE_ATTRIBUTE_EVENT_LISTENER(icecandidate); | |
117 DEFINE_ATTRIBUTE_EVENT_LISTENER(signalingstatechange); | |
118 DEFINE_ATTRIBUTE_EVENT_LISTENER(addstream); | |
119 DEFINE_ATTRIBUTE_EVENT_LISTENER(removestream); | |
120 DEFINE_ATTRIBUTE_EVENT_LISTENER(iceconnectionstatechange); | |
121 DEFINE_ATTRIBUTE_EVENT_LISTENER(datachannel); | |
122 | |
123 // WebRTCPeerConnectionHandlerClient | |
124 virtual void negotiationNeeded() override; | |
125 virtual void didGenerateICECandidate(const WebRTCICECandidate&) override; | |
126 virtual void didChangeSignalingState(SignalingState) override; | |
127 virtual void didChangeICEGatheringState(ICEGatheringState) override; | |
128 virtual void didChangeICEConnectionState(ICEConnectionState) override; | |
129 virtual void didAddRemoteStream(const WebMediaStream&) override; | |
130 virtual void didRemoveRemoteStream(const WebMediaStream&) override; | |
131 virtual void didAddRemoteDataChannel(WebRTCDataChannelHandler*) override; | |
132 virtual void releasePeerConnectionHandler() override; | |
133 virtual void closePeerConnection() override; | |
134 | |
135 // EventTarget | |
136 virtual const AtomicString& interfaceName() const override; | |
137 virtual ExecutionContext* executionContext() const override; | |
138 | |
139 // ActiveDOMObject | |
140 virtual void suspend() override; | |
141 virtual void resume() override; | |
142 virtual void stop() override; | |
143 // We keep the this object alive until either stopped or closed. | |
144 virtual bool hasPendingActivity() const override | |
145 { | |
146 return !m_closed && !m_stopped; | |
147 } | |
148 | |
149 virtual void trace(Visitor*) override; | |
150 | |
151 private: | |
152 RTCPeerConnection(ExecutionContext*, RTCConfiguration*, WebMediaConstraints,
ExceptionState&); | |
153 | |
154 | |
155 static RTCConfiguration* parseConfiguration(const Dictionary&, ExceptionStat
e&); | |
156 static RTCOfferOptions* parseOfferOptions(const Dictionary&, ExceptionState&
); | |
157 | |
158 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>); | |
159 void dispatchScheduledEvent(); | |
160 bool hasLocalStreamWithTrackId(const String& trackId); | |
161 | |
162 void changeSignalingState(WebRTCPeerConnectionHandlerClient::SignalingState)
; | |
163 void changeIceGatheringState(WebRTCPeerConnectionHandlerClient::ICEGathering
State); | |
164 void changeIceConnectionState(WebRTCPeerConnectionHandlerClient::ICEConnecti
onState); | |
165 | |
166 void closeInternal(); | |
167 | |
168 SignalingState m_signalingState; | |
169 ICEGatheringState m_iceGatheringState; | |
170 ICEConnectionState m_iceConnectionState; | |
171 | |
172 MediaStreamVector m_localStreams; | |
173 MediaStreamVector m_remoteStreams; | |
174 | |
175 HeapVector<Member<RTCDataChannel> > m_dataChannels; | |
176 | |
177 OwnPtr<WebRTCPeerConnectionHandler> m_peerHandler; | |
178 | |
179 AsyncMethodRunner<RTCPeerConnection> m_dispatchScheduledEventRunner; | |
180 WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents; | |
181 | |
182 bool m_stopped; | |
183 bool m_closed; | |
184 }; | |
185 | |
186 } // namespace blink | |
187 | |
188 #endif // RTCPeerConnection_h | |
OLD | NEW |