Skip to content

Commit

Permalink
Merge pull request #1 from antonselukh/sockjs#403
Browse files Browse the repository at this point in the history
sockjs#403 Provide SockJS config for minimum transport fallback timeout
  • Loading branch information
antonselukh committed Nov 7, 2017
2 parents 4d18fd5 + 4c11b76 commit 08f4a09
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/main.js
Expand Up @@ -49,6 +49,7 @@ function SockJS(url, protocols, options) {
}
this._transportsWhitelist = options.transports;
this._transportOptions = options.transportOptions || {};
this._transportMinTimeout = options.transportMinTimeout || null;

var sessionId = options.sessionId || 8;
if (typeof sessionId === 'function') {
Expand Down Expand Up @@ -208,8 +209,10 @@ SockJS.prototype._connect = function() {
}
}

// calculate timeout based on RTO and round trips. Default to 5s
var timeoutMs = (this._rto * Transport.roundTrips) || 5000;
// calculate timeout based on RTO and round trips. Default to 5s. Min timeout is null, can be overridden
var timeoutMs = (
(this._rto > this._transportMinTimeout ? this._rto : this._transportMinTimeout) * Transport.roundTrips
) || 5000;
this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
debug('using timeout', timeoutMs);

Expand Down

0 comments on commit 08f4a09

Please sign in to comment.