浏览代码

Introduce features/base/config

The config object defined by lib-jitsi-meet is not used by
lib-jitsi-meet only, jitsi-meet respects its values as well.
Moreover, jitsi-meet defined classes and/or functions which manipulate
that config object. Consequently, it makes sense to move the config
object and the associated classes and functions in a dedicated feature.
master
Lyubo Marinov 8 年前
父节点
当前提交
92e765ea21

+ 2
- 1
react/features/app/actions.js 查看文件

1
 import { setRoom } from '../base/conference';
1
 import { setRoom } from '../base/conference';
2
+import { setConfig } from '../base/config';
2
 import { getDomain, setDomain } from '../base/connection';
3
 import { getDomain, setDomain } from '../base/connection';
3
-import { loadConfig, setConfig } from '../base/lib-jitsi-meet';
4
+import { loadConfig } from '../base/lib-jitsi-meet';
4
 
5
 
5
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
6
 import {
7
 import {

+ 2
- 2
react/features/base/conference/actions.js 查看文件

254
 
254
 
255
         dispatch(_conferenceWillJoin(room));
255
         dispatch(_conferenceWillJoin(room));
256
 
256
 
257
-        const { config } = state['features/base/lib-jitsi-meet'];
257
+        const config = state['features/base/config'];
258
         const conference
258
         const conference
259
             = connection.initJitsiConference(
259
             = connection.initJitsiConference(
260
 
260
 
368
 export function setLastN(lastN: ?number) {
368
 export function setLastN(lastN: ?number) {
369
     return (dispatch: Dispatch<*>, getState: Function) => {
369
     return (dispatch: Dispatch<*>, getState: Function) => {
370
         if (typeof lastN === 'undefined') {
370
         if (typeof lastN === 'undefined') {
371
-            const { config } = getState()['features/base/lib-jitsi-meet'];
371
+            const config = getState()['features/base/config'];
372
 
372
 
373
             /* eslint-disable no-param-reassign */
373
             /* eslint-disable no-param-reassign */
374
 
374
 

+ 14
- 0
react/features/base/config/actionTypes.js 查看文件

1
+import { Symbol } from '../react';
2
+
3
+/**
4
+ * The redux action which sets the configuration represented by the feature
5
+ * base/config. The configuration is defined and consumed by the library
6
+ * lib-jitsi-meet but some of its properties are consumed by the application
7
+ * jitsi-meet as well.
8
+ *
9
+ * {
10
+ *     type: SET_CONFIG,
11
+ *     config: Object
12
+ * }
13
+ */
14
+export const SET_CONFIG = Symbol('SET_CONFIG');

+ 22
- 0
react/features/base/config/actions.js 查看文件

1
+/* @flow */
2
+
3
+import { SET_CONFIG } from './actionTypes';
4
+
5
+/**
6
+ * Sets the configuration represented by the feature base/config. The
7
+ * configuration is defined and consumed by the library lib-jitsi-meet but some
8
+ * of its properties are consumed by the application jitsi-meet as well.
9
+ *
10
+ * @param {Object} config - The configuration to be represented by the feature
11
+ * base/config.
12
+ * @returns {{
13
+ *     type: SET_CONFIG,
14
+ *     config: Object
15
+ * }}
16
+ */
17
+export function setConfig(config: Object) {
18
+    return {
19
+        type: SET_CONFIG,
20
+        config
21
+    };
22
+}

+ 4
- 0
react/features/base/config/index.js 查看文件

1
+export * from './actions';
2
+export * from './actionTypes';
3
+
4
+import './reducer';

+ 63
- 0
react/features/base/config/reducer.js 查看文件

1
+import { ReducerRegistry } from '../redux';
2
+
3
+import { SET_CONFIG } from './actionTypes';
4
+
5
+/**
6
+ * The initial state of the feature base/config. The mandatory configuration to
7
+ * be passed to JitsiMeetJS#init(). The app will download config.js from the
8
+ * Jitsi Meet deployment and take its values into account but the values bellow
9
+ * will be enforced (because they are essential to the correct execution of the
10
+ * application).
11
+ *
12
+ * @type {Object}
13
+ */
14
+const INITIAL_STATE = {
15
+    // FIXME The support for audio levels in lib-jitsi-meet polls the statistics
16
+    // of WebRTC at a short interval multiple times a second. Unfortunately,
17
+    // React Native is slow to fetch these statistics from the native WebRTC
18
+    // API, through the React Native bridge and eventually to JavaScript.
19
+    // Because the audio levels are of no interest to the mobile app, it is
20
+    // fastest to merely disable them.
21
+    disableAudioLevels: true,
22
+
23
+    // FIXME Lib-jitsi-meet uses HTML script elements to asynchronously load
24
+    // certain pieces of JavaScript. Unfortunately, the technique doesn't work
25
+    // on React Native (because there are no HTML elements in the first place).
26
+    // Fortunately, these pieces of JavaScript currently involve third parties
27
+    // and we can temporarily disable them (until we implement an alternative to
28
+    // async script elements on React Native).
29
+    disableThirdPartyRequests: true
30
+};
31
+
32
+ReducerRegistry.register(
33
+    'features/base/config',
34
+    (state = INITIAL_STATE, action) => {
35
+        switch (action.type) {
36
+        case SET_CONFIG:
37
+            return _setConfig(state, action);
38
+
39
+        default:
40
+            return state;
41
+        }
42
+    });
43
+
44
+/**
45
+ * Reduces a specific Redux action SET_CONFIG of the feature
46
+ * base/lib-jitsi-meet.
47
+ *
48
+ * @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
49
+ * @param {Action} action - The Redux action SET_CONFIG to reduce.
50
+ * @private
51
+ * @returns {Object} The new state of the feature base/lib-jitsi-meet after the
52
+ * reduction of the specified action.
53
+ */
54
+function _setConfig(state, action) {
55
+    return {
56
+        ...action.config,
57
+
58
+        // The config of INITIAL_STATE is meant to override the config
59
+        // downloaded from the Jitsi Meet deployment because the former contains
60
+        // values that are mandatory.
61
+        ...INITIAL_STATE
62
+    };
63
+}

+ 0
- 10
react/features/base/lib-jitsi-meet/actionTypes.js 查看文件

49
  */
49
  */
50
 export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
50
 export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
51
 
51
 
52
-/**
53
- * Action to signal that config was set.
54
- *
55
- * {
56
- *     type: SET_CONFIG,
57
- *     config: Object
58
- * }
59
- */
60
-export const SET_CONFIG = Symbol('SET_CONFIG');
61
-
62
 /**
52
 /**
63
  * The type of Redux action which indicates whether WebRTC is ready.
53
  * The type of Redux action which indicates whether WebRTC is ready.
64
  *
54
  *

+ 1
- 19
react/features/base/lib-jitsi-meet/actions.js 查看文件

7
     LIB_INIT_ERROR,
7
     LIB_INIT_ERROR,
8
     LIB_WILL_DISPOSE,
8
     LIB_WILL_DISPOSE,
9
     LIB_WILL_INIT,
9
     LIB_WILL_INIT,
10
-    SET_CONFIG,
11
     SET_WEBRTC_READY
10
     SET_WEBRTC_READY
12
 } from './actionTypes';
11
 } from './actionTypes';
13
 
12
 
42
  */
41
  */
43
 export function initLib() {
42
 export function initLib() {
44
     return (dispatch: Dispatch<*>, getState: Function) => {
43
     return (dispatch: Dispatch<*>, getState: Function) => {
45
-        const { config } = getState()['features/base/lib-jitsi-meet'];
44
+        const config = getState()['features/base/config'];
46
 
45
 
47
         if (!config) {
46
         if (!config) {
48
             throw new Error('Cannot init lib-jitsi-meet without config');
47
             throw new Error('Cannot init lib-jitsi-meet without config');
85
     };
84
     };
86
 }
85
 }
87
 
86
 
88
-/**
89
- * Sets config.
90
- *
91
- * @param {Object} config - The config(uration) object in the format accepted by
92
- * the JitsiMeetJS.init() method.
93
- * @returns {{
94
- *     type: SET_CONFIG,
95
- *     config: Object
96
- * }}
97
- */
98
-export function setConfig(config: Object) {
99
-    return {
100
-        type: SET_CONFIG,
101
-        config
102
-    };
103
-}
104
-
105
 /**
87
 /**
106
  * Sets the indicator which determines whether WebRTC is ready. In execution
88
  * Sets the indicator which determines whether WebRTC is ready. In execution
107
  * environments in which WebRTC is supported via a known plugin such
89
  * environments in which WebRTC is supported via a known plugin such

+ 4
- 1
react/features/base/lib-jitsi-meet/middleware.js 查看文件

1
+/* @flow */
2
+
3
+import { SET_CONFIG } from '../config';
1
 import { PARTICIPANT_LEFT } from '../participants';
4
 import { PARTICIPANT_LEFT } from '../participants';
2
 import { MiddlewareRegistry } from '../redux';
5
 import { MiddlewareRegistry } from '../redux';
3
 
6
 
4
 import { disposeLib, initLib, setWebRTCReady } from './actions';
7
 import { disposeLib, initLib, setWebRTCReady } from './actions';
5
-import { LIB_DID_INIT, LIB_INIT_ERROR, SET_CONFIG } from './actionTypes';
8
+import { LIB_DID_INIT, LIB_INIT_ERROR } from './actionTypes';
6
 import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
9
 import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
7
 
10
 
8
 /**
11
 /**

+ 3
- 59
react/features/base/lib-jitsi-meet/reducer.js 查看文件

4
     LIB_DID_DISPOSE,
4
     LIB_DID_DISPOSE,
5
     LIB_DID_INIT,
5
     LIB_DID_INIT,
6
     LIB_INIT_ERROR,
6
     LIB_INIT_ERROR,
7
-    SET_CONFIG,
8
     SET_WEBRTC_READY
7
     SET_WEBRTC_READY
9
 } from './actionTypes';
8
 } from './actionTypes';
10
 
9
 
11
 /**
10
 /**
12
- * The initial state of 'features/base/lib-jitsi-meet'.
11
+ * The initial state of the feature base/lib-jitsi-meet.
13
  *
12
  *
14
- * @type {{
15
- *     config: Object
16
- * }}
13
+ * @type {Object}
17
  */
14
  */
18
-const INITIAL_STATE = {
19
-    /**
20
-     * The mandatory configuration to be passed to JitsiMeetJS#init(). The app
21
-     * will download config.js from the Jitsi Meet deployment and taks its
22
-     * values into account but the values bellow will be enforced (because they
23
-     * are essential to the correct execution of the application).
24
-     *
25
-     * @type {Object}
26
-     */
27
-    config: {
28
-        // FIXME The support for audio levels in lib-jitsi-meet polls the
29
-        // statistics of WebRTC at a short interval multiple times a second.
30
-        // Unfortunately, React Native is slow to fetch these statistics from
31
-        // the native WebRTC API, through the React Native bridge and eventually
32
-        // to JavaScript. Because the audio levels are of no interest to the
33
-        // mobile app, it is fastest to merely disable them.
34
-        disableAudioLevels: true,
35
-
36
-        // FIXME Lib-jitsi-meet uses HTML script elements to asynchronously load
37
-        // certain pieces of JavaScript. Unfortunately, the technique doesn't
38
-        // work on React Native (because there are no HTML elements in the first
39
-        // place). Fortunately, these pieces of JavaScript currently involve
40
-        // third parties and we can temporarily disable them (until we implement
41
-        // an alternative to async script elements on React Native).
42
-        disableThirdPartyRequests: true
43
-    }
44
-};
15
+const INITIAL_STATE = {};
45
 
16
 
46
 ReducerRegistry.register(
17
 ReducerRegistry.register(
47
     'features/base/lib-jitsi-meet',
18
     'features/base/lib-jitsi-meet',
64
                 initialized: false
35
                 initialized: false
65
             };
36
             };
66
 
37
 
67
-        case SET_CONFIG:
68
-            return _setConfig(state, action);
69
-
70
         case SET_WEBRTC_READY:
38
         case SET_WEBRTC_READY:
71
             return {
39
             return {
72
                 ...state,
40
                 ...state,
77
             return state;
45
             return state;
78
         }
46
         }
79
     });
47
     });
80
-
81
-/**
82
- * Reduces a specific Redux action SET_CONFIG of the feature
83
- * base/lib-jitsi-meet.
84
- *
85
- * @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
86
- * @param {Action} action - The Redux action SET_CONFIG to reduce.
87
- * @private
88
- * @returns {Object} The new state of the feature base/lib-jitsi-meet after the
89
- * reduction of the specified action.
90
- */
91
-function _setConfig(state, action) {
92
-    return {
93
-        ...state,
94
-        config: {
95
-            ...action.config,
96
-
97
-            // The config of INITIAL_STATE is meant to override the config
98
-            // downloaded from the Jitsi Meet deployment because the former
99
-            // contains values that are mandatory.
100
-            ...INITIAL_STATE.config
101
-        }
102
-    };
103
-}

正在加载...
取消
保存