mirror of https://github.com/jitsi/jitsi-meet
parent
7b35dd89bb
commit
a7048fba06
@ -1,50 +0,0 @@ |
||||
/* global $, $iq, config, interfaceConfig */ |
||||
var params = {}; |
||||
function getConfigParamsFromUrl() { |
||||
if(!location.hash) |
||||
return {}; |
||||
var hash = location.hash.substr(1); |
||||
var result = {}; |
||||
hash.split("&").forEach(function(part) { |
||||
var item = part.split("="); |
||||
result[item[0]] = JSON.parse( |
||||
decodeURIComponent(item[1]).replace(/\\&/, "&")); |
||||
}); |
||||
return result; |
||||
} |
||||
|
||||
params = getConfigParamsFromUrl(); |
||||
|
||||
var URLProcessor = { |
||||
setConfigParametersFromUrl: function () { |
||||
for(var key in params) { |
||||
if(typeof key !== "string") |
||||
continue; |
||||
|
||||
var confObj = null, confKey; |
||||
if (key.indexOf("config.") === 0) { |
||||
confObj = config; |
||||
confKey = key.substr("config.".length); |
||||
} else if (key.indexOf("interfaceConfig.") === 0) { |
||||
confObj = interfaceConfig; |
||||
confKey = key.substr("interfaceConfig.".length); |
||||
} |
||||
|
||||
if (!confObj) |
||||
continue; |
||||
|
||||
var value = params[key]; |
||||
if (confObj[confKey] && typeof confObj[confKey] !== typeof value) |
||||
{ |
||||
console.warn("The type of " + key + |
||||
" is wrong. That parameter won't be updated in config.js."); |
||||
continue; |
||||
} |
||||
|
||||
confObj[confKey] = value; |
||||
} |
||||
|
||||
} |
||||
}; |
||||
|
||||
module.exports = URLProcessor; |
@ -0,0 +1,55 @@ |
||||
/* global $, $iq, config, interfaceConfig */ |
||||
|
||||
var configUtil = require('./Util'); |
||||
|
||||
var HttpConfig = { |
||||
/** |
||||
* Sends HTTP POST request to specified <tt>endpoint</tt>. In request |
||||
* the name of the room is included in JSON format: |
||||
* { |
||||
* "rooomName": "someroom12345" |
||||
* } |
||||
* @param endpoint the name of HTTP endpoint to which HTTP POST request will |
||||
* be sent. |
||||
* @param roomName the name of the conference room for which config will be |
||||
* requested. |
||||
* @param complete |
||||
*/ |
||||
obtainConfig: function (endpoint, roomName, complete) { |
||||
console.info( |
||||
"Send config request to " + endpoint + " for room: " + roomName); |
||||
|
||||
var request = new XMLHttpRequest(); |
||||
var error = null; |
||||
request.onreadystatechange = function (aEvt) { |
||||
if (request.readyState == 4) { |
||||
var status = request.status; |
||||
if (status === 200) { |
||||
try { |
||||
var data = JSON.parse(request.responseText); |
||||
configUtil.overrideConfigJSON( |
||||
config, interfaceConfig, data); |
||||
complete(true); |
||||
return; |
||||
} catch (exception) { |
||||
console.error("Parse config error: ", exception); |
||||
error = exception; |
||||
} |
||||
} else { |
||||
console.error("Get config error: ", request, status); |
||||
error = "Get config response status: " + status; |
||||
} |
||||
complete(false, error); |
||||
} |
||||
}; |
||||
|
||||
request.open("POST", endpoint, true); |
||||
|
||||
request.setRequestHeader( |
||||
"Content-Type", "application/json;charset=UTF-8"); |
||||
|
||||
request.send({ "roomName": roomName }); |
||||
} |
||||
}; |
||||
|
||||
module.exports = HttpConfig; |
@ -0,0 +1,65 @@ |
||||
/* global $, $iq, config, interfaceConfig */ |
||||
var configUtils = require('./Util'); |
||||
var params = {}; |
||||
function getConfigParamsFromUrl() { |
||||
if (!location.hash) |
||||
return {}; |
||||
var hash = location.hash.substr(1); |
||||
var result = {}; |
||||
hash.split("&").forEach(function (part) { |
||||
var item = part.split("="); |
||||
result[item[0]] = JSON.parse( |
||||
decodeURIComponent(item[1]).replace(/\\&/, "&")); |
||||
}); |
||||
return result; |
||||
} |
||||
|
||||
params = getConfigParamsFromUrl(); |
||||
|
||||
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: {} |
||||
}; |
||||
for (var key in params) { |
||||
if (typeof key !== "string") { |
||||
console.warn("Invalid config key: ", key); |
||||
continue; |
||||
} |
||||
var confObj = null, confKey; |
||||
if (key.indexOf("config.") === 0) { |
||||
confObj = configJSON.config; |
||||
confKey = key.substr("config.".length); |
||||
} else if (key.indexOf("interfaceConfig.") === 0) { |
||||
confObj = configJSON.interfaceConfig; |
||||
confKey = key.substr("interfaceConfig.".length); |
||||
} |
||||
|
||||
if (!confObj) |
||||
continue; |
||||
|
||||
confObj[confKey] = params[key]; |
||||
} |
||||
configUtils.overrideConfigJSON(config, interfaceConfig, configJSON); |
||||
} |
||||
}; |
||||
|
||||
module.exports = URLProcessor; |
@ -0,0 +1,49 @@ |
||||
/* global $ */ |
||||
var ConfigUtil = { |
||||
/** |
||||
* Method overrides JSON properties in <tt>config</tt> and |
||||
* <tt>interfaceConfig</tt> Objects with the values from <tt>newConfig</tt> |
||||
* @param config the config object for which we'll be overriding properties |
||||
* @param interfaceConfig the interfaceConfig object for which we'll be |
||||
* overriding properties. |
||||
* @param newConfig object containing configuration properties. Destination |
||||
* object is selected based on root property name: |
||||
* { |
||||
* config: { |
||||
* // config.js properties to be
|
||||
* }, |
||||
* interfaceConfig: { |
||||
* // interfaceConfig.js properties here
|
||||
* } |
||||
* } |
||||
*/ |
||||
overrideConfigJSON: function (config, interfaceConfig, newConfig) { |
||||
for (var configRoot in newConfig) { |
||||
|
||||
var confObj = null; |
||||
if (configRoot == "config") { |
||||
confObj = config; |
||||
} else if (configRoot == "interfaceConfig") { |
||||
confObj = interfaceConfig; |
||||
} else { |
||||
continue; |
||||
} |
||||
|
||||
for (var key in newConfig[configRoot]) { |
||||
var value = newConfig[configRoot][key]; |
||||
if (confObj[key] && typeof confObj[key] !== typeof value) |
||||
{ |
||||
console.warn( |
||||
"The type of " + key + |
||||
" is wrong. That parameter won't be updated in: ", |
||||
confObj); |
||||
continue; |
||||
} |
||||
console.info("Overriding " + key + " with: " + value); |
||||
confObj[key] = value; |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
module.exports = ConfigUtil; |
Loading…
Reference in new issue