Create config util
This commit is contained in:
parent
32ea2161eb
commit
96b1f0ca74
|
@ -1,7 +1,9 @@
|
||||||
/* global config,
|
/* global config, createConnectionExternally */
|
||||||
createConnectionExternally,
|
|
||||||
getConfigParamsFromUrl,
|
import {
|
||||||
getRoomName */
|
getRoomName,
|
||||||
|
parseURLParams
|
||||||
|
} from '../react/features/base/config/functions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements external connect using createConnectionExternally function defined
|
* Implements external connect using createConnectionExternally function defined
|
||||||
|
@ -15,14 +17,10 @@
|
||||||
* external_connect.js.
|
* external_connect.js.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const hashParams = getConfigParamsFromUrl('hash', true);
|
const hashParams = parseURLParams(window.location, true);
|
||||||
const searchParams = getConfigParamsFromUrl('search', true);
|
|
||||||
|
|
||||||
// URL params have higher proirity than config params.
|
// URL params have higher proirity than config params.
|
||||||
let url
|
let url = hashParams['config.externalConnectUrl'] || config.externalConnectUrl;
|
||||||
= hashParams.hasOwnProperty('config.externalConnectUrl')
|
|
||||||
? hashParams['config.externalConnectUrl']
|
|
||||||
: config.externalConnectUrl;
|
|
||||||
|
|
||||||
if (url && window.createConnectionExternally) {
|
if (url && window.createConnectionExternally) {
|
||||||
const roomName = getRoomName();
|
const roomName = getRoomName();
|
||||||
|
@ -30,9 +28,14 @@ if (url && window.createConnectionExternally) {
|
||||||
if (roomName) {
|
if (roomName) {
|
||||||
url += `?room=${roomName}`;
|
url += `?room=${roomName}`;
|
||||||
|
|
||||||
const token
|
let token = hashParams['config.token'] || config.token;
|
||||||
= hashParams['config.token'] || config.token || searchParams.jwt;
|
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
const searchParams
|
||||||
|
= parseURLParams(window.location, true, 'search');
|
||||||
|
|
||||||
|
token = searchParams.jwt;
|
||||||
|
}
|
||||||
if (token) {
|
if (token) {
|
||||||
url += `&token=${token}`;
|
url += `&token=${token}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,6 @@
|
||||||
'error', loadErrHandler, true /* capture phase type of listener */);
|
'error', loadErrHandler, true /* capture phase type of listener */);
|
||||||
</script>
|
</script>
|
||||||
<script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
|
<script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
|
||||||
<script src="static/utils.js?v=1"></script>
|
|
||||||
<!--#include virtual="connection_optimization/connection_optimization.html" -->
|
<!--#include virtual="connection_optimization/connection_optimization.html" -->
|
||||||
<script src="libs/do_external_connect.min.js?v=1"></script>
|
<script src="libs/do_external_connect.min.js?v=1"></script>
|
||||||
<script><!--#include virtual="/interface_config.js" --></script>
|
<script><!--#include virtual="/interface_config.js" --></script>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
/* global config, getConfigParamsFromUrl, interfaceConfig, loggingConfig */
|
/* global config, interfaceConfig, loggingConfig */
|
||||||
|
|
||||||
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
||||||
|
|
||||||
var configUtils = require('./Util');
|
import { getConfigParamsFromUrl } from '../../react/features/base/config';
|
||||||
var params = {};
|
|
||||||
|
|
||||||
if (typeof getConfigParamsFromUrl === 'function') {
|
import configUtils from './Util';
|
||||||
params = getConfigParamsFromUrl();
|
|
||||||
}
|
// Parsing config params from URL hash.
|
||||||
|
const URL_PARAMS = getConfigParamsFromUrl(window.location);
|
||||||
|
|
||||||
var URLProcessor = {
|
var URLProcessor = {
|
||||||
setConfigParametersFromUrl: function () {
|
setConfigParametersFromUrl: function () {
|
||||||
|
@ -33,7 +33,7 @@ var URLProcessor = {
|
||||||
interfaceConfig: {},
|
interfaceConfig: {},
|
||||||
loggingConfig: {}
|
loggingConfig: {}
|
||||||
};
|
};
|
||||||
for (var key in params) {
|
for (var key in URL_PARAMS) {
|
||||||
if (typeof key !== "string") {
|
if (typeof key !== "string") {
|
||||||
logger.warn("Invalid config key: ", key);
|
logger.warn("Invalid config key: ", key);
|
||||||
continue;
|
continue;
|
||||||
|
@ -59,7 +59,7 @@ var URLProcessor = {
|
||||||
if (!confObj)
|
if (!confObj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
confObj[confKey] = params[key];
|
confObj[confKey] = URL_PARAMS[key];
|
||||||
}
|
}
|
||||||
configUtils.overrideConfigJSON(
|
configUtils.overrideConfigJSON(
|
||||||
config, interfaceConfig, loggingConfig, configJSON);
|
config, interfaceConfig, loggingConfig, configJSON);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global getConfigParamsFromUrl, config */
|
/* global config */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses and handles JWT tokens. Sets config.token.
|
* Parses and handles JWT tokens. Sets config.token.
|
||||||
|
@ -6,10 +6,12 @@
|
||||||
|
|
||||||
import * as jws from "jws";
|
import * as jws from "jws";
|
||||||
|
|
||||||
|
import { getConfigParamsFromUrl } from '../../react/features/base/config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JWT token from the URL.
|
* Get the JWT token from the URL.
|
||||||
*/
|
*/
|
||||||
let params = getConfigParamsFromUrl("search", true);
|
let params = getConfigParamsFromUrl(window.location, true, 'search');
|
||||||
let jwt = params.jwt;
|
let jwt = params.jwt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/* @flow */
|
||||||
|
|
||||||
|
declare var config: Object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and returns the room name.
|
||||||
|
*
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function getRoomName(): ?string {
|
||||||
|
const { getroomnode } = config;
|
||||||
|
const path = window.location.pathname;
|
||||||
|
let roomName;
|
||||||
|
|
||||||
|
// Determine the room node from the URL.
|
||||||
|
if (getroomnode && typeof getroomnode === 'function') {
|
||||||
|
roomName = getroomnode.call(config, path);
|
||||||
|
} else {
|
||||||
|
// Fall back to the default strategy of making assumptions about how the
|
||||||
|
// URL maps to the room (name). It currently assumes a deployment in
|
||||||
|
// which the last non-directory component of the path (name) is the
|
||||||
|
// room.
|
||||||
|
roomName
|
||||||
|
= path.substring(path.lastIndexOf('/') + 1).toLowerCase()
|
||||||
|
|| undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return roomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the parameters from the URL and returns them as a JS object.
|
||||||
|
*
|
||||||
|
* @param {string} url - URL to parse.
|
||||||
|
* @param {boolean} dontParse - If false or undefined some transformations
|
||||||
|
* (for parsing the value as JSON) are going to be executed.
|
||||||
|
* @param {string} source - Values - "hash"/"search" if "search" the parameters
|
||||||
|
* will parsed from location.search otherwise from location.hash.
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
export function parseURLParams(
|
||||||
|
url: URL,
|
||||||
|
dontParse: boolean = false,
|
||||||
|
source: string = 'hash'): Object {
|
||||||
|
const paramStr = source === 'search' ? url.search : url.hash;
|
||||||
|
const params = {};
|
||||||
|
|
||||||
|
// eslint-disable-next-line newline-per-chained-call
|
||||||
|
paramStr && paramStr.substr(1).split('&').forEach(part => {
|
||||||
|
const param = part.split('=');
|
||||||
|
let value;
|
||||||
|
|
||||||
|
try {
|
||||||
|
value = param[1];
|
||||||
|
if (!dontParse) {
|
||||||
|
value
|
||||||
|
= JSON.parse(
|
||||||
|
decodeURIComponent(param[1]).replace(/\\&/, '&'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
const msg = `Failed to parse URL parameter value: ${String(value)}`;
|
||||||
|
|
||||||
|
console.warn(msg, e);
|
||||||
|
window.onerror && window.onerror(msg, null, null, null, e);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params[param[0]] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
export * from './actions';
|
export * from './actions';
|
||||||
export * from './actionTypes';
|
export * from './actionTypes';
|
||||||
|
export * from './functions';
|
||||||
|
|
||||||
import './reducer';
|
import './reducer';
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/* global config */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines some utility methods that are used before the other JS files are
|
|
||||||
* loaded.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds and returns the room name.
|
|
||||||
*/
|
|
||||||
function getRoomName () { // eslint-disable-line no-unused-vars
|
|
||||||
var getroomnode = config.getroomnode;
|
|
||||||
var path = window.location.pathname;
|
|
||||||
var roomName;
|
|
||||||
|
|
||||||
// Determine the room node from the URL.
|
|
||||||
if (getroomnode && typeof getroomnode === 'function') {
|
|
||||||
// custom function might be responsible for doing the pushstate
|
|
||||||
roomName = getroomnode.call(config, path);
|
|
||||||
} else {
|
|
||||||
// Fall back to the default strategy of making assumptions about how the
|
|
||||||
// URL maps to the room (name). It currently assumes a deployment in
|
|
||||||
// which the last non-directory component of the path (name) is the
|
|
||||||
// room.
|
|
||||||
roomName
|
|
||||||
= path.substring(path.lastIndexOf('/') + 1).toLowerCase()
|
|
||||||
|| undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return roomName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the parameters from the URL and returns them as a JS object.
|
|
||||||
* @param source {string} values - "hash"/"search" if "search" the parameters
|
|
||||||
* will parsed from location.search otherwise from location.hash
|
|
||||||
* @param dontParse if false or undefined some transformations
|
|
||||||
* (for parsing the value as JSON) are going to be executed
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
function getConfigParamsFromUrl(source, dontParse) {
|
|
||||||
var paramStr = (source === "search")? location.search : location.hash;
|
|
||||||
if (!paramStr)
|
|
||||||
return {};
|
|
||||||
paramStr = paramStr.substr(1);
|
|
||||||
var result = {};
|
|
||||||
paramStr.split("&").forEach(function (part) {
|
|
||||||
var item = part.split("=");
|
|
||||||
var value;
|
|
||||||
try {
|
|
||||||
value = (dontParse)? item[1] : JSON.parse(
|
|
||||||
decodeURIComponent(item[1]).replace(/\\&/, "&"));
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Failed to parse URL argument", e);
|
|
||||||
if(window.onerror)
|
|
||||||
window.onerror("Failed to parse URL argument", null, null,
|
|
||||||
null, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
result[item[0]] = value;
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
|
Loading…
Reference in New Issue