-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws_connection_tester.html
67 lines (50 loc) · 1.78 KB
/
ws_connection_tester.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE HTML>
<html>
<head>
<script type = "text/javascript">
function WebSocketTest() {
if ("WebSocket" in window) {
// Let us open a web socket
var ws = new WebSocket("ws://hive.torch.fankserver.com/ws/hive/5bc78ff57e2ea3ce583dc6fb/sector/5bcb8a527e2ea3ce583e3191");
ws.onopen = function() {
var para = document.createElement("p");
var node = document.createTextNode("Connected");
para.appendChild(node);
var element = document.getElementById("log");
element.appendChild(para);
};
ws.onmessage = function (evt) {
var para = document.createElement("p");
var node = document.createTextNode(evt.data);
para.appendChild(node);
var element = document.getElementById("log");
element.appendChild(para);
};
ws.onclose = function() {
var para = document.createElement("p");
var node = document.createTextNode("Connection is closed...");
para.appendChild(node);
var element = document.getElementById("log");
element.appendChild(para);
};
const node = document.getElementById("in");
node.addEventListener("keyup", function(event) {
if (event.key === "Enter") {
ws.send(node.value);
}
});
} else {
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id = "sse">
<a href = "javascript:WebSocketTest()">Run WebSocket</a>
</div>
<input id="in"></div>
<div id="log"></div>
</body>
</html>