f2edef9331316fc7527652a52e39a4b086911787
[mudsync.git] / data / web-static / js / mudsync.js
1 function displayMessage(data) {
2     console.log("received message");
3     console.log(data);
4 }
5
6 function installWebsocket() {
7     // TODO: Don't hardcode the websocket path; pull it from the DOM
8     var ws = new WebSocket("ws://127.0.0.1:8888");
9     ws.onmessage = function(evt) {
10         displayMessage(evt.data);
11     };
12     ws.onopen = function() {
13         console.log("connected");
14         ws.send("Hello, there!");
15     };
16     ws.onclose = function () {
17         console.log("closed websocket");
18     };
19 }
20
21 window.onload = function () {
22     installWebsocket();
23 }