chiark / gitweb /
nicely handle leaving the game
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 23 Nov 2020 19:06:09 +0000 (19:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 23 Nov 2020 19:06:20 +0000 (19:06 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/sse.rs
templates/script.ts

index 7af8637e42c377211d6ad1bf614f41086773bab7..788e56777276b762f2631591db52c925ce610167 100644 (file)
@@ -95,7 +95,7 @@ impl Read for UpdateReader {
       Some(x) => x,
       None => {
         let data = format!("event: player-gone\n\
-                            data: player-gone\n\n")
+                            data: No longer in the game\n\n")
           .into_bytes().into_boxed_slice();
         assert_eq!(self.ending_send, None);
         let ending = self.ending_send.get_or_insert(io::Cursor::new(data));
@@ -120,7 +120,7 @@ impl Read for UpdateReader {
         None => {
           if self.to_send < pu.read_log().front_index()
           && buf.len() == orig_wanted {
-            write!(buf, "event: updates_expired\ndata: {}\n\n",
+            write!(buf, "event: updates-expired\ndata: {}\n\n",
                    self.to_send)
               .map_err(|e| self.wn.trouble("notify updates expired", &e))?;
             debug!("updates expired for {} {}, telling client (#{})",
index 10fb4a1fb32cfff68e409fd25e89611934429b83..577a0311a40111631dbbfec64fc40667515252ca 100644 (file)
@@ -1118,7 +1118,12 @@ function startup() {
     console.log('GOTDATA', event);
     status_node.innerHTML = (event as any).data;
   });
-  es.addEventListener('updates_expired', function(event) {
+  es.addEventListener('player-gone', function(event) {
+    console.log('PLAYER-GONE', event);
+    status_node.innerHTML = (event as any).data;
+    es.close();
+  });
+  es.addEventListener('updates-expired', function(event) {
     console.log('UPDATES-EXPIRED', event);
     string_report_error('connection to server interrupted too long');
   });