Verbesserung: Implementierung eines Protokoll-Fallbacks für die Daemon WebSocket-Verbindung
Änderungen: - Der Verbindungsaufbau des Daemon WebSockets wurde angepasst, um zuerst mit einem spezifischen Subprotokoll zu versuchen und bei Misserfolg auf eine Verbindung ohne Subprotokoll zurückzugreifen. - Zusätzliche Protokollausgaben wurden hinzugefügt, um den Verbindungsstatus und Fehlerdetails besser nachzuvollziehen. Diese Anpassungen erhöhen die Robustheit der WebSocket-Verbindung und verbessern die Fehlerdiagnose.
This commit is contained in:
@@ -131,11 +131,22 @@ const store = createStore({
|
||||
console.log('🔌 Initializing Daemon WebSocket connection to:', daemonUrl);
|
||||
|
||||
const connectDaemonSocket = () => {
|
||||
// Protokoll-Fallback: zuerst mit Subprotokoll, dann ohne
|
||||
const protocols = ['yourpart-protocol', undefined];
|
||||
let attemptIndex = 0;
|
||||
|
||||
const tryConnectWithProtocol = () => {
|
||||
const currentProtocol = protocols[attemptIndex];
|
||||
try {
|
||||
const daemonSocket = new WebSocket(daemonUrl, 'yourpart-protocol');
|
||||
console.log('🔌 Protocol: yourpart-protocol');
|
||||
const daemonSocket = currentProtocol
|
||||
? new WebSocket(daemonUrl, currentProtocol)
|
||||
: new WebSocket(daemonUrl);
|
||||
console.log('🔌 Protocol:', currentProtocol ?? 'none (fallback)');
|
||||
|
||||
let opened = false;
|
||||
|
||||
daemonSocket.onopen = () => {
|
||||
opened = true;
|
||||
console.log('✅ Daemon WebSocket connected successfully');
|
||||
retryCount = 0; // Reset retry counter on successful connection
|
||||
const payload = JSON.stringify({
|
||||
@@ -154,6 +165,13 @@ const store = createStore({
|
||||
wasClean: event.wasClean,
|
||||
readyState: daemonSocket.readyState
|
||||
});
|
||||
// Falls Verbindungsaufbau nicht offen war und es noch einen Fallback gibt → nächsten Versuch ohne Subprotokoll
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
console.warn('🔄 Fallback: versuche erneut ohne Subprotokoll...');
|
||||
tryConnectWithProtocol();
|
||||
return;
|
||||
}
|
||||
retryConnection(connectDaemonSocket);
|
||||
};
|
||||
|
||||
@@ -171,6 +189,13 @@ const store = createStore({
|
||||
location: window.location.href,
|
||||
isSecure: window.location.protocol === 'https:'
|
||||
});
|
||||
// Bei Fehler vor Open: Fallback versuchen
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
console.warn('🔄 Fallback: versuche erneut ohne Subprotokoll (onerror)...');
|
||||
tryConnectWithProtocol();
|
||||
return;
|
||||
}
|
||||
retryConnection(connectDaemonSocket);
|
||||
};
|
||||
|
||||
@@ -193,10 +218,20 @@ const store = createStore({
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to create Daemon WebSocket:', error);
|
||||
console.error('❌ URL attempted:', import.meta.env.VITE_DAEMON_SOCKET);
|
||||
// Beim Konstruktionsfehler ebenfalls Fallback versuchen
|
||||
if (attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
console.warn('🔄 Fallback: Konstruktion ohne Subprotokoll...');
|
||||
tryConnectWithProtocol();
|
||||
return;
|
||||
}
|
||||
retryConnection(connectDaemonSocket);
|
||||
}
|
||||
};
|
||||
|
||||
tryConnectWithProtocol();
|
||||
};
|
||||
|
||||
let retryCount = 0;
|
||||
const maxRetries = 5;
|
||||
const retryConnection = (reconnectFn) => {
|
||||
|
||||
Reference in New Issue
Block a user