arreglado chatsystem para funcionar junto a la reconexion
This commit is contained in:
@@ -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(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user