From dcea0ce37d22e03229dc5a4093719ac8a22d5dc3 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 17 Aug 2022 21:48:39 +0200 Subject: [PATCH] reconnect automatically closes #1 --- pizzicore/static/js/app.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pizzicore/static/js/app.js b/pizzicore/static/js/app.js index 7c87b8d..7bb7e6e 100644 --- a/pizzicore/static/js/app.js +++ b/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()