Browse Source

bug fix: multiple StartCommands

Situation when the RecordingController receives a new START_COMMAND
while it is initializing the recording adapter for the previous
START_COMMAND.
master
Radium Zheng 7 years ago
parent
commit
0f0f9ea1b2
1 changed files with 41 additions and 7 deletions
  1. 41
    7
      react/features/local-recording/controller/RecordingController.js

+ 41
- 7
react/features/local-recording/controller/RecordingController.js View File

40
      */
40
      */
41
     IDLE: Symbol('IDLE'),
41
     IDLE: Symbol('IDLE'),
42
 
42
 
43
+    /**
44
+     * Starting.
45
+     */
46
+    STARTING: Symbol('STARTING'),
47
+
43
     /**
48
     /**
44
      * Engaged (recording).
49
      * Engaged (recording).
45
      */
50
      */
46
-    RECORDING: Symbol('RECORDING')
51
+    RECORDING: Symbol('RECORDING'),
52
+
53
+    /**
54
+     * Stopping.
55
+     */
56
+    STOPPING: Symbol('STOPPING')
47
 });
57
 });
48
 
58
 
49
 /**
59
 /**
314
         return result;
324
         return result;
315
     }
325
     }
316
 
326
 
327
+    _changeState: (Symbol) => void;
328
+
329
+    /**
330
+     * Changes the current state of {@code RecordingController}.
331
+     *
332
+     * @private
333
+     * @param {Symbol} newState - The new state.
334
+     * @returns {void}
335
+     */
336
+    _changeState(newState: Symbol) {
337
+        if (this._state !== newState) {
338
+            logger.log(`state change: ${this._state.toString()} -> `
339
+                + `${newState.toString()}`);
340
+            this._state = newState;
341
+        }
342
+    }
343
+
317
     _updateStats: () => void;
344
     _updateStats: () => void;
318
 
345
 
319
     /**
346
     /**
342
         const { sessionToken, format } = value.attributes;
369
         const { sessionToken, format } = value.attributes;
343
 
370
 
344
         if (this._state === ControllerState.IDLE) {
371
         if (this._state === ControllerState.IDLE) {
372
+            this._changeState(ControllerState.STARTING);
345
             this._format = format;
373
             this._format = format;
346
             this._currentSessionToken = sessionToken;
374
             this._currentSessionToken = sessionToken;
375
+            logger.log(this._currentSessionToken);
347
             this._adapters[sessionToken]
376
             this._adapters[sessionToken]
348
                  = this._createRecordingAdapter();
377
                  = this._createRecordingAdapter();
349
             this._doStartRecording();
378
             this._doStartRecording();
350
-        } else if (this._currentSessionToken !== sessionToken) {
351
-            // we need to restart the recording
379
+        } else if (this._state === ControllerState.RECORDING
380
+            && this._currentSessionToken !== sessionToken) {
381
+            // There is local recording going on, but not for the same session.
382
+            // This means the current state might be out-of-sync with the
383
+            // moderator's, so we need to restart the recording.
384
+            this._changeState(ControllerState.STOPPING);
352
             this._doStopRecording().then(() => {
385
             this._doStopRecording().then(() => {
353
                 this._format = format;
386
                 this._format = format;
354
                 this._currentSessionToken = sessionToken;
387
                 this._currentSessionToken = sessionToken;
371
     _onStopCommand(value) {
404
     _onStopCommand(value) {
372
         if (this._state === ControllerState.RECORDING
405
         if (this._state === ControllerState.RECORDING
373
             && this._currentSessionToken === value.attributes.sessionToken) {
406
             && this._currentSessionToken === value.attributes.sessionToken) {
407
+            this._changeState(ControllerState.STOPPING);
374
             this._doStopRecording();
408
             this._doStopRecording();
375
         }
409
         }
376
     }
410
     }
394
      * @returns {void}
428
      * @returns {void}
395
      */
429
      */
396
     _doStartRecording() {
430
     _doStartRecording() {
397
-        if (this._state === ControllerState.IDLE) {
398
-            this._state = ControllerState.RECORDING;
431
+        if (this._state === ControllerState.STARTING) {
399
             const delegate = this._adapters[this._currentSessionToken];
432
             const delegate = this._adapters[this._currentSessionToken];
400
 
433
 
401
             delegate.start()
434
             delegate.start()
402
             .then(() => {
435
             .then(() => {
436
+                this._changeState(ControllerState.RECORDING);
403
                 logger.log('Local recording engaged.');
437
                 logger.log('Local recording engaged.');
404
                 const message = i18next.t('localRecording.messages.engaged');
438
                 const message = i18next.t('localRecording.messages.engaged');
405
 
439
 
427
      * @returns {Promise<void>}
461
      * @returns {Promise<void>}
428
      */
462
      */
429
     _doStopRecording() {
463
     _doStopRecording() {
430
-        if (this._state === ControllerState.RECORDING) {
464
+        if (this._state === ControllerState.STOPPING) {
431
             const token = this._currentSessionToken;
465
             const token = this._currentSessionToken;
432
 
466
 
433
             return this._adapters[this._currentSessionToken]
467
             return this._adapters[this._currentSessionToken]
434
                 .stop()
468
                 .stop()
435
                 .then(() => {
469
                 .then(() => {
436
-                    this._state = ControllerState.IDLE;
470
+                    this._changeState(ControllerState.IDLE);
437
                     logger.log('Local recording unengaged.');
471
                     logger.log('Local recording unengaged.');
438
                     this.downloadRecordedData(token);
472
                     this.downloadRecordedData(token);
439
 
473
 

Loading…
Cancel
Save