Support RTCPeerConnectionState
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Mar 2017 02:44:57 +0000 (02:44 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Mar 2017 02:44:57 +0000 (02:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169978

Patch by Youenn Fablet <youenn@apple.com> on 2017-03-22
Reviewed by Jon Lee.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt:

Source/WebCore:

Test: webrtc/connection-state.html

Implementing https://www.w3.org/TR/webrtc/#rtcpeerconnectionstate-enum.
Its state and event is based on changes made to ice gathering state and ice connection state.

* CMakeLists.txt: Adding RTCPeerConnectionState idl.
* DerivedSources.make: Ditto.
* Modules/mediastream/RTCPeerConnection.cpp: Splitting close in doClose/doStop so that we can send closed event
in case close is called, but not if stopped.
(WebCore::RTCPeerConnection::doClose):
(WebCore::RTCPeerConnection::close):
(WebCore::RTCPeerConnection::stop):
(WebCore::RTCPeerConnection::doStop):
(WebCore::RTCPeerConnection::updateIceGatheringState):
(WebCore::RTCPeerConnection::updateIceConnectionState):
(WebCore::RTCPeerConnection::updateConnectionState):
* Modules/mediastream/RTCPeerConnection.h:
* Modules/mediastream/RTCPeerConnection.idl: Fixing IDL and minor cosmetic changes
* Modules/mediastream/RTCPeerConnection.js:
(setLocalDescription): Cosmetic change.
(setRemoteDescription):
* Modules/mediastream/RTCPeerConnectionState.idl: Added.
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::OnIceGatheringChange): Adding 'gathering' state
* WebCore.xcodeproj/project.pbxproj:
* dom/EventNames.h:
* platform/mediastream/RTCPeerConnectionState.h: Added.

LayoutTests:

* webrtc/connection-state-expected.txt: Added.
* webrtc/connection-state.html: Added.
* webrtc/rtcpeerconnection-error-messages-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214293 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt
LayoutTests/webrtc/connection-state-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/connection-state.html [new file with mode: 0644]
LayoutTests/webrtc/rtcpeerconnection-error-messages-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/Modules/mediastream/RTCPeerConnection.js
Source/WebCore/Modules/mediastream/RTCPeerConnectionState.idl [new file with mode: 0644]
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventNames.h
Source/WebCore/platform/mediastream/RTCPeerConnectionState.h [new file with mode: 0644]

index 3c4dbf3..9548c83 100644 (file)
@@ -1,3 +1,14 @@
+2017-03-22  Youenn Fablet  <youenn@apple.com>
+
+        Support RTCPeerConnectionState
+        https://bugs.webkit.org/show_bug.cgi?id=169978
+
+        Reviewed by Jon Lee.
+
+        * webrtc/connection-state-expected.txt: Added.
+        * webrtc/connection-state.html: Added.
+        * webrtc/rtcpeerconnection-error-messages-expected.txt:
+
 2017-03-22  Carlos Alberto Lopez Perez  <clopez@igalia.com>
 
         [GTK] Enable CSS filters related tests.
index 3826006..6965696 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-22  Youenn Fablet  <youenn@apple.com>
+
+        Support RTCPeerConnectionState
+        https://bugs.webkit.org/show_bug.cgi?id=169978
+
+        Reviewed by Jon Lee.
+
+        * web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt:
+
 2017-03-22  Chris Dumez  <cdumez@apple.com>
 
         WebKit should disallow beforeunload alerts from web pages users have never interacted with
index 6b38778..4ce1a24 100644 (file)
@@ -100,6 +100,6 @@ PASS pendingRemoteDescription initial value
 PASS signalingState initial value 
 PASS iceGatheringState initial value 
 PASS iceConnectionState initial value 
-FAIL connectionState initial value assert_equals: expected (string) "new" but got (undefined) undefined
+PASS connectionState initial value 
 FAIL canTrickleIceCandidates initial value assert_equals: expected (object) null but got (undefined) undefined
 
diff --git a/LayoutTests/webrtc/connection-state-expected.txt b/LayoutTests/webrtc/connection-state-expected.txt
new file mode 100644 (file)
index 0000000..f43dba0
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS Checking various connection state for video exchange 
+PASS Checking connection state event when closing peer connetion 
+
diff --git a/LayoutTests/webrtc/connection-state.html b/LayoutTests/webrtc/connection-state.html
new file mode 100644 (file)
index 0000000..31200c8
--- /dev/null
@@ -0,0 +1,83 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing basic video exchange from offerer to receiver</title>
+        <script src="../resources/testharness.js"></script>
+        <script src="../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script src ="routines.js"></script>
+        <script>
+promise_test((test) => {
+    if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    var firstConnection, secondConnection;
+    var localConnectionStates = ["new"];
+    var remoteConnectionStates = ["new"];
+    var localIceConnectionStates = ["new"];
+    var remoteIceConnectionStates = ["new"];
+    var localGatheringStates = ["new"];
+    var remoteGatheringStates = ["new"];
+    return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
+        return new Promise((resolve, reject) => {
+            if (window.internals)
+                internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+            createConnections((connection) => {
+                firstConnection = connection;
+                firstConnection.addTrack(stream.getVideoTracks()[0], stream);
+                assert_equals(firstConnection.connectionState, "new");
+                firstConnection.onconnectionstatechange = () => {
+                    localConnectionStates.push(firstConnection.connectionState);
+                }
+                firstConnection.onicegatheringstatechange = () => {
+                    localGatheringStates.push(firstConnection.iceGatheringState);
+                }
+                firstConnection.oniceconnectionstatechange = () => {
+                    localIceConnectionStates.push(firstConnection.iceConnectionState);
+                }
+            }, (connection) => {
+                secondConnection = connection;
+                assert_equals(secondConnection.connectionState, "new");
+                secondConnection.onconnectionstatechange = () => {
+                    remoteConnectionStates.push(secondConnection.connectionState);
+                }
+                secondConnection.onicegatheringstatechange = () => {
+                    remoteGatheringStates.push(secondConnection.iceGatheringState);
+                }
+                secondConnection.oniceconnectionstatechange = () => {
+                    remoteIceConnectionStates.push(secondConnection.iceConnectionState);
+                }
+                secondConnection.ontrack = (trackEvent) => {
+                    resolve(trackEvent.streams[0]);
+                };
+            });
+            setTimeout(() => reject("Test timed out"), 5000);
+        });
+    }).then((stream) => {
+        return waitFor(500);
+    }).then(() => {
+        assert_array_equals(localConnectionStates, ["new", "connecting", "connected"]);
+        assert_array_equals(remoteConnectionStates, ["new", "connecting", "connected"]);
+        assert_array_equals(localGatheringStates, ["new", "gathering", "complete"]);
+        assert_array_equals(remoteGatheringStates, ["new", "gathering", "complete"]);
+        assert_array_equals(localIceConnectionStates, ["new", "checking", "connected", "completed"]);
+        assert_array_equals(remoteIceConnectionStates, ["new", "checking", "connected"]);
+    });
+}, "Checking various connection state for video exchange");
+
+promise_test((test) => {
+    return new Promise((resolve, reject) => {
+        var pc = new RTCPeerConnection();
+        pc.onconnectionstatechange = () => {
+            assert_equals(pc.connectionState, "closed");
+            resolve();
+        };
+        pc.close();
+    })
+}, "Checking connection state event when closing peer connetion");
+        </script>
+    </body>
+</html>
index 0b07728..8013eb5 100644 (file)
@@ -7,7 +7,7 @@ TypeError: The RTCPeerConnection.pendingRemoteDescription getter can only be use
 TypeError: The RTCPeerConnection.signalingState getter can only be used on instances of RTCPeerConnection
 TypeError: The RTCPeerConnection.iceGatheringState getter can only be used on instances of RTCPeerConnection
 TypeError: The RTCPeerConnection.iceConnectionState getter can only be used on instances of RTCPeerConnection
