Browse Source

reconnect automatically

closes #1
boyska 1 year ago
parent
commit
dcea0ce37d
1 changed files with 6 additions and 3 deletions
  1. 6 3
      pizzicore/static/js/app.js

+ 6 - 3
pizzicore/static/js/app.js

@@ -14,11 +14,14 @@ function get_url()
 function do_websocket()
 {
     const socket = new WebSocket(get_url());
-    socket.addEventListener('message', function(evt) {
-        console.log('received', evt.data)
+    socket.onmessage = function(evt) {
         var msg = JSON.parse(evt.data)
         counter = document.getElementsByTagName('text')[0];
         counter.textContent = msg.value.toString()
-    })
+    }
+    socket.onclose = function() {
+        setTimeout(do_websocket, 3000)
+    }
+    socket.onerror = socket.onclose
 }
 do_websocket()