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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user