Bug 1423842 - Part 2: Fire onaddstream after track additions, but before SRD resolves. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 18 Dec 2017 13:41:18 -0600
changeset 397031 24eff1df1d3bf865f0f9befaca9b9ed9e998cb54
parent 397030 17a32b697729c8a2f622f074fe6420e6ceba56a2
child 397032 50dfae23ef9583bff536d60b78aa6bbc8ba84830
push id33123
push userncsoregi@mozilla.com
push dateThu, 21 Dec 2017 10:00:47 +0000
treeherdermozilla-central@06a19fbe2581 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1423842
milestone59.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 1423842 - Part 2: Fire onaddstream after track additions, but before SRD resolves. r=jib MozReview-Commit-ID: BOJv560nKyw
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -361,16 +361,18 @@ class RTCRtpSourceCache {
     // Has a cache wipe already been scheduled
     this.scheduledClear = null;
   }
 }
 
 class RTCPeerConnection {
   constructor() {
     this._receiveStreams = new Map();
+    // Used to fire onaddstream, remove when we don't do that anymore.
+    this._newStreams = [];
     this._transceivers = [];
 
     this._pc = null;
     this._closed = false;
 
     this._localType = null;
     this._remoteType = null;
     // http://rtcweb-wg.github.io/jsep/#rfc.section.4.1.9
@@ -1317,23 +1319,30 @@ class RTCPeerConnection {
 
     this._queueTaskWithClosedCheck(() => {
       if (this._negotiationNeeded) {
         this.dispatchEvent(new this._win.Event("negotiationneeded"));
       }
     });
   }
 
+  // TODO(Bug 1241291): Legacy event, remove eventually
+  _fireLegacyAddStreamEvents() {
+    for (let stream of this._newStreams) {
+      let ev = new this._win.MediaStreamEvent("addstream", { stream });
+      this.dispatchEvent(ev);
+    }
+    this._newStreams = [];
+  }
+
   _getOrCreateStream(id) {
     if (!this._receiveStreams.has(id)) {
       let stream = new this._win.MediaStream();
       stream.assignId(id);
-      // Legacy event, remove eventually
-      let ev = new this._win.MediaStreamEvent("addstream", { stream });
-      this.dispatchEvent(ev);
+      this._newStreams.push(stream);
       this._receiveStreams.set(id, stream);
     }
 
     return this._receiveStreams.get(id);
   }
 
   _insertDTMF(transceiverImpl, tones, duration, interToneGap) {
     return this._impl.insertDTMF(transceiverImpl, tones, duration, interToneGap);
@@ -1642,16 +1651,17 @@ class PeerConnectionObserver {
 
   onSetLocalDescriptionSuccess() {
     this._dompc._syncTransceivers();
     this._dompc._onSetLocalDescriptionSuccess();
   }
 
   onSetRemoteDescriptionSuccess() {
     this._dompc._syncTransceivers();
+    this._dompc._fireLegacyAddStreamEvents();
     this._dompc._onSetRemoteDescriptionSuccess();
   }
 
   onSetLocalDescriptionError(code, message) {
     this._localType = null;
     this._dompc._onSetLocalDescriptionFailure(this.newError(message, code));
   }