Ä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:
@@ -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');
|
||||||
},
|
},
|
||||||
@@ -94,7 +95,8 @@ const store = createStore({
|
|||||||
|
|
||||||
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) => {
|
||||||
|
|||||||
@@ -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: {
|
||||||
|
|||||||
Reference in New Issue
Block a user