Änderung: Verbesserung der Socket.io-Integration und Anpassung der Benutzer-ID-Übertragung

Änderungen:
- Die Logik zur Übertragung der Benutzer-ID an den Socket wurde aktualisiert, um die Verwendung von `hashedId` zu unterstützen.
- In `BranchView.vue` wurde die Socket-Verbindung um zusätzliche Live-Events erweitert und die Handhabung der Socket-Events optimiert.
- Protokollausgaben wurden hinzugefügt, um die Nachverfolgbarkeit der Socket-Interaktionen zu verbessern.

Diese Anpassungen erhöhen die Flexibilität und Robustheit der Socket.io-Integration in der Anwendung.
This commit is contained in:
Torsten Schulz (local)
2025-09-11 11:44:16 +02:00
parent 5c5f8e0f0a
commit 1fc8a75767
2 changed files with 18 additions and 6 deletions

View File

@@ -68,7 +68,8 @@ const store = createStore({
await dispatch('initializeDaemonSocket'); await dispatch('initializeDaemonSocket');
const socket = this.getters.socket; const socket = this.getters.socket;
if (socket) { if (socket) {
socket.emit('setUserId', user.id); const idForSocket = user?.hashedId || user?.id;
if (idForSocket) socket.emit('setUserId', idForSocket);
} }
await dispatch('loadMenu'); await dispatch('loadMenu');
}, },
@@ -91,10 +92,11 @@ const store = createStore({
secure: true, secure: true,
transports: ['websocket', 'polling'] transports: ['websocket', 'polling']
}); });
socket.on('connect', () => { socket.on('connect', () => {
console.log('✅ Socket.io connected successfully'); console.log('✅ Socket.io connected successfully');
socket.emit('setUserId', state.user.id); // Sende user.id, wenn user vorhanden ist const idForSocket = state.user?.hashedId || state.user?.id;
if (idForSocket) socket.emit('setUserId', idForSocket);
}); });
socket.on('disconnect', (reason) => { socket.on('disconnect', (reason) => {

View File

@@ -55,7 +55,7 @@ export default {
}, },
computed: { computed: {
...mapState(['daemonSocket']), ...mapState(['socket', 'daemonSocket']),
}, },
async mounted() { async mounted() {
@@ -72,7 +72,7 @@ export default {
this.selectMainBranch(); this.selectMainBranch();
} }
// Live-Socket-Events // Live-Socket-Events (Daemon WS)
[ [
"production_ready", "stock_change", "price_update", "production_ready", "stock_change", "price_update",
"director_death", "production_started", "selled_items", "director_death", "production_started", "selled_items",
@@ -91,10 +91,20 @@ export default {
}); });
} }
}); });
// Live-Socket-Events (Backend Socket.io)
if (this.socket) {
this.socket.on('falukantUpdateStatus', (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data }));
this.socket.on('falukantBranchUpdate', (data) => this.handleEvent({ event: 'falukantBranchUpdate', ...data }));
}
}, },
beforeUnmount() { beforeUnmount() {
// Daemon WebSocket wird automatisch beim Logout geschlossen // Daemon WebSocket wird automatisch beim Logout geschlossen
if (this.socket) {
this.socket.off('falukantUpdateStatus');
this.socket.off('falukantBranchUpdate');
}
}, },
methods: { methods: {