-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.html
More file actions
44 lines (36 loc) · 1.12 KB
/
index.html
File metadata and controls
44 lines (36 loc) · 1.12 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
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Tahoma, Geneva, sans-serif; }
</style>
<script src="dist/websocket.js"></script>
</head>
<body>
<strong>Messages</strong><br>
<form id="form">
<input type="text" id="input" value="" />
<input type="submit" value="send" />
</form>
<div id="messages"></div>
<script>
var WebSocketClient = WebSocketClient.default;
var host = window.document.location.host.replace(/:.*/, '');
var conn = new WebSocketClient('ws://' + host + ':8080');
conn.onmessage = function (event) {
var node = document.createElement("p");
node.innerHTML = event.data;
document.getElementById('messages').appendChild(node)
};
conn.onclose = function (event) {
console.log("closing connection...")
}
document.getElementById('form').onsubmit = function(e) {
e.preventDefault()
// conn.binaryType = "arraybuffer"
conn.send(document.getElementById('input').value)
document.getElementById('input').value = null
}
</script>
</body>
</html>