refactor: single account-level SSE stream instead of per-monitor connections

This commit is contained in:
M1
2026-03-17 07:06:09 +04:00
parent 55f9f6d8ed
commit 66b368453d
4 changed files with 32 additions and 35 deletions
+5 -5
View File
@@ -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);
}
}