Add heartbeat timeout to detect server disconnection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-27 11:23:00 -08:00
parent d173e8bac6
commit 17d7889d54

View File

@@ -1576,8 +1576,19 @@
function connectSSE() {
const evtSource = new EventSource('/api/status/stream');
let heartbeatTimeout = null;
function resetHeartbeat() {
if (heartbeatTimeout) clearTimeout(heartbeatTimeout);
heartbeatTimeout = setTimeout(() => {
setConnectionStatus(false);
evtSource.close();
setTimeout(connectSSE, 2000);
}, 10000);
}
evtSource.addEventListener('status', async (event) => {
resetHeartbeat();
const data = JSON.parse(event.data);
if (!currentConfig) {
const configResp = await fetch('/api/config');
@@ -1588,9 +1599,11 @@
evtSource.onopen = () => {
setConnectionStatus(true);
resetHeartbeat();
};
evtSource.onerror = () => {
if (heartbeatTimeout) clearTimeout(heartbeatTimeout);
setConnectionStatus(false);
evtSource.close();
setTimeout(connectSSE, 2000);