Browse Source

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

dev1
damencho 4 years ago
parent
commit
9fdde46694
3 changed files with 18 additions and 5 deletions
  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 View File

232
             - `interval` - how often to send ping requests, default: 10000 (10 seconds)
232
             - `interval` - how often to send ping requests, default: 10000 (10 seconds)
233
             - `timeout` - the time to wait for ping responses, default: 5000 (5 seconds)
233
             - `timeout` - the time to wait for ping responses, default: 5000 (5 seconds)
234
             - `threshold` - how many ping failures will be tolerated before the connection is killed, default: 2
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
 2. `connect(options)` - establish server connection
239
 2. `connect(options)` - establish server connection
237
     - `options` - JS Object with `id` and `password` properties.
240
     - `options` - JS Object with `id` and `password` properties.

+ 9
- 5
modules/xmpp/XmppConnection.js View File

46
      * It will enable automatically by default if supported by the XMPP server.
46
      * It will enable automatically by default if supported by the XMPP server.
47
      * @param {Number} [options.websocketKeepAlive=60000] - The websocket keep alive interval.
47
      * @param {Number} [options.websocketKeepAlive=60000] - The websocket keep alive interval.
48
      * It's the interval + a up to a minute of jitter. Pass -1 to disable.
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
      * @param {Object} [options.xmppPing] - The xmpp ping settings.
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
         super();
55
         super();
54
         this._options = {
56
         this._options = {
55
             enableWebsocketResume: typeof enableWebsocketResume === 'undefined' ? true : enableWebsocketResume,
57
             enableWebsocketResume: typeof enableWebsocketResume === 'undefined' ? true : enableWebsocketResume,
56
             pingOptions: xmppPing,
58
             pingOptions: xmppPing,
57
             shard,
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
         this._stropheConn = new Strophe.Connection(serviceUrl);
64
         this._stropheConn = new Strophe.Connection(serviceUrl);
404
      * @returns {Promise}
407
      * @returns {Promise}
405
      */
408
      */
406
     _keepAliveAndCheckShard() {
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
         return fetch(url)
414
         return fetch(url)
411
             .then(response => {
415
             .then(response => {

+ 6
- 0
modules/xmpp/xmpp.js View File

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

Loading…
Cancel
Save