-[object RTCPeerConnection] has no property named connectionState
+TypeError: The RTCPeerConnection.connectionState getter can only be used on instances of RTCPeerConnection
 [object RTCPeerConnection] has no property named canTrickleIceCandidates
 [object RTCPeerConnection] has no property named defaultIceServers
 TypeError: Can only call RTCPeerConnection.getConfiguration on instances of RTCPeerConnection
@@ -19,7 +19,7 @@ TypeError: The RTCPeerConnection.onicecandidate getter can only be used on insta
 TypeError: The RTCPeerConnection.onsignalingstatechange getter can only be used on instances of RTCPeerConnection
 TypeError: The RTCPeerConnection.oniceconnectionstatechange getter can only be used on instances of RTCPeerConnection
 TypeError: The RTCPeerConnection.onicegatheringstatechange getter can only be used on instances of RTCPeerConnection
-[object RTCPeerConnection] has no property named onconnectionstatechange
+TypeError: The RTCPeerConnection.onconnectionstatechange getter can only be used on instances of RTCPeerConnection
 Promise rejected with: TypeError: Can only call RTCPeerConnection.createOffer on instances of RTCPeerConnection
 Promise rejected with: TypeError: Can only call RTCPeerConnection.createAnswer on instances of RTCPeerConnection
 Promise rejected with: TypeError: Can only call RTCPeerConnection.setLocalDescription on instances of RTCPeerConnection
