Просмотр исходного кода

LIB_DID_DISPOSE, LIB_DID_INIT, LIB_WILL_DISPOSE, LIB_WILL_INIT

j8
Lyubo Marinov 8 лет назад
Родитель
Сommit
0b9160fb75

+ 27
- 6
react/features/base/lib-jitsi-meet/actionTypes.js Просмотреть файл

@@ -1,13 +1,23 @@
1 1
 import { Symbol } from '../react';
2 2
 
3 3
 /**
4
- * Action to signal that lib-jitsi-meet library was disposed.
4
+ * The type of Redux action which signals that {@link JitsiMeetJS} was disposed.
5 5
  *
6 6
  * {
7
- *     type: LIB_DISPOSED
7
+ *     type: LIB_DID_DISPOSE
8 8
  * }
9 9
  */
10
-export const LIB_DISPOSED = Symbol('LIB_DISPOSED');
10
+export const LIB_DID_DISPOSE = Symbol('LIB_DID_DISPOSE');
11
+
12
+/**
13
+ * The type of Redux action which signals that {@link JitsiMeetJS.init()} was
14
+ * invoked and completed successfully.
15
+ *
16
+ * {
17
+ *     type: LIB_DID_INIT
18
+ * }
19
+ */
20
+export const LIB_DID_INIT = Symbol('LIB_DID_INIT');
11 21
 
12 22
 /**
13 23
  * Action to signal that lib-jitsi-meet initialized failed with error.
@@ -20,13 +30,24 @@ export const LIB_DISPOSED = Symbol('LIB_DISPOSED');
20 30
 export const LIB_INIT_ERROR = Symbol('LIB_INIT_ERROR');
21 31
 
22 32
 /**
23
- * Action to signal that lib-jitsi-meet initialization succeeded.
33
+ * The type of Redux action which signals that {@link JitsiMeetJS} will be
34
+ * disposed.
35
+ *
36
+ * {
37
+ *     type: LIB_WILL_DISPOSE
38
+ * }
39
+ */
40
+export const LIB_WILL_DISPOSE = Symbol('LIB_WILL_DISPOSE');
41
+
42
+/**
43
+ * The type of Redux action which signals that {@link JitsiMeetJS.init()} will
44
+ * be invoked.
24 45
  *
25 46
  * {
26
- *     type: LIB_INITIALIZED
47
+ *     type: LIB_WILL_INIT
27 48
  * }
28 49
  */
29
-export const LIB_INITIALIZED = Symbol('LIB_INITIALIZED');
50
+export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
30 51
 
31 52
 /**
32 53
  * Action to signal that config was set.

+ 28
- 20
react/features/base/lib-jitsi-meet/actions.js Просмотреть файл

@@ -4,35 +4,40 @@ import type { Dispatch } from 'redux';
4 4
 
5 5
 import JitsiMeetJS from './';
6 6
 import {
7
-    LIB_DISPOSED,
7
+    LIB_DID_DISPOSE,
8
+    LIB_DID_INIT,
8 9
     LIB_INIT_ERROR,
9
-    LIB_INITIALIZED,
10
+    LIB_WILL_DISPOSE,
11
+    LIB_WILL_INIT,
10 12
     SET_CONFIG
11 13
 } from './actionTypes';
12 14
 
13 15
 declare var APP: Object;
14 16
 
15 17
 /**
16
- * Disposes lib-jitsi-meet.
18
+ * Disposes (of) lib-jitsi-meet.
17 19
  *
18 20
  * @returns {Function}
19 21
  */
20 22
 export function disposeLib() {
21
-    // XXX We're wrapping it with Promise, because:
22
-    // a) to be better aligned with initLib() method, which is async.
23
-    // b) as currently there is no implementation for it in lib-jitsi-meet, and
24
-    // there is a big chance it will be async.
25
-    // TODO Currently, lib-jitsi-meet doesn't have any functionality to
26
-    // dispose itself.
27 23
     return (dispatch: Dispatch<*>) => {
28
-        dispatch({ type: LIB_DISPOSED });
24
+        dispatch({ type: LIB_WILL_DISPOSE });
29 25
 
30
-        return Promise.resolve();
26
+        // XXX We're wrapping it with Promise because:
27
+        // a) to be better aligned with initLib() method which is async;
28
+        // b) as currently there is no implementation for it in lib-jitsi-meet
29
+        //    and there is a big chance it will be async.
30
+        // TODO Currently, lib-jitsi-meet doesn't have the functionality to
31
+        // dispose itself.
32
+        return (
33
+            Promise.resolve()
34
+                .then(() => dispatch({ type: LIB_DID_DISPOSE })));
31 35
     };
32 36
 }
33 37
 
34 38
 /**
35
- * Initializes lib-jitsi-meet with passed configuration.
39
+ * Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
40
+ * current config(uration).
36 41
  *
37 42
  * @returns {Function}
38 43
  */
@@ -50,15 +55,18 @@ export function initLib() {
50 55
             return Promise.resolve();
51 56
         }
52 57
 
