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: {