From 4b7b54d4d3d10a8d3ff16d4443aecaf66d77459c Mon Sep 17 00:00:00 2001 From: Sases Date: Mon, 8 Jun 2026 09:55:59 +0200 Subject: [PATCH] data timers --- als_alert_screen.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/als_alert_screen.html b/als_alert_screen.html index cd2e451..a51389e 100644 --- a/als_alert_screen.html +++ b/als_alert_screen.html @@ -281,6 +281,19 @@ const machineData = {}; // id → last data payload const wsStatus = {}; // id → 'connected' | 'error' | 'disconnected' const wsMap = {}; // id → WebSocket instance + const dataTimers = {}; // id → stale-data timeout handle + + // Jeśli przez DATA_STALE_MS nie przyjdzie żadna wiadomość od maszyny + // (nawet przy technicznie otwartym WS), dane uznajemy za nieaktualne. + const DATA_STALE_MS = 10 * 60 * 1000; // 10 minut + + function resetStaleTimer(id) { + clearTimeout(dataTimers[id]); + dataTimers[id] = setTimeout(() => { + delete machineData[id]; + updateDisplay(); + }, DATA_STALE_MS); + } // ── WebSocket management ────────────────────────────────────────────────── @@ -304,7 +317,8 @@ try { const msg = JSON.parse(ev.data); if (msg.data) { - machineData[id] = { ...msg.data, _ts: msg.timestamp }; + machineData[id] = { ...msg.data, _ts: Date.now() }; + resetStaleTimer(id); updateDisplay(); } } catch (e) { @@ -322,6 +336,7 @@ // Usuwamy dane maszyny przy rozłączeniu - nie możemy potwierdzić // aktualnego stanu, więc nie trzymamy przestarzałego alarmu w cache. // Po ponownym połączeniu serwer wyśle aktualny stan. + clearTimeout(dataTimers[id]); delete machineData[id]; updateDisplay(); refreshStatus();