-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
74 lines (63 loc) · 1.53 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do</title>
<style>
html {
text-align: center;
font-size: 1rem;
}
div {
padding: 1rem;
}
#input {
font-size: 1rem;
}
p {
font-size: 1rem;
}
</style>
</head>
<body>
<div>
<h1>User Status</h1>
<pre id="output"></pre>
</div>
<script>
var output = document.getElementById("output");
var socket = new WebSocket("ws://localhost:8080/ws");
var userId = window.location.pathname.split("/")[1]
function sendStatusMessage(status) {
switch (socket.readyState) {
case socket.OPEN:
socket.send(`${userId} ${status}`);
output.innerHTML = `Status : ${status}`
break;
case socket.CONNECTING:
console.log("Socket CONNECTING")
case socket.CLOSING:
console.log("Socket Closing")
case socket.CLOSED:
console.log("Socket Closed")
}
}
if (userId.length < 1) {
output.innerHTML = "C'mon now don't be shy, tell us your identifier...";
} else {
socket.onopen = function () {
sendStatusMessage("ONLINE");
};
function handleBlur() {
sendStatusMessage("OFFLINE");
}
function handleFocus() {
sendStatusMessage("ONLINE");
}
window.addEventListener('blur', handleBlur);
window.addEventListener('focus', handleFocus);
}
</script>
</body>
</html>