From 1fc8a75767a70fc4c0231f5ab877ae7b48318a97 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 11 Sep 2025 11:44:16 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderung:=20Verbesserung=20der=20Socket.io?= =?UTF-8?q?-Integration=20und=20Anpassung=20der=20Benutzer-ID-=C3=9Cbertra?= =?UTF-8?q?gung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ä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. --- frontend/src/store/index.js | 10 ++++++---- frontend/src/views/falukant/BranchView.vue | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 6d8a353..b00f410 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -68,7 +68,8 @@ const store = createStore({ await dispatch('initializeDaemonSocket'); const socket = this.getters.socket; if (socket) { - socket.emit('setUserId', user.id); + const idForSocket = user?.hashedId || user?.id; + if (idForSocket) socket.emit('setUserId', idForSocket); } await dispatch('loadMenu'); }, @@ -91,10 +92,11 @@ const store = createStore({ secure: true, transports: ['websocket', 'polling'] }); - - socket.on('connect', () => { + + socket.on('connect', () => { 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) => { diff --git a/frontend/src/views/falukant/BranchView.vue b/frontend/src/views/falukant/BranchView.vue index 3d19102..fc3d105 100644 --- a/frontend/src/views/falukant/BranchView.vue +++ b/frontend/src/views/falukant/BranchView.vue @@ -55,7 +55,7 @@ export default { }, computed: { - ...mapState(['daemonSocket']), + ...mapState(['socket', 'daemonSocket']), }, async mounted() { @@ -72,7 +72,7 @@ export default { this.selectMainBranch(); } - // Live-Socket-Events + // Live-Socket-Events (Daemon WS) [ "production_ready", "stock_change", "price_update", "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() { // Daemon WebSocket wird automatisch beim Logout geschlossen + if (this.socket) { + this.socket.off('falukantUpdateStatus'); + this.socket.off('falukantBranchUpdate'); + } }, methods: {