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

@@ -139,6 +139,8 @@ class ColyseusService {
// Update current session id for correct role mapping
try { this.sessionId.value = (gameRoom as any).sessionId || this.sessionId.value; } catch {}
console.log('gameRoom.value is now:', this.gameRoom.value);
// Register reconnection token on server for this UUID
try { (gameRoom as any).send("registerReconnection", (gameRoom as any).reconnectionToken || ""); } catch {}
// Don't register message handlers here - let the Game component handle them
@@ -172,6 +174,8 @@ class ColyseusService {
try { this.sessionId.value = (gameRoom as any).sessionId || this.sessionId.value; } catch {}
this.gameRoom.value = gameRoom;
this.currentRoom = gameRoom;
// Register reconnection token on server for this UUID
try { (gameRoom as any).send("registerReconnection", (gameRoom as any).reconnectionToken || ""); } catch {}
// Don't register message handlers here - let the Game component handle them
@@ -316,6 +320,17 @@ class ColyseusService {
}
}
// Used when lobby provides a reconnection token to resume a locked room
async reconnectWithToken(token: string): Promise<Room> {
const room = await (this.client as any).reconnect(token);
this.gameRoom.value = room;
this.currentRoom = room;
try { this.sessionId.value = (room as any).sessionId || this.sessionId.value; } catch {}
// Refresh reconnection token mapping on server
try { (room as any).send("registerReconnection", (room as any).reconnectionToken || ""); } catch {}
return room;
}
private getUuidFromPath(): string {
if (typeof window === 'undefined') return '';
const path = window.location.pathname.replace(/^\/+/, '');