Phase 13: questions, sounds and videos on the scoreboard
A game can now carry a list of items the host puts on the scoreboard one at a time: a question (shown above the standings, with an optional picture and an answer to reveal), a sound (played through the scoreboard's speakers) or a video such as a karaoke track (takes over the screen). - Media is a YouTube link, an https link to a file, or an upload to the private game-media bucket. The scoreboard API signs a URL only for the item that is on screen. - What is on screen is state on the event, like the timer, so the ping still carries no data. An unrevealed answer and a sound's or video's name never reach the scoreboard payload. - Control room: click an item to show it, or "Random" to have one picked (prefers items not played yet). Show/hide answer, pause, take off screen; shortcuts Q / A / X. - Duplicating a game or event copies its items and files; deleting removes the files. Needs supabase/migrations/0006_screen_items.sql applied before deploying. database.types.ts was edited by hand to match; re-run gen:types after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+34
-1
@@ -24,7 +24,8 @@ Next.js (App Router) on Vercel · Supabase (Postgres + Auth + Realtime Broadcast
|
||||
Admin mutations = server actions. `src/proxy.ts` (Next.js 16's name for middleware) protects `/admin/*`: must be logged in AND email in `ADMIN_EMAILS`. Every server action re-checks via `requireAdmin()`.
|
||||
|
||||
## Supabase clients (`src/lib/supabase/`)
|
||||
- `browser.ts` — anon key, used for Realtime subscribe + admin auth session.
|
||||
- `browser.ts` — anon key, used for Realtime subscribe + admin auth session (which is also what
|
||||
uploads an admin's media file straight to storage).
|
||||
- `server.ts` — cookie-based, for admin server actions (RLS applies as the admin user).
|
||||
- `admin.ts` — service role, **server-only** (`import 'server-only'`). Used by public/judge route handlers after token validation.
|
||||
|
||||
@@ -35,6 +36,9 @@ Admin mutations = server actions. `src/proxy.ts` (Next.js 16's name for middlewa
|
||||
- Judge write checks: judge not revoked, game not locked/done, criterion belongs to judge's game, team belongs to the game's event, value within min/max and on step. (DB trigger also enforces range.)
|
||||
- Scoreboard API checks `scoreboard_visibility` and strips scores when `hidden`; returns `frozen_snapshot` when `frozen`.
|
||||
- Buzz checks: the token's team exists, its event's current game has `buzzer_enabled`, isn't done, and nobody has been marked correct for this question. The team and game come from the token alone — the request has no body. One row per (game, team), so a repeat press is a no-op.
|
||||
- Uploaded media lives in the private `game-media` bucket under `{eventId}/…`. Storage policies
|
||||
allow the event's admins only; anon has none. The scoreboard API hands out a signed URL (12 h)
|
||||
for the one item that is on screen, and nothing else. Links (YouTube, files) must be `https://`.
|
||||
- Light rate limiting on judge PUT (20 req/s per token), buzz POST (5 req/s per token) and open-link join (3 req/s per link), in-memory per server instance. An open link can create at most 50 judges per game.
|
||||
|
||||
## Realtime (Broadcast "ping then refetch")
|
||||
@@ -81,9 +85,18 @@ type ScoreboardPayload = {
|
||||
}>;
|
||||
answeringTeamId: string | null; // earliest unmarked buzz; null once someone got it
|
||||
} | null;
|
||||
// null with nothing on screen; sent regardless of score visibility (see "On screen")
|
||||
onScreen:
|
||||
| { kind: 'question'; id: string; shownAt: string; text: string;
|
||||
imageUrl: string | null; answer: string | null } // answer only once revealed
|
||||
| { kind: 'sound'; id: string; shownAt: string; media: ScreenMedia; paused: boolean;
|
||||
answer: string | null }
|
||||
| { kind: 'video'; id: string; shownAt: string; media: ScreenMedia; paused: boolean }
|
||||
| null;
|
||||
updatedAt: string; // server clock; screens use it to correct their own
|
||||
};
|
||||
```
|
||||
`ScreenMedia` = `{ type: 'youtube'; videoId; startSeconds }` or `{ type: 'file'; url }`.
|
||||
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.
|
||||
|
||||
@@ -113,6 +126,26 @@ When frozen, rank/total come from `frozen_snapshot` but `currentGame` stays live
|
||||
and step. The score is written before the mark, so a refused point leaves the answer unmarked.
|
||||
- A buzz is refused once any buzz of the game is marked correct, until the host clears.
|
||||
|
||||
## On screen (questions, sounds, videos)
|
||||
- A game's items are rows in `game_items`. What is on screen is state on `events`
|
||||
(`screen_item_id`, `screen_shown_at`, `screen_answer_shown`, `screen_paused`), like the timer.
|
||||
An item only counts while its game is the current game; switching game clears it.
|
||||
- `src/lib/screen.ts` holds the rules as pure functions: `buildOnScreen` (the sanitised payload
|
||||
part — no unrevealed answer, no sound/video name), `parseYouTube`, `pickRandom`,
|
||||
`nextQuestion`, and the upload checks. Server actions in `live-actions.ts` (show, random,
|
||||
answer, pause, clear) and `item-actions.ts` (setup CRUD).
|
||||
- Rule 4 still holds: the ping carries nothing; the scoreboard refetches and plays what the
|
||||
payload says. Each player is mounted with a key of item id + `shownAt`, so showing an item
|
||||
again restarts it, and it keeps the media URL it started with (a signed URL differs in every
|
||||
payload; following it would restart the file on every refetch).
|
||||
- Playback: files use `<video>` / `<audio>`; YouTube uses the `youtube-nocookie.com` embed, with
|
||||
mute and pause sent as `postMessage` player commands. The control room decides play/pause and
|
||||
restart only — there is no shared playback position, so a scoreboard opened mid-song starts
|
||||
the song from the beginning.
|
||||
- Uploads go from the admin's browser to storage (a server action can't carry 50 MB); the
|
||||
action then records the path, after checking it is inside that event's folder. Deleting an
|
||||
item, game or event deletes its files; duplicating copies them.
|
||||
|
||||
## Folder layout
|
||||
```
|
||||
src/
|
||||
|
||||
@@ -89,5 +89,16 @@ in the scoring grid and on the scoreboard; "Undo" takes it back; "Next question"
|
||||
run the control room alongside A, but has no Delete button and can't change the co-hosts; removing B
|
||||
makes the event disappear from B's list.
|
||||
|
||||
## Phase 13 — Questions, sounds and videos on the scoreboard
|
||||
- Apply `supabase/migrations/0006_screen_items.sql` (table, event columns, the `game-media`
|
||||
bucket and its policies), then `npm run gen:types` and `npm run check:rls`.
|
||||
- Rules in `src/lib/screen.ts` (tested); setup editor per game with links and uploads;
|
||||
control-room panel (show, random, answer, pause, take off screen; `Q` / `A` / `X`).
|
||||
- Scoreboard: question above the standings, sound banner, video takeover.
|
||||
**Done when:** a quiz game shows its questions one by one with `Q` and reveals an answer with `A`
|
||||
(the answer is not in the scoreboard's network tab before that); an uploaded mp3 plays on the
|
||||
scoreboard; a karaoke game with several YouTube links plays the one I click full screen, "Random
|
||||
video" picks one that hasn't been played, and "Take off screen" brings the standings back.
|
||||
|
||||
## Stretch (only if asked)
|
||||
Participants within teams · CSV export of results.
|
||||
|
||||
+4
-2
@@ -1,10 +1,10 @@
|
||||
# Data model
|
||||
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`, `0004_buzz_result.sql`, `0005_cohosts.sql`).
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`, `0004_buzz_result.sql`, `0005_cohosts.sql`, `0006_screen_items.sql`).
|
||||
|
||||
| Table | Purpose | Key columns |
|
||||
|---|---|---|
|
||||
| `events` | A game night | `owner_id`, `scoreboard_token`, `scoreboard_visibility`, `frozen_snapshot`, `current_game_id`, `reveal_active`, `reveal_count`, `timer_visible`, `timer_duration_ms`, `timer_remaining_ms`, `timer_ends_at` |
|
||||
| `events` | A game night | `owner_id`, `scoreboard_token`, `scoreboard_visibility`, `frozen_snapshot`, `current_game_id`, `reveal_active`, `reveal_count`, `timer_visible`, `timer_duration_ms`, `timer_remaining_ms`, `timer_ends_at`, `screen_item_id`, `screen_shown_at`, `screen_answer_shown`, `screen_paused` |
|
||||
| `teams` | Teams in an event | `name`, `color` (#RRGGBB), `sort_order`, `buzzer_token` |
|
||||
| `games` | Activities | `scoring_mode`, `points_mode`, `multiplier`, `placement_points int[]`, `status`, `admin_notes`, `judge_notes`, `open_token`, `open_link_enabled`, `judging_locked`, `spotlight_team_id`, `buzzer_enabled` |
|
||||
| `criteria` | Scoring blocks per game | `label`, `description`, `input_type`, `min_value`, `max_value`, `step`, `weight` |
|
||||
@@ -13,6 +13,7 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
| `adjustments` | Bonus/penalty | `points` (+/-), `reason`, optional `game_id` |
|
||||
| `buzzes` | Who buzzed for the current question | `game_id`, `team_id`, `buzzed_at`, `result` (correct/wrong/NULL) |
|
||||
| `event_cohosts` | Admins an event is shared with | `event_id`, `email` (lower case), unique together |
|
||||
| `game_items` | Questions, sounds and videos a game can put on the scoreboard | `game_id`, `kind` (question/sound/video), `title`, `answer`, `media_url`, `storage_path`, `sort_order`, `played_at` |
|
||||
|
||||
## Notes
|
||||
- `scores` unique on `(team_id, criterion_id, judge_id)` with `NULLS NOT DISTINCT`, so there's exactly one admin row per team+criterion → clean upserts.
|
||||
@@ -22,4 +23,5 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
- Buzzers (`0003_buzzer.sql`): `buzzes` is unique on `(game_id, team_id)` — one buzz per team per question; `buzzed_at` defaults to `clock_timestamp()` and decides the order. Clearing the buzzers deletes the game's rows. A trigger checks the team is in the game's event. `teams.buzzer_token` is a 128-bit token like the others; duplicating an event gives the copied teams new ones.
|
||||
- Buzzer answers (`0004_buzz_result.sql`): `buzzes.result` is the host's mark. The team answering is the earliest buzz with `result IS NULL`, unless some buzz is `correct` (question decided). The point for a correct answer is not stored on the buzz: it is +1 on the admin's `scores` row for the game's first criterion.
|
||||
- Co-hosts (`0005_cohosts.sql`): a share is keyed by email, not user id, so an admin can be added before they have ever logged in. RLS matches it against the email in the login token. `is_event_admin(event)` = owner or co-host and guards every table inside an event; deleting the event and editing `event_cohosts` stay owner-only. A trigger stops `events.owner_id` from changing.
|
||||
- On-screen items (`0006_screen_items.sql`): `title` is the question's text, or the host's name for a sound or video. Media is `media_url` (https link) or `storage_path` (a file in the private `game-media` storage bucket, `{event id}/{uuid}.{ext}`) — never both; a sound or video needs one of them. `played_at` is set when an item goes on screen and only feeds the random pick. `events.screen_item_id` is the item on screen (set null if the item is deleted); `screen_shown_at` changes on every show so screens restart it. The bucket has storage policies for the event's admins only, a 50 MB limit and audio/video/image types.
|
||||
- `frozen_snapshot` holds the `ScoreboardPayload` captured at freeze time.
|
||||
|
||||
+35
-1
@@ -40,6 +40,7 @@ live scoreboard, and judges score from their phones via links. Versatile enough
|
||||
- Quick presets: "Karaoke (5 × 1–5)", "Single score (0–10)", "Points (number)", "Win/Lose (0–1)".
|
||||
- Admin notes + judge notes (multiline).
|
||||
- "Teams buzz in" checkbox: this game uses the team buzzers (see 4.7).
|
||||
- Questions, sounds and videos to put on the scoreboard during the game (see 4.8).
|
||||
- Judges (judged games only):
|
||||
- Nominate judges by name → each gets a personal link (copy button + QR code).
|
||||
- Toggle the open link on/off; anyone opening it types their name and becomes a judge.
|
||||
@@ -73,8 +74,11 @@ This is the screen used during the night. Must be fast and hard to mess up.
|
||||
- "Open scoreboard" button (new tab) + "Reveal mode" button (see 4.3).
|
||||
- Buzzers (buzzer games only): who buzzed, in order, with each team's gap behind the first;
|
||||
"Got it" / "Wrong" for the team answering, "Undo" on a marked team, and "Next question".
|
||||
- On the scoreboard (games with questions, sounds or videos): the game's list, a button per item
|
||||
to show or play it, "Random" per kind, show/hide answer, pause/resume, take off screen (see 4.8).
|
||||
- Keyboard shortcuts: `N` next game, `P` prev game, `H` cycle visibility, `T` start/pause timer,
|
||||
`G` got it, `W` wrong, `B` next question (clears the buzzers), `?` help.
|
||||
`G` got it, `W` wrong, `B` next question (clears the buzzers), `Q` show the next question,
|
||||
`A` show/hide the answer, `X` take it off screen, `?` help.
|
||||
|
||||
### 4.3 Scoreboard (`/s/[token]`)
|
||||
- Projector-first, 16:9, readable from the back of a hall.
|
||||
@@ -150,6 +154,34 @@ For "first to answer" games. A game opts in with the "Teams buzz in" checkbox.
|
||||
whether scores are visible, frozen or hidden (the point itself follows the usual visibility rules).
|
||||
- The phone asks the browser to keep the screen on while the page is open.
|
||||
|
||||
### 4.8 Questions, sounds and videos on the scoreboard
|
||||
A game can carry a list of things the host puts on the scoreboard, one at a time.
|
||||
- Three kinds:
|
||||
- **Question** — text, an optional picture and an optional answer. Shows above the standings.
|
||||
- **Sound** — plays through the scoreboard's speakers; the screen only says "Listen…".
|
||||
Optional answer (e.g. the song's name).
|
||||
- **Video** — a karaoke track or a clip. Takes over the whole screen until taken off.
|
||||
- Media is a link or an upload:
|
||||
- a YouTube link (for a sound, only the audio is used), or an `https://` link to a file;
|
||||
- or a file uploaded from the setup page: image for a question, audio for a sound, video for
|
||||
a video, up to 50 MB each.
|
||||
- Setup: per game, add / edit / reorder / delete items. Duplicating a game or an event copies
|
||||
them, uploaded files included.
|
||||
- Control room: the current game's list. Click an item to put it on screen; clicking the one
|
||||
already showing starts it again. Only one item is on screen at a time, and switching game
|
||||
clears it.
|
||||
- **Random** (per kind, when there are at least two): picks one for the host — e.g. the next
|
||||
karaoke song. It prefers items that haven't been shown yet and never repeats the one on
|
||||
screen. Shown items get a ✓; "Clear the ✓ ticks" starts over.
|
||||
- **Show answer** (`A`) reveals the answer under the question or sound; again to hide it.
|
||||
- **Pause / Resume** for a sound or video. **Take off screen** (`X`) returns to the scoreboard.
|
||||
- `Q` shows the next question in list order.
|
||||
- Nothing here is a score, so it shows whether scores are visible, frozen or hidden.
|
||||
- Secrets stay on the server: an answer is not sent to the scoreboard until it is revealed, and a
|
||||
sound's or video's name is never sent (it is often the answer).
|
||||
- Sound needs the same "Turn sound on" click as the sound effects (4.6). Until then a video
|
||||
plays muted and the screen says the sound is off.
|
||||
|
||||
## 5. Non-functional
|
||||
- Live latency target < 1s on normal Wi-Fi.
|
||||
- Works with ~10 teams, ~20 games, ~10 judges per game without lag.
|
||||
@@ -162,3 +194,5 @@ For "first to answer" games. A game opts in with the "Teams buzz in" checkbox.
|
||||
- Per-game timers (stretch). The event countdown timer is in 4.5; team buzzers are in 4.7.
|
||||
- Buzzers for individual contestants, a configurable points value per correct answer, and
|
||||
penalties for a wrong answer (use the bonus/penalty panel).
|
||||
- Multiple-choice questions, questions on the judges' or teams' phones, importing a list of
|
||||
questions from a file, and seeking within a video from the control room.
|
||||
|
||||
+22
@@ -102,6 +102,28 @@ On the scoreboard the buzzer is a banner in the answering team's colour above th
|
||||
In the control room the answering team's row is highlighted (Floodlight) and carries the two
|
||||
buttons "Got it +1" and "Wrong"; marked rows show ✓ / ✗ and an "Undo".
|
||||
|
||||
### On screen: questions, sounds, videos
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────┐
|
||||
│ Worship Game Night Game 5 of 8: Bible quiz │
|
||||
│ ┌──────────────────────────────────────────────────────────┐ │
|
||||
│ │ Who built the ark? │ │
|
||||
│ │ ▓ Noah ▓ │ │
|
||||
│ └──────────────────────────────────────────────────────────┘ │
|
||||
│ 1 ████ Lions 142 │
|
||||
│ 2 ████ Eagles 128 │
|
||||
└──────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
- Question: a bordered panel above the standings, text in Big Shoulders, sized down as it gets
|
||||
longer; an optional picture above the text. The revealed answer is a Floodlight block that
|
||||
pops in. The standings rows shrink to make room.
|
||||
- Sound: a slim panel "♪ Listen…" ("Paused" while paused), with the answer under it once revealed.
|
||||
- Video: fills the screen. The header and standings make way and the page padding shrinks; the
|
||||
timer, the buzzer banner and the footer stay.
|
||||
- While the browser still blocks sound, a Floodlight note says "Sound is off — click “Turn sound on”".
|
||||
- Control room: a list like the buzzer panel — the item on screen is highlighted (Floodlight),
|
||||
shown items carry a ✓, answers are visible to the host in small text.
|
||||
|
||||
## Copy
|
||||
Plain verbs: "Next game", "Hide scores", "Freeze scores", "Show scores", "Add bonus", "Copy judge link".
|
||||
Errors say what happened + what to do: "This link has been turned off. Ask the host for a new one."
|
||||
|
||||
Reference in New Issue
Block a user