Refactor: Entfernen des Daemon WebSocket und Umstellung auf Socket.io für Event-Verarbeitung

Änderungen:
- Der Daemon WebSocket wurde aus der Anwendung entfernt, um die Komplexität zu reduzieren und die Stabilität zu erhöhen.
- Die Event-Verarbeitung in StatusBar.vue und BranchView.vue wurde aktualisiert, um Socket.io für die Registrierung und Verarbeitung von Live-Events zu verwenden.
- Protokollausgaben wurden hinzugefügt, um den Empfang und die Verarbeitung von Events zu dokumentieren.

Diese Anpassungen verbessern die Nachvollziehbarkeit der Event-Verarbeitung und vereinfachen die Codebasis.
This commit is contained in:
Torsten Schulz (local)
2025-09-08 17:02:14 +02:00
parent 0c9f4bb952
commit 6bb4cd3478
5 changed files with 118 additions and 403 deletions

View File

@@ -55,7 +55,7 @@ export default {
},
computed: {
...mapState(['socket', 'daemonSocket']),
...mapState(['daemonSocket']),
},
async mounted() {
@@ -72,58 +72,32 @@ export default {
this.selectMainBranch();
}
// Daemon WebSocket deaktiviert - verwende Socket.io
this.setupSocketEvents();
// Live-Socket-Events - nur für Events ohne spezielle Behandlung
// Live-Socket-Events
[
"production_ready",
"stock_change",
"price_update",
"director_death",
"production_started",
"selled_items",
"knowledge_update"
"production_ready", "stock_change", "price_update",
"director_death", "production_started", "selled_items",
"knowledge_update", "falukantUpdateStatus", "falukantBranchUpdate"
].forEach(eventName => {
if (this.socket) {
this.socket.on(eventName, data => this.handleEvent({ event: eventName, ...data }));
if (this.daemonSocket) {
this.daemonSocket.addEventListener('message', (event) => {
try {
const data = JSON.parse(event.data);
if (data.event === eventName) {
this.handleEvent(data);
}
} catch (error) {
// Ignore non-JSON messages like ping/pong
}
});
}
});
},
beforeUnmount() {
if (this.socket) {
// Entferne spezielle Event-Listener
this.socket.off("falukantBranchUpdate");
this.socket.off("falukantUpdateStatus");
// Entferne allgemeine Event-Listener
this.socket.off("production_ready");
this.socket.off("stock_change");
this.socket.off("price_update");
this.socket.off("director_death");
this.socket.off("production_started");
this.socket.off("selled_items");
this.socket.off("knowledge_update");
}
// Daemon WebSocket wird automatisch beim Logout geschlossen
},
methods: {
setupSocketEvents() {
if (this.socket) {
this.socket.on('falukantBranchUpdate', (data) => {
console.log('📨 BranchView: falukantBranchUpdate empfangen:', data);
this.handleEvent({ event: 'falukantBranchUpdate', ...data });
});
this.socket.on('falukantUpdateStatus', (data) => {
console.log('📨 BranchView: falukantUpdateStatus empfangen:', data);
this.handleEvent({ event: 'falukantUpdateStatus', ...data });
});
console.log('✅ BranchView: Socket.io Events registriert');
} else {
console.log('⚠️ BranchView: Socket.io noch nicht verfügbar');
setTimeout(() => this.setupSocketEvents(), 1000);
}
},
async loadBranches() {
try {
const result = await apiClient.get('/api/falukant/branches');