Beautify URLProcessor

This commit is contained in:
Ilya Daynatovich 2017-04-19 17:31:40 +03:00 committed by Lyubo Marinov
parent 96b1f0ca74
commit 3af0976a43
2 changed files with 82 additions and 56 deletions

View File

@ -1,69 +1,93 @@
/* global config, interfaceConfig, loggingConfig */ /* global config, interfaceConfig, loggingConfig */
const logger = require("jitsi-meet-logger").getLogger(__filename); import { parseURLParams } from '../../react/features/base/config';
import { getConfigParamsFromUrl } from '../../react/features/base/config';
import configUtils from './Util'; import configUtils from './Util';
// Parsing config params from URL hash. const logger = require("jitsi-meet-logger").getLogger(__filename);
const URL_PARAMS = getConfigParamsFromUrl(window.location);
var URLProcessor = { /**
setConfigParametersFromUrl: function () { * URL params with this prefix should be merged to config.
// Convert 'params' to JSON object */
// We have: const CONFIG_PREFIX = 'config.';
// {
// "config.disableAudioLevels": false, /**
// "config.channelLastN": -1, * URL params with this prefix should be merged to interface config.
// "interfaceConfig.APP_NAME": "Jitsi Meet" */
// } const INTERFACE_CONFIG_PREFIX = 'interfaceConfig.';
// We want to have:
// { /**
// "config": { * Config keys to be ignored.
// "disableAudioLevels": false, *
// "channelLastN": -1 * @type Set
// }, */
// interfaceConfig: { const KEYS_TO_IGNORE = new Set([
// APP_NAME: "Jitsi Meet" 'analyticsScriptUrls',
// } 'callStatsCustomScriptUrl'
// } ]);
var configJSON = {
/**
* URL params with this prefix should be merged to logging config.
*/
const LOGGING_CONFIG_PREFIX = 'loggingConfig.';
/**
* Convert 'URL_PARAMS' to JSON object
* We have:
* {
* "config.disableAudioLevels": false,
* "config.channelLastN": -1,
* "interfaceConfig.APP_NAME": "Jitsi Meet"
* }
* We want to have:
* {
* "config": {
* "disableAudioLevels": false,
* "channelLastN": -1
* },
* interfaceConfig: {
* "APP_NAME": "Jitsi Meet"
* }
* }
*/
export function setConfigParametersFromUrl() {
// Parsing config params from URL hash.
const params = parseURLParams(window.location);
const configJSON = {
config: {}, config: {},
interfaceConfig: {}, interfaceConfig: {},
loggingConfig: {} loggingConfig: {}
}; };
for (var key in URL_PARAMS) {
if (typeof key !== "string") { for (const key in params) {
logger.warn("Invalid config key: ", key); if (typeof key === 'string') {
continue; let confObj = null;
} let confKey;
var confObj = null, confKey;
if (key.indexOf("config.") === 0) { if (key.indexOf(CONFIG_PREFIX) === 0) {
confObj = configJSON.config; confObj = configJSON.config;
confKey = key.substr("config.".length); confKey = key.substr(CONFIG_PREFIX.length);
} else if (key.indexOf(INTERFACE_CONFIG_PREFIX) === 0) {
confObj = configJSON.interfaceConfig;
confKey
= key.substr(INTERFACE_CONFIG_PREFIX.length);
} else if (key.indexOf(LOGGING_CONFIG_PREFIX) === 0) {
confObj = configJSON.loggingConfig;
confKey = key.substr(LOGGING_CONFIG_PREFIX.length);
}
// prevent passing some parameters which can inject scripts // prevent passing some parameters which can inject scripts
if (confKey === 'analyticsScriptUrls' if (confObj && !KEYS_TO_IGNORE.has(confKey)) {
|| confKey === 'callStatsCustomScriptUrl') confObj[confKey] = params[key];
continue; }
} else {
} else if (key.indexOf("interfaceConfig.") === 0) { logger.warn('Invalid config key: ', key);
confObj = configJSON.interfaceConfig; }
confKey = key.substr("interfaceConfig.".length);
} else if (key.indexOf("loggingConfig.") === 0) {
confObj = configJSON.loggingConfig;
confKey = key.substr("loggingConfig.".length);
} }
if (!confObj)
continue;
confObj[confKey] = URL_PARAMS[key];
}
configUtils.overrideConfigJSON( configUtils.overrideConfigJSON(
config, interfaceConfig, loggingConfig, configJSON); config, interfaceConfig, loggingConfig,
configJSON);
} }
};
module.exports = URLProcessor;

View File

@ -1,6 +1,8 @@
import { loadScript } from '../../base/util'; import { loadScript } from '../../base/util';
import URLProcessor from '../../../../modules/config/URLProcessor'; import {
setConfigParametersFromUrl
} from '../../../../modules/config/URLProcessor';
import JitsiMeetJS from './_'; import JitsiMeetJS from './_';
@ -44,7 +46,7 @@ export function loadConfig(host: string, path: string = '/config.js') {
// but URLProcessor still deals with the global variables config, // but URLProcessor still deals with the global variables config,
// interfaceConfig, and loggingConfig and loadConfig. As the latter will // interfaceConfig, and loggingConfig and loadConfig. As the latter will
// surely change in the future, so will the former then. // surely change in the future, so will the former then.
URLProcessor.setConfigParametersFromUrl(); setConfigParametersFromUrl();
return Promise.resolve(window.config); return Promise.resolve(window.config);
} }