Browse Source

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 years ago
parent
commit
3295be78c5
4 changed files with 15 additions and 25 deletions
  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 View File

@@ -32,8 +32,6 @@ TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_IS_DISPOSED]
32 32
     = 'Track has been already disposed';
33 33
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_NO_STREAM_FOUND]
34 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 35
 TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
38 36
     = 'The track has stopped receiving data from it\'s source';
39 37
 

+ 0
- 6
JitsiTrackErrors.js View File

@@ -80,12 +80,6 @@ export const PERMISSION_DENIED = 'gum.permission_denied';
80 80
  */
81 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 84
  * An error which indicates that track has no MediaStream associated.
91 85
  */

+ 0
- 1
doc/API.md View File

@@ -175,7 +175,6 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
175 175
         - CONSTRAINT_FAILED - getUserMedia-related error, indicates that some of requested constraints in getUserMedia call were not satisfied.
176 176
         - TRACK_IS_DISPOSED - an error which indicates that track has been already disposed and cannot be longer used.
177 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 178
         - CHROME_EXTENSION_GENERIC_ERROR - generic error for jidesha extension for Chrome.
180 179
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
181 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 View File

@@ -16,29 +16,20 @@ import VideoType from '../../service/RTC/VideoType';
16 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 23
  * @param {JitsiLocalTrack} track - The track that will be muted/unmuted.
22 24
  * @param {boolean} mute - Whether to mute or unmute the track.
23 25
  * @returns {Promise}
24 26
  */
25 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,7 +100,15 @@ export default class JitsiLocalTrack extends JitsiTrack {
109 100
 
110 101
         this.deviceId = deviceId;
111 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 114
          * The facing mode of the camera from which this JitsiLocalTrack

Loading…
Cancel
Save