Bug 1193731: add missing handlers for icegatheringstatechange draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 21 Nov 2016 12:06:27 -0800
changeset 442134 fd7f5b29e90a94e39889147b06343c1c4300c64b
parent 442133 e4c34be497719ea6211814aefe4969735184a68a
child 442135 be23c0898451a61820de628e592ecc620e1cf9a3
push id36594
push userdrno@ohlmeier.org
push dateMon, 21 Nov 2016 20:11:22 +0000
bugs1193731
milestone53.0a1
Bug 1193731: add missing handlers for icegatheringstatechange MozReview-Commit-ID: ABWJfiImeYU
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -422,16 +422,17 @@ RTCPeerConnection.prototype = {
     this.makeLegacyGetterSetterEH("onaddstream", "Use peerConnection.ontrack instead.");
     this.makeLegacyGetterSetterEH("onaddtrack", "Use peerConnection.ontrack instead.");
     this.makeGetterSetterEH("onicecandidate");
     this.makeGetterSetterEH("onnegotiationneeded");
     this.makeGetterSetterEH("onsignalingstatechange");
     this.makeGetterSetterEH("onremovestream");
     this.makeGetterSetterEH("ondatachannel");
     this.makeGetterSetterEH("oniceconnectionstatechange");
+    this.makeGetterSetterEH("onicegatheringstatechange");
     this.makeGetterSetterEH("onidentityresult");
     this.makeGetterSetterEH("onpeeridentity");
     this.makeGetterSetterEH("onidpassertionerror");
     this.makeGetterSetterEH("onidpvalidationerror");
 
     this._pc = new this._win.PeerConnectionImpl();
     this._operationsChain = this._win.Promise.resolve();
 
@@ -1208,16 +1209,17 @@ RTCPeerConnection.prototype = {
       "SignalingHaveRemotePranswer": "have-remote-pranswer",
       "SignalingClosed":             "closed"
     }[this._impl.signalingState];
   },
 
   changeIceGatheringState: function(state) {
     this._iceGatheringState = state;
     _globalPCList.notifyLifecycleObservers(this, "icegatheringstatechange");
+    this.dispatchEvent(new this._win.Event("icegatheringstatechange"));
   },
 
   changeIceConnectionState: function(state) {
     this._iceConnectionState = state;
     _globalPCList.notifyLifecycleObservers(this, "iceconnectionstatechange");
     this.dispatchEvent(new this._win.Event("iceconnectionstatechange"));
   },
 
@@ -1418,16 +1420,19 @@ PeerConnectionObserver.prototype = {
   //                 intermittently (and resolve itself without action) on a
   //                 flaky network.
   //
   //   closed        The ICE Agent has shut down and is no longer responding to
   //                 STUN requests.
 
   handleIceConnectionStateChange: function(iceConnectionState) {
     let pc = this._dompc;
+    if (pc.iceConnectionState === iceConnectionState) {
+      return;
+    }
     if (pc.iceConnectionState === 'new') {
       var checking_histogram = Services.telemetry.getHistogramById("WEBRTC_ICE_CHECKING_RATE");
       if (iceConnectionState === 'checking') {
         checking_histogram.add(true);
       } else if (iceConnectionState === 'failed') {
         checking_histogram.add(false);
       }
     } else if (pc.iceConnectionState === 'checking') {
@@ -1450,25 +1455,29 @@ PeerConnectionObserver.prototype = {
   // This method is responsible for updating iceGatheringState. This
   // state is defined in the WebRTC specification as follows:
   //
   // iceGatheringState:
   // ------------------
   //   new        The object was just created, and no networking has occurred
   //              yet.
   //
-  //   gathering  The ICE engine is in the process of gathering candidates for
+  //   gathering  The ICE agent is in the process of gathering candidates for
   //              this RTCPeerConnection.
   //
-  //   complete   The ICE engine has completed gathering. Events such as adding
+  //   complete   The ICE agent has completed gathering. Events such as adding
   //              a new interface or a new TURN server will cause the state to
   //              go back to gathering.
   //
   handleIceGatheringStateChange: function(gatheringState) {
-    this._dompc.changeIceGatheringState(gatheringState);
+    let pc = this._dompc;
+    if (pc.iceGatheringState === gatheringState) {
+      return;
+    }
+    pc.changeIceGatheringState(gatheringState);
   },
 
   onStateChange: function(state) {
     switch (state) {
       case "SignalingState":
         this.dispatchEvent(new this._win.Event("signalingstatechange"));
         break;