Separate handling config and profile with precedence (#2784)
This commit is contained in:
parent
76c56339c4
commit
78ff0f7864
|
@ -124,10 +124,8 @@ function _appNavigateToMandatoryLocation(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile = getState()['features/base/profile'];
|
|
||||||
|
|
||||||
return promise.then(() =>
|
return promise.then(() =>
|
||||||
dispatch(setConfig(_mergeConfigWithProfile(config, profile))));
|
dispatch(setConfig(config)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,23 +288,3 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
|
||||||
throw error;
|
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ import {
|
||||||
sendAnalytics
|
sendAnalytics
|
||||||
} from '../../analytics';
|
} from '../../analytics';
|
||||||
import { SET_ROOM, setAudioOnly } from '../conference';
|
import { SET_ROOM, setAudioOnly } from '../conference';
|
||||||
import { parseURLParams } from '../config';
|
|
||||||
import JitsiMeetJS from '../lib-jitsi-meet';
|
import JitsiMeetJS from '../lib-jitsi-meet';
|
||||||
|
import { getPropertyValue } from '../profile';
|
||||||
import { MiddlewareRegistry } from '../redux';
|
import { MiddlewareRegistry } from '../redux';
|
||||||
import { setTrackMuted, TRACK_ADDED } from '../tracks';
|
import { setTrackMuted, TRACK_ADDED } from '../tracks';
|
||||||
|
|
||||||
|
@ -60,34 +60,13 @@ function _setRoom({ dispatch, getState }, next, action) {
|
||||||
// Read the config.
|
// Read the config.
|
||||||
|
|
||||||
const state = getState();
|
const state = getState();
|
||||||
let urlParams;
|
|
||||||
let audioMuted;
|
|
||||||
let videoMuted;
|
|
||||||
|
|
||||||
if (room) {
|
const audioMuted = Boolean(getPropertyValue(state, 'startWithAudioMuted', {
|
||||||
// The Jitsi Meet client may override the Jitsi Meet deployment in the
|
ignoreUrlParams: !room
|
||||||
// (location) URL on the subject of the following:
|
}));
|
||||||
// - startAudioOnly
|
const videoMuted = Boolean(getPropertyValue(state, 'startWithVideoMuted', {
|
||||||
// - startWithAudioMuted
|
ignoreUrlParams: !room
|
||||||
// - 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);
|
|
||||||
|
|
||||||
sendAnalytics(createStartMutedConfigurationEvent(
|
sendAnalytics(createStartMutedConfigurationEvent(
|
||||||
'local', audioMuted, videoMuted));
|
'local', audioMuted, videoMuted));
|
||||||
|
@ -113,10 +92,7 @@ function _setRoom({ dispatch, getState }, next, action) {
|
||||||
let audioOnly;
|
let audioOnly;
|
||||||
|
|
||||||
if (JitsiMeetJS.mediaDevices.supportsVideo()) {
|
if (JitsiMeetJS.mediaDevices.supportsVideo()) {
|
||||||
audioOnly = urlParams && urlParams['config.startAudioOnly'];
|
audioOnly = Boolean(getPropertyValue(state, 'startAudioOnly'));
|
||||||
typeof audioOnly === 'undefined'
|
|
||||||
&& (audioOnly = config.startAudioOnly);
|
|
||||||
audioOnly = Boolean(audioOnly);
|
|
||||||
} else {
|
} else {
|
||||||
// Always default to being audio only if the current environment
|
// Always default to being audio only if the current environment
|
||||||
// does not support sending or receiving video.
|
// does not support sending or receiving video.
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
export * from './actions';
|
export * from './actions';
|
||||||
|
export * from './functions';
|
||||||
|
|
||||||
import './middleware';
|
import './middleware';
|
||||||
import './reducer';
|
import './reducer';
|
||||||
|
|
Loading…
Reference in New Issue