home · contact · privacy
Check server disconnect right on websocket.onclose.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 29 Oct 2020 03:47:25 +0000 (04:47 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 29 Oct 2020 03:47:25 +0000 (04:47 +0100)
new2/rogue_chat_nocanvas_monochrome.html

index 11fbfc64d9f4391d53e59aace62e2797706ac10f..fc5e24c2a397e2f1dc9bdd16201313930eed7698 100644 (file)
@@ -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));
     }
 }