|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+var jssha = require('jssha');
|
|
|
2
|
+
|
|
|
3
|
+module.exports = {
|
|
|
4
|
+ /**
|
|
|
5
|
+ * Looks for a list of possible BOSH addresses in 'config.boshList' and
|
|
|
6
|
+ * sets the value of 'config.bosh' based on that list and 'roomName'.
|
|
|
7
|
+ * @param config the configuration object.
|
|
|
8
|
+ * @param roomName the name of the room/conference.
|
|
|
9
|
+ */
|
|
|
10
|
+ chooseAddress: function(config, roomName) {
|
|
|
11
|
+ if (!roomName || !config.boshList || !Array.isArray(config.boshList) ||
|
|
|
12
|
+ !config.boshList.length) {
|
|
|
13
|
+ return;
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ // This implements the actual choice of an entry in the list based on
|
|
|
17
|
+ // roomName. Please consider the implications for existing deployments
|
|
|
18
|
+ // before introducing changes.
|
|
|
19
|
+ var hash = (new jssha(roomName, 'TEXT')).getHash('SHA-1', 'HEX');
|
|
|
20
|
+ var n = parseInt("0x"+hash.substr(-6));
|
|
|
21
|
+ var idx = n % config.boshList.length;
|
|
|
22
|
+ var attemptFirstAddress;
|
|
|
23
|
+
|
|
|
24
|
+ config.bosh = config.boshList[idx];
|
|
|
25
|
+ console.log('Setting config.bosh to ' + config.bosh +
|
|
|
26
|
+ ' (idx=' + idx + ')');
|
|
|
27
|
+
|
|
|
28
|
+ if (config.boshAttemptFirstList &&
|
|
|
29
|
+ Array.isArray(config.boshAttemptFirstList) &&
|
|
|
30
|
+ config.boshAttemptFirstList.length > 0) {
|
|
|
31
|
+
|
|
|
32
|
+ idx = n % config.boshAttemptFirstList.length;
|
|
|
33
|
+ attemptFirstAddress = config.boshAttemptFirstList[idx];
|
|
|
34
|
+
|
|
|
35
|
+ if (attemptFirstAddress != config.bosh) {
|
|
|
36
|
+ config.boshAttemptFirst = attemptFirstAddress;
|
|
|
37
|
+ console.log('Setting config.boshAttemptFirst=' +
|
|
|
38
|
+ attemptFirstAddress + ' (idx=' + idx + ')');
|
|
|
39
|
+ } else {
|
|
|
40
|
+ console.log('Not setting boshAttemptFirst, address matches.');
|
|
|
41
|
+ }
|
|
|
42
|
+ }
|
|
|
43
|
+ }
|
|
|
44
|
+};
|