Letzte Station bekommt prio
This commit is contained in:
@@ -6,6 +6,7 @@ const ctx = canvas.getContext('2d');
|
||||
let isDrawing = false;
|
||||
let hasSignature = false;
|
||||
let ws = null;
|
||||
let shouldReconnect = true;
|
||||
let currentPdf = null;
|
||||
let pdfDoc = null;
|
||||
let currentPageNum = 1;
|
||||
@@ -45,6 +46,26 @@ function connectWebSocket() {
|
||||
if (warning) {
|
||||
warning.style.display = 'block';
|
||||
}
|
||||
} else if (data.type === 'replaced_by_new_station') {
|
||||
console.log('⚠️ Diese Signatur-Station wurde durch eine neuere Verbindung ersetzt');
|
||||
|
||||
// Zeige eine deutliche Meldung an dieser Station
|
||||
const warning = document.getElementById('alreadyConnectedWarning');
|
||||
if (warning) {
|
||||
warning.textContent = currentLanguage === 'de'
|
||||
? 'Diese Signatur-Station wurde von einer neueren Station abgelöst.'
|
||||
: 'This signature station has been replaced by a newer station.';
|
||||
warning.style.display = 'block';
|
||||
}
|
||||
|
||||
// Nicht automatisch neu verbinden, um Ping-Pong zu vermeiden
|
||||
shouldReconnect = false;
|
||||
|
||||
try {
|
||||
ws.close();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schließen der WebSocket-Verbindung nach Ersatz:', error);
|
||||
}
|
||||
} else if (data.type === 'pdf') {
|
||||
console.log('PDF empfangen');
|
||||
currentPdf = new Uint8Array(data.pdf);
|
||||
@@ -113,7 +134,11 @@ function connectWebSocket() {
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('WebSocket getrennt');
|
||||
if (shouldReconnect) {
|
||||
setTimeout(connectWebSocket, 1000);
|
||||
} else {
|
||||
console.log('Automatischer Reconnect ist deaktiviert (Station wurde ersetzt)');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
35
server.js
35
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 meldet sich an – bestehende Station wird abgemeldet');
|
||||
|
||||
// Informiere die bisher aktive Station, dass sie durch eine neue ersetzt wird
|
||||
try {
|
||||
signatureConnection.send(JSON.stringify({
|
||||
type: 'replaced_by_new_station'
|
||||
}));
|
||||
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('Aktive Signatur-Station über neue Station informiert');
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Informieren der alten Signatur-Station:', error);
|
||||
}
|
||||
|
||||
// No existing connection, register this new one
|
||||
// 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