Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var name = window.location
document.session.name.value = name
var text = document.session.name.value
var ws = new WebSocket("ws://" + window.location.hostname + ":8887/");
ws.onopen = function () {
if (name != null) {
document.write("Connected to websocket server! <br>");
ws.send("name:" + delineate(text));
document.write("Sent data: name:" + delineate(text) + "<br>");
}
};
ws.onmessage = function (evt) {
var sound = new Howl({
urls: ['sounds/' + evt.data + '.ogg']
}).play();
};
ws.onclose = function () {
alert("Closed!");
};
ws.onerror = function (err) {
alert("Error: " + err);
};
function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.lastIndexOf("&");
return (str.substring(theleft, theright));
}