From 09453000a63b8b15b37e58f80c47c7120dc8d89d Mon Sep 17 00:00:00 2001 From: Overtorment Date: Thu, 20 Aug 2020 14:48:11 +0100 Subject: [PATCH] ADD: throws onError if keepalive ping does not return in 9 sec --- index.js | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index faf4769..f094201 100644 --- a/index.js +++ b/index.js @@ -62,9 +62,13 @@ class ElectrumClient extends Client { } this.timeout = setTimeout(() => { if (this.timeLastCall !== 0 && new Date().getTime() > this.timeLastCall + 5000) { + const pingTimer = setTimeout(() => { + this.onError(new Error('keepalive ping timeout')); + }, 9000); this.server_ping().catch((reason) => { console.log('keepalive ping failed because of', reason); - }); + clearTimeout(pingTimer); + }).then(() => clearTimeout(pingTimer)); } }, 5000); } diff --git a/package.json b/package.json index 6ff5692..3108a94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electrum-client", - "version": "1.1.3", + "version": "1.1.4", "description": "Electrum protocol client for React Native & Node.js", "main": "index.js", "scripts": {