Bug 1423842 - Part 2: Fire onaddstream after track additions, but before SRD resolves. r=jib
MozReview-Commit-ID: BOJv560nKyw
--- 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));
}