Quellcode durchsuchen

fix(TPC): Use addTrack instead of addStream in Unified-plan impl.

Do not try to configure encodings on the sender until they are available. This fixes an issue on Chrome (running in unified-plan mode) where unmuting the local source throws a 'Read-only field modified in setParameters()' error.
dev1
Jaya Allamsetty vor 4 Jahren
Ursprung
Commit
61c6cc5fe0
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden
2 geänderte Dateien mit 26 neuen und 13 gelöschten Zeilen
  1. 16
    6
      modules/RTC/TPCUtils.js
  2. 10
    7
      modules/RTC/TraceablePeerConnection.js

+ 16
- 6
modules/RTC/TPCUtils.js Datei anzeigen

@@ -191,8 +191,7 @@ export class TPCUtils {
191 191
     /**
192 192
     * Adds {@link JitsiLocalTrack} to the WebRTC peerconnection for the first time.
193 193
     * @param {JitsiLocalTrack} track - track to be added to the peerconnection.
194
-    * @param {boolean} isInitiator - boolean that indicates if the endpoint is offerer
195
-    * in a p2p connection.
194
+    * @param {boolean} isInitiator - boolean that indicates if the endpoint is offerer in a p2p connection.
196 195
     * @returns {void}
197 196
     */
198 197
     addTrack(localTrack, isInitiator) {
@@ -238,13 +237,18 @@ export class TPCUtils {
238 237
         }
239 238
         logger.debug(`Adding ${localTrack} on ${this.pc}`);
240 239
 
241
-        // If the client starts with audio/video muted setting, the transceiver direction
242
-        // will be set to 'recvonly'. Use addStream here so that a MSID is generated for the stream.
240
+        // If the client starts with audio/video muted setting, the transceiver direction will be set to 'recvonly'.
243 241
         if (transceiver.direction === 'recvonly') {
244 242
             const stream = localTrack.getOriginalStream();
245 243
 
246
-            if (stream) {
247
-                this.pc.peerconnection.addStream(localTrack.getOriginalStream());
244
+            if (stream && track) {
245
+                try {
246
+                    this.pc.peerconnection.addTrack(track, stream);
247
+                } catch (error) {
248
+                    logger.error(`Adding ${localTrack} failed on ${this.pc}:${error?.message}`);
249
+
250
+                    return Promise.reject(error);
251
+                }
248 252
 
249 253
                 return this.setEncodings(localTrack).then(() => {
250 254
                     this.pc.localTracks.set(localTrack.rtcId, localTrack);
@@ -395,6 +399,12 @@ export class TPCUtils {
395 399
             .find(t => t.sender && t.sender.track && t.sender.track.kind === track.getType());
396 400
         const parameters = transceiver.sender.getParameters();
397 401
 
402
+        // Resolve if the encodings are not available yet. This happens immediately after the track is added to the
403
+        // peerconnection on chrome in unified-plan. It is ok to ignore and not report the error here since the
404
+        // action that triggers 'addTrack' (like unmute) will also configure the encodings and set bitrates after that.
405
+        if (!parameters?.encodings?.length) {
406
+            return Promise.resolve();
407
+        }
398 408
         parameters.encodings = this._getStreamEncodings(track);
399 409
 
400 410
         return transceiver.sender.setParameters(parameters);

+ 10
- 7
modules/RTC/TraceablePeerConnection.js Datei anzeigen

@@ -1687,9 +1687,14 @@ TraceablePeerConnection.prototype.addTrack = function(track, isInitiator = false
1687 1687
 
1688 1688
     this.localTracks.set(rtcId, track);
1689 1689
 
1690
-    // For p2p unified case, use addTransceiver API to add the tracks on the peerconnection.
1691
-    if (browser.usesUnifiedPlan() && this.isP2P) {
1692
-        this.tpcUtils.addTrack(track, isInitiator);
1690
+    if (browser.usesUnifiedPlan()) {
1691
+        try {
1692
+            this.tpcUtils.addTrack(track, isInitiator);
1693
+        } catch (error) {
1694
+            logger.error(`Adding ${track} failed on ${this}: ${error?.message}`);
1695
+
1696
+            return Promise.reject(error);
1697
+        }
1693 1698
     } else {
1694 1699
         // In all other cases, i.e., plan-b and unified plan bridge case, use addStream API to
1695 1700
         // add the track to the peerconnection.
@@ -1709,8 +1714,7 @@ TraceablePeerConnection.prototype.addTrack = function(track, isInitiator = false
1709 1714
         }
1710 1715
 
1711 1716
         // Muted video tracks do not have WebRTC stream
1712
-        if (browser.usesPlanB() && browser.doesVideoMuteByStreamRemove()
1713
-                && track.isVideoTrack() && track.isMuted()) {
1717
+        if (browser.doesVideoMuteByStreamRemove() && track.isVideoTrack() && track.isMuted()) {
1714 1718
             const ssrcInfo = this.generateNewStreamSSRCInfo(track);
1715 1719
 
1716 1720
             this.sdpConsistency.setPrimarySsrc(ssrcInfo.ssrcs[0]);
@@ -1737,12 +1741,11 @@ TraceablePeerConnection.prototype.addTrack = function(track, isInitiator = false
1737 1741
             }
1738 1742
         }
1739 1743
     }
1740
-
1741 1744
     let promiseChain = Promise.resolve();
1742 1745
 
1743 1746
     // On Firefox, the encodings have to be configured on the sender only after the transceiver is created.
1744 1747
     if (browser.isFirefox()) {
1745
-        promiseChain = this.tpcUtils.setEncodings(track);
1748
+        promiseChain = promiseChain.then(() => this.tpcUtils.setEncodings(track));
1746 1749
     }
1747 1750
 
1748 1751
     return promiseChain;

Laden…
Abbrechen
Speichern