Skip to content

Commit

Permalink
fix connected serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 29, 2024
1 parent 2e6f1e8 commit 37ed0af
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ const getGameState = (
export type PublicGameState = ReturnType<typeof getGameState>['public'];

export class Room {
// Serialized state
public roster: User[] = [];
public clientIds: Record<string, string> = {};
private chat: ChatMessage[] = [];
private io: Server;
public roomId: string;
public creationTime: Date = new Date();
public jpd: ReturnType<typeof getGameState> = getGameState({}, [], [], []);
public settings = {
Expand All @@ -152,6 +151,10 @@ export class Room {
enableAIJudge: false,
enableAIVoices: undefined as string | undefined,
};

// Unserialized state
private io: Server;
public roomId: string;
// Note: snapshot is not persisted so undo is not possible if server restarts
private jpdSnapshot: ReturnType<typeof getGameState> | undefined;
private undoActivated: boolean | undefined = undefined;
Expand All @@ -167,8 +170,8 @@ export class Room {
roomId: string,
roomData?: string | null | undefined,
) {
this.roomId = roomId;
this.io = io;
this.roomId = roomId;

if (roomData) {
this.deserialize(roomData);
Expand Down Expand Up @@ -445,7 +448,8 @@ export class Room {
this.creationTime = new Date(roomObj.creationTime);
}
if (roomObj.roster) {
this.roster = roomObj.roster;
// Reset connected state to false, reconnects will update it again
this.roster = roomObj.roster.map((p: User) => ({...p, connected: false}));
}
if (roomObj.jpd && roomObj.jpd.public) {
const gameData = roomObj.jpd;
Expand Down

0 comments on commit 37ed0af

Please sign in to comment.