Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Beautify URLProcessor
Ilya Daynatovich3af0976a434c
diff --git a/modules/config/URLProcessor.js b/modules/config/URLProcessor.jsindex a9b9af912e..23c0c40e89 100644--- a/modules/config/URLProcessor.js+++ b/modules/config/URLProcessor.js@@ -1,69 +1,93 @@/* global config, interfaceConfig, loggingConfig */+import { parseURLParams } from '../../react/features/base/config';++import configUtils from './Util';+const logger = require("jitsi-meet-logger").getLogger(__filename);-import { getConfigParamsFromUrl } from '../../react/features/base/config';+/**+ * URL params with this prefix should be merged to config.+ */+const CONFIG_PREFIX = 'config.';-import configUtils from './Util';+/**+ * URL params with this prefix should be merged to interface config.+ */+const INTERFACE_CONFIG_PREFIX = 'interfaceConfig.';-// Parsing config params from URL hash.-const URL_PARAMS = getConfigParamsFromUrl(window.location);+/**+ * Config keys to be ignored.+ *+ * @type Set+ */+const KEYS_TO_IGNORE = new Set([+ 'analyticsScriptUrls',+ 'callStatsCustomScriptUrl'+]);-var URLProcessor = {- setConfigParametersFromUrl: function () {- // Convert '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"- // }- // }- var configJSON = {- config: {},- interfaceConfig: {},- loggingConfig: {}- };- for (var key in URL_PARAMS) {- if (typeof key !== "string") {- logger.warn("Invalid config key: ", key);- continue;- }- var confObj = null, confKey;- if (key.indexOf("config.") === 0) {- confObj = configJSON.config;- confKey = key.substr("config.".length);+/**+ * URL params with this prefix should be merged to logging config.+ */+const LOGGING_CONFIG_PREFIX = 'loggingConfig.';- // prevent passing some parameters which can inject scripts- if (confKey === 'analyticsScriptUrls'- || confKey === 'callStatsCustomScriptUrl')- continue;+/**+ * 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);- } else if (key.indexOf("interfaceConfig.") === 0) {+ const configJSON = {+ config: {},+ interfaceConfig: {},+ loggingConfig: {}+ };++ for (const key in params) {+ if (typeof key === 'string') {+ let confObj = null;+ let confKey;++ if (key.indexOf(CONFIG_PREFIX) === 0) {+ confObj = configJSON.config;+ confKey = key.substr(CONFIG_PREFIX.length);++ } else if (key.indexOf(INTERFACE_CONFIG_PREFIX) === 0) {confObj = configJSON.interfaceConfig;- confKey = key.substr("interfaceConfig.".length);- } else if (key.indexOf("loggingConfig.") === 0) {+ confKey+ = key.substr(INTERFACE_CONFIG_PREFIX.length);+ } else if (key.indexOf(LOGGING_CONFIG_PREFIX) === 0) {confObj = configJSON.loggingConfig;- confKey = key.substr("loggingConfig.".length);+ confKey = key.substr(LOGGING_CONFIG_PREFIX.length);}- if (!confObj)- continue;-- confObj[confKey] = URL_PARAMS[key];+ // prevent passing some parameters which can inject scripts+ if (confObj && !KEYS_TO_IGNORE.has(confKey)) {+ confObj[confKey] = params[key];+ }+ } else {+ logger.warn('Invalid config key: ', key);}- configUtils.overrideConfigJSON(- config, interfaceConfig, loggingConfig, configJSON);}-};-module.exports = URLProcessor;+ configUtils.overrideConfigJSON(+ config, interfaceConfig, loggingConfig,+ configJSON);+}diff --git a/react/features/base/lib-jitsi-meet/functions.js b/react/features/base/lib-jitsi-meet/functions.jsindex 6b5b2cfd21..a5eb353d45 100644--- a/react/features/base/lib-jitsi-meet/functions.js+++ b/react/features/base/lib-jitsi-meet/functions.js@@ -1,6 +1,8 @@import { loadScript } from '../../base/util';-import URLProcessor from '../../../../modules/config/URLProcessor';+import {+ setConfigParametersFromUrl+} from '../../../../modules/config/URLProcessor';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,// interfaceConfig, and loggingConfig and loadConfig. As the latter will// surely change in the future, so will the former then.- URLProcessor.setConfigParametersFromUrl();+ setConfigParametersFromUrl();return Promise.resolve(window.config);}