-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.js
34 lines (30 loc) · 788 Bytes
/
hello.js
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
var ws = null;
function appendmsg(txt) {
var t = document.getElementById("msgtable");
var row = document.createElement("tr");
row.appendChild(document.createElement("td"));
row.children[0].innerText = txt;
t.appendChild(row);
}
function input_submit() {
var n = document.getElementById("in");
var txt = n.value;
n.value = "";
if (ws !== null) {
ws.send(txt);
}
}
function i_am_loaded() {
var n = document.getElementById("in");
n.onkeypress = function(e) {
if (e.key == "Enter") {
input_submit();
e.preventDefault();
}
};
ws = new WebSocket("wss://lua-EZ-server.mahkoe.repl.co/chat.cgi");
ws.onmessage = function(e) {
console.log(e);
appendmsg(e.data);
};
}