Browse Source

Refactor RecordingController

efficient_tiling
Radium Zheng 7 years ago
parent
commit
0490a3cf73

+ 51
- 31
react/features/local-recording/controller/RecordingController.js View File

@@ -157,20 +157,20 @@ class RecordingController {
157 157
      * UI it wants to display a notice. Keeps {@code RecordingController}
158 158
      * decoupled from UI.
159 159
      */
160
-    onNotify: ?(string) => void;
160
+    _onNotify: ?(messageKey: string, messageParams?: Object) => void;
161 161
 
162 162
     /**
163 163
      * FIXME: callback function for the {@code RecordingController} to notify
164 164
      * UI it wants to display a warning. Keeps {@code RecordingController}
165 165
      * decoupled from UI.
166 166
      */
167
-    onWarning: ?(string) => void;
167
+    _onWarning: ?(messageKey: string, messageParams?: Object) => void;
168 168
 
169 169
     /**
170 170
      * FIXME: callback function for the {@code RecordingController} to notify
171 171
      * UI that the local recording state has changed.
172 172
      */
173
-    onStateChanged: ?(boolean) => void;
173
+    _onStateChanged: ?(boolean) => void;
174 174
 
175 175
     /**
176 176
      * Constructor.
@@ -214,6 +214,36 @@ class RecordingController {
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 248
      * Signals the participants to start local recording.
219 249
      *
@@ -229,12 +259,8 @@ class RecordingController {
229 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,13 +278,8 @@ class RecordingController {
252 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,13 +490,12 @@ class RecordingController {
469 490
             .then(() => {
470 491
                 this._changeState(ControllerState.RECORDING);
471 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 500
                 this._updateStats();
481 501
             })
@@ -505,19 +525,19 @@ class RecordingController {
505 525
                     logger.log('Local recording unengaged.');
506 526
                     this.downloadRecordedData(token);
507 527
 
508
-                    const message
509
-                        = i18next.t(this._conference.isModerator()
528
+                    const messageKey
529
+                        = this._conference.isModerator()
510 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 542
                     this._updateStats();
523 543
                 })

+ 5
- 5
react/features/local-recording/middleware.js View File

@@ -1,6 +1,6 @@
1 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 4
 import { CONFERENCE_JOINED } from '../base/conference';
5 5
 import { i18next } from '../base/i18n';
6 6
 import { MiddlewareRegistry } from '../base/redux';
@@ -32,17 +32,17 @@ MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
32 32
             }
33 33
         };
34 34
 
35
-        recordingController.onWarning = function(message) {
35
+        recordingController.onWarning = function(messageKey, messageParams) {
36 36
             dispatch(showNotification({
37 37
                 title: i18next.t('localRecording.localRecording'),
38
-                description: message
38
+                description: i18next.t(messageKey, messageParams)
39 39
             }, 10000));
40 40
         };
41 41
 
42
-        recordingController.onNotify = function(message) {
42
+        recordingController.onNotify = function(messageKey, messageParams) {
43 43
             dispatch(showNotification({
44 44
                 title: i18next.t('localRecording.localRecording'),
45
-                description: message
45
+                description: i18next.t(messageKey, messageParams)
46 46
             }, 10000));
47 47
         };
48 48
         break;

Loading…
Cancel
Save