index 1d9f04b..6ff4aca 100644 (file)
@@ -249,6 +249,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/mediastream/RTCOfferAnswerOptions.idl
     Modules/mediastream/RTCOfferOptions.idl
     Modules/mediastream/RTCPeerConnection.idl
+    Modules/mediastream/RTCPeerConnectionState.idl
     Modules/mediastream/RTCRtpReceiver.idl
     Modules/mediastream/RTCRtpSender.idl
     Modules/mediastream/RTCRtpTransceiver.idl
index 66edeff..ead05e0 100644 (file)
@@ -1,3 +1,38 @@
+2017-03-22  Youenn Fablet  <youenn@apple.com>
+
+        Support RTCPeerConnectionState
+        https://bugs.webkit.org/show_bug.cgi?id=169978
+
+        Reviewed by Jon Lee.
+
+        Test: webrtc/connection-state.html
+
+        Implementing https://www.w3.org/TR/webrtc/#rtcpeerconnectionstate-enum.
+        Its state and event is based on changes made to ice gathering state and ice connection state.
+
+        * CMakeLists.txt: Adding RTCPeerConnectionState idl.
+        * DerivedSources.make: Ditto.
+        * Modules/mediastream/RTCPeerConnection.cpp: Splitting close in doClose/doStop so that we can send closed event
+        in case close is called, but not if stopped.
+        (WebCore::RTCPeerConnection::doClose):
+        (WebCore::RTCPeerConnection::close):
+        (WebCore::RTCPeerConnection::stop):
+        (WebCore::RTCPeerConnection::doStop):
+        (WebCore::RTCPeerConnection::updateIceGatheringState):
+        (WebCore::RTCPeerConnection::updateIceConnectionState):
+        (WebCore::RTCPeerConnection::updateConnectionState):
+        * Modules/mediastream/RTCPeerConnection.h:
+        * Modules/mediastream/RTCPeerConnection.idl: Fixing IDL and minor cosmetic changes
+        * Modules/mediastream/RTCPeerConnection.js:
+        (setLocalDescription): Cosmetic change.
+        (setRemoteDescription):
+        * Modules/mediastream/RTCPeerConnectionState.idl: Added.
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::OnIceGatheringChange): Adding 'gathering' state
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/EventNames.h:
+        * platform/mediastream/RTCPeerConnectionState.h: Added.
+
 2017-03-22  Jiewen Tan  <jiewen_tan@apple.com>
 
         ASSERT_WITH_SECURITY_IMPLICATION hit when removing an <input type="range"> while dragging on iOS
index fc4fe73..757efa3 100644 (file)
@@ -193,6 +193,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/mediastream/RTCOfferAnswerOptions.idl \
     $(WebCore)/Modules/mediastream/RTCOfferOptions.idl \
     $(WebCore)/Modules/mediastream/RTCPeerConnection.idl \
+    $(WebCore)/Modules/mediastream/RTCPeerConnectionState.idl \
     $(WebCore)/Modules/mediastream/RTCRtpReceiver.idl \
     $(WebCore)/Modules/mediastream/RTCRtpSender.idl \
     $(WebCore)/Modules/mediastream/RTCRtpTransceiver.idl \
