4단계 방·대기실: 방 만들기(게스트 포함)·6자리 코드·열린 방 목록(🔒 비밀번호 방), 인원 무제한 대기실(방장·준비·넘기기·내보내기·60초 자리 유지), 방 설정 전체 즉시 반영, 조건에 맞는 곡 N곡 + 원곡 확인 중 곡 수(1분마다 다시 셈), 대기실 채팅, 서버 재시작 안내

- 서버 테스트 49개, 브라우저 e2e(e2e/rooms.e2e.ts, 3명) 11단계
- 사용자 결정(추천안)은 docs/12 "4단계 확인"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 21:07:54 +09:00
parent c018bc5a9d
commit 735ddd0322
24 changed files with 2391 additions and 15 deletions

View File

@@ -3,20 +3,69 @@
* room/game messages are added in later stages.
*/
import { z } from 'zod';
import { CHAT_MAX } from './types';
export const PROTOCOL = 1;
export const MAX_CLIENT_MESSAGE_BYTES = 16 * 1024;
/** Chat line limit (docs/06). */
export const CHAT_MAX = 200;
export const ClientMessage = z.discriminatedUnion('t', [
/** Clock sync (docs/12 Q1): the client sends its own clock, the server echoes it with the server clock. */
z.object({ t: z.literal('ping'), c: z.number() }),
// ---- rooms (docs/04, stage 4)
z.object({ t: z.literal('join'), code: z.string().regex(/^\d{6}$/), password: z.string().max(40).optional() }),
z.object({ t: z.literal('leave') }),
/** Host only: partial RoomConfig; validated with RoomConfigSchema on the server. */
z.object({ t: z.literal('config'), patch: z.record(z.string(), z.unknown()) }),
/** Host only: room password for visibility 'password' (null clears it). */
z.object({ t: z.literal('password'), value: z.string().min(1).max(40).nullable() }),
z.object({ t: z.literal('ready'), on: z.boolean() }),
z.object({ t: z.literal('kick'), userId: z.string().max(40) }),
z.object({ t: z.literal('host'), userId: z.string().max(40) }),
/** Room chat (docs/06; stage 4 = waiting room only). `n` echoes back so the sender can confirm its optimistic line. */
z.object({ t: z.literal('chat'), text: z.string().min(1).max(CHAT_MAX), n: z.string().max(24).optional() }),
]);
export type ClientMessage = z.infer<typeof ClientMessage>;
export interface RoomPlayerView {
id: string;
nickname: string;
avatar: string | null;
kind: 'guest' | 'member';
ready: boolean;
online: boolean;
}
export interface RoomView {
code: string;
hostId: string;
status: 'lobby' | 'playing';
config: import('./room-config').RoomConfig;
hasPassword: boolean;
players: RoomPlayerView[];
/** 조건에 맞는 곡: playable now / including songs still waiting for a YouTube match. */
pool: { playable: number; total: number };
artists: { id: number; name: string }[];
}
/** One chat log line (docs/06 한 줄 로그). `seq` is per room; system lines have no userId. */
export interface ChatLine {
seq: number;
at: number;
userId: string | null;
nickname: string;
text: string;
/** Sender's nonce for its optimistic line. */
n?: string;
}
export type ServerMessage =
| { t: 'welcome'; protocol: number; userId: string; serverNow: number }
| { t: 'room'; room: RoomView }
| { t: 'left'; code: string; reason: 'leave' | 'kicked' | 'closed' | 'elsewhere' }
| { t: 'chat'; code: string; line: ChatLine }
/** Recent lines for someone who just joined (or came back). */
| { t: 'chatlog'; code: string; lines: ChatLine[] }
| { t: 'notice'; text: string }
| { t: 'pong'; c: number; s: number }
| { t: 'error'; message: string };