-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
57 lines (48 loc) · 1.56 KB
/
index.html
File metadata and controls
57 lines (48 loc) · 1.56 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
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Socket.IO Fiddle</title>
</head>
<body>
<div id="bg" style="height: 100vh; width: 100vw">
<h2>Status: <span id="status">Disconnected</span></h2>
<h2>Messages:</h2>
<ul id="messages"></ul>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
const status = document.getElementById('status');
const messages = document.getElementById('messages');
const appendMessage = (content) => {
const item = document.createElement('li');
item.textContent = content;
messages.appendChild(item);
};
const socket = io({
// Socket.IO options
});
socket.on('connect', () => {
status.innerText = 'Connected';
appendMessage(`status: connected`);
});
socket.on('connect_error', (err) => {
appendMessage(`event: connect_error | reason: ${err.message}`);
});
socket.on('disconnect', (reason) => {
status.innerText = 'Disconnected';
appendMessage(`event: disconnect | reason: ${reason}`);
});
let resetTimeout = undefined;
socket.on('blink-now', (args) => {
const bg = document.getElementById('bg');
bg.style.backgroundColor = args.colour;
console.log('i should blink now with these settings:', args);
clearTimeout(resetTimeout);
resetTimeout = setTimeout(() => {
bg.style.backgroundColor = 'black';
}, args.timeToGlowInMs);
});
</script>
</body>
</html>