-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.html
74 lines (62 loc) · 1.96 KB
/
timer.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>
<head>
<meta charset="UTF-8" />
<title>Socket.io Timer</title>
<script
src="https://cdn.socket.io/4.6.0/socket.io.min.js"
integrity="sha384-c79GN5VsunZvi+Q/WObgk2in0CbZsHnjEqvFxC5DxHn9lTfNce2WW6h2pH6u/kF+"
crossorigin="anonymous"></script>
<script>
var socket = io("ws://15.184.79.6:4000");
var myTimerId = "match1";
socket.on("connect", function () {
console.log('connected');
socket.emit('set up', myTimerId);
});
var sendStartSignal = function () {
if (socket.connected && myTimerId !== null) {
socket.emit("start timer", myTimerId);
}
};
var sendStopSignal = function () {
if (socket.connected && myTimerId !== null) {
socket.emit("stop timer", myTimerId);
}
};
var sendResetSignal = function () {
if (socket.connected && myTimerId !== null) {
socket.emit("reset timer", myTimerId);
}
};
socket.on("update timer", (arg) => {
document.getElementById("timer-time").innerText = `${arg.hours}:${arg.minutes}:${arg.seconds}`;
console.log(arg);
});
socket.on("new user joining", (arg) => {
console.log(arg);
});
socket.on("done set up", (arg) => {
console.log(arg);
});
socket.on("timer started", (arg) => {
console.log(arg);
});
socket.on("timer stopped", (arg) => {
console.log(arg);
});
socket.on("timer error", (arg) => {
console.log(arg);
});
</script>
</head>
<body>
<h1>Socket.io Timer</h1>
<div id="timer-time"></div>
<div>
<button onclick="sendStartSignal()">Start</button>
<button onclick="sendStopSignal()">Stop</button>
<button onclick="sendResetSignal()">Reset</button>
</div>
</body>
</html>