add connected/disconnected text
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 3 Feb 2017 12:20:50 +0000 (06:20 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 3 Feb 2017 12:20:50 +0000 (06:20 -0600)
data/web-static/css/main.css
data/web-static/js/mudsync.js
mudsync/networking.scm

index 7ef34ddc056483c286002d0b940f9d0458889413..e965980607836f3cde9a33b92283984f29c9bc38 100644 (file)
@@ -99,6 +99,13 @@ ul li:before {
     border-left-color: #b4b4b4;
 }
 
+#connection-status.connected {
+    color: #88be7e;
+}
+
+#connection-status.disconnected {
+    color: #be8b7e;
+}
 \f
 
 #input-metabox {
index 0e7ebe6f1c94abc23f64b582c8f87ea0c06436c3..c5b7dca82d47cd928e351035814fda29b01327e1 100644 (file)
@@ -19,7 +19,7 @@
 */
 
 function scrollDown() {
-    var stream_metabox = document.getElementById("stream-metabox");
+    var stream_metabox = document.getElementById("stream-metabox");o
     stream_metabox.scrollTop = stream_metabox.scrollHeight;
 }
 
@@ -53,6 +53,12 @@ function displayMessage(data, self_sent) {
         });
 }
 
+function setConnectedText(string, to_class) {
+    var stream_metabox = document.getElementById("connection-status");
+    stream_metabox.textContent = "[" + string + "]";
+    stream_metabox.setAttribute("class", to_class);
+}
+
 function installWebsocket() {
     // TODO: Don't hardcode the websocket path; pull it from the DOM
     var address = "ws://".concat(window.location.hostname, ":", window.location.port);
@@ -61,9 +67,16 @@ function installWebsocket() {
         displayMessage(evt.data, false);
     };
     ws.onopen = function() {
+        setConnectedText("connected", "connected");
         console.log("connected");
     };
     ws.onclose = function () {
+        setConnectedText("disconnected", "disconnected");
+        // kludge, we shouldn't be using self_sent like this because it
+        // wipes the input
+        displayMessage(
+            "* You have been disconnected.  Refresh to (hopefully) reconnect.",
+            true);
         console.log("closed websocket");
     };
     installUIHooks(ws);
index 33ad424f3234c497f01e8de21bf0580bad128af0..b541c1ee99da72ff881e73c2a6bfc0b2e4891e3d 100644 (file)
@@ -249,7 +249,11 @@ like the web one"
                 ;;      (p (b "<bar>") " Last one!"))
                 ))
       (div (@ (id "input-metabox"))
-           (input (@ (id "main-input"))))))
+           (input (@ (id "main-input")))
+           " "
+           (span (@ (id "connection-status")
+                    (class "disconnected"))
+                 "[disconnected]"))))
 
   (define (main-tmpl)
     `(html (@ (xmlns "http://www.w3.org/1999/xhtml"))