feat: SSE live ping stream for monitors
This commit is contained in:
@@ -93,3 +93,21 @@ function escapeHtml(str) {
|
||||
div.textContent = str;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Subscribe to live ping updates for a monitor via SSE
|
||||
// onPing(ping) called with each new ping object
|
||||
function watchMonitor(monitorId, onPing) {
|
||||
const key = localStorage.getItem('pingql_key');
|
||||
if (!key) return null;
|
||||
|
||||
const url = `/monitors/${monitorId}/stream`;
|
||||
const es = new EventSource(url + `?auth=${encodeURIComponent(key)}`);
|
||||
|
||||
es.onmessage = (e) => {
|
||||
try { onPing(JSON.parse(e.data)); } catch {}
|
||||
};
|
||||
es.onerror = () => {
|
||||
// Reconnect is automatic with EventSource
|
||||
};
|
||||
return es;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user