瀏覽代碼

feat(JitsiLocalTrack): make mute/unmute more resilient

Instead of failing with an error if another operation is in progress, which is
impossible to know as a user, chain them using the primises API.
dev1
Saúl Ibarra Corretgé 8 年之前
父節點
當前提交
3295be78c5
共有 4 個文件被更改,包括 15 次插入25 次删除
  1. 0
    2
      JitsiTrackError.js
  2. 0
    6
      JitsiTrackErrors.js
  3. 0
    1
      doc/API.md
  4. 15
    16
      modules/RTC/JitsiLocalTrack.js

+ 0
- 2
JitsiTrackError.js 查看文件

32
     = 'Track has been already disposed';
32
     = 'Track has been already disposed';
33
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_NO_STREAM_FOUND]
33
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_NO_STREAM_FOUND]
34
     = 'Track does not have an associated Media Stream';
34
     = 'Track does not have an associated Media Stream';
35
-TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_MUTE_UNMUTE_IN_PROGRESS]
36
-    = 'Track mute/unmute process is currently in progress';
37
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
35
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
38
     = 'The track has stopped receiving data from it\'s source';
36
     = 'The track has stopped receiving data from it\'s source';
39
 
37
 

+ 0
- 6
JitsiTrackErrors.js 查看文件

80
  */
80
  */
81
 export const TRACK_IS_DISPOSED = 'track.track_is_disposed';
81
 export const TRACK_IS_DISPOSED = 'track.track_is_disposed';
82
 
82
 
83
-/**
84
- * An error which indicates that track is currently in progress of muting or
85
- * unmuting itself.
86
- */
87
-export const TRACK_MUTE_UNMUTE_IN_PROGRESS = 'track.mute_unmute_inprogress';
88
-
89
 /**
83
 /**
90
  * An error which indicates that track has no MediaStream associated.
84
  * An error which indicates that track has no MediaStream associated.
91
  */
85
  */

+ 0
- 1
doc/API.md 查看文件

175
         - CONSTRAINT_FAILED - getUserMedia-related error, indicates that some of requested constraints in getUserMedia call were not satisfied.
175
         - CONSTRAINT_FAILED - getUserMedia-related error, indicates that some of requested constraints in getUserMedia call were not satisfied.
176
         - TRACK_IS_DISPOSED - an error which indicates that track has been already disposed and cannot be longer used.
176
         - TRACK_IS_DISPOSED - an error which indicates that track has been already disposed and cannot be longer used.
177
         - TRACK_NO_STREAM_FOUND - an error which indicates that track has no MediaStream associated.
177
         - TRACK_NO_STREAM_FOUND - an error which indicates that track has no MediaStream associated.
178
-        - TRACK_MUTE_UNMUTE_IN_PROGRESS - an error which indicates that track is currently in progress of muting or unmuting itself.
179
         - CHROME_EXTENSION_GENERIC_ERROR - generic error for jidesha extension for Chrome.
178
         - CHROME_EXTENSION_GENERIC_ERROR - generic error for jidesha extension for Chrome.
180
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
179
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
181
         - CHROME_EXTENSION_INSTALLATION_ERROR - an error which indicates that the jidesha extension for Chrome is failed to install.
180
         - CHROME_EXTENSION_INSTALLATION_ERROR - an error which indicates that the jidesha extension for Chrome is failed to install.

+ 15
- 16
modules/RTC/JitsiLocalTrack.js 查看文件

16
 const logger = getLogger(__filename);
16
 const logger = getLogger(__filename);
17
 
17
 
18
 /**
18
 /**
19
- * Creates Promise for mute/unmute operation.
19
+ * Creates Promise for mute/unmute operation. Mute operations are chained, so
20
+ * this function can be called as many times as needed in a row and operations
21
+ * will be executed in a serialized fashion.
20
  *
22
  *
21
  * @param {JitsiLocalTrack} track - The track that will be muted/unmuted.
23
  * @param {JitsiLocalTrack} track - The track that will be muted/unmuted.
22
  * @param {boolean} mute - Whether to mute or unmute the track.
24
  * @param {boolean} mute - Whether to mute or unmute the track.
23
  * @returns {Promise}
25
  * @returns {Promise}
24
  */
26
  */
25
 function createMuteUnmutePromise(track, mute) {
27
 function createMuteUnmutePromise(track, mute) {
26
-    if (track.inMuteOrUnmuteProgress) {
27
-        return Promise.reject(
28
-            new JitsiTrackError(JitsiTrackErrors.TRACK_MUTE_UNMUTE_IN_PROGRESS)
29
-        );
30
-    }
28
+    const doMute = () => track._setMute(mute);
31
 
29
 
32
-    track.inMuteOrUnmuteProgress = true;
30
+    track._mutePromise = track._mutePromise.then(doMute, doMute);
33
 
31
 
34
-    return track._setMute(mute)
35
-        .then(() => {
36
-            track.inMuteOrUnmuteProgress = false;
37
-        })
38
-        .catch(status => {
39
-            track.inMuteOrUnmuteProgress = false;
40
-            throw status;
41
-        });
32
+    return track._mutePromise;
42
 }
33
 }
43
 
34
 
44
 /**
35
 /**
109
 
100
 
110
         this.deviceId = deviceId;
101
         this.deviceId = deviceId;
111
         this.storedMSID = this.getMSID();
102
         this.storedMSID = this.getMSID();
112
-        this.inMuteOrUnmuteProgress = false;
103
+
104
+        /**
105
+         * The promise which indicates a mute or unmute operation is in
106
+         * progress.
107
+         *
108
+         * @private
109
+         * @type {Promise}
110
+         */
111
+        this._mutePromise = Promise.resolve();
113
 
112
 
114
         /**
113
         /**
115
          * The facing mode of the camera from which this JitsiLocalTrack
114
          * The facing mode of the camera from which this JitsiLocalTrack

Loading…
取消
儲存