index e9fc81d..822cb43 100644 (file)
@@ -353,10 +353,10 @@ ExceptionOr<Ref<RTCDataChannel>> RTCPeerConnection::createDataChannel(ScriptExec
     return RTCDataChannel::create(context, WTFMove(channelHandler), WTFMove(label), WTFMove(options));
 }
 
-void RTCPeerConnection::close()
+bool RTCPeerConnection::doClose()
 {
     if (m_signalingState == RTCSignalingState::Closed)
-        return;
+        return false;
 
     m_iceConnectionState = RTCIceConnectionState::Closed;
     m_signalingState = RTCSignalingState::Closed;
@@ -366,8 +366,18 @@ void RTCPeerConnection::close()
     for (RTCRtpSender& sender : m_transceiverSet->senders())
         sender.stop();
 
-    unregisterFromController();
-    unsetPendingActivity(this);
+    return true;
+}
+
+void RTCPeerConnection::close()
+{
+    if (!doClose())
+        return;
+
+    updateConnectionState();
+    scriptExecutionContext()->postTask([protectedThis = makeRef(*this)](ScriptExecutionContext&) {
+        protectedThis->doStop();
+    });
 }
 
 void RTCPeerConnection::emulatePlatformEvent(const String& action)
@@ -377,7 +387,20 @@ void RTCPeerConnection::emulatePlatformEvent(const String& action)
 
 void RTCPeerConnection::stop()
 {
-    close();
+    if (!doClose())
+        return;
+
+    doStop();
+}
+
+void RTCPeerConnection::doStop()
+{
+    if (m_isStopped)
+        return;
+
+    m_isStopped = true;
+    unregisterFromController();
+    unsetPendingActivity(this);
 }
 
 RTCController& RTCPeerConnection::rtcController()
@@ -427,6 +450,7 @@ void RTCPeerConnection::updateIceGatheringState(RTCIceGatheringState newState)
 
         protectedThis->m_iceGatheringState = newState;
         protectedThis->dispatchEvent(Event::create(eventNames().icegatheringstatechangeEvent, false, false));
+        protectedThis->updateConnectionState();
     });
 }
 
@@ -438,9 +462,36 @@ void RTCPeerConnection::updateIceConnectionState(RTCIceConnectionState newState)
 
         protectedThis->m_iceConnectionState = newState;
         protectedThis->dispatchEvent(Event::create(eventNames().iceconnectionstatechangeEvent, false, false));
+        protectedThis->updateConnectionState();
     });
 }
 
+void RTCPeerConnection::updateConnectionState()
+{
+    RTCPeerConnectionState state;
+
+    if (m_iceConnectionState == RTCIceConnectionState::New && m_iceGatheringState == RTCIceGatheringState::New)
+        state = RTCPeerConnectionState::New;
+    else if (m_iceConnectionState == RTCIceConnectionState::Checking || m_iceGatheringState == RTCIceGatheringState::Gathering)
+        state = RTCPeerConnectionState::Connecting;
+    else if ((m_iceConnectionState == RTCIceConnectionState::Completed || m_iceConnectionState == RTCIceConnectionState::Connected) && m_iceGatheringState == RTCIceGatheringState::Complete)
+        state = RTCPeerConnectionState::Connected;
+    else if (m_iceConnectionState == RTCIceConnectionState::Disconnected)
+        state = RTCPeerConnectionState::Disconnected;
+    else if (m_iceConnectionState == RTCIceConnectionState::Failed)
+        state = RTCPeerConnectionState::Failed;
+    else if (m_iceConnectionState == RTCIceConnectionState::Closed)
+        state = RTCPeerConnectionState::Closed;
+    else
+        return;
+
+    if (state == m_connectionState)
+        return;
+
+    m_connectionState = state;
+    dispatchEvent(Event::create(eventNames().connectionstatechangeEvent, false, false));
+}
+
 void RTCPeerConnection::scheduleNegotiationNeededEvent()
 {
     scriptExecutionContext()->postTask([protectedThis = makeRef(*this)](ScriptExecutionContext&) {
index eb1f6d8..863763f 100644 (file)
@@ -42,6 +42,7 @@
 #include "RTCDataChannel.h"
 #include "RTCIceConnectionState.h"
 #include "RTCIceGatheringState.h"
+#include "RTCPeerConnectionState.h"
 #include "RTCRtpTransceiver.h"
 #include "RTCSignalingState.h"
 
@@ -89,6 +90,7 @@ public:
     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&&);
@@ -159,9 +161,15 @@ private:
     // RTCRtpSenderClient
     void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&) 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()) };
 
