Переглянути джерело

feat: Adds option to set ws keepalive url through config.

dev1
damencho 4 роки тому
джерело
коміт
9fdde46694
3 змінених файлів з 18 додано та 5 видалено
  1. 3
    0
      doc/API.md
  2. 9
    5
      modules/xmpp/XmppConnection.js
  3. 6
    0
      modules/xmpp/xmpp.js

+ 3
- 0
doc/API.md Переглянути файл

@@ -232,6 +232,9 @@ This objects represents the server connection. You can create new `JitsiConnecti
232 232
             - `interval` - how often to send ping requests, default: 10000 (10 seconds)
233 233
             - `timeout` - the time to wait for ping responses, default: 5000 (5 seconds)
234 234
             - `threshold` - how many ping failures will be tolerated before the connection is killed, default: 2
235
+        7. websocketKeepAlive - (optional) Setting the interval of websocket keepalive GET requests. By default, the value is 1 minute(which means a minute + a minute of jitter).
236
+           Used for certain deployments where a stick table entry needs to be kept alive we use those GET requests.
237
+        8. websocketKeepAliveUrl - (optional) Specific Url to use for the websocket keepalive GET requests.
235 238
 
236 239
 2. `connect(options)` - establish server connection
237 240
     - `options` - JS Object with `id` and `password` properties.

+ 9
- 5
modules/xmpp/XmppConnection.js Переглянути файл

@@ -46,16 +46,19 @@ export default class XmppConnection extends Listenable {
46 46
      * It will enable automatically by default if supported by the XMPP server.
47 47
      * @param {Number} [options.websocketKeepAlive=60000] - The websocket keep alive interval.
48 48
      * It's the interval + a up to a minute of jitter. Pass -1 to disable.
49
-     * The keep alive is HTTP GET request to the {@link options.serviceUrl}.
49
+     * The keep alive is HTTP GET request to {@link options.serviceUrl} or to {@link options.websocketKeepAliveUrl}.
50
+     * @param {Number} [options.websocketKeepAliveUrl] - The websocket keep alive url to use if any,
51
+     * if missing the serviceUrl url will be used.
50 52
      * @param {Object} [options.xmppPing] - The xmpp ping settings.
51 53
      */
52
-    constructor({ enableWebsocketResume, websocketKeepAlive, serviceUrl, shard, xmppPing }) {
54
+    constructor({ enableWebsocketResume, websocketKeepAlive, websocketKeepAliveUrl, serviceUrl, shard, xmppPing }) {
53 55
         super();
54 56
         this._options = {
55 57
             enableWebsocketResume: typeof enableWebsocketResume === 'undefined' ? true : enableWebsocketResume,
56 58
             pingOptions: xmppPing,
57 59
             shard,
58
-            websocketKeepAlive: typeof websocketKeepAlive === 'undefined' ? 60 * 1000 : Number(websocketKeepAlive)
60
+            websocketKeepAlive: typeof websocketKeepAlive === 'undefined' ? 60 * 1000 : Number(websocketKeepAlive),
61
+            websocketKeepAliveUrl
59 62
         };
60 63
 
61 64
         this._stropheConn = new Strophe.Connection(serviceUrl);
@@ -404,8 +407,9 @@ export default class XmppConnection extends Listenable {
404 407
      * @returns {Promise}
405 408
      */
406 409
     _keepAliveAndCheckShard() {
407
-        const { shard } = this._options;
408
-        const url = this.service.replace('wss://', 'https://').replace('ws://', 'http://');
410
+        const { shard, websocketKeepAliveUrl } = this._options;
411
+        const url = websocketKeepAliveUrl ? websocketKeepAliveUrl
412
+            : this.service.replace('wss://', 'https://').replace('ws://', 'http://');
409 413
 
410 414
         return fetch(url)
411 415
             .then(response => {

+ 6
- 0
modules/xmpp/xmpp.js Переглянути файл

@@ -33,6 +33,7 @@ const logger = getLogger(__filename);
33 33
  * @param {string} options.shard - The shard where XMPP connection initially landed.
34 34
  * @param {string} options.enableWebsocketResume - True to enable stream resumption.
35 35
  * @param {number} [options.websocketKeepAlive] - See {@link XmppConnection} constructor.
36
+ * @param {number} [options.websocketKeepAliveUrl] - See {@link XmppConnection} constructor.
36 37
  * @param {Object} [options.xmppPing] - See {@link XmppConnection} constructor.
37 38
  * @returns {XmppConnection}
38 39
  */
@@ -42,6 +43,7 @@ function createConnection({
42 43
     shard,
43 44
     token,
44 45
     websocketKeepAlive,
46
+    websocketKeepAliveUrl,
45 47
     xmppPing }) {
46 48
 
47 49
     // Append token as URL param
@@ -54,6 +56,7 @@ function createConnection({
54 56
         enableWebsocketResume,
55 57
         serviceUrl,
56 58
         websocketKeepAlive,
59
+        websocketKeepAliveUrl,
57 60
         xmppPing,
58 61
         shard
59 62
     });
@@ -113,6 +116,8 @@ export default class XMPP extends Listenable {
113 116
      * module try to resume the session in case the Websocket connection breaks.
114 117
      * @param {number} [options.websocketKeepAlive] - The websocket keep alive interval. See {@link XmppConnection}
115 118
      * constructor for more details.
119
+     * @param {number} [options.websocketKeepAliveUrl] - The websocket keep alive url. See {@link XmppConnection}
120
+     * constructor for more details.
116 121
      * @param {Object} [options.xmppPing] - The xmpp ping settings.
117 122
      * @param {Array<Object>} options.p2pStunServers see {@link JingleConnectionPlugin} for more details.
118 123
      * @param token
@@ -140,6 +145,7 @@ export default class XMPP extends Listenable {
140 145
             serviceUrl: options.serviceUrl || options.bosh,
141 146
             token,
142 147
             websocketKeepAlive: options.websocketKeepAlive,
148
+            websocketKeepAliveUrl: options.websocketKeepAliveUrl,
143 149
             xmppPing,
144 150
             shard: options.deploymentInfo?.shard
145 151
         });

Завантаження…
Відмінити
Зберегти