Bladeren bron

Separate handling config and profile with precedence (#2784)

master
Zoltan Bettenbuk 7 jaren geleden
bovenliggende
commit
78ff0f7864

+ 1
- 23
react/features/app/actions.js Bestand weergeven

@@ -124,10 +124,8 @@ function _appNavigateToMandatoryLocation(
124 124
             });
125 125
         }
126 126
 
127
-        const profile = getState()['features/base/profile'];
128
-
129 127
         return promise.then(() =>
130
-            dispatch(setConfig(_mergeConfigWithProfile(config, profile))));
128
+            dispatch(setConfig(config)));
131 129
     }
132 130
 }
133 131
 
@@ -290,23 +288,3 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
290 288
             throw error;
291 289
         });
292 290
 }
293
-
294
-/**
295
- * Merges the downloaded config with the current profile values. The profile
296
- * values are named the same way as the config values in the config.js so
297
- * a clean merge is possible.
298
- *
299
- * @param {Object|undefined} config - The downloaded config.
300
- * @param {Object} profile - The persisted profile.
301
- * @returns {Object}
302
- */
303
-function _mergeConfigWithProfile(config, profile) {
304
-    if (!config) {
305
-        return;
306
-    }
307
-
308
-    return {
309
-        ...config,
310
-        ...profile
311
-    };
312
-}

+ 8
- 32
react/features/base/media/middleware.js Bestand weergeven

@@ -7,8 +7,8 @@ import {
7 7
     sendAnalytics
8 8
 } from '../../analytics';
9 9
 import { SET_ROOM, setAudioOnly } from '../conference';
10
-import { parseURLParams } from '../config';
11 10
 import JitsiMeetJS from '../lib-jitsi-meet';
11
+import { getPropertyValue } from '../profile';
12 12
 import { MiddlewareRegistry } from '../redux';
13 13
 import { setTrackMuted, TRACK_ADDED } from '../tracks';
14 14
 
@@ -60,34 +60,13 @@ function _setRoom({ dispatch, getState }, next, action) {
60 60
     // Read the config.
61 61
 
62 62
     const state = getState();
63
-    let urlParams;
64
-    let audioMuted;
65
-    let videoMuted;
66 63
 
67
-    if (room) {
68
-        // The Jitsi Meet client may override the Jitsi Meet deployment in the
69
-        // (location) URL on the subject of the following:
70
-        // - startAudioOnly
71
-        // - startWithAudioMuted
72
-        // - startWithVideoMuted
73
-        urlParams
74
-            = parseURLParams(state['features/base/connection'].locationURL);
75
-
76
-        audioMuted = urlParams['config.startWithAudioMuted'];
77
-        videoMuted = urlParams['config.startWithVideoMuted'];
78
-    }
79
-
80
-    // Of course, the Jitsi Meet deployment defines config.js which should be
81
-    // respected if the client did not override it.
82
-    const config = state['features/base/config'];
83
-
84
-    typeof audioMuted === 'undefined'
85
-        && (audioMuted = config.startWithAudioMuted);
86
-    typeof videoMuted === 'undefined'
87
-        && (videoMuted = config.startWithVideoMuted);
88
-
89
-    audioMuted = Boolean(audioMuted);
90
-    videoMuted = Boolean(videoMuted);
64
+    const audioMuted = Boolean(getPropertyValue(state, 'startWithAudioMuted', {
65
+        ignoreUrlParams: !room
66
+    }));
67
+    const videoMuted = Boolean(getPropertyValue(state, 'startWithVideoMuted', {
68
+        ignoreUrlParams: !room
69
+    }));
91 70
 
92 71
     sendAnalytics(createStartMutedConfigurationEvent(
93 72
         'local', audioMuted, videoMuted));
@@ -113,10 +92,7 @@ function _setRoom({ dispatch, getState }, next, action) {
113 92
         let audioOnly;
114 93
 
115 94
         if (JitsiMeetJS.mediaDevices.supportsVideo()) {
116
-            audioOnly = urlParams && urlParams['config.startAudioOnly'];
117
-            typeof audioOnly === 'undefined'
118
-                && (audioOnly = config.startAudioOnly);
119
-            audioOnly = Boolean(audioOnly);
95
+            audioOnly = Boolean(getPropertyValue(state, 'startAudioOnly'));
120 96
         } else {
121 97
             // Always default to being audio only if the current environment
122 98
             // does not support sending or receiving video.

+ 68
- 0
react/features/base/profile/functions.js Bestand weergeven

@@ -0,0 +1,68 @@
1
+// @flow
2
+
3
+import { parseURLParams } from '../config';
4
+import { toState } from '../redux';
5
+
6
+/**
7
+ * Returns the effective value of a property by applying a precedence
8
+ * between values in URL, config and profile.
9
+ *
10
+ * @param {Object|Function} stateful - The redux state object or function
11
+ * to retreive the state.
12
+ * @param {string} propertyName - The name of the property we need.
13
+ * @param {{
14
+ *     ignoreJWT: boolean,
15
+ *     ignoreUrlParams: boolean,
16
+ *     ignoreProfile: boolean,
17
+ *     ignoreConfig: boolean
18
+ * }} precedence - A structure of booleans to set which property sources
19
+ * should be ignored.
20
+ * @returns {any}
21
+ */
22
+export function getPropertyValue(
23
+        stateful: Object | Function,
24
+        propertyName: string,
25
+        precedence: Object = {
26
+            ignoreJWT: false,
27
+            ignoreUrlParams: false,
28
+            ignoreProfile: false,
29
+            ignoreConfig: false
30
+        }
31
+) {
32
+    const state = toState(stateful);
33
+    const jwt = state['features/base/jwt'];
34
+    const urlParams
35
+        = parseURLParams(state['features/base/connection'].locationURL);
36
+    const profile = state['features/base/profile'];
37
+    const config = state['features/base/config'];
38
+    const urlParamName = `config.${propertyName}`;
39
+
40
+    // Precedence: jwt -> urlParams -> profile -> config
41
+
42
+    if (
43
+        !precedence.ignoreJWT
44
+        && typeof jwt[propertyName] !== 'undefined'
45
+    ) {
46
+        return jwt[propertyName];
47
+    }
48
+
49
+    if (
50
+        !precedence.ignoreUrlParams
51
+        && typeof urlParams[urlParamName] !== 'undefined'
52
+    ) {
53
+        return urlParams[urlParamName];
54
+    }
55
+
56
+    if (
57
+        !precedence.ignoreProfile
58
+        && typeof profile[propertyName] !== 'undefined'
59
+    ) {
60
+        return profile[propertyName];
61
+    }
62
+
63
+    if (!precedence.ignoreConfig) {
64
+        return config[propertyName];
65
+    }
66
+
67
+    return undefined;
68
+}

+ 1
- 0
react/features/base/profile/index.js Bestand weergeven

@@ -1,4 +1,5 @@
1 1
 export * from './actions';
2
+export * from './functions';
2 3
 
3 4
 import './middleware';
4 5
 import './reducer';

Laden…
Annuleren
Opslaan