Lyubo Marinov 7 лет назад
Родитель
Сommit
ac3e2824f4
1 измененных файлов: 23 добавлений и 22 удалений
  1. 23
    22
      modules/RTC/JitsiLocalTrack.js

+ 23
- 22
modules/RTC/JitsiLocalTrack.js Просмотреть файл

15
 
15
 
16
 const logger = getLogger(__filename);
16
 const logger = getLogger(__filename);
17
 
17
 
18
-/**
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.
22
- *
23
- * @param {JitsiLocalTrack} track - The track that will be muted/unmuted.
24
- * @param {boolean} mute - Whether to mute or unmute the track.
25
- * @returns {Promise}
26
- */
27
-function createMuteUnmutePromise(track, mute) {
28
-    const doMute = () => track._setMute(mute);
29
-
30
-    track._mutePromise = track._mutePromise.then(doMute, doMute);
31
-
32
-    return track._mutePromise;
33
-}
34
-
35
 /**
18
 /**
36
  * Represents a single media track(either audio or video).
19
  * Represents a single media track(either audio or video).
37
  * One <tt>JitsiLocalTrack</tt> corresponds to one WebRTC MediaStreamTrack.
20
  * One <tt>JitsiLocalTrack</tt> corresponds to one WebRTC MediaStreamTrack.
102
         this.storedMSID = this.getMSID();
85
         this.storedMSID = this.getMSID();
103
 
86
 
104
         /**
87
         /**
105
-         * The promise which indicates a mute or unmute operation is in
106
-         * progress.
88
+         * The <tt>Promise</tt> which represents the progress of a previously
89
+         * queued/scheduled {@link _setMute} (from the point of view of
90
+         * {@link _queueSetMute}).
107
          *
91
          *
108
          * @private
92
          * @private
109
          * @type {Promise}
93
          * @type {Promise}
110
          */
94
          */
111
-        this._mutePromise = Promise.resolve();
95
+        this._prevSetMute = Promise.resolve();
112
 
96
 
113
         /**
97
         /**
114
          * The facing mode of the camera from which this JitsiLocalTrack
98
          * The facing mode of the camera from which this JitsiLocalTrack
306
      * @returns {Promise}
290
      * @returns {Promise}
307
      */
291
      */
308
     mute() {
292
     mute() {
309
-        return createMuteUnmutePromise(this, true);
293
+        return this._queueSetMute(true);
310
     }
294
     }
311
 
295
 
312
     /**
296
     /**
315
      * @returns {Promise}
299
      * @returns {Promise}
316
      */
300
      */
317
     unmute() {
301
     unmute() {
318
-        return createMuteUnmutePromise(this, false);
302
+        return this._queueSetMute(false);
303
+    }
304
+
305
+    /**
306
+     * Initializes a new Promise to execute {@link _setMute}. May be called
307
+     * multiple times in a row and the invocations of {@link _setMute} and,
308
+     * consequently, {@link mute} and/or {@link unmute} will be resolved in a
309
+     * serialized fashion.
310
+     *
311
+     * @param {boolean} mute - Whether to mute or unmute this track.
312
+     * @returns {Promise}
313
+     */
314
+    _queueSetMute(mute) {
315
+        const setMute = this._setMute.bind(this, mute);
316
+
317
+        this._prevSetMute = this._prevSetMute.then(setMute, setMute);
318
+
319
+        return this._prevSetMute;
319
     }
320
     }
320
 
321
 
321
     /**
322
     /**

Загрузка…
Отмена
Сохранить