From 25c34496ce23be265460bc4c95cba6036ff577a2 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 3 Feb 2017 06:20:50 -0600 Subject: [PATCH] add connected/disconnected text --- data/web-static/css/main.css | 7 +++++++ data/web-static/js/mudsync.js | 15 ++++++++++++++- mudsync/networking.scm | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) 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")) -- 2.31.1