diff --git a/.gitignore b/.gitignore index 5e22eb2..8dc474a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ pubspec.lock .dart_tool .packages node_modules +/.idea diff --git a/lib/sockjs.js b/lib/sockjs.js index 9f3d5c9..1684d0a 100644 --- a/lib/sockjs.js +++ b/lib/sockjs.js @@ -516,13 +516,13 @@ 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); } @@ -547,7 +547,7 @@ 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') ; @@ -555,11 +555,15 @@ this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo); + + if (timeout === undefined) { + timeout = InfoReceiver.timeout + } 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); @@ -731,7 +735,7 @@ , 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)); } diff --git a/lib/src/client.dart b/lib/src/client.dart index 77579e8..058a036 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -187,10 +187,14 @@ class SockJSOptions { /// can be useful if you need to disable certain fallback transports. final List transports; + /// The minimum timeout, in milliseconds. If sockJS's internally calculated + /// timeout is higher, that will be used instead. + final int timeout; + /// Construct a [SockJSOptions] instance to be passed to the [SockJSClient] /// constructor. - SockJSOptions({this.server, this.transports}); + SockJSOptions({this.server, this.transports, this.timeout}); js_interop.SockJSOptions _toJs() => - js_interop.SockJSOptions(server: server, transports: transports); + js_interop.SockJSOptions(server: server, transports: transports, timeout: timeout); } diff --git a/lib/src/js_interop.dart b/lib/src/js_interop.dart index fd7dd7e..61295a6 100644 --- a/lib/src/js_interop.dart +++ b/lib/src/js_interop.dart @@ -93,7 +93,7 @@ class SockJSOptions { /// Example: /// /// {server: 'foo', transports: ['websocket', 'xhr-polling']} - external factory SockJSOptions({String server, List transports}); + external factory SockJSOptions({String server, List transports, int timeout}); /// String to append to url for actual data connection. ///