X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=data%2Fweb-static%2Fjs%2Fmudsync.js;fp=data%2Fweb-static%2Fjs%2Fmudsync.js;h=f2edef9331316fc7527652a52e39a4b086911787;hp=0000000000000000000000000000000000000000;hb=18c74950d1bd9fc915411bde06b99a273b55ae25;hpb=f19d236c49f1145138e2274d2f5ab3fb1be3e890 diff --git a/data/web-static/js/mudsync.js b/data/web-static/js/mudsync.js new file mode 100644 index 0000000..f2edef9 --- /dev/null +++ b/data/web-static/js/mudsync.js @@ -0,0 +1,23 @@ +function displayMessage(data) { + console.log("received message"); + console.log(data); +} + +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); + }; + ws.onopen = function() { + console.log("connected"); + ws.send("Hello, there!"); + }; + ws.onclose = function () { + console.log("closed websocket"); + }; +} + +window.onload = function () { + installWebsocket(); +}