Просмотр исходного кода

Implements choosing from a list of possible BOSH addresses.

master
Boris Grozev 10 лет назад
Родитель
Сommit
23ff99db6e
2 измененных файлов: 51 добавлений и 2 удалений
  1. 7
    2
      app.js
  2. 44
    0
      modules/config/BoshAddressChoice.js

+ 7
- 2
app.js Просмотреть файл

46
 }
46
 }
47
 
47
 
48
 /**
48
 /**
49
- * If we have HTTP endpoint for getting confgi.json configured we're going to
49
+ * If we have an HTTP endpoint for getting config.json configured we're going to
50
  * read it and override properties from config.js and interfaceConfig.js.
50
  * read it and override properties from config.js and interfaceConfig.js.
51
  * If there is no endpoint we'll just continue with initialization.
51
  * If there is no endpoint we'll just continue with initialization.
52
  * Keep in mind that if the endpoint has been configured and we fail to obtain
52
  * Keep in mind that if the endpoint has been configured and we fail to obtain
54
  * will be displayed to the user.
54
  * will be displayed to the user.
55
  */
55
  */
56
 function obtainConfigAndInit() {
56
 function obtainConfigAndInit() {
57
+    var roomName = APP.UI.getRoomNode();
58
+
57
     if (config.configLocation) {
59
     if (config.configLocation) {
58
         APP.configFetch.obtainConfig(
60
         APP.configFetch.obtainConfig(
59
-            config.configLocation, APP.UI.getRoomNode(),
61
+            config.configLocation, roomName,
60
             // Get config result callback
62
             // Get config result callback
61
             function(success, error) {
63
             function(success, error) {
62
                 if (success) {
64
                 if (success) {
71
                 }
73
                 }
72
             });
74
             });
73
     } else {
75
     } else {
76
+        require("./modules/config/BoshAddressChoice").chooseAddress(
77
+            config, roomName);
78
+
74
         init();
79
         init();
75
     }
80
     }
76
 }
81
 }

+ 44
- 0
modules/config/BoshAddressChoice.js Просмотреть файл

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
+};

Загрузка…
Отмена
Сохранить