-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (37 loc) · 1.07 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
<!DOCTYPE html>
<html>
<body>
<h1>Test site</h1>
<p>Pixel updates will appear here when they occur: </p>
<div id="logs"></div>
<script>
const socket = new WebSocket('ws://localhost:3000/api/live');
socket.onopen = () => {
console.log("Connected to server");
};
socket.onmessage = (msg) => {
var data;
try {
data = JSON.parse(msg.data);
} catch (e) {
console.log("Invalid JSON: ", e, msg);
return;
}
switch (data.type.toLowerCase()) {
case "update":
console.log("Pixel update received: ", data.data);
var p = document.createElement("p");
p.innerHTML = "Pixel update: " + JSON.stringify(data.data);
document.getElementById("logs").appendChild(p);
break;
default:
console.log("Data received: ", data);
var p = document.createElement("p");
p.innerHTML = "Data: " + JSON.stringify(data.data);
document.getElementById("logs").appendChild(p);
break;
}
};
</script>
</body>
</html>