53
-        return JitsiMeetJS.init(config)
54
-            .then(() => dispatch({ type: LIB_INITIALIZED }))
55
-            .catch(error => {
56
-                dispatch(libInitError(error));
58
+        dispatch({ type: LIB_WILL_INIT });
57 59
 
58
-                // TODO Handle LIB_INIT_ERROR error somewhere instead.
59
-                console.error('lib-jitsi-meet failed to init:', error);
60
-                throw error;
61
-            });
60
+        return (
61
+            JitsiMeetJS.init(config)
62
+                .then(() => dispatch({ type: LIB_DID_INIT }))
63
+                .catch(error => {
64
+                    dispatch(libInitError(error));
65
+
66
+                    // TODO Handle LIB_INIT_ERROR error somewhere instead.
67
+                    console.error('lib-jitsi-meet failed to init:', error);
68
+                    throw error;
69
+                }));
62 70
     };
63 71
 }
64 72
 

+ 3
- 5
react/features/base/lib-jitsi-meet/middleware.js Просмотреть файл

@@ -1,10 +1,7 @@
1 1
 import { PARTICIPANT_LEFT } from '../participants';
2 2
 import { MiddlewareRegistry } from '../redux';
3 3
 
4
-import {
5
-    disposeLib,
6
-    initLib
7
-} from './actions';
4
+import { disposeLib, initLib } from './actions';
8 5
 import { SET_CONFIG } from './actionTypes';
9 6
 
10 7
 /**
@@ -15,6 +12,7 @@ import { SET_CONFIG } from './actionTypes';
15 12
  *
16 13
  * @param {Store} store - Redux store.
17 14
  * @returns {Function}
15
+ * @private
18 16
  */
19 17
 MiddlewareRegistry.register(store => next => action => {
20 18
     switch (action.type) {
@@ -39,9 +37,9 @@ MiddlewareRegistry.register(store => next => action => {
39 37
  * specified action to the specified store.
40 38
  * @param {Action} action - The Redux action SET_CONFIG which is being
41 39
  * dispatched in the specified store.
42
- * @private
43 40
  * @returns {Object} The new state that is the result of the reduction of the
44 41
  * specified action.
42
+ * @private
45 43
  */
46 44
 function _setConfig(store, next, action) {
47 45
     const { dispatch, getState } = store;

+ 9
- 9
react/features/base/lib-jitsi-meet/reducer.js Просмотреть файл

@@ -1,9 +1,9 @@
1 1
 import { ReducerRegistry } from '../redux';
2 2
 
3 3
 import {
4
-    LIB_DISPOSED,
4
+    LIB_DID_DISPOSE,
5
+    LIB_DID_INIT,
5 6
     LIB_INIT_ERROR,
6
-    LIB_INITIALIZED,
7 7
     SET_CONFIG
8 8
 } from './actionTypes';
9 9
 
@@ -46,21 +46,21 @@ ReducerRegistry.register(
46 46
     'features/base/lib-jitsi-meet',
47 47
     (state = INITIAL_STATE, action) => {
48 48
         switch (action.type) {
49
-        case LIB_DISPOSED:
49
+        case LIB_DID_DISPOSE:
50 50
             return INITIAL_STATE;
51 51
 
52
-        case LIB_INIT_ERROR:
52
+        case LIB_DID_INIT:
53 53
             return {
54 54
                 ...state,
55
-                initError: action.error,
56
-                initialized: false
55
+                initError: undefined,
56
+                initialized: true
57 57
             };
58 58
 
59
-        case LIB_INITIALIZED:
59
+        case LIB_INIT_ERROR:
60 60
             return {
61 61
                 ...state,
62
-                initError: undefined,
63
-                initialized: true
62
+                initError: action.error,
63
+                initialized: false
64 64
             };
65 65
 
66 66
         case SET_CONFIG:

+ 8
- 8
react/features/base/tracks/middleware.js Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 /* @flow */
2 2
 
3
-import { LIB_DISPOSED, LIB_INITIALIZED } from '../lib-jitsi-meet';
3
+import { LIB_DID_DISPOSE, LIB_DID_INIT } from '../lib-jitsi-meet';
4 4
 import {
5 5
     MEDIA_TYPE,
6 6
     SET_AUDIO_MUTED,
@@ -16,21 +16,21 @@ import { TRACK_UPDATED } from './actionTypes';
16 16
 import { getLocalTrack, setTrackMuted } from './functions';
17 17
 
18 18
 /**
19
- * Middleware that captures LIB_INITIALIZED and LIB_DISPOSED actions
20
- * and respectively creates/destroys local media tracks. Also listens to media-
21
- * related actions and performs corresponding operations with tracks.
19
+ * Middleware that captures LIB_DID_DISPOSE and LIB_DID_INIT actions and,
20
+ * respectively, creates/destroys local media tracks. Also listens to
21
+ * media-related actions and performs corresponding operations with tracks.
22 22
  *
23 23
  * @param {Store} store - Redux store.
24 24
  * @returns {Function}
25 25
  */
26 26
 MiddlewareRegistry.register(store => next => action => {
27 27
     switch (action.type) {
28
-    case LIB_INITIALIZED:
29
-        store.dispatch(createLocalTracks());
28
+    case LIB_DID_DISPOSE:
29
+        store.dispatch(destroyLocalTracks());
30 30
         break;
31 31
 
32
-    case LIB_DISPOSED:
33
-        store.dispatch(destroyLocalTracks());
32
+    case LIB_DID_INIT:
33
+        store.dispatch(createLocalTracks());
34 34
         break;
35 35
 
36 36
     case SET_AUDIO_MUTED:

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