]> git.cworth.org Git - empires-html/commitdiff
Add a message when the connection to the server is lost
authorCarl Worth <cworth@cworth.org>
Sun, 10 May 2020 15:45:02 +0000 (08:45 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 10 May 2020 16:14:33 +0000 (09:14 -0700)
Making it clear to the user that something has gone wrong.

empires-client.js

index 5f489f8780c547c6f8af2a743561a965ebdcd07c..ff952a3e5281d2bdd15a8918c9a76542e152e939 100644 (file)
@@ -34,6 +34,12 @@ function register(form) {
 
 const events = new EventSource(API + "events");
 
+events.onerror = function(event) {
+  if (event.target.readyState === EventSource.CLOSED) {
+      add_message("danger", "Connection to server lost.");
+  }
+};
+
 events.addEventListener("players", function(event) {
   const players_element = document.getElementById("players");
   const players = JSON.parse(event.data);