reconexion basada en el UUID

This commit is contained in:
2025-08-15 18:51:46 -06:00
parent 811f569391
commit 310fb3455a
6 changed files with 176 additions and 2 deletions

View File

@@ -115,6 +115,36 @@ onMounted(async () => {
const room = await colyseusService.joinLobby();
colorInput.value = colyseusService.playerColor.value || '#667eea';
// Prefer reconnection token path to bypass locked rooms
room.onMessage("resumeReconnection", async (data: any) => {
try {
await colyseusService.reconnectWithToken(data.token);
// Leave lobby before navigating
if (colyseusService.lobbyRoom.value) {
colyseusService.lobbyRoom.value.leave();
colyseusService.lobbyRoom.value = null;
}
await router.push(`/${routeUuid.value}/demo`);
} catch (error) {
console.error('Reconnection failed:', error);
}
});
// Listen for server-initiated resume to existing game (fallback joinById)
room.onMessage("resumeGame", async (data: any) => {
try {
const gameRoom = await colyseusService.joinGameRoom(data.roomId);
// Leave lobby before navigating
if (colyseusService.lobbyRoom.value) {
colyseusService.lobbyRoom.value.leave();
colyseusService.lobbyRoom.value = null;
}
await router.push(`/${routeUuid.value}/demo`);
} catch (error) {
console.error('Auto-join failed:', error);
}
});
// Keep color input synced with server-updated color
watch(() => colyseusService.playerColor.value, (c) => {
if (c && c !== colorInput.value) colorInput.value = c;