Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Separate handling config and profile with precedence (#2784)
Zoltan Bettenbuk78ff0f78646d
diff --git a/react/features/app/actions.js b/react/features/app/actions.jsindex 79167cb870..255d21f4db 100644--- a/react/features/app/actions.js+++ b/react/features/app/actions.js@@ -124,10 +124,8 @@ function _appNavigateToMandatoryLocation(});}- const profile = getState()['features/base/profile'];-return promise.then(() =>- dispatch(setConfig(_mergeConfigWithProfile(config, profile))));+ dispatch(setConfig(config)));}}@@ -290,23 +288,3 @@ function _loadConfig({ contextRoot, host, protocol, room }) {throw error;});}--/**- * Merges the downloaded config with the current profile values. The profile- * values are named the same way as the config values in the config.js so- * a clean merge is possible.- *- * @param {Object|undefined} config - The downloaded config.- * @param {Object} profile - The persisted profile.- * @returns {Object}- */-function _mergeConfigWithProfile(config, profile) {- if (!config) {- return;- }-- return {- ...config,- ...profile- };-}diff --git a/react/features/base/media/middleware.js b/react/features/base/media/middleware.jsindex d999f754f6..f44ffff7b5 100644--- a/react/features/base/media/middleware.js+++ b/react/features/base/media/middleware.js@@ -7,8 +7,8 @@ import {sendAnalytics} from '../../analytics';import { SET_ROOM, setAudioOnly } from '../conference';-import { parseURLParams } from '../config';import JitsiMeetJS from '../lib-jitsi-meet';+import { getPropertyValue } from '../profile';import { MiddlewareRegistry } from '../redux';import { setTrackMuted, TRACK_ADDED } from '../tracks';@@ -60,34 +60,13 @@ function _setRoom({ dispatch, getState }, next, action) {// Read the config.const state = getState();- let urlParams;- let audioMuted;- let videoMuted;- if (room) {- // The Jitsi Meet client may override the Jitsi Meet deployment in the- // (location) URL on the subject of the following:- // - startAudioOnly- // - startWithAudioMuted- // - startWithVideoMuted- urlParams- = parseURLParams(state['features/base/connection'].locationURL);-- audioMuted = urlParams['config.startWithAudioMuted'];- videoMuted = urlParams['config.startWithVideoMuted'];- }-- // Of course, the Jitsi Meet deployment defines config.js which should be- // respected if the client did not override it.- const config = state['features/base/config'];-- typeof audioMuted === 'undefined'- && (audioMuted = config.startWithAudioMuted);- typeof videoMuted === 'undefined'- && (videoMuted = config.startWithVideoMuted);-- audioMuted = Boolean(audioMuted);- videoMuted = Boolean(videoMuted);+ const audioMuted = Boolean(getPropertyValue(state, 'startWithAudioMuted', {+ ignoreUrlParams: !room+ }));+ const videoMuted = Boolean(getPropertyValue(state, 'startWithVideoMuted', {+ ignoreUrlParams: !room+ }));sendAnalytics(createStartMutedConfigurationEvent('local', audioMuted, videoMuted));@@ -113,10 +92,7 @@ function _setRoom({ dispatch, getState }, next, action) {let audioOnly;if (JitsiMeetJS.mediaDevices.supportsVideo()) {- audioOnly = urlParams && urlParams['config.startAudioOnly'];- typeof audioOnly === 'undefined'- && (audioOnly = config.startAudioOnly);- audioOnly = Boolean(audioOnly);+ audioOnly = Boolean(getPropertyValue(state, 'startAudioOnly'));} else {// Always default to being audio only if the current environment// does not support sending or receiving video.diff --git a/react/features/base/profile/functions.js b/react/features/base/profile/functions.jsnew file mode 100644index 0000000000..3733f9a72a--- /dev/null+++ b/react/features/base/profile/functions.js@@ -0,0 +1,68 @@+// @flow++import { parseURLParams } from '../config';+import { toState } from '../redux';++/**+ * Returns the effective value of a property by applying a precedence+ * between values in URL, config and profile.+ *+ * @param {Object|Function} stateful - The redux state object or function+ * to retreive the state.+ * @param {string} propertyName - The name of the property we need.+ * @param {{+ * ignoreJWT: boolean,+ * ignoreUrlParams: boolean,+ * ignoreProfile: boolean,+ * ignoreConfig: boolean+ * }} precedence - A structure of booleans to set which property sources+ * should be ignored.+ * @returns {any}+ */+export function getPropertyValue(+ stateful: Object | Function,+ propertyName: string,+ precedence: Object = {+ ignoreJWT: false,+ ignoreUrlParams: false,+ ignoreProfile: false,+ ignoreConfig: false+ }+) {+ const state = toState(stateful);+ const jwt = state['features/base/jwt'];+ const urlParams+ = parseURLParams(state['features/base/connection'].locationURL);+ const profile = state['features/base/profile'];+ const config = state['features/base/config'];+ const urlParamName = `config.${propertyName}`;++ // Precedence: jwt -> urlParams -> profile -> config++ if (+ !precedence.ignoreJWT+ && typeof jwt[propertyName] !== 'undefined'+ ) {+ return jwt[propertyName];+ }++ if (+ !precedence.ignoreUrlParams+ && typeof urlParams[urlParamName] !== 'undefined'+ ) {+ return urlParams[urlParamName];+ }++ if (+ !precedence.ignoreProfile+ && typeof profile[propertyName] !== 'undefined'+ ) {+ return profile[propertyName];+ }++ if (!precedence.ignoreConfig) {+ return config[propertyName];+ }++ return undefined;+}diff --git a/react/features/base/profile/index.js b/react/features/base/profile/index.jsindex dbf9c8839e..eea8d73936 100644--- a/react/features/base/profile/index.js+++ b/react/features/base/profile/index.js@@ -1,4 +1,5 @@export * from './actions';+export * from './functions';import './middleware';import './reducer';