# HG changeset patch
# User Edouard Tisserant
# Date 1666943073 -7200
# Node ID 9256c344c2da3db7be56dd0083d8e70678d27814
# Parent  61fa60130ad62f8e52f9f380a74c86c343f50388
SVGHMI: enable periodical reconnect when browser is QtWebengine, working around memory leak with websocket on Qt's embedded Chromium.

diff -r 61fa60130ad6 -r 9256c344c2da svghmi/svghmi.js
--- a/svghmi/svghmi.js	Thu Oct 27 10:52:24 2022 +0200
+++ b/svghmi/svghmi.js	Fri Oct 28 09:44:33 2022 +0200
@@ -586,20 +586,21 @@
 switch_page(default_page);
 
 var reconnect_delay = 0;
-// var periodic_reconnect_timer;
+var periodic_reconnect_timer;
 
 // Once connection established
 function ws_onopen(evt) {
-    /* 
-    // to force reconnect every hour
-    if(periodic_reconnect_timer){
-        window.clearTimeout(periodic_reconnect_timer);
-    }
-    periodic_reconnect_timer = window.setTimeout(() => {
-        ws.close();
-        periodic_reconnect_timer = null;
-    }, 3600*1000);
-    */
+    // Work around memory leak with websocket on QtWebEngine
+    // reconnect every hour to force deallocate websocket garbage
+    if(window.navigator.userAgent.includes("QtWebEngine")){
+        if(periodic_reconnect_timer){
+            window.clearTimeout(periodic_reconnect_timer);
+        }
+        periodic_reconnect_timer = window.setTimeout(() => {
+            ws.close();
+            periodic_reconnect_timer = null;
+        }, 3600000);
+    }
 
     // forget subscriptions remotely
     send_reset();