2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../app/types';
|
2023-02-23 18:43:16 +00:00
|
|
|
import { iAmVisitor } from '../../visitors/functions';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { IStateful } from '../app/types';
|
|
|
|
import CONFIG_WHITELIST from '../config/configWhitelist';
|
|
|
|
import { IConfigState } from '../config/reducer';
|
|
|
|
import { IJwtState } from '../jwt/reducer';
|
|
|
|
import { toState } from '../redux/functions';
|
|
|
|
import { parseURLParams } from '../util/parseURLParams';
|
2018-04-11 17:02:31 +00:00
|
|
|
|
2018-07-11 08:57:07 +00:00
|
|
|
import { DEFAULT_SERVER_URL } from './constants';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { ISettingsState } from './reducer';
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2018-04-11 17:02:31 +00:00
|
|
|
/**
|
2018-04-13 10:57:12 +00:00
|
|
|
* Returns the effective value of a configuration/preference/setting by applying
|
2018-04-12 19:58:20 +00:00
|
|
|
* a precedence among the values specified by JWT, URL, settings,
|
|
|
|
* and config.
|
2018-04-11 17:02:31 +00:00
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {Object|Function} stateful - The redux state object or {@code getState} function.
|
2018-04-13 10:57:12 +00:00
|
|
|
* @param {string} propertyName - The name of the
|
|
|
|
* configuration/preference/setting (property) to retrieve.
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {Object} sources - Flags indicating the configuration/preference/setting sources to
|
|
|
|
* consider/retrieve values from.
|
|
|
|
* @param {boolean} sources.config - Config.
|
|
|
|
* @param {boolean} jwt - JWT.
|
|
|
|
* @param {boolean} settings - Settings.
|
|
|
|
* @param {boolean} urlParams - URL parameters.
|
2018-04-11 17:02:31 +00:00
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
export function getPropertyValue(
|
2022-09-14 07:54:56 +00:00
|
|
|
stateful: IStateful,
|
2018-04-11 17:02:31 +00:00
|
|
|
propertyName: string,
|
2022-09-14 07:54:56 +00:00
|
|
|
sources?: any
|
2018-04-11 17:02:31 +00:00
|
|
|
) {
|
2018-04-13 10:57:12 +00:00
|
|
|
// Default values don't play nicely with partial objects and we want to make
|
|
|
|
// the function easy to use without exhaustively defining all flags:
|
|
|
|
sources = { // eslint-disable-line no-param-reassign
|
|
|
|
// Defaults:
|
|
|
|
config: true,
|
|
|
|
jwt: true,
|
2018-04-12 19:58:20 +00:00
|
|
|
settings: true,
|
2018-04-13 10:57:12 +00:00
|
|
|
urlParams: true,
|
|
|
|
|
|
|
|
...sources
|
|
|
|
};
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
// Precedence: jwt -> urlParams -> settings -> config.
|
2018-04-13 10:57:12 +00:00
|
|
|
|
2018-04-11 17:02:31 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// jwt
|
|
|
|
if (sources.jwt) {
|
2022-09-14 07:54:56 +00:00
|
|
|
const value = state['features/base/jwt'][propertyName as keyof IJwtState];
|
2018-04-11 17:02:31 +00:00
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
2022-09-14 07:54:56 +00:00
|
|
|
return value[propertyName as keyof typeof value];
|
2018-04-13 10:57:12 +00:00
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// urlParams
|
|
|
|
if (sources.urlParams) {
|
2019-11-01 13:24:52 +00:00
|
|
|
if (CONFIG_WHITELIST.indexOf(propertyName) !== -1) {
|
|
|
|
const urlParams
|
2022-09-14 07:54:56 +00:00
|
|
|
= parseURLParams(state['features/base/connection'].locationURL ?? '');
|
2019-11-01 13:24:52 +00:00
|
|
|
const value = urlParams[`config.${propertyName}`];
|
2018-04-13 10:57:12 +00:00
|
|
|
|
2019-11-01 13:24:52 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-13 10:57:12 +00:00
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
// settings
|
|
|
|
if (sources.settings) {
|
2022-09-14 07:54:56 +00:00
|
|
|
const value = state['features/base/settings'][propertyName as keyof ISettingsState];
|
2018-04-13 10:57:12 +00:00
|
|
|
|
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// config
|
|
|
|
if (sources.config) {
|
2022-09-14 07:54:56 +00:00
|
|
|
const value = state['features/base/config'][propertyName as keyof IConfigState];
|
2018-04-13 10:57:12 +00:00
|
|
|
|
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
2018-07-11 08:57:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the currently configured server URL.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string} - The currently configured server URL.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function getServerURL(stateful: IStateful) {
|
2018-07-11 08:57:07 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
|
|
|
|
return state['features/base/settings'].serverURL || DEFAULT_SERVER_URL;
|
|
|
|
}
|
2019-05-07 08:53:01 +00:00
|
|
|
|
2021-07-07 08:07:30 +00:00
|
|
|
/**
|
|
|
|
* Should we hide the helper dialog when a user tries to do audio only screen sharing.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the application.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function shouldHideShareAudioHelper(state: IReduxState): boolean | undefined {
|
2021-07-07 08:07:30 +00:00
|
|
|
|
|
|
|
return state['features/base/settings'].hideShareAudioHelper;
|
|
|
|
}
|
2021-12-16 16:55:45 +00:00
|
|
|
|
|
|
|
/**
|
2023-02-08 18:39:08 +00:00
|
|
|
* Gets the disabled self view setting.
|
2021-12-16 16:55:45 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getHideSelfView(state: IReduxState) {
|
2023-02-08 18:39:08 +00:00
|
|
|
return state['features/base/config'].disableSelfView || state['features/base/settings'].disableSelfView
|
2023-02-23 18:43:16 +00:00
|
|
|
|| iAmVisitor(state);
|
2021-12-16 16:55:45 +00:00
|
|
|
}
|