X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=data%2Fweb-static%2Fjs%2Fmudsync.js;h=90f3daa4ef9af9d995cf1c0649a6c19ab1ff0c71;hp=1a08b47178142d7b148cc02362ebc5c4801efa9c;hb=829df0120213f2bf7420b8ae153e761feb675106;hpb=8f1cfd1d4bcc9ecd7434e4d1f352d75ac371794f diff --git a/data/web-static/js/mudsync.js b/data/web-static/js/mudsync.js index 1a08b47..90f3daa 100644 --- a/data/web-static/js/mudsync.js +++ b/data/web-static/js/mudsync.js @@ -18,7 +18,7 @@ ;;; along with Mudsync. If not, see . */ -function displayMessage(data) { +function displayMessage(data, self_sent) { var new_entry = document.createElement("div"); var new_text = document.createTextNode(data); var stream_metabox = document.getElementById("stream-metabox"); @@ -28,7 +28,11 @@ function displayMessage(data) { should_scroll = true; } document.getElementById("main-input").value = ""; - new_entry.setAttribute("class", "stream-entry"); + if (self_sent) { + new_entry.setAttribute("class", "stream-entry self-sent"); + } else { + new_entry.setAttribute("class", "stream-entry"); + } new_entry.appendChild(new_text); document.getElementById("stream").appendChild(new_entry); if (should_scroll) { @@ -40,11 +44,10 @@ function installWebsocket() { // TODO: Don't hardcode the websocket path; pull it from the DOM var ws = new WebSocket("ws://127.0.0.1:8888"); ws.onmessage = function(evt) { - displayMessage(evt.data); + displayMessage(evt.data, false); }; ws.onopen = function() { console.log("connected"); - ws.send("Hello, there!"); }; ws.onclose = function () { console.log("closed websocket"); @@ -58,7 +61,9 @@ function installUIHooks(ws) { if (!e) e = window.event; var keyCode = e.keyCode || e.which; if (keyCode == '13') { - sendMessageToServer(ws, input.value); + var input_val = input.value; + displayMessage("> ".concat(input_val), true); + sendMessageToServer(ws, input_val); } } }