From 075c59ed2ca74f841c543554ca0f7108725c85d7 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 3 Nov 2019 16:48:35 +0100 Subject: [PATCH] fix(core): update --- ts/smartsocket.classes.smartsocketclient.ts | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ts/smartsocket.classes.smartsocketclient.ts b/ts/smartsocket.classes.smartsocketclient.ts index e08bd13..c05d96a 100644 --- a/ts/smartsocket.classes.smartsocketclient.ts +++ b/ts/smartsocket.classes.smartsocketclient.ts @@ -70,6 +70,14 @@ export class SmartsocketClient { this.socketConnection.listenToFunctionRequests(); done.resolve(); }); + + // handle errors + this.socketConnection.socket.on('reconnect_failed', async () => { + this.disconnect(); + }); + this.socketConnection.socket.on('connect_error', async () => { + this.disconnect(); + }); }); return done.promise; } @@ -78,9 +86,18 @@ export class SmartsocketClient { * disconnect from the server */ public async disconnect() { - this.socketConnection.socket.disconnect(true); - this.socketConnection = undefined; - plugins.smartlog.defaultLogger.log('ok', 'disconnected!'); + if (this.socketConnection) { + this.socketConnection.socket.disconnect(true); + this.socketConnection = undefined; + plugins.smartlog.defaultLogger.log('ok', 'disconnected!'); + } + } + + /** + * try a reconnection + */ + public async tryReconnect() { + } /**