Skip to content

Commit

Permalink
REF: reconnect improvements; remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Overtorment committed Jun 12, 2020
1 parent d1baea7 commit cc018ef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ElectrumClient extends Client {
} else if (this.persistencePolicy == null) {
this.reconnect();
}
}, 10000);
}, 1000);
}

// ElectrumX persistancy
Expand All @@ -62,7 +62,9 @@ class ElectrumClient extends Client {
}
this.timeout = setTimeout(() => {
if (this.timeLastCall !== 0 && new Date().getTime() > this.timeLastCall + 5000) {
this.server_ping();
this.server_ping().catch((reason) => {
console.log('keepalive ping failed because of', reason);
});
}
}, 5000);
}
Expand All @@ -76,6 +78,7 @@ class ElectrumClient extends Client {
}

reconnect() {
console.log('electrum reconnect');
this.initSocket();
return this.initElectrum(this.electrumConfig);
}
Expand Down
12 changes: 0 additions & 12 deletions lib/TlsSocketWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ class TlsSocketWrapper {
this._socket.on('data', data => {
this._passOnEvent('data', data);
});
this._socket.on('end', data => {
this._passOnEvent('end', data);
});
this._socket.on('timeout', () => {
this._passOnEvent('timeout');
});
this._socket.on('onerror', data => {
this._passOnEvent('onerror', data);
});
this._socket.on('error', data => {
this._passOnEvent('error', data);
});
Expand All @@ -103,9 +94,6 @@ class TlsSocketWrapper {
this._socket.on('connect', data => {
this._passOnEvent('connect', data);
});
this._socket.on('secureConnect', data => {
this._passOnEvent('secureConnect', data);
});
this._socket.on('connection', data => {
this._passOnEvent('connection', data);
});
Expand Down
24 changes: 3 additions & 21 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,13 @@ class Client {
this.conn.on('close', e => {
this.onClose(e);
});
this.conn.on('timeout', () => {
const e = new Error('ETIMEDOUT');
e.errorno = 'ETIMEDOUT';
e.code = 'ETIMEDOUT';
e.connect = false;
this.conn.emit('error', e);
});
this.conn.on('data', chunk => {
this.conn.setTimeout(0);
this.onRecv(chunk);
});
this.conn.on('end', e => {
this.conn.setTimeout(0);
this.onEnd(e);
});
this.conn.on('error', e => {
this.onError(e);
});
this.conn.on('onerror', e => {
this.onError(e);
});
this.status = 0;
}

Expand Down Expand Up @@ -115,7 +101,7 @@ class Client {

request(method, params) {
if (this.status === 0) {
return Promise.reject(new Error('ESOCKET'));
return Promise.reject(new Error('Connection to server lost, please retry'));
}
return new Promise((resolve, reject) => {
const id = ++this.id;
Expand All @@ -127,7 +113,7 @@ class Client {

requestBatch(method, params, secondParam) {
if (this.status === 0) {
return Promise.reject(new Error('ESOCKET'));
return Promise.reject(new Error('Connection to server lost, please retry'));
}
return new Promise((resolve, reject) => {
let arguments_far_calls = {};
Expand Down Expand Up @@ -170,7 +156,7 @@ class Client {
callback(null, msg.result || msg);
}
} else {
console.log("Can't get callback"); // can't get callback
console.log("Can't get callback");
}
}

Expand Down Expand Up @@ -201,10 +187,6 @@ class Client {
this.mp.run(chunk);
}

onEnd(e) {
console.log('OnEnd:' + e);
}

onError(e) {
console.log('OnError:' + e);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrum-client",
"version": "1.1.2",
"version": "1.1.3",
"description": "Electrum protocol client for React Native & Node.js",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cc018ef

Please sign in to comment.