fixxed status check

This commit is contained in:
2026-02-12 19:06:39 +01:00
parent 33c2515044
commit da40eb5599
2 changed files with 56 additions and 15 deletions
+23 -15
View File
@@ -309,31 +309,39 @@ document.addEventListener('DOMContentLoaded', () => {
// Initialer Status
updateStatus(false);
// ── Automatische Verbindungsprüfung ────────────────────────────────────────
let connectionCheckInterval = null;
// ── Automatische Verbindungsprüfung ────────────────────────────────────────
let connectionCheckInterval = null;
function startConnectionCheck() {
function startConnectionCheck() {
if (connectionCheckInterval) clearInterval(connectionCheckInterval);
connectionCheckInterval = setInterval(async () => {
try {
const res = await fetch('/api/control', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ port: 'ping', value: 0 }) // Dummy
});
try {
console.log("→ Status-Check: Sende /api/status ...");
const res = await fetch('/api/status');
if (!res.ok) {
throw new Error('Check fehlgeschlagen');
throw new Error(`Status-Check HTTP ${res.status}`);
}
updateStatus(true);
} catch (err) {
const data = await res.json();
console.log("→ Status-Check Ergebnis:", data);
if (data.connected) {
updateStatus(true);
} else {
throw new Error(data.message || 'Nicht verbunden');
}
} catch (err) {
console.warn('Verbindungs-Check fehlgeschlagen:', err);
updateStatus(false, 'Verbindung verloren');
}
}, 8000); // 8 Sekunden
}
}
}, 8000); // alle 8 Sekunden
}
// Im Connect- und Reconnect-Handler nach erfolgreichem Connect/Reconnect aufrufen:
startConnectionCheck();
updateStatus(true);
window.addEventListener('beforeunload', () => {
if (connectionCheckInterval) clearInterval(connectionCheckInterval);