From 69a1b7efea83e0e8de9660394970f455b3c8890e Mon Sep 17 00:00:00 2001 From: dcore94 Date: Mon, 13 Mar 2023 17:36:15 +0100 Subject: [PATCH] improved life check on websockets --- ccp/js/executionhistorycontroller.js | 13 +++++++++++-- ccp/js/executionmonitorcontroller.js | 11 ++++++++++- ccp/js/infrastructurelistcontroller.js | 11 ++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ccp/js/executionhistorycontroller.js b/ccp/js/executionhistorycontroller.js index 7dfd188..22e36c9 100644 --- a/ccp/js/executionhistorycontroller.js +++ b/ccp/js/executionhistorycontroller.js @@ -7,6 +7,7 @@ class CCPExecutionHistory extends HTMLElement { #data = []; #filtered = []; #socket = null; + #interval = null; #searchfield = null; constructor(){ @@ -239,8 +240,16 @@ class CCPExecutionHistory extends HTMLElement { if(exec){ this.refreshExecution(exec.id) } - } - window.setInterval( ()=>this.#socket.send("ping"), 30000) + } + this.#interval = window.setInterval( ()=>{ + if(this.#socket.readyState === 3){ + this.#socket.close() + window.clearInterval(this.#interval) + this.connectBroadcast() + }else{ + this.#socket.send("ping") + } + }, 30000) } download(url, name) { diff --git a/ccp/js/executionmonitorcontroller.js b/ccp/js/executionmonitorcontroller.js index 585d248..2fdcac6 100644 --- a/ccp/js/executionmonitorcontroller.js +++ b/ccp/js/executionmonitorcontroller.js @@ -6,6 +6,7 @@ class CCPExecutionMonitor extends HTMLElement { #broadcasturl = null; #executions = []; #socket = null; + #interval = null; constructor(){ super() @@ -81,7 +82,15 @@ class CCPExecutionMonitor extends HTMLElement { this.refreshExecution(exec) } } - window.setInterval( ()=>this.#socket.send("ping"), 30000) + this.#interval = window.setInterval( ()=>{ + if(this.#socket.readyState === 3){ + this.#socket.close() + window.clearInterval(this.#interval) + this.connectBroadcast() + }else{ + this.#socket.send("ping") + } + }, 30000) } download(url, name) { diff --git a/ccp/js/infrastructurelistcontroller.js b/ccp/js/infrastructurelistcontroller.js index aaf12f0..f26e65b 100644 --- a/ccp/js/infrastructurelistcontroller.js +++ b/ccp/js/infrastructurelistcontroller.js @@ -2,6 +2,7 @@ class CCPInfrastructureList extends HTMLElement{ #boot; #socket; + #interval = null; #infrastructures; #runtimes; #rootdoc; @@ -230,7 +231,15 @@ class CCPInfrastructureList extends HTMLElement{ this.#socket.onmessage = event=>{ this.fetchInfrastructures() } - window.setInterval( ()=>this.#socket.send("ping"), 30000) + this.#interval = window.setInterval( ()=>{ + if(this.#socket.readyState === 3){ + this.#socket.close() + window.clearInterval(this.#interval) + this.connectBroadcast() + }else{ + this.#socket.send("ping") + } + }, 30000) } getCompatibleRuntimes(rts){