index 0acada2..2481744 100644 (file)
@@ -75,8 +75,7 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
     [JSBuiltin] Promise<RTCSessionDescriptionInit> createOffer(optional RTCOfferOptions offerOptions);
     [JSBuiltin] Promise<RTCSessionDescriptionInit> createAnswer(optional RTCAnswerOptions answerOptions);
 
-    // FIXME 169644: change to RTCSessionDescriptionInit
-    [JSBuiltin] Promise<void> setLocalDescription(RTCSessionDescription description);
+    [JSBuiltin] Promise<void> setLocalDescription(RTCSessionDescriptionInit description);
     // FIXME 169644: change to nullable
     readonly attribute RTCSessionDescription localDescription;
     // FIXME 169644: change to nullable
@@ -99,8 +98,7 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
     readonly attribute RTCSignalingState signalingState;
     readonly attribute RTCIceGatheringState iceGatheringState;
     readonly attribute RTCIceConnectionState iceConnectionState;
-
-    // FIXME 169644: missing connectionState
+    readonly attribute RTCPeerConnectionState connectionState;
     // FIXME 169644: missing canTrickleIceCandidates
     // FIXME 169644: missing defaultIceServers
 
@@ -110,12 +108,11 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
 
     attribute EventHandler onnegotiationneeded;
     attribute EventHandler onicecandidate;
-    // FIXME 169644: missing onicecandidateerror
     attribute EventHandler onsignalingstatechange;
     attribute EventHandler oniceconnectionstatechange;
     attribute EventHandler onicegatheringstatechange;
-    // FIXME 169644: missing onconnectionstatechanged
-    // FIXME 169644: missing onfingerprintfailure
+    attribute EventHandler onconnectionstatechange;
+    // FIXME 169644: missing onfingerprintfailure and onicecandidateerror
 
     // Private API used to implement the overloaded operations above. Queued functions are called by runQueuedOperation().
     // See RTCPeerConnectionInternals.js.
@@ -126,11 +123,6 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
     [PrivateIdentifier] Promise<void> queuedAddIceCandidate(RTCIceCandidate candidate);
 
 
-    // 4.3.3.1 Legacy extensions supported
-    // JSBuiltin attributes above handles support of the extensions
-    // FIXME 169646: wrap legacy calls in runtime flag
-
-
     // 4.11 Certificate management
     // FIXME 169644: missing generateCertificate
 
@@ -144,7 +136,6 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
     [PrivateIdentifier, PublicIdentifier, MayThrowException] RTCRtpSender addTrack(MediaStreamTrack track, MediaStream... streams);
     [PrivateIdentifier, PublicIdentifier, MayThrowException] void removeTrack(RTCRtpSender sender);
 
-    // FIXME 169644: convert to (MediaStreamTrack or DOMString)
     [MayThrowException] RTCRtpTransceiver addTransceiver(MediaStreamTrack track, optional RTCRtpTransceiverInit init);
     [MayThrowException] RTCRtpTransceiver addTransceiver(DOMString kind, optional RTCRtpTransceiverInit init);
 
index 2cb6a40..c2cc603 100644 (file)
@@ -184,7 +184,7 @@ function setLocalDescription()
 
     const peerConnection = this;
 
