Handle transient network suspension in frontend polling and SSE

This commit is contained in:
Smittix
2026-02-24 22:25:59 +00:00
parent 636ca84282
commit 2ef6dfe472
5 changed files with 78 additions and 7 deletions
+9 -1
View File
@@ -7,6 +7,7 @@ const AlertCenter = (function() {
let rules = [];
let eventSource = null;
let reconnectTimer = null;
let lastConnectionWarningAt = 0;
function init() {
loadRules();
@@ -31,7 +32,14 @@ const AlertCenter = (function() {
};
eventSource.onerror = function() {
console.warn('[Alerts] SSE connection error');
const now = Date.now();
const offline = (typeof window.isOffline === 'function' && window.isOffline()) ||
(typeof navigator !== 'undefined' && navigator.onLine === false);
const shouldLog = !offline && !document.hidden && (now - lastConnectionWarningAt) > 15000;
if (shouldLog) {
lastConnectionWarningAt = now;
console.warn('[Alerts] SSE connection error; retrying');
}
if (reconnectTimer) clearTimeout(reconnectTimer);
reconnectTimer = setTimeout(connect, 2500);
};