arreglado chatsystem para funcionar junto a la reconexion

This commit is contained in:
2025-08-11 18:40:34 -06:00
parent 9a44afc81a
commit ee0243d456

View File

@@ -228,15 +228,25 @@ function scrollToBottomSoon() {
}); });
} }
onMounted(() => { function bindToRoom(room: any) {
const room = colyseusService.gameRoom.value; // Detach previous
if (room) { if (removeHandler) { try { removeHandler(); } catch {}
const handler = (data: any) => handleIncoming(data); removeHandler = null;
room.onMessage("chat", handler);
removeHandler = () => {
try { room.off?.("chat", handler as any); } catch(e) {}
};
} }
if (!room) return;
const handler = (data: any) => handleIncoming(data);
try { room.onMessage("chat", handler); } catch {}
removeHandler = () => {
try { room.off?.("chat", handler as any); } catch(e) {}
};
}
onMounted(() => {
bindToRoom(colyseusService.gameRoom.value);
});
watch(() => colyseusService.gameRoom.value, (room) => {
bindToRoom(room);
}); });
onUnmounted(() => { onUnmounted(() => {