Bug 1550177 - Part 4: Simplify ICE gathering state change callback stuff. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 19 Jun 2019 16:55:10 +0000
changeset 479217 2653b8243f4f70522212368e30a0c6ccacc26cc2
parent 479216 01c9aca208929febfaac5f1860e11ff7cbef64b1
child 479218 8f9779bb2d41a44485b85d9342a7dcbb376f9a5b
push id36174
push useropoprus@mozilla.com
push dateWed, 19 Jun 2019 21:38:13 +0000
treeherdermozilla-central@5b9a3de04646 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1550177
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550177 - Part 4: Simplify ICE gathering state change callback stuff. r=jib Differential Revision: https://phabricator.services.mozilla.com/D30994
dom/media/PeerConnection.jsm
--- a/dom/media/PeerConnection.jsm
+++ b/dom/media/PeerConnection.jsm
@@ -391,18 +391,18 @@ class RTCPeerConnection {
     this._currentRole = null;
     this._pendingRole = null;
 
     // http://rtcweb-wg.github.io/jsep/#rfc.section.4.1.9
     // canTrickle == null means unknown; when a remote description is received it
     // is set to true or false based on the presence of the "trickle" ice-option
     this._canTrickle = null;
 
-    // States
-    this._iceGatheringState = this._iceConnectionState = "new";
+    // So we can record telemetry on state transitions
+    this._iceConnectionState = "new";
 
     this._hasStunServer = this._hasTurnServer = false;
     this._iceGatheredRelayCandidates = false;
     // Stored webrtc timing information
     this._storedRtpSourceReferenceTime = null;
     // Stores cached RTP sources state
     this._rtpSourceCache = new RTCRtpSourceCache();
     // Records telemetry
@@ -1566,30 +1566,29 @@ class RTCPeerConnection {
     const type = this._pendingRole == "offerer" ? "answer" : "offer";
     return new this._win.RTCSessionDescription({ type, sdp });
   }
 
   get peerIdentity() { return this._peerIdentity; }
   get idpLoginUrl() { return this._localIdp.idpLoginUrl; }
   get id() { return this._impl.id; }
   set id(s) { this._impl.id = s; }
-  get iceGatheringState() { return this._iceGatheringState; }
+  get iceGatheringState() { return this._pc.iceGatheringState; }
   get iceConnectionState() { return this._iceConnectionState; }
 
   get signalingState() {
     // checking for our local pc closed indication
     // before invoking the pc methods.
     if (this._closed) {
       return "closed";
     }
     return this._impl.signalingState;
   }
 
-  changeIceGatheringState(state) {
-    this._iceGatheringState = state;
+  handleIceGatheringStateChange() {
     _globalPCList.notifyLifecycleObservers(this, "icegatheringstatechange");
     this.dispatchEvent(new this._win.Event("icegatheringstatechange"));
     if (this.iceGatheringState === "complete") {
       this.dispatchEvent(new this._win.RTCPeerConnectionIceEvent(
         "icecandidate", { candidate: null }));
     }
   }
 
@@ -1852,39 +1851,16 @@ class PeerConnectionObserver {
       } else {
         pc.logError("ICE failed, see about:webrtc for more details");
       }
     }
 
     pc.changeIceConnectionState(iceConnectionState);
   }
 
-  // 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 agent is in the process of gathering candidates for
-  //              this RTCPeerConnection.
-  //
-  //   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(gatheringState) {
-    let pc = this._dompc;
-    if (pc.iceGatheringState === gatheringState) {
-      return;
-    }
-    pc.changeIceGatheringState(gatheringState);
-  }
-
   onStateChange(state) {
     if (!this._dompc) {
       return;
     }
 
     if (state == "SignalingState") {
       this.dispatchEvent(new this._win.Event("signalingstatechange"));
       return;
@@ -1898,17 +1874,17 @@ class PeerConnectionObserver {
       case "IceConnectionState":
         let connState = this._dompc._pc.iceConnectionState;
         this._dompc._queueTaskWithClosedCheck(() => {
           this.handleIceConnectionStateChange(connState);
         });
         break;
 
       case "IceGatheringState":
-        this.handleIceGatheringStateChange(this._dompc._pc.iceGatheringState);
+        this._dompc.handleIceGatheringStateChange();
         break;
 
       default:
         this._dompc.logWarning("Unhandled state type: " + state);
         break;
     }
   }