diff --git a/main.js b/main.js index 349c1bc6eea55b27b10f900252436e9a91f56baf..e1132e9a3de79a8252e8d6dfe962d28605f392ce 100644 --- a/main.js +++ b/main.js @@ -50,6 +50,10 @@ class ModuleInstance extends InstanceBase { clearTimeout(this.reconnect_timer) this.reconnect_timer = null } + if (this.ping_timer) { + clearTimeout(this.ping_timer) + this.ping_timer = null + } if (this.ws) { this.ws.close(1000) delete this.ws @@ -119,11 +123,27 @@ class ModuleInstance extends InstanceBase { } } + startPingTrigger() { + if (this.isInitialized) { + if (this.ping_timer) { + clearTimeout(this.ping_timer) + } + this.log('debug', "Start Ping Timer"); + this.ping_timer = setInterval(() => { + this.sendToWebSocket('ping', {}); + }, 60 * 1000) + } + } + initWebSocket() { if (this.reconnect_timer) { clearTimeout(this.reconnect_timer) this.reconnect_timer = null } + if (this.ping_timer) { + clearTimeout(this.ping_timer) + this.ping_timer = null + } if (this.config.host == null || this.config.port == null) { this.log('debug', `PlayWall host '${this.config.host}' or port '${this.config.port}' is invalid`); @@ -148,6 +168,7 @@ class ModuleInstance extends InstanceBase { this.ws.on('open', () => { this.updateStatus(InstanceStatus.Ok) this.log('debug', `Connection opened`) + this.startPingTrigger(); this.sendToWebSocket('project-current', {}); })