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
Implements choosing from a list of possible BOSH addresses.
Boris Grozev23ff99db6e79
diff --git a/app.js b/app.jsindex 5170e2295c..889096d2ef 100644--- a/app.js+++ b/app.js@@ -46,7 +46,7 @@ function init() {}/**- * If we have HTTP endpoint for getting confgi.json configured we're going to+ * If we have an HTTP endpoint for getting config.json configured we're going to* read it and override properties from config.js and interfaceConfig.js.* If there is no endpoint we'll just continue with initialization.* Keep in mind that if the endpoint has been configured and we fail to obtain@@ -54,9 +54,11 @@ function init() {* will be displayed to the user.*/function obtainConfigAndInit() {+ var roomName = APP.UI.getRoomNode();+if (config.configLocation) {APP.configFetch.obtainConfig(- config.configLocation, APP.UI.getRoomNode(),+ config.configLocation, roomName,// Get config result callbackfunction(success, error) {if (success) {@@ -71,6 +73,9 @@ function obtainConfigAndInit() {}});} else {+ require("./modules/config/BoshAddressChoice").chooseAddress(+ config, roomName);+init();}}diff --git a/modules/config/BoshAddressChoice.js b/modules/config/BoshAddressChoice.jsnew file mode 100644index 0000000000..b2a16eb99a--- /dev/null+++ b/modules/config/BoshAddressChoice.js@@ -0,0 +1,44 @@+var jssha = require('jssha');++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.+ var hash = (new jssha(roomName, 'TEXT')).getHash('SHA-1', 'HEX');+ var n = parseInt("0x"+hash.substr(-6));+ var idx = n % config.boshList.length;+ var attemptFirstAddress;++ config.bosh = config.boshList[idx];+ console.log('Setting config.bosh to ' + config.bosh ++ ' (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;+ console.log('Setting config.boshAttemptFirst=' ++ attemptFirstAddress + ' (idx=' + idx + ')');+ } else {+ console.log('Not setting boshAttemptFirst, address matches.');+ }+ }+ }+};