From 537352c7d8db0b6fbd3b4d63be4a98cb9af6062a Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Thu, 22 Aug 2019 15:28:34 -0400 Subject: [PATCH] Add minimum timeout option Fix #403 --- README.md | 7 +++++++ lib/main.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e00e44ec..0c3a794f 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,13 @@ Where `options` is a hash which can contain: If you don't specify this option, the default is to use the default random string generator to generate 8-character long session ids. + * **timeout (number)** + + Specify a minimum timeout in milliseconds to use for the transport connections. + By default this is dynamically calculated based on the measured RTT and + the number of expected round trips. This setting will establish a minimum, + but if the calculated timeout is higher, that will be used. + Although the 'SockJS' object tries to emulate the 'WebSocket' behaviour, it's impossible to support all of its features. An important SockJS limitation is the fact that you're not allowed to diff --git a/lib/main.js b/lib/main.js index 01bb894c..c92c57f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,6 +49,7 @@ function SockJS(url, protocols, options) { } this._transportsWhitelist = options.transports; this._transportOptions = options.transportOptions || {}; + this._timeout = options.timeout || 0; var sessionId = options.sessionId || 8; if (typeof sessionId === 'function') { @@ -209,7 +210,7 @@ SockJS.prototype._connect = function() { } // calculate timeout based on RTO and round trips. Default to 5s - var timeoutMs = (this._rto * Transport.roundTrips) || 5000; + var timeoutMs = Math.max(this._timeout, (this._rto * Transport.roundTrips) || 5000); this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs); debug('using timeout', timeoutMs);