-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_template.html
More file actions
87 lines (81 loc) · 2.12 KB
/
dashboard_template.html
File metadata and controls
87 lines (81 loc) · 2.12 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AEGIS1 Dashboard</title>
<style>
body {
font-family: system-ui;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
}
.connected {
background: #d4edda;
color: #155724;
}
.disconnected {
background: #f8d7da;
color: #721c24;
}
.event {
border: 1px solid #ddd;
padding: 10px;
margin: 5px 0;
border-radius: 4px;
}
#events {
max-height: 600px;
overflow-y: auto;
}
</style>
</head>
<body>
<h1>AEGIS1 Dashboard</h1>
<div id="status" class="status disconnected">Connecting...</div>
<div id="events"></div>
<script>
const s = document.getElementById("status");
const e = document.getElementById("events");
let ws = null;
function connect() {
const p = window.location.protocol === "https:" ? "wss:" : "ws:";
const url = p + "//" + window.location.host + "/ws/dashboard";
ws = new WebSocket(url);
ws.onopen = () => {
s.textContent = "Connected";
s.className = "status connected";
};
ws.onmessage = (ev) => {
try {
const msg = JSON.parse(ev.data);
const el = document.createElement("div");
el.className = "event";
el.textContent = JSON.stringify(msg, null, 2);
e.insertBefore(el, e.firstChild);
if (e.children.length > 100) e.removeChild(e.lastChild);
} catch (err) {
console.error("Failed to parse message:", err);
}
};
ws.onerror = () => {
console.error("WebSocket error", { url: ws.url, readyState: ws.readyState });
s.textContent = "Error";
s.className = "status disconnected";
};
ws.onclose = (ev) => {
console.error("WebSocket closed", { code: ev.code, reason: ev.reason });
s.textContent = "Reconnecting...";
s.className = "status disconnected";
setTimeout(connect, 3000);
};
}
connect();
</script>
</body>
</html>