Mixed mode (default):
- gameType is now mixed | quiz | blindtest, default "mixed"; the lobby
interleaves quiz + blindtest rounds so modes alternate
- lobby reworked: 3-way game-type switch, quiz count and/or blindtest config
+ track submission shown per selected type
Free-text quiz questions:
- quiz supports the `free` format (e.g. maths) alongside mcq/truefalse:
payload without choices, {text} vote, tolerant matching on acceptedAnswers
- shared QuizQuestionPayload.choices optional; reveal truth carries answer
- match util moved to game/match.ts (shared by quiz + blindtest)
- repo/seed include free + acceptedAnswers; in-code bank gains free questions
- client quiz view renders a text input for free questions
Mode-aware transitions:
- RoundTransition themed per mode (colors/label/emoji); announces the mode
on change (quiz <-> blindtest), lighter teaser within the same mode
- custom media buckets per mode: assets/transitions/{quiz,blindtest}/ + shared
- store tracks roundModeChanged
Verified e2e: mixed game alternates quiz/blindtest to completion; free-text
scoring covered by tests (22 pass).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
152 lines
4 KiB
TypeScript
152 lines
4 KiB
TypeScript
// Events Socket.IO typés, partagés par le serveur et le client.
|
|
// Convention : `CLIENT → SERVER` et `SERVER → CLIENT`. Tout timestamp est serveur.
|
|
|
|
import type {
|
|
Answer,
|
|
BlindtestMode,
|
|
GameType,
|
|
PlayerScore,
|
|
RoomSnapshot,
|
|
RoundConfig,
|
|
RoundType,
|
|
} from "./domain"
|
|
|
|
// --- Payloads ------------------------------------------------------------
|
|
|
|
export interface RoomCreatePayload {
|
|
playerName: string
|
|
}
|
|
|
|
export interface RoomCreatedPayload {
|
|
roomCode: string
|
|
playerId: string
|
|
}
|
|
|
|
export interface RoomJoinPayload {
|
|
roomCode: string
|
|
playerName: string
|
|
}
|
|
|
|
export interface UpdateSettingsPayload {
|
|
gameType: GameType
|
|
blindtestMode: BlindtestMode
|
|
roundDuration: number
|
|
tracksPerPlayer: number
|
|
rounds: RoundConfig[]
|
|
}
|
|
|
|
export interface PlayerRefPayload {
|
|
playerId: string
|
|
}
|
|
|
|
export interface SubmitTrackPayload {
|
|
youtubeUrl: string
|
|
}
|
|
|
|
export interface SubmitOkPayload {
|
|
accepted: boolean
|
|
reason?: string
|
|
/** Titre récupéré (oEmbed) si accepté — pour confirmation côté client. */
|
|
title?: string
|
|
/** Nombre total de titres soumis par ce joueur après cet ajout. */
|
|
count?: number
|
|
}
|
|
|
|
export interface RoundStartPayload {
|
|
type: RoundType
|
|
djId?: string
|
|
/** Timestamp serveur de début des réponses (après le délai de préparation / transition). */
|
|
startsAt: number
|
|
/** Timestamp serveur de fin de manche (startsAt + roundDuration). */
|
|
endsAt: number
|
|
/** Payload spécifique au type d'épreuve, SANS la réponse. */
|
|
payload: unknown
|
|
}
|
|
|
|
export type MediaAction = "play" | "pause" | "seek"
|
|
|
|
/** Contrôle média émis par le DJ uniquement. */
|
|
export interface MediaControlPayload {
|
|
action: MediaAction
|
|
positionSec: number
|
|
}
|
|
|
|
/** Diffusion de recalage à tous les clients. */
|
|
export interface MediaSyncPayload {
|
|
action: MediaAction
|
|
positionSec: number
|
|
atServerTs: number
|
|
}
|
|
|
|
export interface VotePayload {
|
|
answer: Answer
|
|
}
|
|
|
|
/** Progression des votes. `voted` = playerIds ayant validé (jamais leur réponse). */
|
|
export interface VoteAckPayload {
|
|
count: number
|
|
total: number
|
|
voted: string[]
|
|
}
|
|
|
|
export interface RevealPayload {
|
|
truth: unknown
|
|
perPlayerResult: unknown
|
|
}
|
|
|
|
export interface ScoreUpdatePayload {
|
|
scores: PlayerScore[]
|
|
}
|
|
|
|
export interface GameEndPayload {
|
|
finalScores: PlayerScore[]
|
|
spotifyExport?: unknown
|
|
}
|
|
|
|
export interface ErrorPayload {
|
|
code: string
|
|
message: string
|
|
}
|
|
|
|
// --- Maps d'events Socket.IO ---------------------------------------------
|
|
|
|
/** Ack standard renvoyé par le serveur sur les commandes critiques. */
|
|
export type Ack<T> = (result: { ok: true; data: T } | { ok: false; error: ErrorPayload }) => void
|
|
|
|
/** CLIENT → SERVER */
|
|
export interface ClientToServerEvents {
|
|
"room:create": (payload: RoomCreatePayload, ack: Ack<RoomCreatedPayload>) => void
|
|
"room:join": (payload: RoomJoinPayload, ack: Ack<RoomCreatedPayload>) => void
|
|
"lobby:updateSettings": (payload: UpdateSettingsPayload) => void
|
|
"game:start": (ack: Ack<null>) => void
|
|
"blindtest:submitTrack": (
|
|
payload: SubmitTrackPayload,
|
|
ack: (res: SubmitOkPayload) => void
|
|
) => void
|
|
"media:control": (payload: MediaControlPayload) => void
|
|
"round:vote": (payload: VotePayload) => void
|
|
}
|
|
|
|
/** SERVER → CLIENT */
|
|
export interface ServerToClientEvents {
|
|
"room:state": (payload: RoomSnapshot) => void
|
|
"player:left": (payload: PlayerRefPayload) => void
|
|
"player:rejoined": (payload: PlayerRefPayload) => void
|
|
"blindtest:submitOk": (payload: SubmitOkPayload) => void
|
|
"round:start": (payload: RoundStartPayload) => void
|
|
"media:sync": (payload: MediaSyncPayload) => void
|
|
"round:voteAck": (payload: VoteAckPayload) => void
|
|
"round:reveal": (payload: RevealPayload) => void
|
|
"score:update": (payload: ScoreUpdatePayload) => void
|
|
"game:end": (payload: GameEndPayload) => void
|
|
"error": (payload: ErrorPayload) => void
|
|
}
|
|
|
|
/** Events serveur ↔ serveur (inutilisés en V1, pas de Redis adapter). */
|
|
export type InterServerEvents = Record<string, never>
|
|
|
|
/** Données attachées à chaque socket côté serveur. */
|
|
export interface SocketData {
|
|
playerId?: string
|
|
roomCode?: string
|
|
}
|