Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the provided timeout option, if set, for the InfoReceiver. ⏰ #594

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/info-receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ if (process.env.NODE_ENV !== 'production') {
debug = require('debug')('sockjs-client:info-receiver');
}

function InfoReceiver(baseUrl, urlInfo) {
function InfoReceiver(baseUrl, urlInfo, timeout) {
debug(baseUrl);
var self = this;
EventEmitter.call(this);

setTimeout(function() {
self.doXhr(baseUrl, urlInfo);
self.doXhr(baseUrl, urlInfo, timeout);
}, 0);
}

Expand All @@ -47,19 +47,22 @@ InfoReceiver._getReceiver = function(baseUrl, url, urlInfo) {
return new InfoAjax(url, XHRFake);
};

InfoReceiver.prototype.doXhr = function(baseUrl, urlInfo) {
InfoReceiver.prototype.doXhr = function(baseUrl, urlInfo, timeout) {
var self = this
, url = urlUtils.addPath(baseUrl, '/info')
;
debug('doXhr', url);

this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);

if (timeout === undefined) {
timeout = InfoReceiver.timeout
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw in the documentation that SockJS will use the bigger timeout of either the "internally calculated" timeout, or the timeout option. Do you want this to apply here, too? Something like

if (timeout < InfoReceiver.timeout) {
  timeout = InfoReceiver.timeout
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really "calculated," though. 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

this.timeoutRef = setTimeout(function() {
debug('timeout');
self._cleanup(false);
self.emit('finish');
}, InfoReceiver.timeout);
}, timeout);

this.xo.once('finish', function(info, rtt) {
debug('finish', info, rtt);
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function SockJS(url, protocols, options) {
, sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
};

this._ir = new InfoReceiver(this.url, this._urlInfo);
this._ir = new InfoReceiver(this.url, this._urlInfo, options.timeout);
this._ir.once('finish', this._receiveInfo.bind(this));
}

Expand Down