reconnect automatically

closes #1
This commit is contained in:
boyska 2022-08-17 21:48:39 +02:00
parent 1b78cd9fee
commit dcea0ce37d

View file

@ -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()