2022-09-14 07:54:56 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
// @ts-ignore
|
2021-06-02 19:21:39 +00:00
|
|
|
import Bourne from '@hapi/bourne';
|
2022-09-14 07:54:56 +00:00
|
|
|
// @ts-ignore
|
2020-07-09 07:17:23 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
2017-06-28 14:56:57 +00:00
|
|
|
import _ from 'lodash';
|
2017-05-04 15:20:41 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../app/types';
|
2022-03-15 17:24:49 +00:00
|
|
|
import { browser } from '../lib-jitsi-meet';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { parseURLParams } from '../util/parseURLParams';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
import { IConfig } from './configType';
|
2019-09-25 17:49:29 +00:00
|
|
|
import CONFIG_WHITELIST from './configWhitelist';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { FEATURE_FLAGS, _CONFIG_STORE_PREFIX } from './constants';
|
2019-09-25 17:49:29 +00:00
|
|
|
import INTERFACE_CONFIG_WHITELIST from './interfaceConfigWhitelist';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2017-05-04 15:20:41 +00:00
|
|
|
|
2020-05-07 22:26:37 +00:00
|
|
|
// XXX The function getRoomName is split out of
|
2022-03-17 14:13:58 +00:00
|
|
|
// functions.any.js because it is bundled in both app.bundle and
|
2017-05-04 15:20:41 +00:00
|
|
|
// do_external_connect, webpack 1 does not support tree shaking, and we don't
|
|
|
|
// want all functions to be bundled in do_external_connect.
|
|
|
|
export { default as getRoomName } from './getRoomName';
|
|
|
|
|
2019-09-13 14:51:58 +00:00
|
|
|
/**
|
|
|
|
* Create a "fake" configuration object for the given base URL. This is used in case the config
|
|
|
|
* couldn't be loaded in the welcome page, so at least we have something to try with.
|
|
|
|
*
|
|
|
|
* @param {string} baseURL - URL of the deployment for which we want the fake config.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function createFakeConfig(baseURL: string) {
|
|
|
|
const url = new URL(baseURL);
|
|
|
|
|
|
|
|
return {
|
|
|
|
hosts: {
|
|
|
|
domain: url.hostname,
|
|
|
|
muc: `conference.${url.hostname}`
|
|
|
|
},
|
|
|
|
bosh: `${baseURL}http-bind`,
|
|
|
|
p2p: {
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-21 08:36:18 +00:00
|
|
|
/**
|
|
|
|
* Selector used to get the meeting region.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getMeetingRegion(state: IReduxState) {
|
2021-06-21 08:36:18 +00:00
|
|
|
return state['features/base/config']?.deploymentInfo?.region || '';
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
/**
|
2022-04-29 14:32:16 +00:00
|
|
|
* Selector for determining if receiving multiple stream support is enabled.
|
2022-03-15 17:24:49 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getMultipleVideoSupportFeatureFlag(state: IReduxState) {
|
2022-09-20 17:16:54 +00:00
|
|
|
return (getFeatureFlag(state, FEATURE_FLAGS.MULTIPLE_VIDEO_STREAMS_SUPPORT)
|
|
|
|
&& getSourceNameSignalingFeatureFlag(state)) ?? true;
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selector for determining if sending multiple stream support is enabled.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getMultipleVideoSendingSupportFeatureFlag(state: IReduxState) {
|
2022-08-29 18:23:21 +00:00
|
|
|
return navigator.product !== 'ReactNative'
|
2022-09-20 17:16:54 +00:00
|
|
|
&& ((getMultipleVideoSupportFeatureFlag(state) ?? true) && isUnifiedPlanEnabled(state));
|
2022-03-15 17:24:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 17:49:36 +00:00
|
|
|
/**
|
|
|
|
* Selector used to get the sourceNameSignaling feature flag.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getSourceNameSignalingFeatureFlag(state: IReduxState) {
|
2022-09-20 17:16:54 +00:00
|
|
|
return getFeatureFlag(state, FEATURE_FLAGS.SOURCE_NAME_SIGNALING) ?? true;
|
2021-12-16 17:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selector used to get a feature flag.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @param {string} featureFlag - The name of the feature flag.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getFeatureFlag(state: IReduxState, featureFlag: string) {
|
2021-12-16 17:49:36 +00:00
|
|
|
const featureFlags = state['features/base/config']?.flags || {};
|
|
|
|
|
2022-09-20 17:16:54 +00:00
|
|
|
return featureFlags[featureFlag as keyof typeof featureFlags];
|
2021-12-16 17:49:36 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 21:53:25 +00:00
|
|
|
/**
|
|
|
|
* Selector used to get the disableRemoveRaisedHandOnFocus.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getDisableRemoveRaisedHandOnFocus(state: IReduxState) {
|
2021-09-09 21:53:25 +00:00
|
|
|
return state['features/base/config']?.disableRemoveRaisedHandOnFocus || false;
|
|
|
|
}
|
|
|
|
|
2021-06-21 08:36:18 +00:00
|
|
|
/**
|
|
|
|
* Selector used to get the endpoint used for fetching the recording.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The global state.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getRecordingSharingUrl(state: IReduxState) {
|
2021-06-21 08:36:18 +00:00
|
|
|
return state['features/base/config'].recordingSharingUrl;
|
|
|
|
}
|
|
|
|
|
2017-04-21 10:55:08 +00:00
|
|
|
/**
|
2017-05-04 15:20:41 +00:00
|
|
|
* Overrides JSON properties in {@code config} and
|
|
|
|
* {@code interfaceConfig} Objects with the values from {@code newConfig}.
|
2017-12-12 19:16:55 +00:00
|
|
|
* Overrides only the whitelisted keys.
|
2017-04-21 10:55:08 +00:00
|
|
|
*
|
2017-05-04 15:20:41 +00:00
|
|
|
* @param {Object} config - The config Object in which we'll be overriding
|
|
|
|
* properties.
|
|
|
|
* @param {Object} interfaceConfig - The interfaceConfig Object in which we'll
|
|
|
|
* be overriding properties.
|
|
|
|
* @param {Object} json - Object containing configuration properties.
|
|
|
|
* Destination object is selected based on root property name:
|
|
|
|
* {
|
|
|
|
* config: {
|
|
|
|
* // config.js properties here
|
|
|
|
* },
|
|
|
|
* interfaceConfig: {
|
|
|
|
* // interface_config.js properties here
|
|
|
|
* }
|
|
|
|
* }.
|
|
|
|
* @returns {void}
|
2017-04-21 10:55:08 +00:00
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function overrideConfigJSON(config: IConfig, interfaceConfig: any, json: any) {
|
2017-05-04 15:20:41 +00:00
|
|
|
for (const configName of Object.keys(json)) {
|
|
|
|
let configObj;
|
|
|
|
|
|
|
|
if (configName === 'config') {
|
|
|
|
configObj = config;
|
|
|
|
} else if (configName === 'interfaceConfig') {
|
|
|
|
configObj = interfaceConfig;
|
|
|
|
}
|
|
|
|
if (configObj) {
|
2017-12-12 19:16:55 +00:00
|
|
|
const configJSON
|
2022-09-14 07:54:56 +00:00
|
|
|
= getWhitelistedJSON(configName as 'interfaceConfig' | 'config', json[configName]);
|
2017-05-04 15:20:41 +00:00
|
|
|
|
2017-06-28 14:56:57 +00:00
|
|
|
if (!_.isEmpty(configJSON)) {
|
|
|
|
logger.info(
|
2017-08-17 17:43:28 +00:00
|
|
|
`Extending ${configName} with: ${
|
|
|
|
JSON.stringify(configJSON)}`);
|
|
|
|
|
|
|
|
// eslint-disable-next-line arrow-body-style
|
|
|
|
_.mergeWith(configObj, configJSON, (oldValue, newValue) => {
|
|
|
|
|
|
|
|
// XXX We don't want to merge the arrays, we want to
|
|
|
|
// overwrite them.
|
|
|
|
return Array.isArray(oldValue) ? newValue : undefined;
|
|
|
|
});
|
2017-04-21 10:55:08 +00:00
|
|
|
}
|
2017-05-04 15:20:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 16:08:23 +00:00
|
|
|
/* eslint-enable max-params, no-shadow */
|
|
|
|
|
2017-12-12 19:16:55 +00:00
|
|
|
/**
|
2022-08-17 12:32:40 +00:00
|
|
|
* Apply whitelist filtering for configs with whitelists.
|
2017-12-12 19:16:55 +00:00
|
|
|
* Only extracts overridden values for keys we allow to be overridden.
|
|
|
|
*
|
2022-08-17 12:32:40 +00:00
|
|
|
* @param {string} configName - The config name, one of config or interfaceConfig.
|
2017-12-12 19:16:55 +00:00
|
|
|
* @param {Object} configJSON - The object with keys and values to override.
|
|
|
|
* @returns {Object} - The result object only with the keys
|
|
|
|
* that are whitelisted.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function getWhitelistedJSON(configName: 'interfaceConfig' | 'config', configJSON: any): Object {
|
2019-09-25 17:49:29 +00:00
|
|
|
if (configName === 'interfaceConfig') {
|
|
|
|
return _.pick(configJSON, INTERFACE_CONFIG_WHITELIST);
|
|
|
|
} else if (configName === 'config') {
|
|
|
|
return _.pick(configJSON, CONFIG_WHITELIST);
|
2017-12-12 19:16:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 17:49:29 +00:00
|
|
|
return configJSON;
|
2017-12-12 19:16:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 10:01:13 +00:00
|
|
|
/**
|
|
|
|
* Selector for determining if the display name is read only.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the app.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isNameReadOnly(state: IReduxState): boolean {
|
2022-09-14 07:54:56 +00:00
|
|
|
return Boolean(state['features/base/config'].disableProfile
|
|
|
|
|| state['features/base/config'].readOnlyName);
|
2021-09-06 10:01:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:17:27 +00:00
|
|
|
/**
|
|
|
|
* Selector for determining if the display name is visible.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the app.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isDisplayNameVisible(state: IReduxState): boolean {
|
2022-01-25 11:17:27 +00:00
|
|
|
return !state['features/base/config'].hideDisplayName;
|
|
|
|
}
|
2021-09-06 10:01:13 +00:00
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
/**
|
|
|
|
* Selector for determining if Unified plan support is enabled.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the app.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isUnifiedPlanEnabled(state: IReduxState): boolean {
|
2022-03-15 17:24:49 +00:00
|
|
|
const { enableUnifiedOnChrome = true } = state['features/base/config'];
|
|
|
|
|
|
|
|
return browser.supportsUnifiedPlan()
|
|
|
|
&& (!browser.isChromiumBased() || (browser.isChromiumBased() && enableUnifiedOnChrome));
|
|
|
|
}
|
|
|
|
|
2018-05-14 20:49:00 +00:00
|
|
|
/**
|
|
|
|
* Restores a Jitsi Meet config.js from {@code localStorage} if it was
|
|
|
|
* previously downloaded from a specific {@code baseURL} and stored with
|
|
|
|
* {@link storeConfig}.
|
|
|
|
*
|
|
|
|
* @param {string} baseURL - The base URL from which the config.js was
|
|
|
|
* previously downloaded and stored with {@code storeConfig}.
|
|
|
|
* @returns {?Object} The Jitsi Meet config.js which was previously downloaded
|
|
|
|
* from {@code baseURL} and stored with {@code storeConfig} if it was restored;
|
|
|
|
* otherwise, {@code undefined}.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function restoreConfig(baseURL: string) {
|
2018-05-14 20:49:00 +00:00
|
|
|
const key = `${_CONFIG_STORE_PREFIX}/${baseURL}`;
|
2020-05-01 19:48:08 +00:00
|
|
|
const config = jitsiLocalStorage.getItem(key);
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
if (config) {
|
|
|
|
try {
|
2021-06-02 19:21:39 +00:00
|
|
|
return Bourne.parse(config) || undefined;
|
2020-05-01 19:48:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Somehow incorrect data ended up in the storage. Clean it up.
|
|
|
|
jitsiLocalStorage.removeItem(key);
|
2018-05-14 20:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2018-03-06 16:08:23 +00:00
|
|
|
/* eslint-disable max-params */
|
2017-05-04 15:20:41 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-06 16:08:23 +00:00
|
|
|
* Inspects the hash part of the location URI and overrides values specified
|
|
|
|
* there in the corresponding config objects given as the arguments. The syntax
|
|
|
|
* is: {@code https://server.com/room#config.debug=true
|
2022-08-17 12:32:40 +00:00
|
|
|
* &interfaceConfig.showButton=false}.
|
2017-05-04 15:20:41 +00:00
|
|
|
*
|
2018-03-06 16:08:23 +00:00
|
|
|
* In the hash part each parameter will be parsed to JSON and then the root
|
|
|
|
* object will be matched with the corresponding config object given as the
|
|
|
|
* argument to this function.
|
|
|
|
*
|
|
|
|
* @param {Object} config - This is the general config.
|
|
|
|
* @param {Object} interfaceConfig - This is the interface config.
|
|
|
|
* @param {URI} location - The new location to which the app is navigating to.
|
2017-05-04 15:20:41 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-03-06 16:08:23 +00:00
|
|
|
export function setConfigFromURLParams(
|
2022-09-14 07:54:56 +00:00
|
|
|
config: IConfig, interfaceConfig: any, location: string | URL) {
|
2018-03-06 16:08:23 +00:00
|
|
|
const params = parseURLParams(location);
|
2022-09-14 07:54:56 +00:00
|
|
|
const json: any = {};
|
2017-04-21 10:55:08 +00:00
|
|
|
|
2018-03-06 16:08:23 +00:00
|
|
|
// At this point we have:
|
|
|
|
// params = {
|
|
|
|
// "config.disableAudioLevels": false,
|
|
|
|
// "config.channelLastN": -1,
|
|
|
|
// "interfaceConfig.APP_NAME": "Jitsi Meet"
|
|
|
|
// }
|
|
|
|
// We want to have:
|
|
|
|
// json = {
|
|
|
|
// config: {
|
|
|
|
// "disableAudioLevels": false,
|
|
|
|
// "channelLastN": -1
|
|
|
|
// },
|
|
|
|
// interfaceConfig: {
|
|
|
|
// "APP_NAME": "Jitsi Meet"
|
|
|
|
// }
|
|
|
|
// }
|
2017-05-04 15:20:41 +00:00
|
|
|
config && (json.config = {});
|
|
|
|
interfaceConfig && (json.interfaceConfig = {});
|
|
|
|
|
|
|
|
for (const param of Object.keys(params)) {
|
2017-06-28 14:56:57 +00:00
|
|
|
let base = json;
|
|
|
|
const names = param.split('.');
|
2022-09-14 07:54:56 +00:00
|
|
|
const last = names.pop() ?? '';
|
2017-06-28 14:56:57 +00:00
|
|
|
|
|
|
|
for (const name of names) {
|
|
|
|
base = base[name] = base[name] || {};
|
2017-04-21 10:55:08 +00:00
|
|
|
}
|
2017-06-28 14:56:57 +00:00
|
|
|
|
|
|
|
base[last] = params[param];
|
2017-05-04 15:20:41 +00:00
|
|
|
}
|
2017-04-21 10:55:08 +00:00
|
|
|
|
2022-08-17 12:32:40 +00:00
|
|
|
overrideConfigJSON(config, interfaceConfig, json);
|
2017-04-21 10:55:08 +00:00
|
|
|
}
|
2018-03-06 16:08:23 +00:00
|
|
|
|
|
|
|
/* eslint-enable max-params */
|