Reconnect if connection fails
This commit is contained in:
@@ -67,17 +67,22 @@ module.exports = class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
|
||||
async _connect() {
|
||||
if(this.readyState === READY_STATE_INITIAL) this.readyState = READY_STATE_CONNECTING;
|
||||
try {
|
||||
if(this.readyState === READY_STATE_INITIAL) this.readyState = READY_STATE_CONNECTING;
|
||||
|
||||
const authParams = await this._authenticate();
|
||||
const url = wsUrls[this.options.livenet ? 'livenet' : 'testnet'] + authParams;
|
||||
const authParams = await this._authenticate();
|
||||
const url = wsUrls[this.options.livenet ? 'livenet' : 'testnet'] + authParams;
|
||||
|
||||
this.ws = new WebSocket(url);
|
||||
this.ws = new WebSocket(url);
|
||||
|
||||
this.ws.on('open', this._wsOpenHandler.bind(this));
|
||||
this.ws.on('message', this._wsMessageHandler.bind(this));
|
||||
this.ws.on('error', this._wsOnErrorHandler.bind(this));
|
||||
this.ws.on('close', this._wsCloseHandler.bind(this));
|
||||
this.ws.on('open', this._wsOpenHandler.bind(this));
|
||||
this.ws.on('message', this._wsMessageHandler.bind(this));
|
||||
this.ws.on('error', this._wsOnErrorHandler.bind(this));
|
||||
this.ws.on('close', this._wsCloseHandler.bind(this));
|
||||
} catch(err) {
|
||||
this.logger.error('Connection failed', err);
|
||||
this._reconnect(this.options.reconnectTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
async _authenticate() {
|
||||
|
||||
Reference in New Issue
Block a user