SVGHMI: fix periodic reconnect triggering watchdog
authorEdouard Tisserant
Fri, 18 Nov 2022 10:40:57 +0100
changeset 3683 bbcbb1bba9f1
parent 3682 c613afdab571
child 3684 2239f8e3de48
SVGHMI: fix periodic reconnect triggering watchdog
svghmi/svghmi.js
--- a/svghmi/svghmi.js	Thu Nov 17 11:08:36 2022 +0100
+++ b/svghmi/svghmi.js	Fri Nov 18 10:40:57 2022 +0100
@@ -607,6 +607,7 @@
 
 var reconnect_delay = 0;
 var periodic_reconnect_timer;
+var force_reconnect = false;
 
 // Once connection established
 function ws_onopen(evt) {
@@ -617,6 +618,7 @@
             window.clearTimeout(periodic_reconnect_timer);
         }
         periodic_reconnect_timer = window.setTimeout(() => {
+            force_reconnect = true;
             ws.close();
             periodic_reconnect_timer = null;
         }, 3600000);
@@ -635,17 +637,16 @@
 function ws_onclose(evt) {
     console.log("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+" Reload in "+reconnect_delay+"ms.");
     ws = null;
-    // reconect
-    // TODO : add visible notification while waiting for reload
-    console.log(evt.wasClean)
-    console.log(evt.reason)
-    if(evt.code=1000){
-        // Do not attempt to reconnect immediately in case of Normal Closure
+    // Do not attempt to reconnect immediately in case:
+    //    - connection was closed by server (PLC stop)
+    //    - connection was closed locally with an intention to reconnect
+    if(evt.code=1000 && !force_reconnect){
         window.alert("Connection closed by server");
         location.reload();
     }
     window.setTimeout(create_ws, reconnect_delay);
     reconnect_delay += 500;
+    force_reconnect = false;
 };
 
 var ws_url =