From 3fb6d99dcc9b1bd5661bc13707fd27ab2564392d Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 26 Mar 2020 13:28:54 -0700 Subject: [PATCH] 0.1.9 fix initTimeout and retryWait option setting for when zero --- package.json | 6 +++--- src/WSConsumer.js | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6c2c373..935183f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/websocket-client", - "version": "0.1.8", + "version": "0.1.9", "description": "JSON packet browser client over web socket", "main": "src", "watch": { @@ -34,10 +34,10 @@ "npm-watch": "^0.6.0" }, "dependencies": { - "auto-bind": "^2.1.0", + "auto-bind": "^4.0.0", "better-try-catch": "^0.6.2", "delay": "^4.3.0", "eventemitter3": "^4.0.0", - "ws": "^7.1.2" + "ws": "^7.2.3" } } diff --git a/src/WSConsumer.js b/src/WSConsumer.js index 85cc3df..bb3f3d4 100644 --- a/src/WSConsumer.js +++ b/src/WSConsumer.js @@ -26,8 +26,8 @@ class WSConsumer extends EventEmitter { this.name = opts.name || 'browser' this.instanceID = new Date().getTime() this.url = url - this.initTimeout = opts.initTimeout * 1000 || 60000 - this.retryWait = opts.retryWait * 1000 || 5000 + this.initTimeout = opts.initTimeout!=null ? opts.initTimeout * 1000 : 60000 + this.retryWait = opts.retryWait!=null ? opts.retryWait * 1000 : 5000 this.protocol = opts.protocol // available if needed but not documented this.opts = opts this._connected = false @@ -38,6 +38,9 @@ class WSConsumer extends EventEmitter { autoBind(this) } + // TODO refactor like for tcp socket + // emit connection events + /** * connect - After instantiating this must be called to connect to a UCI WesbSocket Sever * @required @@ -52,8 +55,8 @@ class WSConsumer extends EventEmitter { this._conAttempt = 1 this.url = opts.url || this.url this.name = opts.name || this.name - this.initTimeout = opts.initTimeout || this.initTimeout - this.retryWait = opts.retryWait || this.retryWait + this.initTimeout = opts.initTimeout!=null ? opts.initTimeout * 1000 : this.initTimeout + this.retryWait = opts.retryWait!=null ? opts.retryWait * 1000 : this.retryWait return new Promise((resolve, reject) => {