-    // FIXME: According the spec, we should throw when receiving a RTCSessionDescription.
+    // FIXME 169644: According the spec, we should throw when receiving a RTCSessionDescription.
     const objectInfo = {
         "constructor": @RTCSessionDescription,
         "argName": "description",
@@ -215,7 +215,7 @@ function setRemoteDescription()
 
     const peerConnection = this;
 
-    // FIXME: According the spec, we should throw when receiving a RTCSessionDescription.
+    // FIXME: According the spec, we should only expect RTCSessionDescriptionInit.
     const objectInfo = {
         "constructor": @RTCSessionDescription,
         "argName": "description",
diff --git a/Source/WebCore/Modules/mediastream/RTCPeerConnectionState.idl b/Source/WebCore/Modules/mediastream/RTCPeerConnectionState.idl
new file mode 100644 (file)
index 0000000..dc217bb
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection
+] enum RTCPeerConnectionState {
+    "new",
+    "connecting",
+    "connected",
+    "disconnected",
+    "failed",
+    "closed"
+};
index d43b8b7..7c537db 100644 (file)
@@ -585,13 +585,14 @@ void LibWebRTCMediaEndpoint::OnIceConnectionChange(webrtc::PeerConnectionInterfa
 
 void LibWebRTCMediaEndpoint::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState state)
 {
-    if (state == webrtc::PeerConnectionInterface::kIceGatheringComplete) {
-        callOnMainThread([protectedThis = makeRef(*this)] {
-            if (protectedThis->isStopped())
-                return;
+    callOnMainThread([protectedThis = makeRef(*this), state] {
+        if (protectedThis->isStopped())
+            return;
+        if (state == webrtc::PeerConnectionInterface::kIceGatheringComplete)
             protectedThis->m_peerConnectionBackend.doneGatheringCandidates();
-        });
-    }
+        else if (state == webrtc::PeerConnectionInterface::kIceGatheringGathering)
+            protectedThis->m_peerConnectionBackend.connection().updateIceGatheringState(RTCIceGatheringState::Gathering);
+    });
 }
 
 void LibWebRTCMediaEndpoint::OnIceCandidate(const webrtc::IceCandidateInterface *rtcCandidate)
index 41f20ce..13dad98 100644 (file)
                319AE064142D6B24006563A1 /* StyleFilterData.h in Headers */ = {isa = PBXBuildFile; fileRef = 319AE062142D6B24006563A1 /* StyleFilterData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                319BDE511E7A860400BA296C /* JSRTCIceTransport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 319BDE4F1E7A858A00BA296C /* JSRTCIceTransport.cpp */; };
                319BDE541E7A86CA00BA296C /* JSRTCIceTransportState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 319BDE521E7A86C100BA296C /* JSRTCIceTransportState.cpp */; };
+               319BDE541E7A86CA00BA296D /* JSRTCPeerConnectionState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 319BDE521E7A86C100BA296D /* JSRTCPeerConnectionState.cpp */; };
                319FBD5F15D2F464009640A6 /* CachedImageClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 319FBD5D15D2F444009640A6 /* CachedImageClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                31A089041E737D51003B6609 /* WebGPUBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31A088C61E737B4D003B6609 /* WebGPUBuffer.cpp */; };
                31A089051E737D51003B6609 /* WebGPUCommandBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31A088C91E737B4D003B6609 /* WebGPUCommandBuffer.cpp */; };
                319BDE4F1E7A858A00BA296C /* JSRTCIceTransport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRTCIceTransport.cpp; sourceTree = "<group>"; };
                319BDE501E7A858A00BA296C /* JSRTCIceTransport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCIceTransport.h; sourceTree = "<group>"; };
                319BDE521E7A86C100BA296C /* JSRTCIceTransportState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRTCIceTransportState.cpp; sourceTree = "<group>"; };
+               319BDE521E7A86C100BA296D /* JSRTCPeerConnectionState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRTCPeerConnectionState.cpp; sourceTree = "<group>"; };
                319BDE531E7A86C100BA296C /* JSRTCIceTransportState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCIceTransportState.h; sourceTree = "<group>"; };
+               319BDE531E7A86C100BA296D /* JSRTCPeerConnectionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCPeerConnectionState.h; sourceTree = "<group>"; };
                319FBD5D15D2F444009640A6 /* CachedImageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedImageClient.h; sourceTree = "<group>"; };
                31A088C41E737B2C003B6609 /* JSWebGPURenderingContextCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderingContextCustom.cpp; sourceTree = "<group>"; };
                31A088C51E737B2C003B6609 /* JSWebGPURenderPassAttachmentDescriptorCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderPassAttachmentDescriptorCustom.cpp; sourceTree = "<group>"; };
                41A1B01B1E542396007F3769 /* JSDOMGuardedObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMGuardedObject.cpp; sourceTree = "<group>"; };
                41A3D58C101C152D00316D07 /* DedicatedWorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DedicatedWorkerThread.cpp; sourceTree = "<group>"; };
                41A3D58D101C152D00316D07 /* DedicatedWorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DedicatedWorkerThread.h; sourceTree = "<group>"; };
+               41A48A9C1E83129100D2AC2D /* RTCPeerConnectionState.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCPeerConnectionState.idl; sourceTree = "<group>"; };
+               41A48A9D1E8312EB00D2AC2D /* RTCPeerConnectionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCPeerConnectionState.h; sourceTree = "<group>"; };
                41ABE6791D0580D5006D862D /* CrossOriginPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossOriginPreflightChecker.cpp; sourceTree = "<group>"; };
                41ABE67A1D0580D5006D862D /* CrossOriginPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossOriginPreflightChecker.h; sourceTree = "<group>"; };
                41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
                                316DCB2C1E78F3A9001B5F87 /* RTCAnswerOptions.idl */,
                                07AB996518DA3C010018771E /* RTCConfiguration.h */,
                                07AB996618DA3C010018771E /* RTCConfiguration.idl */,
