projects
/
mudsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
websockets support works! :D
[mudsync.git]
/
data
/
web-static
/
js
/
mudsync.js
diff --git
a/data/web-static/js/mudsync.js
b/data/web-static/js/mudsync.js
index 1a08b47178142d7b148cc02362ebc5c4801efa9c..90f3daa4ef9af9d995cf1c0649a6c19ab1ff0c71 100644
(file)
--- a/
data/web-static/js/mudsync.js
+++ b/
data/web-static/js/mudsync.js
@@
-18,7
+18,7
@@
;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
*/
;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
*/
-function displayMessage(data) {
+function displayMessage(data
, self_sent
) {
var new_entry = document.createElement("div");
var new_text = document.createTextNode(data);
var stream_metabox = document.getElementById("stream-metabox");
var new_entry = document.createElement("div");
var new_text = document.createTextNode(data);
var stream_metabox = document.getElementById("stream-metabox");
@@
-28,7
+28,11
@@
function displayMessage(data) {
should_scroll = true;
}
document.getElementById("main-input").value = "";
should_scroll = true;
}
document.getElementById("main-input").value = "";
- new_entry.setAttribute("class", "stream-entry");
+ if (self_sent) {
+ new_entry.setAttribute("class", "stream-entry self-sent");
+ } else {
+ new_entry.setAttribute("class", "stream-entry");
+ }
new_entry.appendChild(new_text);
document.getElementById("stream").appendChild(new_entry);
if (should_scroll) {
new_entry.appendChild(new_text);
document.getElementById("stream").appendChild(new_entry);
if (should_scroll) {
@@
-40,11
+44,10
@@
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) {
// 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);
+ displayMessage(evt.data
, false
);
};
ws.onopen = function() {
console.log("connected");
};
ws.onopen = function() {
console.log("connected");
- ws.send("Hello, there!");
};
ws.onclose = function () {
console.log("closed websocket");
};
ws.onclose = function () {
console.log("closed websocket");
@@
-58,7
+61,9
@@
function installUIHooks(ws) {
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13') {
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13') {
- sendMessageToServer(ws, input.value);
+ var input_val = input.value;
+ displayMessage("> ".concat(input_val), true);
+ sendMessageToServer(ws, input_val);
}
}
}
}
}
}