瀏覽代碼

Refactor RecordingController

master
Radium Zheng 7 年之前
父節點
當前提交
0490a3cf73

+ 51
- 31
react/features/local-recording/controller/RecordingController.js 查看文件

157
      * UI it wants to display a notice. Keeps {@code RecordingController}
157
      * UI it wants to display a notice. Keeps {@code RecordingController}
158
      * decoupled from UI.
158
      * decoupled from UI.
159
      */
159
      */
160
-    onNotify: ?(string) => void;
160
+    _onNotify: ?(messageKey: string, messageParams?: Object) => void;
161
 
161
 
162
     /**
162
     /**
163
      * FIXME: callback function for the {@code RecordingController} to notify
163
      * FIXME: callback function for the {@code RecordingController} to notify
164
      * UI it wants to display a warning. Keeps {@code RecordingController}
164
      * UI it wants to display a warning. Keeps {@code RecordingController}
165
      * decoupled from UI.
165
      * decoupled from UI.
166
      */
166
      */
167
-    onWarning: ?(string) => void;
167
+    _onWarning: ?(messageKey: string, messageParams?: Object) => void;
168
 
168
 
169
     /**
169
     /**
170
      * FIXME: callback function for the {@code RecordingController} to notify
170
      * FIXME: callback function for the {@code RecordingController} to notify
171
      * UI that the local recording state has changed.
171
      * UI that the local recording state has changed.
172
      */
172
      */
173
-    onStateChanged: ?(boolean) => void;
173
+    _onStateChanged: ?(boolean) => void;
174
 
174
 
175
     /**
175
     /**
176
      * Constructor.
176
      * Constructor.
214
         }
214
         }
215
     }
215
     }
216
 
216
 
217
+    /**
218
+     * Sets the event handler for {@code onStateChanged}.
219
+     *
220
+     * @param {Function} delegate - The event handler.
221
+     * @returns {void}
222
+     */
223
+    set onStateChanged(delegate: Function) {
224
+        this._onStateChanged = delegate;
225
+    }
226
+
227
+    /**
228
+     * Sets the event handler for {@code onNotify}.
229
+     *
230
+     * @param {Function} delegate - The event handler.
231
+     * @returns {void}
232
+     */
233
+    set onNotify(delegate: Function) {
234
+        this._onNotify = delegate;
235
+    }
236
+
237
+    /**
238
+     * Sets the event handler for {@code onWarning}.
239
+     *
240
+     * @param {Function} delegate - The event handler.
241
+     * @returns {void}
242
+     */
243
+    set onWarning(delegate: Function) {
244
+        this._onWarning = delegate;
245
+    }
246
+
217
     /**
247
     /**
218
      * Signals the participants to start local recording.
248
      * Signals the participants to start local recording.
219
      *
249
      *
229
                     format: this._format
259
                     format: this._format
230
                 }
260
                 }
231
             });
261
             });
232
-        } else {
233
-            const message = i18next.t('localRecording.messages.notModerator');
234
-
235
-            if (this.onWarning) {
236
-                this.onWarning(message);
237
-            }
262
+        } else if (this._onWarning) {
263
+            this._onWarning('localRecording.messages.notModerator');
238
         }
264
         }
239
     }
265
     }
240
 
266
 
252
                         sessionToken: this._currentSessionToken
278
                         sessionToken: this._currentSessionToken
253
                     }
279
                     }
254
                 });
280
                 });
255
-            } else {
256
-                const message
257
-                    = i18next.t('localRecording.messages.notModerator');
258
-
259
-                if (this.onWarning) {
260
-                    this.onWarning(message);
261
-                }
281
+            } else if (this._onWarning) {
282
+                this._onWarning('localRecording.messages.notModerator');
262
             }
283
             }
263
         }
284
         }
264
     }
285
     }
469
             .then(() => {
490
             .then(() => {
470
                 this._changeState(ControllerState.RECORDING);
491
                 this._changeState(ControllerState.RECORDING);
471
                 logger.log('Local recording engaged.');
492
                 logger.log('Local recording engaged.');
472
-                const message = i18next.t('localRecording.messages.engaged');
473
 
493
 
474
-                if (this.onNotify) {
475
-                    this.onNotify(message);
494
+                if (this._onNotify) {
495
+                    this._onNotify('localRecording.messages.engaged');
476
                 }
496
                 }
477
-                if (this.onStateChanged) {
478
-                    this.onStateChanged(true);
497
+                if (this._onStateChanged) {
498
+                    this._onStateChanged(true);
479
                 }
499
                 }
480
                 this._updateStats();
500
                 this._updateStats();
481
             })
501
             })
505
                     logger.log('Local recording unengaged.');
525
                     logger.log('Local recording unengaged.');
506
                     this.downloadRecordedData(token);
526
                     this.downloadRecordedData(token);
507
 
527
 
508
-                    const message
509
-                        = i18next.t(this._conference.isModerator()
528
+                    const messageKey
529
+                        = this._conference.isModerator()
510
                             ? 'localRecording.messages.finishedModerator'
530
                             ? 'localRecording.messages.finishedModerator'
511
-                            : 'localRecording.messages.finished',
512
-                            {
513
-                                token
514
-                            });
531
+                            : 'localRecording.messages.finished';
532
+                    const messageParams = {
533
+                        token
534
+                    };
515
 
535
 
516
-                    if (this.onNotify) {
517
-                        this.onNotify(message);
536
+                    if (this._onNotify) {
537
+                        this._onNotify(messageKey, messageParams);
518
                     }
538
                     }
519
-                    if (this.onStateChanged) {
520
-                        this.onStateChanged(false);
539
+                    if (this._onStateChanged) {
540
+                        this._onStateChanged(false);
521
                     }
541
                     }
522
                     this._updateStats();
542
                     this._updateStats();
523
                 })
543
                 })

+ 5
- 5
react/features/local-recording/middleware.js 查看文件

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
-import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
3
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
4
 import { CONFERENCE_JOINED } from '../base/conference';
4
 import { CONFERENCE_JOINED } from '../base/conference';
5
 import { i18next } from '../base/i18n';
5
 import { i18next } from '../base/i18n';
6
 import { MiddlewareRegistry } from '../base/redux';
6
 import { MiddlewareRegistry } from '../base/redux';
32
             }
32
             }
33
         };
33
         };
34
 
34
 
35
-        recordingController.onWarning = function(message) {
35
+        recordingController.onWarning = function(messageKey, messageParams) {
36
             dispatch(showNotification({
36
             dispatch(showNotification({
37
                 title: i18next.t('localRecording.localRecording'),
37
                 title: i18next.t('localRecording.localRecording'),
38
-                description: message
38
+                description: i18next.t(messageKey, messageParams)
39
             }, 10000));
39
             }, 10000));
40
         };
40
         };
41
 
41
 
42
-        recordingController.onNotify = function(message) {
42
+        recordingController.onNotify = function(messageKey, messageParams) {
43
             dispatch(showNotification({
43
             dispatch(showNotification({
44
                 title: i18next.t('localRecording.localRecording'),
44
                 title: i18next.t('localRecording.localRecording'),
45
-                description: message
45
+                description: i18next.t(messageKey, messageParams)
46
             }, 10000));
46
             }, 10000));
47
         };
47
         };
48
         break;
48
         break;

Loading…
取消
儲存