+                               41A48A9C1E83129100D2AC2D /* RTCPeerConnectionState.idl */,
                                418205481E53EAAD00D62207 /* RTCController.cpp */,
                                418205451E53C8CD00D62207 /* RTCController.h */,
                                07221B6317CEC32700848E51 /* RTCDataChannel.cpp */,
                                313591021E7DDC6000F30630 /* RTCIceTransportPolicy.h */,
                                313591031E7DDC6000F30630 /* RTCIceTransportState.h */,
                                07221BAA17CF0AD400848E51 /* RTCPeerConnectionHandlerClient.h */,
+                               41A48A9D1E8312EB00D2AC2D /* RTCPeerConnectionState.h */,
                                31EB54DD1E7DC74400C1623B /* RTCRtpTransceiverDirection.h */,
                                313591041E7DDC6000F30630 /* RTCSdpType.h */,
                                07221BAB17CF0AD400848E51 /* RTCSessionDescriptionDescriptor.cpp */,
                                319BDE501E7A858A00BA296C /* JSRTCIceTransport.h */,
                                319BDE521E7A86C100BA296C /* JSRTCIceTransportState.cpp */,
                                319BDE531E7A86C100BA296C /* JSRTCIceTransportState.h */,
+                               319BDE521E7A86C100BA296D /* JSRTCPeerConnectionState.cpp */,
+                               319BDE531E7A86C100BA296D /* JSRTCPeerConnectionState.h */,
                                316DCB191E78CA55001B5F87 /* JSRTCOfferAnswerOptions.cpp */,
                                316DCB1A1E78CA55001B5F87 /* JSRTCOfferAnswerOptions.h */,
                                316DCB2F1E78F496001B5F87 /* JSRTCOfferOptions.cpp */,
                                0F3C725E1974874B00AEDD0C /* ImageSource.cpp in Sources */,
                                4B3480930EEF50D400AC1B41 /* ImageSourceCGMac.mm in Sources */,
                                319BDE541E7A86CA00BA296C /* JSRTCIceTransportState.cpp in Sources */,
+                               319BDE541E7A86CA00BA296D /* JSRTCPeerConnectionState.cpp in Sources */,
                                316FE1170E6E1DA700BF6088 /* ImplicitAnimation.cpp in Sources */,
                                BE961C5418AD338500D07DC5 /* InbandDataTextTrack.cpp in Sources */,
                                BE16C59217CFE17200852C04 /* InbandGenericTextTrack.cpp in Sources */,
index 3ec71c1..02394e8 100644 (file)
@@ -83,6 +83,7 @@ namespace WebCore {
     macro(compositionstart) \
     macro(compositionupdate) \
     macro(connect) \
+    macro(connectionstatechange) \
     macro(connecting) \
     macro(contextmenu) \
     macro(copy) \
diff --git a/Source/WebCore/platform/mediastream/RTCPeerConnectionState.h b/Source/WebCore/platform/mediastream/RTCPeerConnectionState.h
new file mode 100644 (file)
index 0000000..b877dbe
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_RTC)
+
+namespace WebCore {
+
+enum class RTCPeerConnectionState {
+    New,
+    Connecting,
+    Connected,
+    Disconnected,
+    Failed,
+    Closed
+};
+
+}; // namespace WebCore
+
+#endif