Initial commit
This commit is contained in:
33
static/admin.js
Normal file
33
static/admin.js
Normal file
@@ -0,0 +1,33 @@
|
||||
(() => {
|
||||
// Optional live updates on dashboard
|
||||
if (!document.getElementById('tbl-displays')) return;
|
||||
|
||||
const socket = io({ transports: ['websocket'], upgrade: false });
|
||||
socket.on('connect', () => {
|
||||
socket.emit('admin_join');
|
||||
});
|
||||
|
||||
function updateRow(publicId, patch) {
|
||||
const row = document.querySelector(`tr[data-public-id="${publicId}"]`);
|
||||
if (!row) return;
|
||||
if (patch.is_online !== undefined) row.querySelector('.st').textContent = patch.is_online ? 'online' : 'offline';
|
||||
if (patch.last_seen) row.querySelector('.ls').textContent = patch.last_seen;
|
||||
if (patch.latency_ms !== undefined) row.querySelector('.lat').textContent = patch.latency_ms ? `${patch.latency_ms.toFixed(1)}ms` : '';
|
||||
if (patch.offset_ms !== undefined) row.querySelector('.off').textContent = patch.offset_ms ? `${patch.offset_ms.toFixed(1)}ms` : '';
|
||||
}
|
||||
|
||||
socket.on('admin_snapshot', (msg) => {
|
||||
const live = msg.live || {};
|
||||
Object.keys(live).forEach(pid => updateRow(pid, { ...live[pid], is_online: true }));
|
||||
});
|
||||
|
||||
socket.on('admin_display_update', (msg) => {
|
||||
updateRow(msg.public_id, msg);
|
||||
});
|
||||
|
||||
socket.on('admin_event_triggered', (msg) => {
|
||||
const el = document.getElementById('active-event');
|
||||
if (!el) return;
|
||||
el.innerHTML = `<div><strong>${msg.event_name}</strong> (#${msg.event_id})</div><div>Start: <code>${msg.start_time_ms.toFixed(3)}</code></div>`;
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user