From 2f3d424718c3bc6a1f5ba11bd9052b2a8d62c2b3 Mon Sep 17 00:00:00 2001 From: Zhang Zengbo Date: Wed, 12 Dec 2018 11:54:07 +0800 Subject: [PATCH] ws transport: fix for node env without global window --- packages/api/src/transport/ws/ws.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/api/src/transport/ws/ws.js b/packages/api/src/transport/ws/ws.js index 08cde330..eda9e378 100644 --- a/packages/api/src/transport/ws/ws.js +++ b/packages/api/src/transport/ws/ws.js @@ -75,7 +75,7 @@ class Ws extends JsonRpcBase { } if (this._reconnectTimeoutId) { - window.clearTimeout(this._reconnectTimeoutId); + clearTimeout(this._reconnectTimeoutId); this._reconnectTimeoutId = null; } @@ -118,7 +118,7 @@ class Ws extends JsonRpcBase { count: 0 }; - window.setInterval(() => { + setInterval(() => { const n = this._count - this._lastCount.count; const t = (Date.now() - this._lastCount.timestamp) / 1000; const s = Math.round(1000 * n / t) / 1000; @@ -133,7 +133,9 @@ class Ws extends JsonRpcBase { }; }, 5000); - window._parityWS = this; + if(typeof window !== 'undefined') { + window._parityWS = this; + } } this._connectPromise = new Promise((resolve, reject) => { @@ -194,7 +196,7 @@ class Ws extends JsonRpcBase { _onError (event) { // Only print error if the WS is connected // ie. don't print if error == closed - window.setTimeout(() => { + setTimeout(() => { if (this._connected) { console.error('ws:onError');