Bug 1437832 - Part 2: Use the same C++ logic for replaceTrack, removeTrack, and addTrack (when on a pre-existing transceiver). r+jib draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 13 Feb 2018 13:25:19 -0600
changeset 754900 688f982047496ab2f0f5461f42aceb013381c554
parent 754899 209a55ed377fa3b55f72217af8c712919bfcec53
child 754901 bccbf46a52dd7a1156172389d5e930144a560f85
push id99037
push userbcampen@mozilla.com
push dateWed, 14 Feb 2018 14:55:46 +0000
bugs1437832
milestone60.0a1
Bug 1437832 - Part 2: Use the same C++ logic for replaceTrack, removeTrack, and addTrack (when on a pre-existing transceiver). r+jib MozReview-Commit-ID: KQSlagkmAZ
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1196,19 +1196,16 @@ class RTCPeerConnection {
     let transceiver =
       this._transceivers.find(transceiver => transceiver.sender == sender);
 
     // If the transceiver was removed due to rollback, let it slide.
     if (!transceiver || !sender.track) {
       return;
     }
 
-    // TODO(bug 1401983): Move to TransceiverImpl?
-    this._impl.removeTrack(sender.track);
-
     sender.setTrack(null);
     if (transceiver.direction == "sendrecv") {
       transceiver.setDirectionInternal("recvonly");
     } else if (transceiver.direction == "sendonly") {
       transceiver.setDirectionInternal("inactive");
     }
 
     transceiver.sync();
@@ -1371,18 +1368,17 @@ class RTCPeerConnection {
   _insertDTMF(transceiverImpl, tones, duration, interToneGap) {
     return this._impl.insertDTMF(transceiverImpl, tones, duration, interToneGap);
   }
 
   _getDTMFToneBuffer(sender) {
     return this._impl.getDTMFToneBuffer(sender.__DOM_IMPL__);
   }
 
-  _replaceTrack(transceiverImpl, withTrack) {
-    this._checkClosed();
+  _replaceTrackNoRenegotiation(transceiverImpl, withTrack) {
     this._impl.replaceTrackNoRenegotiation(transceiverImpl, withTrack);
   }
 
   close() {
     if (this._closed) {
       return;
     }
     this._closed = true;
@@ -1960,17 +1956,17 @@ class RTCRtpSender {
       throw new this._pc._win.DOMException(
           "Cannot replaceTrack with a different kind!",
           "TypeError");
     }
 
     // Updates the track on the MediaPipeline; this is needed whether or not
     // we've associated this transceiver, the spec language notwithstanding.
     // Synchronous, and will throw on failure.
-    this._pc._replaceTrack(this._transceiverImpl, withTrack);
+    this._pc._replaceTrackNoRenegotiation(this._transceiverImpl, withTrack);
 
     let setTrack = () => {
       this.track = withTrack;
       this._transceiver.sync();
     };
 
     // Spec is a little weird here; we only queue if the transceiver was
     // associated, otherwise we update the track synchronously.
@@ -2034,16 +2030,17 @@ class RTCRtpSender {
     this._streams = streams;
   }
 
   getStreams() {
     return this._streams;
   }
 
   setTrack(track) {
+    this._pc._replaceTrackNoRenegotiation(this._transceiverImpl, track);
     this.track = track;
   }
 
   getStats() {
     return this._pc._async(
       async () => this._pc._getStats(this.track));
   }