2019-04-30 10:24:12 +00:00
|
|
|
// @flow
|
2017-04-21 10:55:08 +00:00
|
|
|
|
2017-06-28 14:56:57 +00:00
|
|
|
import _ from 'lodash';
|
2017-05-04 15:20:41 +00:00
|
|
|
|
2018-05-14 20:49:00 +00:00
|
|
|
import { _CONFIG_STORE_PREFIX } from './constants';
|
2017-05-04 15:20:41 +00:00
|
|
|
import parseURLParams from './parseURLParams';
|
|
|
|
|
|
|
|
declare var $: Object;
|
|
|
|
|
|
|
|
/**
|
2017-12-12 19:16:55 +00:00
|
|
|
* The config keys to whitelist, the keys that can be overridden.
|
|
|
|
* Currently we can only whitelist the first part of the properties, like
|
|
|
|
* 'p2p.useStunTurn' and 'p2p.enabled' we whitelist all p2p options.
|
|
|
|
* The whitelist is used only for config.js.
|
2017-05-04 15:20:41 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type Array
|
|
|
|
*/
|
2017-12-12 19:16:55 +00:00
|
|
|
const WHITELISTED_KEYS = [
|
2019-01-10 23:39:17 +00:00
|
|
|
'_desktopSharingSourceDevice',
|
2017-12-12 19:16:55 +00:00
|
|
|
'_peerConnStatusOutOfLastNTimeout',
|
|
|
|
'_peerConnStatusRtcMuteTimeout',
|
|
|
|
'abTesting',
|
|
|
|
'autoRecord',
|
|
|
|
'autoRecordToken',
|
|
|
|
'avgRtpStatsN',
|
2018-05-23 21:52:44 +00:00
|
|
|
'callFlowsEnabled',
|
2017-12-12 19:16:55 +00:00
|
|
|
'callStatsConfIDNamespace',
|
|
|
|
'callStatsID',
|
|
|
|
'callStatsSecret',
|
2018-05-25 16:39:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The display name of the CallKit call representing the conference/meeting
|
|
|
|
* associated with this config.js including while the call is ongoing in the
|
|
|
|
* UI presented by CallKit and in the system-wide call history. The property
|
|
|
|
* is meant for use cases in which the room name is not desirable as a
|
|
|
|
* display name for CallKit purposes and the desired display name is not
|
|
|
|
* provided in the form of a JWT callee. As the value is associated with a
|
|
|
|
* conference/meeting, the value makes sense not as a deployment-wide
|
|
|
|
* configuration, only as a runtime configuration override/overwrite
|
|
|
|
* provided by, for example, Jitsi Meet SDK for iOS.
|
|
|
|
*
|
|
|
|
* @type string
|
|
|
|
*/
|
|
|
|
'callDisplayName',
|
|
|
|
|
2018-06-08 14:40:55 +00:00
|
|
|
/**
|
2018-06-08 18:08:45 +00:00
|
|
|
* The handle
|
|
|
|
* ({@link https://developer.apple.com/documentation/callkit/cxhandle}) of
|
|
|
|
* the CallKit call representing the conference/meeting associated with this
|
|
|
|
* config.js. The property is meant for use cases in which the room URL is
|
|
|
|
* not desirable as the handle for CallKit purposes. As the value is
|
2018-06-08 14:40:55 +00:00
|
|
|
* associated with a conference/meeting, the value makes sense not as a
|
|
|
|
* deployment-wide configuration, only as a runtime configuration
|
|
|
|
* override/overwrite provided by, for example, Jitsi Meet SDK for iOS.
|
|
|
|
*
|
|
|
|
* @type string
|
|
|
|
*/
|
|
|
|
'callHandle',
|
|
|
|
|
2018-05-25 16:39:38 +00:00
|
|
|
/**
|
|
|
|
* The UUID of the CallKit call representing the conference/meeting
|
|
|
|
* associated with this config.js. The property is meant for use cases in
|
|
|
|
* which Jitsi Meet is to work with a CallKit call created outside of Jitsi
|
|
|
|
* Meet and to be adopted by Jitsi Meet such as, for example, an incoming
|
|
|
|
* and/or outgoing CallKit call created by Jitsi Meet SDK for iOS
|
|
|
|
* clients/consumers prior to giving control to Jitsi Meet. As the value is
|
|
|
|
* associated with a conference/meeting, the value makes sense not as a
|
|
|
|
* deployment-wide configuration, only as a runtime configuration
|
|
|
|
* override/overwrite provided by, for example, Jitsi Meet SDK for iOS.
|
|
|
|
*
|
|
|
|
* @type string
|
|
|
|
*/
|
2018-04-18 15:11:56 +00:00
|
|
|
'callUUID',
|
2018-05-25 16:39:38 +00:00
|
|
|
|
2017-12-12 19:16:55 +00:00
|
|
|
'channelLastN',
|
|
|
|
'constraints',
|
|
|
|
'debug',
|
|
|
|
'debugAudioLevels',
|
|
|
|
'defaultLanguage',
|
|
|
|
'desktopSharingChromeDisabled',
|
|
|
|
'desktopSharingChromeExtId',
|
|
|
|
'desktopSharingChromeMinExtVersion',
|
|
|
|
'desktopSharingChromeSources',
|
2018-02-26 17:45:42 +00:00
|
|
|
'desktopSharingFrameRate',
|
2017-12-12 19:16:55 +00:00
|
|
|
'desktopSharingFirefoxDisabled',
|
|
|
|
'desktopSharingSources',
|
|
|
|
'disable1On1Mode',
|
|
|
|
'disableAEC',
|
|
|
|
'disableAGC',
|
|
|
|
'disableAP',
|
|
|
|
'disableAudioLevels',
|
|
|
|
'disableH264',
|
|
|
|
'disableHPF',
|
|
|
|
'disableNS',
|
|
|
|
'disableRemoteControl',
|
|
|
|
'disableRtx',
|
|
|
|
'disableSuspendVideo',
|
|
|
|
'displayJids',
|
2018-08-07 18:31:51 +00:00
|
|
|
'e2eping',
|
2017-12-12 19:16:55 +00:00
|
|
|
'enableDisplayNameInStats',
|
2018-06-12 16:06:10 +00:00
|
|
|
'enableLayerSuspension',
|
2017-12-12 19:16:55 +00:00
|
|
|
'enableLipSync',
|
|
|
|
'enableLocalVideoFlip',
|
2018-04-23 23:15:11 +00:00
|
|
|
'enableRemb',
|
2017-12-12 19:16:55 +00:00
|
|
|
'enableStatsID',
|
|
|
|
'enableTalkWhileMuted',
|
2018-04-23 23:15:11 +00:00
|
|
|
'enableTcc',
|
2017-12-12 19:16:55 +00:00
|
|
|
'etherpad_base',
|
|
|
|
'failICE',
|
2018-06-06 05:19:28 +00:00
|
|
|
'fileRecordingsEnabled',
|
2017-12-12 19:16:55 +00:00
|
|
|
'firefox_fake_device',
|
|
|
|
'forceJVB121Ratio',
|
2018-03-05 17:12:39 +00:00
|
|
|
'gatherStats',
|
2018-03-23 17:52:32 +00:00
|
|
|
'googleApiApplicationClientID',
|
2017-12-12 19:16:55 +00:00
|
|
|
'hiddenDomain',
|
|
|
|
'hosts',
|
|
|
|
'iAmRecorder',
|
|
|
|
'iAmSipGateway',
|
2018-02-28 19:28:47 +00:00
|
|
|
'iceTransportPolicy',
|
2017-12-12 19:16:55 +00:00
|
|
|
'ignoreStartMuted',
|
2018-06-06 05:19:28 +00:00
|
|
|
'liveStreamingEnabled',
|
2019-01-29 16:22:50 +00:00
|
|
|
'localRecording',
|
2018-04-23 23:15:11 +00:00
|
|
|
'minParticipants',
|
2017-12-12 19:16:55 +00:00
|
|
|
'nick',
|
|
|
|
'openBridgeChannel',
|
|
|
|
'p2p',
|
|
|
|
'preferH264',
|
|
|
|
'requireDisplayName',
|
|
|
|
'resolution',
|
|
|
|
'startAudioMuted',
|
|
|
|
'startAudioOnly',
|
|
|
|
'startBitrate',
|
|
|
|
'startScreenSharing',
|
|
|
|
'startVideoMuted',
|
|
|
|
'startWithAudioMuted',
|
|
|
|
'startWithVideoMuted',
|
|
|
|
'testing',
|
|
|
|
'useIPv6',
|
|
|
|
'useNicks',
|
|
|
|
'useStunTurn',
|
|
|
|
'webrtcIceTcpDisable',
|
|
|
|
'webrtcIceUdpDisable'
|
2017-05-04 15:20:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
|
|
|
// XXX The functions getRoomName and parseURLParams are split out of
|
|
|
|
// functions.js because they are bundled in both app.bundle and
|
|
|
|
// 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';
|
|
|
|
export { parseURLParams };
|
|
|
|
|
2018-07-12 03:57:44 +00:00
|
|
|
/**
|
|
|
|
* Promise wrapper on obtain config method. When HttpConfigFetch will be moved
|
|
|
|
* to React app it's better to use load config instead.
|
|
|
|
*
|
|
|
|
* @param {string} location - URL of the domain from which the config is to be
|
|
|
|
* obtained.
|
|
|
|
* @param {string} room - Room name.
|
|
|
|
* @private
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
export function obtainConfig(location: string, room: string): Promise<void> {
|
|
|
|
return new Promise((resolve, reject) =>
|
|
|
|
_obtainConfig(location, room, (success, error) => {
|
|
|
|
success ? resolve() : reject(error);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Sends HTTP POST request to specified {@code endpoint}. In request the name
|
2017-05-04 15:20:41 +00:00
|
|
|
* of the room is included in JSON format:
|
|
|
|
* {
|
|
|
|
* "rooomName": "someroom12345"
|
|
|
|
* }.
|
|
|
|
*
|
|
|
|
* @param {string} endpoint - The name of HTTP endpoint to which to send
|
|
|
|
* the HTTP POST request.
|
|
|
|
* @param {string} roomName - The name of the conference room for which config
|
|
|
|
* is requested.
|
|
|
|
* @param {Function} complete - The callback to invoke upon success or failure.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-07-12 03:57:44 +00:00
|
|
|
function _obtainConfig(endpoint: string, roomName: string, complete: Function) {
|
2017-05-04 15:20:41 +00:00
|
|
|
logger.info(`Send config request to ${endpoint} for room: ${roomName}`);
|
|
|
|
$.ajax(
|
|
|
|
endpoint,
|
|
|
|
{
|
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify({ roomName }),
|
|
|
|
dataType: 'json',
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
error(jqXHR, textStatus, errorThrown) {
|
|
|
|
logger.error('Get config error: ', jqXHR, errorThrown);
|
|
|
|
complete(false, `Get config response status: ${textStatus}`);
|
|
|
|
},
|
|
|
|
success(data) {
|
|
|
|
const { config, interfaceConfig, loggingConfig } = window;
|
|
|
|
|
|
|
|
try {
|
|
|
|
overrideConfigJSON(
|
|
|
|
config, interfaceConfig, loggingConfig,
|
|
|
|
data);
|
|
|
|
complete(true);
|
|
|
|
} catch (e) {
|
|
|
|
logger.error('Parse config error: ', e);
|
|
|
|
complete(false, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-04-21 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
/* eslint-disable max-params, no-shadow */
|
|
|
|
|
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} loggingConfig - The loggingConfig 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
|
|
|
|
* },
|
|
|
|
* loggingConfig: {
|
|
|
|
* // logging_config.js properties here
|
|
|
|
* }
|
|
|
|
* }.
|
|
|
|
* @returns {void}
|
2017-04-21 10:55:08 +00:00
|
|
|
*/
|
2017-05-04 15:20:41 +00:00
|
|
|
export function overrideConfigJSON(
|
2018-03-06 16:08:23 +00:00
|
|
|
config: ?Object, interfaceConfig: ?Object, loggingConfig: ?Object,
|
2017-05-04 15:20:41 +00:00
|
|
|
json: Object) {
|
|
|
|
for (const configName of Object.keys(json)) {
|
|
|
|
let configObj;
|
|
|
|
|
|
|
|
if (configName === 'config') {
|
|
|
|
configObj = config;
|
|
|
|
} else if (configName === 'interfaceConfig') {
|
|
|
|
configObj = interfaceConfig;
|
|
|
|
} else if (configName === 'loggingConfig') {
|
|
|
|
configObj = loggingConfig;
|
|
|
|
}
|
|
|
|
if (configObj) {
|
2017-12-12 19:16:55 +00:00
|
|
|
const configJSON
|
|
|
|
= _getWhitelistedJSON(configName, 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
|
|
|
/**
|
|
|
|
* Whitelist only config.js, skips this for others configs
|
|
|
|
* (interfaceConfig, loggingConfig).
|
|
|
|
* Only extracts overridden values for keys we allow to be overridden.
|
|
|
|
*
|
|
|
|
* @param {string} configName - The config name, one of config,
|
|
|
|
* interfaceConfig, loggingConfig.
|
|
|
|
* @param {Object} configJSON - The object with keys and values to override.
|
2018-03-06 16:08:23 +00:00
|
|
|
* @private
|
2017-12-12 19:16:55 +00:00
|
|
|
* @returns {Object} - The result object only with the keys
|
|
|
|
* that are whitelisted.
|
|
|
|
*/
|
|
|
|
function _getWhitelistedJSON(configName, configJSON) {
|
|
|
|
if (configName !== 'config') {
|
|
|
|
return configJSON;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _.pick(configJSON, WHITELISTED_KEYS);
|
|
|
|
}
|
|
|
|
|
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}.
|
|
|
|
*/
|
|
|
|
export function restoreConfig(baseURL: string): ?Object {
|
|
|
|
let storage;
|
|
|
|
const key = `${_CONFIG_STORE_PREFIX}/${baseURL}`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// XXX Even reading the property localStorage of window may throw an
|
|
|
|
// error (which is user agent-specific behavior).
|
|
|
|
storage = window.localStorage;
|
|
|
|
|
|
|
|
const config = storage.getItem(key);
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
return JSON.parse(config) || undefined;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Somehow incorrect data ended up in the storage. Clean it up.
|
|
|
|
storage && storage.removeItem(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
* &interfaceConfig.showButton=false&loggingConfig.something=1}.
|
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 {Object} loggingConfig - The logging 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(
|
|
|
|
config: ?Object,
|
|
|
|
interfaceConfig: ?Object,
|
|
|
|
loggingConfig: ?Object,
|
|
|
|
location: Object) {
|
|
|
|
const params = parseURLParams(location);
|
2017-05-04 15:20:41 +00:00
|
|
|
const json = {};
|
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 = {});
|
|
|
|
loggingConfig && (json.loggingConfig = {});
|
|
|
|
|
|
|
|
for (const param of Object.keys(params)) {
|
2017-06-28 14:56:57 +00:00
|
|
|
let base = json;
|
|
|
|
const names = param.split('.');
|
|
|
|
const last = names.pop();
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
overrideConfigJSON(config, interfaceConfig, loggingConfig, json);
|
2017-04-21 10:55:08 +00:00
|
|
|
}
|
2018-03-06 16:08:23 +00:00
|
|
|
|
|
|
|
/* eslint-enable max-params */
|