move hardbeat handling into backend, add publish lanestate for lighttower

This commit is contained in:
Carsten Graf
2025-07-31 01:15:44 +02:00
parent 4a1e0b8bca
commit 0166e1a695
7 changed files with 123 additions and 20 deletions

Binary file not shown.

View File

@@ -144,7 +144,26 @@
};
ws.onmessage = (event) => {
console.log("WebSocket message received:", event.data);
const data = JSON.parse(event.data);
if (data.button && data.mac && data.active !== undefined) {
const indicatorId =
data.button === "start1"
? "heartbeat1"
: data.button === "stop1"
? "heartbeat2"
: data.button === "start2"
? "heartbeat3"
: data.button === "stop2"
? "heartbeat4"
: null;
if (indicatorId) {
if (data.active) {
document.getElementById(indicatorId).classList.add("active");
} else {
document.getElementById(indicatorId).classList.remove("active");
}
}
}
try {
const data = JSON.parse(event.data);
@@ -328,20 +347,23 @@
let display1 = timer1;
let display2 = timer2;
if (status1 === "running") {
// Status für Bahn 1
const s1 = document.getElementById("status1");
const lane1Connected = areBothButtonsConnected(1);
// Status für Bahn 2
const s2 = document.getElementById("status2");
const lane2Connected = areBothButtonsConnected(2);
if (status1 === "running" && lane1Connected) {
display1 += (now - lastSync) / 1000;
}
if (status2 === "running") {
if (status2 === "running" && lane2Connected) {
display2 += (now - lastSync) / 1000;
}
document.getElementById("time1").textContent = formatTime(display1);
// Status für Bahn 1
const s1 = document.getElementById("status1");
const lane1Connected = areBothButtonsConnected(1);
if (status1 === "ready" && !lane1Connected) {
if (!lane1Connected) {
s1.className = "status standby";
s1.textContent = "Standby: Bitte beide Buttons 1x betätigen";
} else {
@@ -356,13 +378,9 @@
document.getElementById("time2").textContent = formatTime(display2);
// Status für Bahn 2
const s2 = document.getElementById("status2");
const lane2Connected = areBothButtonsConnected(2);
if (status2 === "ready" && !lane2Connected) {
if (!lane2Connected) {
s2.className = "status standby";
s2.textContent = "Standby: Bitte beide Buttons 1x betätigen";
s2.textContent = "Standby: Bitte beide 1x betätigen";
} else {
s2.className = `status ${status2}`;
s2.textContent =