feat: expansion of web dashboard with live activity feed and metrics
This commit is contained in:
@@ -56,12 +56,41 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
// We can optionally verify if client clock is drifting, but let's keep it simple.
|
||||
} else if (msg.type === "WELCOME") {
|
||||
console.log(msg.message);
|
||||
} else if (msg.type === "LOG") {
|
||||
appendToActivityFeed(msg.data);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("WS Parse Error", e);
|
||||
}
|
||||
};
|
||||
|
||||
function appendToActivityFeed(log) {
|
||||
const list = document.querySelector(".activity-feed");
|
||||
if (!list) return;
|
||||
|
||||
const item = document.createElement("li");
|
||||
item.className = `activity-item ${log.type}`;
|
||||
|
||||
const timeSpan = document.createElement("span");
|
||||
timeSpan.className = "time";
|
||||
timeSpan.textContent = log.timestamp;
|
||||
|
||||
const messageSpan = document.createElement("span");
|
||||
messageSpan.className = "message";
|
||||
messageSpan.textContent = log.message;
|
||||
|
||||
item.appendChild(timeSpan);
|
||||
item.appendChild(messageSpan);
|
||||
|
||||
// Prepend to top
|
||||
list.insertBefore(item, list.firstChild);
|
||||
|
||||
// Limit history
|
||||
if (list.children.length > 50) {
|
||||
list.removeChild(list.lastChild);
|
||||
}
|
||||
}
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log("WS Disconnected");
|
||||
if (statusIndicator) statusIndicator.classList.remove("online");
|
||||
|
||||
@@ -65,4 +65,17 @@ export class WebServer {
|
||||
this.server = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static broadcastLog(type: string, message: string) {
|
||||
if (this.server) {
|
||||
this.server.publish("status-updates", JSON.stringify({
|
||||
type: "LOG",
|
||||
data: {
|
||||
timestamp: new Date().toLocaleTimeString(),
|
||||
type,
|
||||
message
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user