From: Scott Worley Date: Sun, 29 Jul 2012 18:22:35 +0000 (-0700) Subject: Send messages with X-Git-Url: http://git.scottworley.com/reliable-chat/commitdiff_plain/991a5820ea736f8acaafe4b3437befb741f0915b Send messages with --- diff --git a/webclient/rc.css b/webclient/rc.css index bc5ea69..c878e19 100644 --- a/webclient/rc.css +++ b/webclient/rc.css @@ -2,3 +2,4 @@ html, body, #outer-table, #history { width: 99.9%; height: 100%; margin: 0; padd #status { background-color: #eef } #say { width: 100% } #history { vertical-align: bottom } +img { width: 1px; height: 1px; } diff --git a/webclient/rc.js b/webclient/rc.js index 13190c5..8e565c5 100644 --- a/webclient/rc.js +++ b/webclient/rc.js @@ -1,3 +1,29 @@ +var servers = ['chkno.net', 'localhost'] + +var session = Math.random(); + +function addport(server) { + // Add the default port if server doesn't contain a port number already + if (server.indexOf(":") == -1) { + return server + ":21059"; + } else { + return server; + } +} + +function rcsend(d, message) { + var id = new Date().getTime() + "-" + session + "-" + Math.random(); + var path = "/speak" + + "?id=" + encodeURIComponent(id) + + "&text=" + encodeURIComponent(message); + for (i in servers) { + var uri = "http://" + addport(servers[i]) + path; + var img = document.createElement("img"); + img.setAttribute("src", uri); + d.appendChild(img); + } +} + function rckeydown(event) { if (event.keyCode == 13) { var d = document.createElement("div"); @@ -5,6 +31,7 @@ function rckeydown(event) { var h = document.getElementById("history"); h.appendChild(d); window.scrollTo(0, document.body.scrollHeight); + rcsend(d, document.input.say.value); document.input.say.value = ""; return false; }