2016-11-11 15:00:54 +00:00
|
|
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
|
|
|
2016-01-25 17:15:49 +00:00
|
|
|
var JSSHA = require('jssha');
|
2015-10-20 15:41:15 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
* Looks for a list of possible BOSH addresses in 'config.boshList' and
|
|
|
|
* sets the value of 'config.bosh' based on that list and 'roomName'.
|
|
|
|
* @param config the configuration object.
|
|
|
|
* @param roomName the name of the room/conference.
|
|
|
|
*/
|
|
|
|
chooseAddress: function(config, roomName) {
|
|
|
|
if (!roomName || !config.boshList || !Array.isArray(config.boshList) ||
|
|
|
|
!config.boshList.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This implements the actual choice of an entry in the list based on
|
|
|
|
// roomName. Please consider the implications for existing deployments
|
|
|
|
// before introducing changes.
|
2016-01-25 17:15:49 +00:00
|
|
|
var hash = (new JSSHA(roomName, 'TEXT')).getHash('SHA-1', 'HEX');
|
2015-10-20 15:41:15 +00:00
|
|
|
var n = parseInt("0x"+hash.substr(-6));
|
|
|
|
var idx = n % config.boshList.length;
|
|
|
|
var attemptFirstAddress;
|
|
|
|
|
|
|
|
config.bosh = config.boshList[idx];
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.log('Setting config.bosh to ' + config.bosh +
|
2015-10-20 15:41:15 +00:00
|
|
|
' (idx=' + idx + ')');
|
|
|
|
|
|
|
|
if (config.boshAttemptFirstList &&
|
|
|
|
Array.isArray(config.boshAttemptFirstList) &&
|
|
|
|
config.boshAttemptFirstList.length > 0) {
|
|
|
|
|
|
|
|
idx = n % config.boshAttemptFirstList.length;
|
|
|
|
attemptFirstAddress = config.boshAttemptFirstList[idx];
|
|
|
|
|
|
|
|
if (attemptFirstAddress != config.bosh) {
|
|
|
|
config.boshAttemptFirst = attemptFirstAddress;
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.log('Setting config.boshAttemptFirst=' +
|
2015-10-20 15:41:15 +00:00
|
|
|
attemptFirstAddress + ' (idx=' + idx + ')');
|
|
|
|
} else {
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.log('Not setting boshAttemptFirst, address matches.');
|
2015-10-20 15:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|