From: Christian Heller Date: Thu, 29 Oct 2020 03:47:25 +0000 (+0100) Subject: Check server disconnect right on websocket.onclose. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/tasks?a=commitdiff_plain;h=3d0f035d4a276fd53b767e2be8b481a678a7360b;p=plomrogue2-experiments Check server disconnect right on websocket.onclose. --- diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 11fbfc6..fc5e24c 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -132,16 +132,15 @@ let server = { this.websocket = new WebSocket(url); this.websocket.onopen = function(event) { window.setInterval(function() { server.send(['PING']) }, 30000); - tui.log_msg("@ server connected!"); + tui.log_msg("@ server connected! :)"); tui.init_login(); }; + this.websocket.onclose = function(event) { + tui.log_msg('@ server disconnected :('); + } }, send: function(tokens) { - if (this.websocket.readyState !== WebSocket.OPEN) { - tui.log_msg('server disconnected :('); - } else { - this.websocket.send(unparser.untokenize(tokens)); - } + this.websocket.send(unparser.untokenize(tokens)); } }