- Add ws/ directory: server setup, auth, router, connections map - WebSocket auth rejects upgrade with 401 if no Better Auth session - Router parses WsClientMessageSchema, dispatches to handlers, two-layer error handling (AppError -> WsErrorSchema, unknown -> 500) - connections.ts: in-memory Map<lobbyId, Map<userId, WebSocket>> with addConnection, removeConnection, broadcastToLobby - LobbyGameStore interface + InMemoryLobbyGameStore implementation following existing GameSessionStore pattern - multiplayerGameService: generateMultiplayerQuestions() decoupled from single-player flow, hardcoded defaults en->it nouns easy 3 rounds - handleLobbyJoin and handleLobbyLeave implemented - WsErrorSchema added to shared schemas - server.ts switched to createServer + setupWebSocket
17 lines
730 B
TypeScript
17 lines
730 B
TypeScript
import type { MultiplayerQuestion } from "../services/multiplayerGameService.js";
|
|
|
|
export type LobbyGameData = {
|
|
questions: MultiplayerQuestion[];
|
|
currentIndex: number;
|
|
// NOTE: Map types are used here for O(1) lookups in-process.
|
|
// When migrating to Valkey, convert to plain objects for JSON serialization.
|
|
playerAnswers: Map<string, number | null>; // userId → selectedOptionId, null = timed out
|
|
scores: Map<string, number>; // userId → running total
|
|
};
|
|
|
|
export interface LobbyGameStore {
|
|
create(lobbyId: string, data: LobbyGameData): Promise<void>;
|
|
get(lobbyId: string): Promise<LobbyGameData | null>;
|
|
set(lobbyId: string, data: LobbyGameData): Promise<void>;
|
|
delete(lobbyId: string): Promise<void>;
|
|
}
|