-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
40 lines (37 loc) · 1.11 KB
/
Copy pathindex.html
File metadata and controls
40 lines (37 loc) · 1.11 KB
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
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>title</title>
<script src="firesocket.js"></script>
</head>
<body>
<textarea id="chat" readonly style="width: 100%;"></textarea>
<br />
<div style="display: flex;">
<input id="input" type="input" style="width: 100%;" />
<input id="submit" type="submit" />
</div>
<script defer>
const Socket = FireSocket || WebSocket;
const chat = document.getElementById("chat");
const input = document.getElementById("input");
const ws = new Socket(window.location.href.replace("http", "ws"));
ws.addEventListener("open", () => {
document.getElementById("submit").onclick = submit;
input.onkeydown = e => {
if (e.key === "Enter") submit();
};
});
ws.addEventListener("message", ev => {
chat.textContent += ev.data + "\n";
chat.style.height = "auto";
chat.style.height = chat.scrollHeight + "px";
});
function submit() {
ws.send(input.value);
input.value = "";
}
</script>
</body>
</html>