-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
48 lines (48 loc) · 1.47 KB
/
index.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
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="WebSocket client for send received message private and broadcast">
<meta name="keywords" content="HTML, JavaScript, WebSocket, WebSocket Client">
<meta name="author" content="bangjii">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jii WebSocket</title>
</head>
<body>
<center>
<h1>Debug</h1>
<textarea id="txtReceived" rows="8" cols="40">
</textarea>
<button onclick="clear()">Clear</button>
</center>
<script>
var myUser = "debug";
var basicAuth = {user:myUser};
var HOST = location.origin.replace(/^http/, 'ws')
var ws = new WebSocket(HOST + '/' + JSON.stringify(basicAuth));
var textArea = document.getElementById('txtReceived');
textArea.value = "";
textArea.value += 'websocket client started\n' + '-------------------' + '\n';
ws.onopen = function (e) {
textArea.value += 'websocket connected!\n' + '-------------------' + '\n';
console.log(e);
}
ws.onclose = function (e) {
textArea.value += 'websocket closed!\n' + '-------------------' + '\n';
console.log(e);
}
ws.onmessage = function (e) {
if (e.data != "PING!"){
console.log(e);
textArea.value += e.data + '\n' + '-------------------' + '\n';
}
}
ws.onerror = function (e) {
textArea.value += 'websocket disconnected!\n' + '-------------------' + '\n';
console.log(e);
}
function clear(){
textArea.value = "";
}
</script>
</body>
</html>