home · contact · privacy
In web client, only reconnect if websocket.readyState != 1.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 10 Dec 2020 20:25:23 +0000 (21:25 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 10 Dec 2020 20:25:23 +0000 (21:25 +0100)
This eliminates a bug where the client's reconnect impatience would
never allow a connection to be established, if the server was too busy.

rogue_chat.html

index ebe64f2041fe4a4f755da1bea1a670185c23cdc2..1b62a81ad77c63aa1fc8b3f37697aab52c8f3759 100644 (file)
@@ -454,7 +454,6 @@ let server = {
         this.url = url;
         this.websocket = new WebSocket(this.url);
         this.websocket.onopen = function(event) {
-            server.connected = true;
             game.thing_types = {};
             game.terrains = {};
             server.send(['TASKS']);
@@ -464,7 +463,6 @@ let server = {
             tui.switch_mode('login');
         };
         this.websocket.onclose = function(event) {
-            server.connected = false;
             tui.switch_mode('waiting_for_server');
             tui.log_msg("@ server disconnected :(");
         };
@@ -1660,13 +1658,13 @@ for (let key_selector of key_selectors) {
     }, false);
 }
 window.setInterval(function() {
-    if (server.connected) {
+    if (server.websocket.readyState == 1) {
         server.send(['PING']);
     } else {
         server.reconnect_to(server.url);
         tui.log_msg('@ attempting reconnect …')
     }
-}, 5000);
+}, 1000);
 window.setInterval(function() {
     let val = "?";
     let span_decoration = "none";