fixxed status check
This commit is contained in:
+23
-15
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user