From: Christopher Allan Webber Date: Fri, 3 Feb 2017 12:20:50 +0000 (-0600) Subject: add connected/disconnected text X-Git-Tag: fosdem-2017~13 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=25c34496ce23be265460bc4c95cba6036ff577a2;p=mudsync.git add connected/disconnected text --- diff --git a/data/web-static/css/main.css b/data/web-static/css/main.css index 7ef34dd..e965980 100644 --- a/data/web-static/css/main.css +++ b/data/web-static/css/main.css @@ -99,6 +99,13 @@ ul li:before { border-left-color: #b4b4b4; } +#connection-status.connected { + color: #88be7e; +} + +#connection-status.disconnected { + color: #be8b7e; +} #input-metabox { diff --git a/data/web-static/js/mudsync.js b/data/web-static/js/mudsync.js index 0e7ebe6..c5b7dca 100644 --- a/data/web-static/js/mudsync.js +++ b/data/web-static/js/mudsync.js @@ -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); diff --git a/mudsync/networking.scm b/mudsync/networking.scm index 33ad424..b541c1e 100644 --- a/mudsync/networking.scm +++ b/mudsync/networking.scm @@ -249,7 +249,11 @@ like the web one" ;; (p (b "") " 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"))