]> git.scottworley.com Git - reliable-chat/blob - webclient/rc.js
8e565c588ffd93a7a5ddd171670a2becf33f2b84
[reliable-chat] / webclient / rc.js
1 var servers = ['chkno.net', 'localhost']
2
3 var session = Math.random();
4
5 function addport(server) {
6 // Add the default port if server doesn't contain a port number already
7 if (server.indexOf(":") == -1) {
8 return server + ":21059";
9 } else {
10 return server;
11 }
12 }
13
14 function rcsend(d, message) {
15 var id = new Date().getTime() + "-" + session + "-" + Math.random();
16 var path = "/speak" +
17 "?id=" + encodeURIComponent(id) +
18 "&text=" + encodeURIComponent(message);
19 for (i in servers) {
20 var uri = "http://" + addport(servers[i]) + path;
21 var img = document.createElement("img");
22 img.setAttribute("src", uri);
23 d.appendChild(img);
24 }
25 }
26
27 function rckeydown(event) {
28 if (event.keyCode == 13) {
29 var d = document.createElement("div");
30 d.appendChild(document.createTextNode(document.input.say.value));
31 var h = document.getElementById("history");
32 h.appendChild(d);
33 window.scrollTo(0, document.body.scrollHeight);
34 rcsend(d, document.input.say.value);
35 document.input.say.value = "";
36 return false;
37 }
38 }