From ea92e795edecfa2d5efaa87ab26ee203c94bb0e7 Mon Sep 17 00:00:00 2001 From: Tom Connell Date: Wed, 29 Jun 2022 12:28:49 -0600 Subject: [PATCH 1/4] =?UTF-8?q?SockJS=20allows=20setting=20a=20minimum=20t?= =?UTF-8?q?imeout.=20=20I=20think=20this=20should=20do=20it.=20?= =?UTF-8?q?=F0=9F=A4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + lib/src/client.dart | 8 ++++++-- lib/src/js_interop.dart | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) 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/src/client.dart b/lib/src/client.dart index 77579e8..31620f9 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. /// From 30d4a510e38f2efb6cb585ed17b2c1662a671717 Mon Sep 17 00:00:00 2001 From: Tom Connell Date: Fri, 1 Jul 2022 10:19:45 -0600 Subject: [PATCH 2/4] Increase the sockjs info receiver timeout (experiment) --- lib/sockjs.js | 3 ++- lib/src/client.dart | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/sockjs.js b/lib/sockjs.js index 9f3d5c9..4f3b188 100644 --- a/lib/sockjs.js +++ b/lib/sockjs.js @@ -584,7 +584,8 @@ this._cleanup(false); }; - InfoReceiver.timeout = 8000; + // Is it This? + InfoReceiver.timeout = 60000; module.exports = InfoReceiver; diff --git a/lib/src/client.dart b/lib/src/client.dart index 31620f9..058a036 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -187,8 +187,8 @@ 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. + /// 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] From be47eb35471eac7dd0640e4eedb5c925bd90b457 Mon Sep 17 00:00:00 2001 From: Tom Connell Date: Fri, 8 Jul 2022 14:10:24 -0600 Subject: [PATCH 3/4] Plumb options --- lib/sockjs.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/sockjs.js b/lib/sockjs.js index 4f3b188..c5d9cb7 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') ; @@ -559,7 +559,7 @@ debug('timeout'); self._cleanup(false); self.emit('finish'); - }, InfoReceiver.timeout); + }, timeout); this.xo.once('finish', function(info, rtt) { debug('finish', info, rtt); @@ -584,8 +584,7 @@ this._cleanup(false); }; - // Is it This? - InfoReceiver.timeout = 60000; + InfoReceiver.timeout = 8000; module.exports = InfoReceiver; @@ -732,7 +731,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)); } From af4fac960bb9004c9658f6108e1eaa3816415eb7 Mon Sep 17 00:00:00 2001 From: Tom Connell Date: Fri, 8 Jul 2022 14:31:56 -0600 Subject: [PATCH 4/4] This completes passing the options to override the default. Does it fix my timeouts? --- lib/sockjs.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sockjs.js b/lib/sockjs.js index c5d9cb7..1684d0a 100644 --- a/lib/sockjs.js +++ b/lib/sockjs.js @@ -555,6 +555,10 @@ this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo); + + if (timeout === undefined) { + timeout = InfoReceiver.timeout + } this.timeoutRef = setTimeout(function() { debug('timeout'); self._cleanup(false);