瀏覽代碼

fix(mute/unmute): Make mute/unmute async

Trigger renegotiation only for plan-b when tracks are muted or unmuted
dev1
Jaya Allamsetty 5 年之前
父節點
當前提交
55f793f394
共有 3 個檔案被更改,包括 42 行新增39 行删除
  1. 11
    9
      modules/RTC/TPCUtils.js
  2. 12
    10
      modules/RTC/TraceablePeerConnection.js
  3. 19
    20
      modules/xmpp/JingleSessionPC.js

+ 11
- 9
modules/RTC/TPCUtils.js 查看文件

@@ -193,7 +193,8 @@ export class TPCUtils {
193 193
     /**
194 194
      * Adds a track on the RTCRtpSender as part of the unmute operation.
195 195
      * @param {JitsiLocalTrack} localTrack - track to be unmuted.
196
-     * @returns {Promise<void>}
196
+     * @returns {Promise<boolean>} - Promise that resolves to false if unmute
197
+     * operation is successful, a reject otherwise.
197 198
      */
198 199
     addTrackUnmute(localTrack) {
199 200
         const mediaType = localTrack.getType();
@@ -205,9 +206,7 @@ export class TPCUtils {
205 206
             .find(t => t.receiver && t.receiver.track && t.receiver.track.kind === mediaType);
206 207
 
207 208
         if (!transceiver) {
208
-            logger.error(`RTCRtpTransceiver for ${mediaType} on ${this.pc} not found`);
209
-
210
-            return false;
209
+            return Promise.reject(new Error(`RTCRtpTransceiver for ${mediaType} not found`));
211 210
         }
212 211
         logger.debug(`Adding ${localTrack} on ${this.pc}`);
213 212
 
@@ -219,19 +218,22 @@ export class TPCUtils {
219 218
             this.pc.localTracks.set(localTrack.rtcId, localTrack);
220 219
             transceiver.direction = 'sendrecv';
221 220
 
222
-            return true;
221
+            return Promise.resolve(false);
223 222
         }
224 223
 
225 224
         return transceiver.sender.replaceTrack(track)
226 225
             .then(() => {
227 226
                 this.pc.localTracks.set(localTrack.rtcId, localTrack);
227
+
228
+                return Promise.resolve(false);
228 229
             });
229 230
     }
230 231
 
231 232
     /**
232 233
      * Removes the track from the RTCRtpSender as part of the mute operation.
233 234
      * @param {JitsiLocalTrack} localTrack - track to be removed.
234
-     * @returns {Promise<void>}
235
+     * @returns {Promise<boolean>} - Promise that resolves to false if unmute
236
+     * operation is successful, a reject otherwise.
235 237
      */
236 238
     removeTrackMute(localTrack) {
237 239
         const mediaType = localTrack.getType();
@@ -239,9 +241,7 @@ export class TPCUtils {
239 241
             .find(t => t.sender && t.sender.track && t.sender.track.id === localTrack.getTrackId());
240 242
 
241 243
         if (!transceiver) {
242
-            logger.error(`RTCRtpTransceiver for ${mediaType} on ${this.pc} not found`);
243
-
244
-            return false;
244
+            return Promise.reject(new Error(`RTCRtpTransceiver for ${mediaType} not found`));
245 245
         }
246 246
 
247 247
         logger.debug(`Removing ${localTrack} on ${this.pc}`);
@@ -249,6 +249,8 @@ export class TPCUtils {
249 249
         return transceiver.sender.replaceTrack(null)
250 250
             .then(() => {
251 251
                 this.pc.localTracks.delete(localTrack.rtcId);
252
+
253
+                return Promise.resolve(false);
252 254
             });
253 255
     }
254 256
 

+ 12
- 10
modules/RTC/TraceablePeerConnection.js 查看文件

@@ -1477,8 +1477,9 @@ TraceablePeerConnection.prototype.addTrack = function(track, isInitiator = false
1477 1477
  * Adds local track as part of the unmute operation.
1478 1478
  * @param {JitsiLocalTrack} track the track to be added as part of the unmute
1479 1479
  * operation
1480
- * @return {boolean} <tt>true</tt> if the state of underlying PC has changed and
1481
- * the renegotiation is required or <tt>false</tt> otherwise.
1480
+ * @return {Promise<boolean>} Promise that resolves to true if the underlying PeerConnection's
1481
+ * state has changed and renegotiation is required, false if no renegotiation is needed or
1482
+ * Promise is rejected when something goes wrong.
1482 1483
  */
1483 1484
 TraceablePeerConnection.prototype.addTrackUnmute = function(track) {
1484 1485
     if (browser.usesUnifiedPlan()) {
@@ -1486,7 +1487,7 @@ TraceablePeerConnection.prototype.addTrackUnmute = function(track) {
1486 1487
     }
1487 1488
     if (!this._assertTrackBelongs('addTrackUnmute', track)) {
1488 1489
         // Abort
1489
-        return false;
1490
+        return Promise.reject('Track not found on the peerconnection');
1490 1491
     }
1491 1492
 
1492 1493
     logger.info(`Adding ${track} as unmute to ${this}`);
@@ -1496,11 +1497,11 @@ TraceablePeerConnection.prototype.addTrackUnmute = function(track) {
1496 1497
         logger.error(
1497 1498
             `Unable to add ${track} as unmute to ${this} - no WebRTC stream`);
1498 1499
 
1499
-        return false;
1500
+        return Promise.reject('Stream not found');
1500 1501
     }
1501 1502
     this._addStream(webRtcStream);
1502 1503
 
1503
-    return true;
1504
+    return Promise.resolve(true);
1504 1505
 };
1505 1506
 
1506 1507
 /**
@@ -1676,8 +1677,9 @@ TraceablePeerConnection.prototype.replaceTrack = function(oldTrack, newTrack) {
1676 1677
  * Removes local track as part of the mute operation.
1677 1678
  * @param {JitsiLocalTrack} localTrack the local track to be remove as part of
1678 1679
  * the mute operation.
1679
- * @return {boolean} <tt>true</tt> if the underlying PeerConnection's state has
1680
- * changed and the renegotiation is required or <tt>false</tt> otherwise.
1680
+ * @return {Promise<boolean>} Promise that resolves to true if the underlying PeerConnection's
1681
+ * state has changed and renegotiation is required, false if no renegotiation is needed or
1682
+ * Promise is rejected when something goes wrong.
1681 1683
  */
1682 1684
 TraceablePeerConnection.prototype.removeTrackMute = function(localTrack) {
1683 1685
     if (browser.usesUnifiedPlan()) {
@@ -1691,19 +1693,19 @@ TraceablePeerConnection.prototype.removeTrackMute = function(localTrack) {
1691 1693
 
1692 1694
     if (!this._assertTrackBelongs('removeStreamMute', localTrack)) {
1693 1695
         // Abort - nothing to be done here
1694
-        return false;
1696
+        return Promise.reject('Track not found in the peerconnection');
1695 1697
     }
1696 1698
     if (webRtcStream) {
1697 1699
         logger.info(
1698 1700
             `Removing ${localTrack} as mute from ${this}`);
1699 1701
         this._removeStream(webRtcStream);
1700 1702
 
1701
-        return true;
1703
+        return Promise.resolve(true);
1702 1704
     }
1703 1705
 
1704 1706
     logger.error(`removeStreamMute - no WebRTC stream for ${localTrack}`);
1705 1707
 
1706
-    return false;
1708
+    return Promise.reject('Stream not found');
1707 1709
 };
1708 1710
 
1709 1711
 /**

+ 19
- 20
modules/xmpp/JingleSessionPC.js 查看文件

@@ -1994,29 +1994,28 @@ export default class JingleSessionPC extends JingleSession {
1994 1994
                 return;
1995 1995
             }
1996 1996
             const oldLocalSDP = tpc.localDescription.sdp;
1997
-            const tpcOperation
1997
+            const operationPromise
1998 1998
                 = isMute
1999
-                    ? tpc.removeTrackMute.bind(tpc, track)
2000
-                    : tpc.addTrackUnmute.bind(tpc, track);
1999
+                    ? tpc.removeTrackMute(track)
2000
+                    : tpc.addTrackUnmute(track);
2001 2001
 
2002
-            if (!tpcOperation()) {
2003
-                finishedCallback(`${operationName} failed!`);
2004
-
2005
-            // Do not renegotiate when browser is running in Unified-plan mode.
2006
-            } else if (!oldLocalSDP || !tpc.remoteDescription.sdp || browser.usesUnifiedPlan()) {
2007
-                finishedCallback();
2008
-            } else {
2009
-                this._renegotiate()
2010
-                    .then(() => {
2011
-                        // The results are ignored, as this check failure is not
2012
-                        // enough to fail the whole operation. It will log
2013
-                        // an error inside.
2014
-                        this._verifyNoSSRCChanged(
2015
-                            operationName, new SDP(oldLocalSDP));
2002
+            operationPromise
2003
+                .then(shouldRenegotiate => {
2004
+                    if (shouldRenegotiate && oldLocalSDP && tpc.remoteDescription.sdp) {
2005
+                        this._renegotiate()
2006
+                            .then(() => {
2007
+                                // The results are ignored, as this check failure is not
2008
+                                // enough to fail the whole operation. It will log
2009
+                                // an error inside.
2010
+                                this._verifyNoSSRCChanged(
2011
+                                    operationName, new SDP(oldLocalSDP));
2012
+                                finishedCallback();
2013
+                            });
2014
+                    } else {
2016 2015
                         finishedCallback();
2017
-                    },
2018
-                    finishedCallback /* will be called with an error */);
2019
-            }
2016
+                    }
2017
+                },
2018
+                finishedCallback /* will be called with an error */);
2020 2019
         };
2021 2020
 
2022 2021
         return new Promise((resolve, reject) => {

Loading…
取消
儲存