Browse Source

vad processor initialize fix

dev1
Andrei Gavrilescu 5 years ago
parent
commit
4e7034ee6a
1 changed files with 6 additions and 8 deletions
  1. 6
    8
      modules/detection/VADTalkMutedDetection.js

+ 6
- 8
modules/detection/VADTalkMutedDetection.js View File

79
          * we destroy it ( when changing the device for instance), or when we use it from an external point of entry
79
          * we destroy it ( when changing the device for instance), or when we use it from an external point of entry
80
          * i.e. (TRACK_MUTE_CHANGED event callback).
80
          * i.e. (TRACK_MUTE_CHANGED event callback).
81
          */
81
          */
82
-        this._vadInitTracker = null;
82
+        this._vadInitTracker = Promise.resolve();
83
 
83
 
84
         /**
84
         /**
85
          * Listens for {@link TrackVADEmitter} events and processes them.
85
          * Listens for {@link TrackVADEmitter} events and processes them.
189
         if (track.isLocalAudioTrack()) {
189
         if (track.isLocalAudioTrack()) {
190
             // Keep a track promise so we take into account successive TRACK_ADD events being generated so that we
190
             // Keep a track promise so we take into account successive TRACK_ADD events being generated so that we
191
             // destroy/create the processing context in the proper order.
191
             // destroy/create the processing context in the proper order.
192
-            this._vadInitTracker = this._createVADProcessor()
192
+            this._vadInitTracker = this._vadInitTracker.then(() => this._createVADProcessor())
193
                 .then(vadProcessor =>
193
                 .then(vadProcessor =>
194
                     TrackVADEmitter.create(track.getDeviceId(), VAD_EMITTER_SAMPLE_RATE, vadProcessor)
194
                     TrackVADEmitter.create(track.getDeviceId(), VAD_EMITTER_SAMPLE_RATE, vadProcessor)
195
                 )
195
                 )
214
      * @listens TRACK_MUTE_CHANGED
214
      * @listens TRACK_MUTE_CHANGED
215
      */
215
      */
216
     _trackMuteChanged(track) {
216
     _trackMuteChanged(track) {
217
-        if (track.isLocalAudioTrack() && this._vadInitTracker) {
217
+        if (track.isLocalAudioTrack()) {
218
             // On a mute toggle reset the state.
218
             // On a mute toggle reset the state.
219
-            this._vadInitTracker.then(() => {
219
+            this._vadInitTracker = this._vadInitTracker.then(() => {
220
 
220
 
221
                 // Reset the processing context in between muted states so that each individual mute phase can generate
221
                 // Reset the processing context in between muted states so that each individual mute phase can generate
222
                 // it's own event.
222
                 // it's own event.
239
      * @listens TRACK_REMOVED
239
      * @listens TRACK_REMOVED
240
      */
240
      */
241
     _trackRemoved(track) {
241
     _trackRemoved(track) {
242
-        if (track.isLocalAudioTrack() && this._vadInitTracker) {
242
+        if (track.isLocalAudioTrack()) {
243
             // Use the promise to make sure operations are in sequence.
243
             // Use the promise to make sure operations are in sequence.
244
-            this._vadInitTracker.then(() => {
244
+            this._vadInitTracker = this._vadInitTracker.then(() => {
245
                 logger.debug('Removing track from VAD detection - ', track.getTrackLabel());
245
                 logger.debug('Removing track from VAD detection - ', track.getTrackLabel());
246
 
246
 
247
                 if (this._vadEmitter) {
247
                 if (this._vadEmitter) {
250
                     this._vadEmitter.destroy();
250
                     this._vadEmitter.destroy();
251
                     this._vadEmitter = null;
251
                     this._vadEmitter = null;
252
                 }
252
                 }
253
-
254
-                this._vadInitTracker = null;
255
             });
253
             });
256
         }
254
         }
257
     }
255
     }

Loading…
Cancel
Save