Add scoreboard countdown timer and sound effects
- Timer: one per event, set from the control room (duration, presets, start/pause/resume/reset, show/hide, T shortcut). Rules are pure functions in src/lib/timer.ts; the server's clock sets the end time and each screen counts down locally, corrected for its own clock. Needs supabase/migrations/0002_timer.sql. - Sound effects on the scoreboard, synthesised with Web Audio (no files): drum-roll + crash per revealed team, fanfare for first place, a chime on game change, ticks for the last 10 seconds and a buzzer at zero. Triggers are pure functions comparing consecutive payloads. - 'Turn sound on' button on the scoreboard, since browsers block audio until a click; the choice is remembered across reloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+16
-1
@@ -59,12 +59,27 @@ type ScoreboardPayload = {
|
||||
rank?: number; total?: number;
|
||||
// v1 sends totals only; no per-game points.
|
||||
}>;
|
||||
updatedAt: string;
|
||||
// null while the host has the timer hidden; sent regardless of score visibility
|
||||
timer: {
|
||||
status: 'idle' | 'running' | 'paused' | 'finished';
|
||||
remainingMs: number; // as of updatedAt
|
||||
endsAt: string | null; // set while running
|
||||
durationMs: number;
|
||||
} | null;
|
||||
updatedAt: string; // server clock; screens use it to correct their own
|
||||
};
|
||||
```
|
||||
During reveal mode, teams not yet revealed are sent without rank/total, alphabetically and before the revealed ones, so their order leaks nothing.
|
||||
When frozen, rank/total come from `frozen_snapshot` but `currentGame` stays live. A missing or invalid snapshot is treated as hidden, never as live.
|
||||
|
||||
## Timer and sound
|
||||
- Timer state lives on `events` (see DATA_MODEL.md). `src/lib/timer.ts` holds the rules as pure
|
||||
functions; server actions apply them using the server's clock. Screens count down locally
|
||||
between pings from `endsAt`, offset by `updatedAt` minus their own clock.
|
||||
- Sound effects are synthesised in `src/lib/sound.ts` with the Web Audio API. Which sound a
|
||||
change triggers is decided by pure functions in `src/lib/scoreboard-sounds.ts`; the
|
||||
scoreboard compares each new payload with the previous one. No sound data travels over Realtime.
|
||||
|
||||
## Folder layout
|
||||
```
|
||||
src/
|
||||
|
||||
Reference in New Issue
Block a user