Remove the Timer parameters from timer callbacks
[WebKit-https.git] / Source / WebCore / Modules / mediastream / RTCPeerConnection.h
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer
13  *    in the documentation and/or other materials provided with the
14  *    distribution.
15  * 3. Neither the name of Google Inc. nor the names of its contributors
16  *    may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef RTCPeerConnection_h
33 #define RTCPeerConnection_h
34
35 #if ENABLE(MEDIA_STREAM)
36
37 #include "ActiveDOMObject.h"
38 #include "Dictionary.h"
39 #include "EventTarget.h"
40 #include "ExceptionBase.h"
41 #include "MediaStream.h"
42 #include "RTCIceCandidate.h"
43 #include "RTCPeerConnectionHandler.h"
44 #include "RTCPeerConnectionHandlerClient.h"
45 #include "ScriptWrappable.h"
46 #include "Timer.h"
47 #include <wtf/RefCounted.h>
48
49 namespace WebCore {
50
51 class MediaStreamTrack;
52 class RTCConfiguration;
53 class RTCDTMFSender;
54 class RTCDataChannel;
55 class RTCPeerConnectionErrorCallback;
56 class RTCSessionDescription;
57 class RTCSessionDescriptionCallback;
58 class RTCStatsCallback;
59 class VoidCallback;
60
61 class RTCPeerConnection final : public RefCounted<RTCPeerConnection>, public ScriptWrappable, public RTCPeerConnectionHandlerClient, public EventTargetWithInlineData, public ActiveDOMObject, public MediaStream::Observer {
62 public:
63     static PassRefPtr<RTCPeerConnection> create(ScriptExecutionContext&, const Dictionary& rtcConfiguration, ExceptionCode&);
64     ~RTCPeerConnection();
65
66     void createOffer(PassRefPtr<RTCSessionDescriptionCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, const Dictionary& offerOptions, ExceptionCode&);
67
68     void createAnswer(PassRefPtr<RTCSessionDescriptionCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, const Dictionary& answerOptions, ExceptionCode&);
69
70     void setLocalDescription(PassRefPtr<RTCSessionDescription>, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
71     PassRefPtr<RTCSessionDescription> localDescription(ExceptionCode&);
72
73     void setRemoteDescription(PassRefPtr<RTCSessionDescription>, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
74     PassRefPtr<RTCSessionDescription> remoteDescription(ExceptionCode&);
75
76     String signalingState() const;
77
78     void updateIce(const Dictionary& rtcConfiguration, ExceptionCode&);
79
80     void addIceCandidate(RTCIceCandidate*, PassRefPtr<VoidCallback>, PassRefPtr<RTCPeerConnectionErrorCallback>, ExceptionCode&);
81
82     String iceGatheringState() const;
83
84     String iceConnectionState() const;
85
86     RTCConfiguration* getConfiguration() const;
87
88     Vector<RefPtr<MediaStream>> getLocalStreams() const;
89
90     Vector<RefPtr<MediaStream>> getRemoteStreams() const;
91
92     MediaStream* getStreamById(const String& streamId);
93
94     void addStream(PassRefPtr<MediaStream>, ExceptionCode&);
95
96     void removeStream(PassRefPtr<MediaStream>, ExceptionCode&);
97
98     void getStats(PassRefPtr<RTCStatsCallback> successCallback, PassRefPtr<RTCPeerConnectionErrorCallback>, PassRefPtr<MediaStreamTrack> selector);
99
100     PassRefPtr<RTCDataChannel> createDataChannel(String label, const Dictionary& dataChannelDict, ExceptionCode&);
101
102     PassRefPtr<RTCDTMFSender> createDTMFSender(PassRefPtr<MediaStreamTrack>, ExceptionCode&);
103
104     void close(ExceptionCode&);
105
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);
113
114     // RTCPeerConnectionHandlerClient
115     virtual void negotiationNeeded() override;
116     virtual void didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescriptor>) override;
117     virtual void didChangeSignalingState(SignalingState) override;
118     virtual void didChangeIceGatheringState(IceGatheringState) override;
119     virtual void didChangeIceConnectionState(IceConnectionState) override;
120     virtual void didAddRemoteStream(PassRefPtr<MediaStreamPrivate>) override;
121     virtual void didRemoveRemoteStream(MediaStreamPrivate*) override;
122     virtual void didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler>) override;
123
124     // EventTarget
125     virtual EventTargetInterface eventTargetInterface() const override { return RTCPeerConnectionEventTargetInterfaceType; }
126     virtual ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
127
128     // ActiveDOMObject
129     virtual void stop() override;
130
131     // MediaStream::Observer
132     virtual void didAddOrRemoveTrack() override;
133
134     using RefCounted<RTCPeerConnection>::ref;
135     using RefCounted<RTCPeerConnection>::deref;
136
137 private:
138     RTCPeerConnection(ScriptExecutionContext&, PassRefPtr<RTCConfiguration>, ExceptionCode&);
139
140     static PassRefPtr<RTCConfiguration> parseConfiguration(const Dictionary& configuration, ExceptionCode&);
141     void scheduleDispatchEvent(PassRefPtr<Event>);
142     void scheduledEventTimerFired();
143     bool hasLocalStreamWithTrackId(const String& trackId);
144
145     // EventTarget implementation.
146     virtual void refEventTarget() override { ref(); }
147     virtual void derefEventTarget() override { deref(); }
148
149     void changeSignalingState(SignalingState);
150     void changeIceGatheringState(IceGatheringState);
151     void changeIceConnectionState(IceConnectionState);
152
153     bool checkStateForLocalDescription(RTCSessionDescription*);
154     bool checkStateForRemoteDescription(RTCSessionDescription*);
155
156     SignalingState m_signalingState;
157     IceGatheringState m_iceGatheringState;
158     IceConnectionState m_iceConnectionState;
159
160     Vector<RefPtr<MediaStream>> m_localStreams;
161     Vector<RefPtr<MediaStream>> m_remoteStreams;
162
163     Vector<RefPtr<RTCDataChannel>> m_dataChannels;
164
165     std::unique_ptr<RTCPeerConnectionHandler> m_peerHandler;
166
167     Timer m_scheduledEventTimer;
168     Vector<RefPtr<Event>> m_scheduledEvents;
169
170     RefPtr<RTCConfiguration> m_configuration;
171
172     bool m_stopped;
173 };
174
175 } // namespace WebCore
176
177 #endif // ENABLE(MEDIA_STREAM)
178
179 #endif // RTCPeerConnection_h