Selaa lähdekoodia

ref(config): override config from URL on mobile

Moves the things around to be able to override the config with the URL
params specified in the hash part of the location URI to which the app
is navigating to.
master
paweldomas 7 vuotta sitten
vanhempi
commit
ef52f09910

+ 33
- 8
react/features/base/config/actions.js Näytä tiedosto

@@ -1,10 +1,13 @@
1
-/* @flow */
1
+// @flow
2
+
3
+import type { Dispatch } from 'redux';
2 4
 
3 5
 import {
4 6
     CONFIG_WILL_LOAD,
5 7
     LOAD_CONFIG_ERROR,
6 8
     SET_CONFIG
7 9
 } from './actionTypes';
10
+import { setConfigFromURLParams } from './functions';
8 11
 
9 12
 /**
10 13
  * Signals that the configuration for a specific locationURL will be loaded now.
@@ -51,14 +54,36 @@ export function loadConfigError(error: Error, locationURL: string | URL) {
51 54
  *
52 55
  * @param {Object} config - The configuration to be represented by the feature
53 56
  * base/config.
54
- * @returns {{
55
- *     type: SET_CONFIG,
56
- *     config: Object
57
- * }}
57
+ * @returns {Function}
58 58
  */
59 59
 export function setConfig(config: Object = {}) {
60
-    return {
61
-        type: SET_CONFIG,
62
-        config
60
+    return (dispatch: Dispatch<*>, getState: Function) => {
61
+        const { locationURL } = getState()['features/base/connection'];
62
+
63
+        // Now that the loading of the config was successful override the values
64
+        // with the parameters passed in the hash part of the location URI.
65
+        // TODO We're still in the middle ground between old Web with config,
66
+        // interfaceConfig, and loggingConfig used via global variables and new
67
+        // Web and mobile reading the respective values from the redux store.
68
+        // On React Native there's no interfaceConfig at all yet and
69
+        // loggingConfig is not loaded but there's a default value in the redux
70
+        // store.
71
+        // Only the config will be overridden on React Native, as the other
72
+        // globals will be undefined here. It's intentional - we do not care to
73
+        // override those configs yet.
74
+        locationURL
75
+            && setConfigFromURLParams(
76
+
77
+                // On Web the config also comes from the window.config global,
78
+                // but it is resolved in the loadConfig procedure.
79
+                config,
80
+                window.interfaceConfig,
81
+                window.loggingConfig,
82
+                locationURL);
83
+
84
+        dispatch({
85
+            type: SET_CONFIG,
86
+            config
87
+        });
63 88
     };
64 89
 }

+ 41
- 29
react/features/base/config/functions.js Näytä tiedosto

@@ -179,7 +179,7 @@ export function obtainConfig(
179 179
  * @returns {void}
180 180
  */
181 181
 export function overrideConfigJSON(
182
-        config: Object, interfaceConfig: Object, loggingConfig: Object,
182
+        config: ?Object, interfaceConfig: ?Object, loggingConfig: ?Object,
183 183
         json: Object) {
184 184
     for (const configName of Object.keys(json)) {
185 185
         let configObj;
@@ -212,6 +212,8 @@ export function overrideConfigJSON(
212 212
     }
213 213
 }
214 214
 
215
+/* eslint-enable max-params, no-shadow */
216
+
215 217
 /**
216 218
  * Whitelist only config.js, skips this for others configs
217 219
  * (interfaceConfig, loggingConfig).
@@ -220,9 +222,9 @@ export function overrideConfigJSON(
220 222
  * @param {string} configName - The config name, one of config,
221 223
  * interfaceConfig, loggingConfig.
222 224
  * @param {Object} configJSON - The object with keys and values to override.
225
+ * @private
223 226
  * @returns {Object} - The result object only with the keys
224 227
  * that are whitelisted.
225
- * @private
226 228
  */
227 229
 function _getWhitelistedJSON(configName, configJSON) {
228 230
     if (configName !== 'config') {
@@ -232,40 +234,48 @@ function _getWhitelistedJSON(configName, configJSON) {
232 234
     return _.pick(configJSON, WHITELISTED_KEYS);
233 235
 }
234 236
 
235
-/* eslint-enable max-params, no-shadow */
237
+/* eslint-disable max-params */
236 238
 
237 239
 /**
238
- * Converts 'URL_PARAMS' to JSON object.
239
- * We have:
240
- * {
241
- *      "config.disableAudioLevels": false,
242
- *      "config.channelLastN": -1,
243
- *      "interfaceConfig.APP_NAME": "Jitsi Meet"
244
- * }.
245
- * We want to have:
246
- * {
247
- *      "config": {
248
- *          "disableAudioLevels": false,
249
- *          "channelLastN": -1
250
- *      },
251
- *      interfaceConfig: {
252
- *          "APP_NAME": "Jitsi Meet"
253
- *      }
254
- * }.
240
+ * Inspects the hash part of the location URI and overrides values specified
241
+ * there in the corresponding config objects given as the arguments. The syntax
242
+ * is: {@code https://server.com/room#config.debug=true
243
+ * &interfaceConfig.showButton=false&loggingConfig.something=1}.
255 244
  *
245
+ * In the hash part each parameter will be parsed to JSON and then the root
246
+ * object will be matched with the corresponding config object given as the
247
+ * argument to this function.
248
+ *
249
+ * @param {Object} config - This is the general config.
250
+ * @param {Object} interfaceConfig - This is the interface config.
251
+ * @param {Object} loggingConfig - The logging config.
252
+ * @param {URI} location - The new location to which the app is navigating to.
256 253
  * @returns {void}
257 254
  */
258
-export function setConfigFromURLParams() {
259
-    const params = parseURLParams(window.location);
260
-
261
-    const { config, interfaceConfig, loggingConfig } = window;
255
+export function setConfigFromURLParams(
256
+        config: ?Object,
257
+        interfaceConfig: ?Object,
258
+        loggingConfig: ?Object,
259
+        location: Object) {
260
+    const params = parseURLParams(location);
262 261
     const json = {};
263 262
 
264
-    // TODO We're still in the middle ground between old Web with config,
265
-    // interfaceConfig, and loggingConfig used via global variables and new Web
266
-    // and mobile reading the respective values from the redux store. On React
267
-    // Native there's no interfaceConfig at all yet and loggingConfig is not
268
-    // loaded but there's a default value in the redux store.
263
+    // At this point we have:
264
+    // params = {
265
+    //     "config.disableAudioLevels": false,
266
+    //     "config.channelLastN": -1,
267
+    //     "interfaceConfig.APP_NAME": "Jitsi Meet"
268
+    // }
269
+    // We want to have:
270
+    // json = {
271
+    //     config: {
272
+    //         "disableAudioLevels": false,
273
+    //         "channelLastN": -1
274
+    //     },
275
+    //     interfaceConfig: {
276
+    //         "APP_NAME": "Jitsi Meet"
277
+    //     }
278
+    // }
269 279
     config && (json.config = {});
270 280
     interfaceConfig && (json.interfaceConfig = {});
271 281
     loggingConfig && (json.loggingConfig = {});
@@ -284,3 +294,5 @@ export function setConfigFromURLParams() {
284 294
 
285 295
     overrideConfigJSON(config, interfaceConfig, loggingConfig, json);
286 296
 }
297
+
298
+/* eslint-enable max-params */

+ 4
- 14
react/features/base/lib-jitsi-meet/functions.js Näytä tiedosto

@@ -1,6 +1,5 @@
1 1
 // @flow
2 2
 
3
-import { setConfigFromURLParams } from '../config';
4 3
 import { toState } from '../redux';
5 4
 import { loadScript } from '../util';
6 5
 
@@ -12,7 +11,7 @@ const JitsiConferenceErrors = JitsiMeetJS.errors.conference;
12 11
 const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
13 12
 
14 13
 /**
15
- * Creates a JitsiLocalTrack model from the given device id.
14
+ * Creates a {@link JitsiLocalTrack} model from the given device id.
16 15
  *
17 16
  * @param {string} type - The media type of track being created. Expected values
18 17
  * are "video" or "audio".
@@ -107,9 +106,9 @@ export function isFatalJitsiConnectionError(error: Object | string) {
107 106
  * Loads config.js from a specific remote server.
108 107
  *
109 108
  * @param {string} url - The URL to load.
110
- * @param {number} [timeout] - The timeout for the configuration to be loaded,
111
- * in milliseconds. If not specified, a default value deamed appropriate for the
112
- * purpsoe is used.
109
+ * @param {number} [timeout] - The timeout in milliseconds for the {@code url}
110
+ * to load. If not specified, a default value deemed appropriate for the purpose
111
+ * is used.
113 112
  * @returns {Promise<Object>}
114 113
  */
115 114
 export function loadConfig(
@@ -145,14 +144,5 @@ export function loadConfig(
145 144
         promise = Promise.resolve(window.config);
146 145
     }
147 146
 
148
-    // FIXME It's neither here nor there at the time of this writing where
149
-    // config, interfaceConfig, and loggingConfig should be overwritten by URL
150
-    // params.
151
-    promise = promise.then(value => {
152
-        setConfigFromURLParams();
153
-
154
-        return value;
155
-    });
156
-
157 147
     return promise;
158 148
 }

Loading…
Peruuta
Tallenna