瀏覽代碼

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
     /**
193
     /**
194
      * Adds a track on the RTCRtpSender as part of the unmute operation.
194
      * Adds a track on the RTCRtpSender as part of the unmute operation.
195
      * @param {JitsiLocalTrack} localTrack - track to be unmuted.
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
     addTrackUnmute(localTrack) {
199
     addTrackUnmute(localTrack) {
199
         const mediaType = localTrack.getType();
200
         const mediaType = localTrack.getType();
205
             .find(t => t.receiver && t.receiver.track && t.receiver.track.kind === mediaType);
206
             .find(t => t.receiver && t.receiver.track && t.receiver.track.kind === mediaType);
206
 
207
 
207
         if (!transceiver) {
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
         logger.debug(`Adding ${localTrack} on ${this.pc}`);
211
         logger.debug(`Adding ${localTrack} on ${this.pc}`);
213
 
212
 
219
             this.pc.localTracks.set(localTrack.rtcId, localTrack);
218
             this.pc.localTracks.set(localTrack.rtcId, localTrack);
220
             transceiver.direction = 'sendrecv';
219
             transceiver.direction = 'sendrecv';
221
 
220
 
222
-            return true;
221
+            return Promise.resolve(false);
223
         }
222
         }
224
 
223
 
225
         return transceiver.sender.replaceTrack(track)
224
         return transceiver.sender.replaceTrack(track)
226
             .then(() => {
225
             .then(() => {
227
                 this.pc.localTracks.set(localTrack.rtcId, localTrack);
226
                 this.pc.localTracks.set(localTrack.rtcId, localTrack);
227
+
228
+                return Promise.resolve(false);
228
             });
229
             });
229
     }
230
     }
230
 
231
 
231
     /**
232
     /**
232
      * Removes the track from the RTCRtpSender as part of the mute operation.
233
      * Removes the track from the RTCRtpSender as part of the mute operation.
233
      * @param {JitsiLocalTrack} localTrack - track to be removed.
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
     removeTrackMute(localTrack) {
238
     removeTrackMute(localTrack) {
237
         const mediaType = localTrack.getType();
239
         const mediaType = localTrack.getType();
239
             .find(t => t.sender && t.sender.track && t.sender.track.id === localTrack.getTrackId());
241
             .find(t => t.sender && t.sender.track && t.sender.track.id === localTrack.getTrackId());
240
 
242
 
241
         if (!transceiver) {
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
         logger.debug(`Removing ${localTrack} on ${this.pc}`);
247
         logger.debug(`Removing ${localTrack} on ${this.pc}`);
249
         return transceiver.sender.replaceTrack(null)
249
         return transceiver.sender.replaceTrack(null)
250
             .then(() => {
250
             .then(() => {
251
                 this.pc.localTracks.delete(localTrack.rtcId);
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
  * Adds local track as part of the unmute operation.
1477
  * Adds local track as part of the unmute operation.
1478
  * @param {JitsiLocalTrack} track the track to be added as part of the unmute
1478
  * @param {JitsiLocalTrack} track the track to be added as part of the unmute
1479
  * operation
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
 TraceablePeerConnection.prototype.addTrackUnmute = function(track) {
1484
 TraceablePeerConnection.prototype.addTrackUnmute = function(track) {
1484
     if (browser.usesUnifiedPlan()) {
1485
     if (browser.usesUnifiedPlan()) {
1486
     }
1487
     }
1487
     if (!this._assertTrackBelongs('addTrackUnmute', track)) {
1488
     if (!this._assertTrackBelongs('addTrackUnmute', track)) {
1488
         // Abort
1489
         // Abort
1489
-        return false;
1490
+        return Promise.reject('Track not found on the peerconnection');
1490
     }
1491
     }
1491
 
1492
 
1492
     logger.info(`Adding ${track} as unmute to ${this}`);
1493
     logger.info(`Adding ${track} as unmute to ${this}`);
1496
         logger.error(
1497
         logger.error(
1497
             `Unable to add ${track} as unmute to ${this} - no WebRTC stream`);
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
     this._addStream(webRtcStream);
1502
     this._addStream(webRtcStream);
1502
 
1503
 
1503
-    return true;
1504
+    return Promise.resolve(true);
1504
 };
1505
 };
1505
 
1506
 
1506
 /**
1507
 /**
1676
  * Removes local track as part of the mute operation.
1677
  * Removes local track as part of the mute operation.
1677
  * @param {JitsiLocalTrack} localTrack the local track to be remove as part of
1678
  * @param {JitsiLocalTrack} localTrack the local track to be remove as part of
1678
  * the mute operation.
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
 TraceablePeerConnection.prototype.removeTrackMute = function(localTrack) {
1684
 TraceablePeerConnection.prototype.removeTrackMute = function(localTrack) {
1683
     if (browser.usesUnifiedPlan()) {
1685
     if (browser.usesUnifiedPlan()) {
1691
 
1693
 
1692
     if (!this._assertTrackBelongs('removeStreamMute', localTrack)) {
1694
     if (!this._assertTrackBelongs('removeStreamMute', localTrack)) {
1693
         // Abort - nothing to be done here
1695
         // Abort - nothing to be done here
1694
-        return false;
1696
+        return Promise.reject('Track not found in the peerconnection');
1695
     }
1697
     }
1696
     if (webRtcStream) {
1698
     if (webRtcStream) {
1697
         logger.info(
1699
         logger.info(
1698
             `Removing ${localTrack} as mute from ${this}`);
1700
             `Removing ${localTrack} as mute from ${this}`);
1699
         this._removeStream(webRtcStream);
1701
         this._removeStream(webRtcStream);
1700
 
1702
 
1701
-        return true;
1703
+        return Promise.resolve(true);
1702
     }
1704
     }
1703
 
1705
 
1704
     logger.error(`removeStreamMute - no WebRTC stream for ${localTrack}`);
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
                 return;
1994
                 return;
1995
             }
1995
             }
1996
             const oldLocalSDP = tpc.localDescription.sdp;
1996
             const oldLocalSDP = tpc.localDescription.sdp;
1997
-            const tpcOperation
1997
+            const operationPromise
1998
                 = isMute
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
                         finishedCallback();
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
         return new Promise((resolve, reject) => {
2021
         return new Promise((resolve, reject) => {

Loading…
取消
儲存