Reconnect if connection fails

This commit is contained in:
Stefan Aebischer
2019-09-16 15:06:18 +02:00
parent 452b5f47e1
commit 4660dc98b8

View File

@@ -67,6 +67,7 @@ module.exports = class WebsocketClient extends EventEmitter {
} }
async _connect() { async _connect() {
try {
if(this.readyState === READY_STATE_INITIAL) this.readyState = READY_STATE_CONNECTING; if(this.readyState === READY_STATE_INITIAL) this.readyState = READY_STATE_CONNECTING;
const authParams = await this._authenticate(); const authParams = await this._authenticate();
@@ -78,6 +79,10 @@ module.exports = class WebsocketClient extends EventEmitter {
this.ws.on('message', this._wsMessageHandler.bind(this)); this.ws.on('message', this._wsMessageHandler.bind(this));
this.ws.on('error', this._wsOnErrorHandler.bind(this)); this.ws.on('error', this._wsOnErrorHandler.bind(this));
this.ws.on('close', this._wsCloseHandler.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() { async _authenticate() {