From 407c3b359b7d108f85439e517c77b8ca5462a454 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 4 Mar 2026 17:24:15 +0100 Subject: [PATCH] Update chat configuration and remove MultiChat component: Change chat port to 1236 in chatBridge.json, update WebSocket URL in .env.local, and delete the MultiChat.vue component to streamline chat functionality. --- backend/config/chatBridge.json | 2 +- frontend/.env.local | 2 +- frontend/src/dialogues/chat/MultiChat.vue | 148 ------------------ .../src/dialogues/chat/MultiChatDialog.vue | 58 +++++-- 4 files changed, 43 insertions(+), 167 deletions(-) delete mode 100644 frontend/src/dialogues/chat/MultiChat.vue diff --git a/backend/config/chatBridge.json b/backend/config/chatBridge.json index f9fb53a..bbe581c 100644 --- a/backend/config/chatBridge.json +++ b/backend/config/chatBridge.json @@ -1,4 +1,4 @@ { "host": "localhost", - "port": 1235 + "port": 1236 } diff --git a/frontend/.env.local b/frontend/.env.local index e404b21..321fcc3 100644 --- a/frontend/.env.local +++ b/frontend/.env.local @@ -1,4 +1,4 @@ VITE_API_BASE_URL=http://localhost:3001 VITE_TINYMCE_API_KEY=xjqnfymt2wd5q95onkkwgblzexams6l6naqjs01x72ftzryg VITE_DAEMON_SOCKET=ws://localhost:4551 -VITE_CHAT_WS_URL=ws://localhost.de:1235 +VITE_CHAT_WS_URL=ws://127.0.0.1:1235 diff --git a/frontend/src/dialogues/chat/MultiChat.vue b/frontend/src/dialogues/chat/MultiChat.vue deleted file mode 100644 index bb076a9..0000000 --- a/frontend/src/dialogues/chat/MultiChat.vue +++ /dev/null @@ -1,148 +0,0 @@ - - - - - diff --git a/frontend/src/dialogues/chat/MultiChatDialog.vue b/frontend/src/dialogues/chat/MultiChatDialog.vue index 07f9690..b2ebaef 100644 --- a/frontend/src/dialogues/chat/MultiChatDialog.vue +++ b/frontend/src/dialogues/chat/MultiChatDialog.vue @@ -216,7 +216,7 @@ export default { selectedRoom(newVal, oldVal) { if (newVal && this.transportConnected) { const room = this.getSelectedRoomName(); - if (room) this.sendWithToken({ type: 'join', room, name: this.user?.username || '' }); + if (room) this.sendWithToken({ type: 'join', room, password: '' }); this.messages = []; this.usersInRoom = []; this.selectedTargetUser = null; @@ -301,14 +301,9 @@ export default { async reloadRoomsAdmin() { if (!this.isAdmin) return; try { - const current = this.selectedRoom; - const data = await fetchPublicRooms(); - const rooms = Array.isArray(data) ? data : []; - this.rooms = rooms; - if (!rooms.find(r => r.id === current)) { - this.selectedRoom = rooms.length ? rooms[0].id : null; - } - this.messages.push({ id: Date.now(), user: 'System', text: 'Raumliste aktualisiert.' }); + this.sendWithToken({ type: 'reload_rooms' }); + this.sendWithToken({ type: 'rooms' }); + this.messages.push({ id: Date.now(), user: 'System', text: 'Raum-Reload angefordert.' }); } catch (e) { console.error('Fehler beim Neuladen der Räume', e); this.messages.push({ id: Date.now(), user: 'System', text: 'Fehler beim Neuladen der Raumliste.' }); @@ -446,7 +441,7 @@ export default { // Drop references to losers so GC can collect this.pendingWs = []; // Prepare handshake like before - const init = { type: 'init', name: this.user?.username || '', room: this.getSelectedRoomName() || '' }; + const init = { type: 'init', name: this.user?.username || '', room: this.getSelectedRoomName() || '', password: '' }; if (this.debug) console.log('[Chat WS >>]', init); this.wsSend(init); if (this.connectAttemptTimeout) clearTimeout(this.connectAttemptTimeout); @@ -543,7 +538,7 @@ export default { this.transportConnected = true; const dt = Date.now() - (this.wsStartAt || Date.now()); console.log('[Chat WS] open in', dt, 'ms', '| protocol:', ws.protocol || '(none)', '| url:', url); - const init = { type: 'init', name: this.user?.username || '', room: this.getSelectedRoomName() || '' }; + const init = { type: 'init', name: this.user?.username || '', room: this.getSelectedRoomName() || '', password: '' }; if (this.debug) console.log('[Chat WS >>]', init); this.wsSend(init); if (this.connectOpenTimer) { clearTimeout(this.connectOpenTimer); this.connectOpenTimer = null; } @@ -661,9 +656,8 @@ export default { } try { - // Send a ping message to keep connection alive - this.wsSend({ type: 'ping' }); - console.log('[Chat WS] Heartbeat sent'); + // Keepalive via supported protocol command + if (this.token) this.wsSend({ type: 'userlist', token: this.token }); } catch (error) { console.warn('[Chat WS] Heartbeat failed:', error); this.stopHeartbeat(); @@ -823,7 +817,7 @@ export default { action() { if (!this.input.trim()) return; if (!this.selectedTargetUser) return; // Nur mit Auswahl - const payload = { type: 'do', value: this.input, to: this.selectedTargetUser }; + const payload = { type: 'do', message: `${this.input} ${this.selectedTargetUser}`.trim() }; if (this.debug) console.log('[Chat WS >>]', payload); this.sendWithToken(payload); this.input = ''; @@ -1053,6 +1047,12 @@ export default { }, onWsObject(obj) { if (!obj) return; + if (obj.type === 'error') { + const text = obj.message || 'chat_error'; + this.setStatus('error'); + this.messages.push({ id: Date.now(), user: 'System', text: `Fehler: ${text}` }); + return; + } // Token handshake: only when explicitly marked as token-type if (obj.type === 'token' || obj.type === 1) { let tok = obj.token; @@ -1062,6 +1062,8 @@ export default { } if (tok) { this.token = tok; + this.sendWithToken({ type: 'rooms' }); + this.sendWithToken({ type: 'userlist' }); // No extra join here; we already sent init with room if (this.joinFallbackTimer) { clearTimeout(this.joinFallbackTimer); this.joinFallbackTimer = null; } this.flushPending(); @@ -1136,11 +1138,33 @@ export default { return; } if (obj.type === 3 && Array.isArray(obj.message)) { - const names = obj.message.map(r => r.name).filter(Boolean).join(', '); - this.handleIncoming({ type: 'system', text: names ? `Rooms: ${names}` : 'Rooms updated' }); + const mapped = obj.message + .filter(r => r && r.name) + .map((r, index) => ({ + id: r.name || index + 1, + title: r.name, + name: r.name, + users: Number(r.users || 0) + })); + if (mapped.length > 0) { + const currentName = this.getSelectedRoomName(); + this.rooms = mapped; + if (currentName) { + const existing = mapped.find(r => r.name === currentName); + this.selectedRoom = existing ? existing.id : mapped[0].id; + } else if (!this.selectedRoom) { + this.selectedRoom = mapped[0].id; + } + } return; } if (obj.type === 5) { + if (obj.message === 'room_entered') { + const to = obj.to || obj.room || this.getSelectedRoomName(); + this.handleIncoming({ type: 'system', code: 'room_entered', tr: 'room_entered', to }); + this.sendWithToken({ type: 'userlist' }); + return; + } const msg = obj.message; if (typeof msg === 'string') { // Some servers send a JSON-encoded string here; parse if it looks like JSON