Letzte Station bekommt prio
This commit is contained in:
43
server.js
43
server.js
@@ -205,22 +205,37 @@ function handleMasterRegister(ws) {
|
||||
}
|
||||
|
||||
function handleSignatureRegister(ws) {
|
||||
// Check if another signature station is already connected
|
||||
// Wenn bereits eine Signatur-Station verbunden ist, erhält die NEUE Station Priorität.
|
||||
if (signatureConnection && signatureConnection.readyState === WebSocket.OPEN) {
|
||||
// Inform the new station that another station is already connected
|
||||
ws.send(JSON.stringify({
|
||||
type: 'already_connected'
|
||||
}));
|
||||
console.log('⚠️ Neue Signatur-Station versucht sich zu verbinden, aber bereits eine Station verbunden');
|
||||
console.log('⚠️ Neue Station wurde informiert, alte Station bleibt aktiv');
|
||||
// Keep the old connection, don't replace it
|
||||
// Don't register the new connection as signatureConnection
|
||||
return; // Exit without registering the new connection
|
||||
}
|
||||
console.log('⚠️ Neue Signatur-Station meldet sich an – bestehende Station wird abgemeldet');
|
||||
|
||||
// No existing connection, register this new one
|
||||
signatureConnection = ws;
|
||||
console.log('Signatur-Station registriert');
|
||||
// Informiere die bisher aktive Station, dass sie durch eine neue ersetzt wird
|
||||
try {
|
||||
signatureConnection.send(JSON.stringify({
|
||||
type: 'replaced_by_new_station'
|
||||
}));
|
||||
console.log('Aktive Signatur-Station über neue Station informiert');
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Informieren der alten Signatur-Station:', error);
|
||||
}
|
||||
|
||||
// Alte Verbindung merken und neue sofort als aktive Station setzen
|
||||
const oldConnection = signatureConnection;
|
||||
signatureConnection = ws;
|
||||
console.log('Signatur-Station gewechselt: neue Verbindung ist nun aktiv');
|
||||
|
||||
// Alte Verbindung sauber schließen (dieser Close-Event betrifft NICHT die neue Station)
|
||||
try {
|
||||
oldConnection.close();
|
||||
console.log('Alte Signatur-Station Verbindung geschlossen');
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schließen der alten Signatur-Station:', error);
|
||||
}
|
||||
} else {
|
||||
// Keine bestehende Station – neue Verbindung einfach registrieren
|
||||
signatureConnection = ws;
|
||||
console.log('Signatur-Station registriert');
|
||||
}
|
||||
|
||||
// Notify master that signature station is now connected
|
||||
if (masterConnection && masterConnection.readyState === WebSocket.OPEN) {
|
||||
|
||||
Reference in New Issue
Block a user