refactor: single account-level SSE stream instead of per-monitor connections
This commit is contained in:
@@ -58,14 +58,15 @@ function escapeHtml(str) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Subscribe to live ping updates for a monitor via SSE (fetch-based for auth header support)
|
||||
// Returns an AbortController — call .abort() to close
|
||||
function watchMonitor(monitorId, onPing) {
|
||||
// Subscribe to live ping updates for the whole account via a single SSE stream.
|
||||
// onPing receives each ping object (includes monitor_id).
|
||||
// Returns an AbortController — call .abort() to close.
|
||||
function watchAccount(onPing) {
|
||||
const ac = new AbortController();
|
||||
|
||||
async function connect() {
|
||||
try {
|
||||
const res = await fetch(`/monitors/${monitorId}/stream`, {
|
||||
const res = await fetch(`/account/stream`, {
|
||||
credentials: 'same-origin',
|
||||
signal: ac.signal,
|
||||
});
|
||||
@@ -87,7 +88,6 @@ function watchMonitor(monitorId, onPing) {
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.name === 'AbortError') return;
|
||||
// Reconnect after a short delay on unexpected disconnect
|
||||
setTimeout(connect, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user