@hadoku/game-ui 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chrome/HeaderLinks.d.ts +16 -0
- package/dist/chrome/HeaderLinks.js +24 -0
- package/dist/components/ActionButton.d.ts +9 -0
- package/dist/components/ActionButton.js +49 -0
- package/dist/components/Avatar.d.ts +43 -0
- package/dist/components/Avatar.js +53 -0
- package/dist/components/ConnectionBanner.css +77 -0
- package/dist/components/ConnectionBanner.d.ts +33 -0
- package/dist/components/ConnectionBanner.js +33 -0
- package/dist/components/Modal.css +69 -0
- package/dist/components/Modal.d.ts +12 -0
- package/dist/components/Modal.js +31 -0
- package/dist/components/OverPage.d.ts +4 -0
- package/dist/components/OverPage.js +21 -0
- package/dist/components/Popover.css +58 -0
- package/dist/components/Popover.d.ts +20 -0
- package/dist/components/Popover.js +63 -0
- package/dist/components/RadioCards.css +178 -0
- package/dist/components/RadioCards.d.ts +33 -0
- package/dist/components/RadioCards.js +41 -0
- package/dist/components/StatusPill.d.ts +16 -0
- package/dist/components/StatusPill.js +17 -0
- package/dist/components/connection-state.d.ts +32 -0
- package/dist/components/connection-state.js +5 -0
- package/dist/dom.d.ts +17 -0
- package/dist/dom.js +57 -0
- package/dist/front/Gallery.d.ts +22 -0
- package/dist/front/Gallery.js +48 -0
- package/dist/front/PatchNotesCard.d.ts +1 -0
- package/dist/front/PatchNotesCard.js +59 -0
- package/dist/front/camera.d.ts +80 -0
- package/dist/front/camera.js +120 -0
- package/dist/front/countdown.d.ts +2 -0
- package/dist/front/countdown.js +16 -0
- package/dist/front/discordChat.d.ts +22 -0
- package/dist/front/discordChat.js +52 -0
- package/dist/front/gallery.d.ts +13 -0
- package/dist/front/gallery.js +32 -0
- package/dist/front/gate.d.ts +23 -0
- package/dist/front/gate.js +55 -0
- package/dist/front/icons.d.ts +43 -0
- package/dist/front/icons.js +99 -0
- package/dist/front/patchNotes.d.ts +37 -0
- package/dist/front/patchNotes.js +95 -0
- package/dist/front/polls.d.ts +24 -0
- package/dist/front/polls.js +95 -0
- package/dist/front/shape.d.ts +11 -0
- package/dist/front/shape.js +52 -0
- package/dist/http.d.ts +28 -0
- package/dist/http.js +83 -0
- package/dist/idle.d.ts +2 -0
- package/dist/idle.js +7 -0
- package/dist/lazy.d.ts +9 -0
- package/dist/lazy.js +63 -0
- package/dist/popover.d.ts +13 -0
- package/dist/popover.js +39 -0
- package/dist/registered.d.ts +5 -0
- package/dist/registered.js +6 -0
- package/dist/restart-notice.d.ts +20 -0
- package/dist/restart-notice.js +54 -0
- package/dist/room/RoomShell.d.ts +116 -0
- package/dist/room/RoomShell.js +222 -0
- package/dist/room/SessionPrompt.d.ts +12 -0
- package/dist/room/SessionPrompt.js +54 -0
- package/dist/room/avatar.d.ts +31 -0
- package/dist/room/avatar.js +60 -0
- package/dist/room/look.css +13 -0
- package/dist/room/look.d.ts +35 -0
- package/dist/room/look.js +189 -0
- package/dist/room/seatsOpen.d.ts +7 -0
- package/dist/room/seatsOpen.js +37 -0
- package/dist/room/session.d.ts +26 -0
- package/dist/room/session.js +108 -0
- package/dist/room/socket-options.d.ts +33 -0
- package/dist/room/socket-options.js +40 -0
- package/dist/room/tab-id.d.ts +6 -0
- package/dist/room/tab-id.js +90 -0
- package/dist/room/whoami.d.ts +15 -0
- package/dist/room/whoami.js +48 -0
- package/dist/rooms/bundle-slot.fixture.d.ts +11 -0
- package/dist/rooms/bundle-slot.fixture.js +21 -0
- package/dist/rooms/game-clients.d.ts +12 -0
- package/dist/rooms/game-clients.js +30 -0
- package/dist/rooms/game-setup.d.ts +63 -0
- package/dist/rooms/game-setup.js +33 -0
- package/dist/rooms/relay-channel.d.ts +29 -0
- package/dist/rooms/relay-channel.js +123 -0
- package/dist/rooms/screen/RoomShell.d.ts +33 -0
- package/dist/rooms/screen/RoomShell.js +7 -0
- package/dist/screens/route.d.ts +143 -0
- package/dist/screens/route.js +359 -0
- package/dist/settings/Settings.d.ts +39 -0
- package/dist/settings/Settings.js +131 -0
- package/dist/settings/TrimScreen.d.ts +2 -0
- package/dist/settings/TrimScreen.js +29 -0
- package/dist/settings/settings.css +116 -0
- package/dist/settings/siteTrim.d.ts +3 -0
- package/dist/settings/siteTrim.js +9 -0
- package/dist/settings/trim-screen.css +30 -0
- package/dist/sound/index.d.ts +12 -0
- package/dist/sound/index.js +34 -0
- package/dist/stale-build.d.ts +16 -0
- package/dist/stale-build.js +59 -0
- package/dist/top-layer.css +22 -0
- package/dist/topLayer.d.ts +19 -0
- package/dist/topLayer.js +44 -0
- package/dist/usage.d.ts +5 -0
- package/dist/usage.js +17 -0
- package/dist/visible.d.ts +14 -0
- package/dist/visible.js +35 -0
- package/package.json +41 -4
- package/README.md +0 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A room made for an event seats nobody until `SEATS_OPEN_BEFORE_MS` before it starts: anyone may
|
|
4
|
+
* come in and chat, but its seats are drawn shut, with one line saying when they open. The server
|
|
5
|
+
* holds the rule by its own clock (`Lobby.seatsShutUntil`); this only draws it, and redraws at the
|
|
6
|
+
* opening so the seats come alive without a reload.
|
|
7
|
+
*/
|
|
8
|
+
import { useEffect, useState } from 'react';
|
|
9
|
+
import { seatsOpenAt } from '@wolffm/platform-wire/events';
|
|
10
|
+
import { countdown } from "../front/countdown.js";
|
|
11
|
+
/** When a room whose event starts at `scheduledFor` (ISO) opens its seats, in ms, while that is after `now`; null once open or for a room no event made. */
|
|
12
|
+
export function seatsShutUntil(scheduledFor, now) {
|
|
13
|
+
if (scheduledFor === null)
|
|
14
|
+
return null;
|
|
15
|
+
const starts = Date.parse(scheduledFor);
|
|
16
|
+
if (Number.isNaN(starts))
|
|
17
|
+
return null;
|
|
18
|
+
const opens = seatsOpenAt(starts);
|
|
19
|
+
return now < opens ? opens : null;
|
|
20
|
+
}
|
|
21
|
+
/** How often the line's countdown is redrawn: its finest unit is a minute. */
|
|
22
|
+
const TICK_MS = 30_000;
|
|
23
|
+
/** `seatsShutUntil` against the browser's clock, redrawn each tick until the seats open. */
|
|
24
|
+
export function useSeatsShutUntil(scheduledFor) {
|
|
25
|
+
const [now, setNow] = useState(() => Date.now());
|
|
26
|
+
const shut = seatsShutUntil(scheduledFor, now);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (shut === null)
|
|
29
|
+
return undefined;
|
|
30
|
+
const timer = setTimeout(() => setNow(Date.now()), Math.min(TICK_MS, Math.max(0, shut - Date.now())));
|
|
31
|
+
return () => clearTimeout(timer);
|
|
32
|
+
}, [shut, now]);
|
|
33
|
+
return shut;
|
|
34
|
+
}
|
|
35
|
+
export function SeatsOpenNote({ opensAt }) {
|
|
36
|
+
return (_jsxs("p", { className: "lobby__note", "data-testid": "seats-open-at", children: ["Seats open ", countdown(new Date(opensAt).toISOString(), Date.now())] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type SessionClaimStatus } from '@wolffm/rooms-protocol';
|
|
2
|
+
/** `pending` until the first answer; `taken` once another tab of this account took the room. */
|
|
3
|
+
export type SessionState = 'pending' | SessionClaimStatus | 'taken';
|
|
4
|
+
/** The part of a socket.io client this file uses. */
|
|
5
|
+
export interface SessionSocket {
|
|
6
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
7
|
+
emit(event: string, payload: unknown, ack: (answer: unknown) => void): void;
|
|
8
|
+
readonly connected: boolean;
|
|
9
|
+
connect(): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface RoomSessionDeps {
|
|
13
|
+
connect?: () => SessionSocket;
|
|
14
|
+
tabId?: () => Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface RoomSession {
|
|
17
|
+
state(): SessionState;
|
|
18
|
+
/** Called on every change of state. Returns the unsubscribe. */
|
|
19
|
+
subscribe(listener: () => void): () => void;
|
|
20
|
+
/** Take the room from the tab holding it: the ask's yes, and the taken tab's way back. */
|
|
21
|
+
take(): void;
|
|
22
|
+
/** Claim again while playing or watching: whether this account plays here may have changed. */
|
|
23
|
+
reclaim(): void;
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function roomSession(room: string, deps?: RoomSessionDeps): RoomSession;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This tab's claim on the room it is in: one live tab per player per room.
|
|
3
|
+
*
|
|
4
|
+
* The operator, 2026-11-07: a player opening a game they already have open elsewhere is asked, in the
|
|
5
|
+
* middle of the screen with the rest of the site greyed out, whether to take over here; yes ends the
|
|
6
|
+
* other session. The rule and the wire are the shared room layer's (`@wolffm/rooms-protocol`'s
|
|
7
|
+
* `session.ts`); the server's half is `packages/game-server/src/room/session.ts`. This is the screen's half:
|
|
8
|
+
*
|
|
9
|
+
* - one socket per room screen, opened when the screen has a room, which sends `session:claim`
|
|
10
|
+
* with this tab's settled id (`./tab-id.ts`) on every connect;
|
|
11
|
+
* - its answer is the state: `granted` and `watcher` play on, `held` asks, and `refused` (a request
|
|
12
|
+
* the server could not read) plays on as before rather than lock a player out;
|
|
13
|
+
* - `taken` (told, or closed by the server, which is how a take ends a tab's sockets) stops the
|
|
14
|
+
* screen and offers to take it back; that and the ask's yes are the same claim with `take`;
|
|
15
|
+
* - the screen claims again when it moves to another kind of screen in the room (the room → its
|
|
16
|
+
* match), so a watcher who sat down holds the room once their game starts;
|
|
17
|
+
* - the server's `session:beat` is answered at once. It arrives as a message, so a hidden tab whose
|
|
18
|
+
* timers the browser throttles still answers, and only a tab that is really gone goes stale.
|
|
19
|
+
*
|
|
20
|
+
* A server-side close does not reconnect, so a taken tab never loops back into the room by itself.
|
|
21
|
+
*/
|
|
22
|
+
import { io } from 'socket.io-client';
|
|
23
|
+
import { SESSION_EVENTS, parseSessionAnswer, parseSessionTaken } from '@wolffm/rooms-protocol';
|
|
24
|
+
import { socketOptions } from "./socket-options.js";
|
|
25
|
+
import { settledTabId } from "./tab-id.js";
|
|
26
|
+
export function roomSession(room, deps = {}) {
|
|
27
|
+
const listeners = new Set();
|
|
28
|
+
let state = 'pending';
|
|
29
|
+
let closed = false;
|
|
30
|
+
let wantTake = false;
|
|
31
|
+
let socket = null;
|
|
32
|
+
let tabId = null;
|
|
33
|
+
const set = (next) => {
|
|
34
|
+
if (closed || next === state)
|
|
35
|
+
return;
|
|
36
|
+
state = next;
|
|
37
|
+
for (const l of [...listeners])
|
|
38
|
+
l();
|
|
39
|
+
};
|
|
40
|
+
const claim = () => {
|
|
41
|
+
if (closed || socket === null || tabId === null || !socket.connected)
|
|
42
|
+
return;
|
|
43
|
+
const take = wantTake;
|
|
44
|
+
const request = take ? { room, tabId, take } : { room, tabId };
|
|
45
|
+
socket.emit(SESSION_EVENTS.claim, request, (raw) => {
|
|
46
|
+
const answer = parseSessionAnswer(raw);
|
|
47
|
+
if (answer === null) {
|
|
48
|
+
console.warn('[session] an answer the wire does not allow', raw);
|
|
49
|
+
set('refused');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (take && answer.status !== 'held')
|
|
53
|
+
wantTake = false;
|
|
54
|
+
set(answer.status);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const open = (id) => {
|
|
58
|
+
if (closed)
|
|
59
|
+
return;
|
|
60
|
+
tabId = id;
|
|
61
|
+
const s = (deps.connect ?? (() => io(socketOptions())))();
|
|
62
|
+
socket = s;
|
|
63
|
+
s.on('connect', claim);
|
|
64
|
+
s.on(SESSION_EVENTS.beat, (...args) => {
|
|
65
|
+
const ack = args.at(-1);
|
|
66
|
+
if (typeof ack === 'function')
|
|
67
|
+
ack();
|
|
68
|
+
});
|
|
69
|
+
s.on(SESSION_EVENTS.taken, (raw) => {
|
|
70
|
+
if (parseSessionTaken(raw)?.room === room)
|
|
71
|
+
set('taken');
|
|
72
|
+
});
|
|
73
|
+
s.on('disconnect', (reason) => {
|
|
74
|
+
// Only a take closes a session socket from the server's side.
|
|
75
|
+
if (reason === 'io server disconnect')
|
|
76
|
+
set('taken');
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
void (deps.tabId ?? settledTabId)().then(open, (err) => {
|
|
80
|
+
console.warn('[session] no tab id; the room plays on without a claim', err);
|
|
81
|
+
set('refused');
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
state: () => state,
|
|
85
|
+
subscribe(listener) {
|
|
86
|
+
listeners.add(listener);
|
|
87
|
+
return () => listeners.delete(listener);
|
|
88
|
+
},
|
|
89
|
+
take() {
|
|
90
|
+
wantTake = true;
|
|
91
|
+
if (socket === null)
|
|
92
|
+
return;
|
|
93
|
+
if (socket.connected)
|
|
94
|
+
claim();
|
|
95
|
+
else
|
|
96
|
+
socket.connect();
|
|
97
|
+
},
|
|
98
|
+
reclaim() {
|
|
99
|
+
if (state === 'granted' || state === 'watcher')
|
|
100
|
+
claim();
|
|
101
|
+
},
|
|
102
|
+
close() {
|
|
103
|
+
closed = true;
|
|
104
|
+
socket?.close();
|
|
105
|
+
listeners.clear();
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/cardtable/` → `/cardtable/socket.io/`.
|
|
3
|
+
*
|
|
4
|
+
* Pure, and tested as such, because the value it produces is only observable
|
|
5
|
+
* in a browser against a live edge — which is the definition of a thing that
|
|
6
|
+
* gets shipped wrong.
|
|
7
|
+
*/
|
|
8
|
+
export declare function socketPath(base: string): string;
|
|
9
|
+
/** The path for THIS bundle, from the base Vite was built with. */
|
|
10
|
+
export declare function defaultSocketPath(): string;
|
|
11
|
+
/**
|
|
12
|
+
* A dropped socket tries again after a quarter second, and never waits more than a second between
|
|
13
|
+
* tries. socket.io's default (1 s doubling to 5 s) let a socket sit out up to five seconds after a
|
|
14
|
+
* deploy's restart had already finished. The edge holds each try's handshake through the restart
|
|
15
|
+
* (hadoku_site's `proxy.ts`, `holdThroughRestart`), so a short delay costs a few held requests, not
|
|
16
|
+
* a storm of failed ones, and the socket lands the moment the new server listens.
|
|
17
|
+
*/
|
|
18
|
+
export declare const RECONNECT_DELAY_MS = 250;
|
|
19
|
+
export declare const RECONNECT_DELAY_MAX_MS = 1000;
|
|
20
|
+
/**
|
|
21
|
+
* How every socket on the page connects: a websocket first, and long-polling only if the websocket
|
|
22
|
+
* fails to open (`tryAllTransports`), so a network that refuses websockets still connects. socket.io's
|
|
23
|
+
* default starts on long-polling and upgrades, which cost each connection three or four extra round
|
|
24
|
+
* trips through the edge before its first frame, each a run of the edge worker. Watchparty connects
|
|
25
|
+
* websocket-first through the same edge.
|
|
26
|
+
*/
|
|
27
|
+
export declare function socketOptions(path?: string): {
|
|
28
|
+
path: string;
|
|
29
|
+
transports: ('websocket' | 'polling')[];
|
|
30
|
+
tryAllTransports: true;
|
|
31
|
+
reconnectionDelay: number;
|
|
32
|
+
reconnectionDelayMax: number;
|
|
33
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How every socket on the page connects: its path under the bundle's base, and its transports and
|
|
3
|
+
* reconnect pacing. Not any one game's: the draft, the match, the room feed and the room's session
|
|
4
|
+
* claim all connect this way.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* `/cardtable/` → `/cardtable/socket.io/`.
|
|
8
|
+
*
|
|
9
|
+
* Pure, and tested as such, because the value it produces is only observable
|
|
10
|
+
* in a browser against a live edge — which is the definition of a thing that
|
|
11
|
+
* gets shipped wrong.
|
|
12
|
+
*/
|
|
13
|
+
export function socketPath(base) {
|
|
14
|
+
const prefix = base === '' ? '/' : base;
|
|
15
|
+
return `${prefix.endsWith('/') ? prefix : `${prefix}/`}socket.io/`;
|
|
16
|
+
}
|
|
17
|
+
/** The path for THIS bundle, from the base Vite was built with. */
|
|
18
|
+
export function defaultSocketPath() {
|
|
19
|
+
const base = import.meta.env?.BASE_URL;
|
|
20
|
+
return socketPath(typeof base === 'string' ? base : '/');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A dropped socket tries again after a quarter second, and never waits more than a second between
|
|
24
|
+
* tries. socket.io's default (1 s doubling to 5 s) let a socket sit out up to five seconds after a
|
|
25
|
+
* deploy's restart had already finished. The edge holds each try's handshake through the restart
|
|
26
|
+
* (hadoku_site's `proxy.ts`, `holdThroughRestart`), so a short delay costs a few held requests, not
|
|
27
|
+
* a storm of failed ones, and the socket lands the moment the new server listens.
|
|
28
|
+
*/
|
|
29
|
+
export const RECONNECT_DELAY_MS = 250;
|
|
30
|
+
export const RECONNECT_DELAY_MAX_MS = 1000;
|
|
31
|
+
/**
|
|
32
|
+
* How every socket on the page connects: a websocket first, and long-polling only if the websocket
|
|
33
|
+
* fails to open (`tryAllTransports`), so a network that refuses websockets still connects. socket.io's
|
|
34
|
+
* default starts on long-polling and upgrades, which cost each connection three or four extra round
|
|
35
|
+
* trips through the edge before its first frame, each a run of the edge worker. Watchparty connects
|
|
36
|
+
* websocket-first through the same edge.
|
|
37
|
+
*/
|
|
38
|
+
export function socketOptions(path = defaultSocketPath()) {
|
|
39
|
+
return { path, transports: ['websocket', 'polling'], tryAllTransports: true, reconnectionDelay: RECONNECT_DELAY_MS, reconnectionDelayMax: RECONNECT_DELAY_MAX_MS };
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The stored id this page may keep, given how it was loaded: only a reload's; exported for its test. */
|
|
2
|
+
export declare function storedCandidate(navigation: string, stored: string | null): string | null;
|
|
3
|
+
/** This tab's id once no other live tab claims it: what a player's claim and joins carry. */
|
|
4
|
+
export declare function settledTabId(): Promise<string>;
|
|
5
|
+
/** Run `use` with this tab's settled id: now when it is known, else once the probe has answered. */
|
|
6
|
+
export declare function withSettledTabId(use: (id: string) => void): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This browser tab's identity, sent with every room claim (`room/session.ts`), match join
|
|
3
|
+
* (`MatchRequest.tabId`) and pod join.
|
|
4
|
+
*
|
|
5
|
+
* The server holds one live tab per player per room (`packages/game-server/src/room/session.ts`): a reload or
|
|
6
|
+
* reconnect of the SAME tab is the same holder and never asks, and a socket cut without a close
|
|
7
|
+
* reaching the server (match m-ca7bad04b715, 2026-10-28) is replaced by its own tab's reconnect at
|
|
8
|
+
* once. A second tab is another holder, and is asked before it takes over.
|
|
9
|
+
*
|
|
10
|
+
* One id per page load, held in memory: every socket this page opens — every reconnect — carries the
|
|
11
|
+
* same id. A reload keeps it, read back from sessionStorage. Only a reload: a duplicate, a restored
|
|
12
|
+
* tab, a new tab and a link navigate as something other than `reload`, so they mint their own. And
|
|
13
|
+
* because a duplicated tab starts with a COPY of the original's sessionStorage, the stored id is
|
|
14
|
+
* also probed (`@wolffm/rooms-protocol`'s `settleTabId`): if another live tab answers that it uses
|
|
15
|
+
* it, this one mints a fresh one. Every id the page sends is the settled one: an id handed out
|
|
16
|
+
* before the probe answered could be the duplicate's, and a join carrying it would hold the room
|
|
17
|
+
* for the other tab while this one's claim was asked about itself. `settledTabId` waits for it, and
|
|
18
|
+
* `withSettledTabId` hands it over at once when it is known (every page but a reload's first 150 ms).
|
|
19
|
+
*/
|
|
20
|
+
import { answerTabProbes, browserTabChannel, isTabId, mintTabId, settleTabId } from '@wolffm/rooms-protocol';
|
|
21
|
+
const STORAGE_KEY = 'cardtable:tab-id';
|
|
22
|
+
/** How this page was loaded: `reload`, or anything else (`navigate`, `back_forward`, `prerender`, unknown). */
|
|
23
|
+
function loadedBy() {
|
|
24
|
+
const entry = typeof performance === 'undefined' ? undefined : performance.getEntriesByType?.('navigation')[0];
|
|
25
|
+
return entry !== undefined && 'type' in entry ? String(entry.type) : 'unknown';
|
|
26
|
+
}
|
|
27
|
+
function storage() {
|
|
28
|
+
try {
|
|
29
|
+
return typeof sessionStorage === 'undefined' ? null : sessionStorage;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
// A sandboxed frame throws on the accessor: the id then lives for this page only.
|
|
33
|
+
console.warn('[tab-id] no sessionStorage', err);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** The stored id this page may keep, given how it was loaded: only a reload's; exported for its test. */
|
|
38
|
+
export function storedCandidate(navigation, stored) {
|
|
39
|
+
return navigation === 'reload' && isTabId(stored) ? stored : null;
|
|
40
|
+
}
|
|
41
|
+
let provisional = null;
|
|
42
|
+
let settled = null;
|
|
43
|
+
let settling = null;
|
|
44
|
+
function begin() {
|
|
45
|
+
if (settling !== null)
|
|
46
|
+
return settling;
|
|
47
|
+
const store = storage();
|
|
48
|
+
let stored = null;
|
|
49
|
+
try {
|
|
50
|
+
stored = store?.getItem(STORAGE_KEY) ?? null;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.warn('[tab-id] could not read the stored id', err);
|
|
54
|
+
}
|
|
55
|
+
const candidate = storedCandidate(loadedBy(), stored);
|
|
56
|
+
provisional = candidate ?? mintTabId();
|
|
57
|
+
let channel = null;
|
|
58
|
+
try {
|
|
59
|
+
channel = browserTabChannel();
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.warn('[tab-id] no BroadcastChannel', err);
|
|
63
|
+
}
|
|
64
|
+
if (channel !== null)
|
|
65
|
+
answerTabProbes(channel, () => settled ?? provisional);
|
|
66
|
+
// A freshly minted id is nobody else's: only a kept one is probed.
|
|
67
|
+
settling = settleTabId({ candidate: provisional, channel: candidate === null ? null : channel }).then((id) => {
|
|
68
|
+
settled = id;
|
|
69
|
+
try {
|
|
70
|
+
store?.setItem(STORAGE_KEY, id);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.warn('[tab-id] could not store the id', err);
|
|
74
|
+
}
|
|
75
|
+
return id;
|
|
76
|
+
});
|
|
77
|
+
return settling;
|
|
78
|
+
}
|
|
79
|
+
/** This tab's id once no other live tab claims it: what a player's claim and joins carry. */
|
|
80
|
+
export function settledTabId() {
|
|
81
|
+
return begin();
|
|
82
|
+
}
|
|
83
|
+
/** Run `use` with this tab's settled id: now when it is known, else once the probe has answered. */
|
|
84
|
+
export function withSettledTabId(use) {
|
|
85
|
+
const pending = begin();
|
|
86
|
+
if (settled !== null)
|
|
87
|
+
use(settled);
|
|
88
|
+
else
|
|
89
|
+
void pending.then(use);
|
|
90
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { whoami as hadokuWhoami } from '@wolffm/prefs-client';
|
|
2
|
+
export interface Who {
|
|
3
|
+
userId: string;
|
|
4
|
+
/** The fleet's own tier list, so a tier it adds (`member`) is not a type error here. */
|
|
5
|
+
tier: Awaited<ReturnType<typeof hadokuWhoami>>['userType'];
|
|
6
|
+
/** The viewer's display name. Null when the fleet has none for them. */
|
|
7
|
+
name: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The viewer's tier as cardtable treats it: a member the operator has verified IS a friend here (the
|
|
11
|
+
* operator, 2026-11-05: *"for cardtable they will be equivalent"*). The server's `tierOf` makes the
|
|
12
|
+
* same call for every gate; this is the tier the fleet chrome is handed to show.
|
|
13
|
+
*/
|
|
14
|
+
export declare function tierOfWhoami(r: Pick<Awaited<ReturnType<typeof hadokuWhoami>>, 'userType' | 'verified'>): Who['tier'];
|
|
15
|
+
export declare function useWhoami(): Who | null | 'pending';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Who this viewer is, from the fleet.
|
|
3
|
+
*
|
|
4
|
+
* `whoami()` from `@wolffm/prefs-client` is the fleet's own, returns `name`,
|
|
5
|
+
* and shares one in-flight promise per page (`globalThis.__hadokuWhoami`) so
|
|
6
|
+
* several apps on a page do not each re-fetch it. Read the same way by the
|
|
7
|
+
* standalone app (`RoomShell`) and by the watchparty embed (`EmbedApp`): the
|
|
8
|
+
* edge path, never the host's `ctx.identity` (D21's identity rule).
|
|
9
|
+
*
|
|
10
|
+
* Nothing here invents an identity: a failed answer is `null`, and the caller
|
|
11
|
+
* decides what a table with nobody known at it looks like.
|
|
12
|
+
*/
|
|
13
|
+
import { useEffect, useState } from 'react';
|
|
14
|
+
import { whoami as hadokuWhoami } from '@wolffm/prefs-client';
|
|
15
|
+
/**
|
|
16
|
+
* The viewer's tier as cardtable treats it: a member the operator has verified IS a friend here (the
|
|
17
|
+
* operator, 2026-11-05: *"for cardtable they will be equivalent"*). The server's `tierOf` makes the
|
|
18
|
+
* same call for every gate; this is the tier the fleet chrome is handed to show.
|
|
19
|
+
*/
|
|
20
|
+
export function tierOfWhoami(r) {
|
|
21
|
+
return r.userType === 'member' && r.verified === true ? 'friend' : r.userType;
|
|
22
|
+
}
|
|
23
|
+
export function useWhoami() {
|
|
24
|
+
const [who, setWho] = useState('pending');
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
let live = true;
|
|
27
|
+
// Same-origin on purpose. `whoami()` defaults to the edge-router origin,
|
|
28
|
+
// which in production IS this page's origin — but hard-coding it makes the
|
|
29
|
+
// app reach `https://hadoku.me` from wherever it happens to be served,
|
|
30
|
+
// which the e2e correctly flags as an off-host request and which would be
|
|
31
|
+
// wrong for any future preview host. Same-origin gives the identical
|
|
32
|
+
// answer in production and stays local everywhere else.
|
|
33
|
+
hadokuWhoami({ whoamiUrl: `${globalThis.location.origin}/session/whoami` })
|
|
34
|
+
.then((r) => {
|
|
35
|
+
if (!live)
|
|
36
|
+
return;
|
|
37
|
+
setWho({ userId: r.userId, tier: tierOfWhoami(r), name: r.name ?? null });
|
|
38
|
+
})
|
|
39
|
+
.catch(() => {
|
|
40
|
+
if (live)
|
|
41
|
+
setWho(null);
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
live = false;
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
return who;
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A real `GameBundleModule` for `BundleSlot.test.ts`, loaded by the same relative specifier
|
|
3
|
+
* `BundleSlot` loads any bundle by (`import(src)`, where the test's `src` prop names this file).
|
|
4
|
+
* `mount` records every call it gets into `calls`, so the test can assert on the context it was
|
|
5
|
+
* handed; `ctx.roomKey === 'throw'` makes `mount` itself throw, to prove `BundleSlot` reports a
|
|
6
|
+
* failed mount through its own error UI rather than crashing.
|
|
7
|
+
*/
|
|
8
|
+
import type { GameBundleContext, MountedGameBundle } from '@wolffm/rooms-protocol';
|
|
9
|
+
export type FixtureCall = ['mount', GameBundleContext] | ['update', GameBundleContext] | ['unmount', string];
|
|
10
|
+
export declare const calls: FixtureCall[];
|
|
11
|
+
export declare function mount(_el: HTMLElement, ctx: GameBundleContext): Promise<MountedGameBundle>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A real `GameBundleModule` for `BundleSlot.test.ts`, loaded by the same relative specifier
|
|
3
|
+
* `BundleSlot` loads any bundle by (`import(src)`, where the test's `src` prop names this file).
|
|
4
|
+
* `mount` records every call it gets into `calls`, so the test can assert on the context it was
|
|
5
|
+
* handed; `ctx.roomKey === 'throw'` makes `mount` itself throw, to prove `BundleSlot` reports a
|
|
6
|
+
* failed mount through its own error UI rather than crashing.
|
|
7
|
+
*/
|
|
8
|
+
export const calls = [];
|
|
9
|
+
export async function mount(_el, ctx) {
|
|
10
|
+
calls.push(['mount', ctx]);
|
|
11
|
+
if (ctx.roomKey === 'throw')
|
|
12
|
+
throw new Error('mount exploded');
|
|
13
|
+
return {
|
|
14
|
+
update(next) {
|
|
15
|
+
calls.push(['update', next]);
|
|
16
|
+
},
|
|
17
|
+
unmount() {
|
|
18
|
+
calls.push(['unmount', ctx.roomKey]);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export declare function GameClientsProvider<T>({ value, children }: {
|
|
3
|
+
value: T;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}): ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* The clients the nearest `GameClientsProvider` above this component provided, typed as whatever
|
|
8
|
+
* shape the caller names. Throws rather than hand back `undefined` silently: a game's `setup`/
|
|
9
|
+
* `game` rendered outside the room shell that is supposed to wrap it is a wiring bug, not a state
|
|
10
|
+
* to render through.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useGameClients<T>(): T;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* The seam a room screen hands a game's own clients through: the room shell knows it has to
|
|
4
|
+
* inject SOMETHING (a tables client, a feed, a transport factory, whatever the game's module
|
|
5
|
+
* needs to talk to the server), but the SHAPE of that bundle is the game's own business, never
|
|
6
|
+
* this file's. `platform`: this file names no game's own type. A game's module declares its own
|
|
7
|
+
* clients interface and calls `useGameClients<ThatInterface>()`; the room shell that mounts it
|
|
8
|
+
* provides the matching value with `<GameClientsProvider value={...}>`.
|
|
9
|
+
*
|
|
10
|
+
* One underlying React context, reused by every game type that wants this — not one context per
|
|
11
|
+
* `T`, because nothing here needs to tell two games' providers apart; each game's own module is
|
|
12
|
+
* the only thing that ever reads what it provided, under the type it asked for.
|
|
13
|
+
*/
|
|
14
|
+
import { createContext, useContext } from 'react';
|
|
15
|
+
const GameClientsContext = createContext(undefined);
|
|
16
|
+
export function GameClientsProvider({ value, children }) {
|
|
17
|
+
return _jsx(GameClientsContext.Provider, { value: value, children: children });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The clients the nearest `GameClientsProvider` above this component provided, typed as whatever
|
|
21
|
+
* shape the caller names. Throws rather than hand back `undefined` silently: a game's `setup`/
|
|
22
|
+
* `game` rendered outside the room shell that is supposed to wrap it is a wiring bug, not a state
|
|
23
|
+
* to render through.
|
|
24
|
+
*/
|
|
25
|
+
export function useGameClients() {
|
|
26
|
+
const value = useContext(GameClientsContext);
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
throw new Error('useGameClients: no room shell has provided its clients here');
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The room's own fields a game type reads: the platform half of the room view. `@hadoku/shared`'s
|
|
4
|
+
* `RoomBody`, which is Magic's composition and what the screen already holds, satisfies it as it is.
|
|
5
|
+
*/
|
|
6
|
+
export interface RoomViewBase {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
gameType: string;
|
|
10
|
+
members: readonly {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
avatarId?: string;
|
|
14
|
+
}[];
|
|
15
|
+
/** Who holds each of the room's game seats, by seat number (a member id, or null when open); a member not in it watches. */
|
|
16
|
+
seats: readonly (string | null)[];
|
|
17
|
+
you: {
|
|
18
|
+
id: string;
|
|
19
|
+
leader: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface GameSetupProps {
|
|
23
|
+
/** The parsed public view, or null while it has not resolved. */
|
|
24
|
+
view: RoomViewBase | null;
|
|
25
|
+
me: {
|
|
26
|
+
/** The caller's own member id (`view.you.id`), or `''` while `view` is null. */
|
|
27
|
+
userId: string;
|
|
28
|
+
/**
|
|
29
|
+
* The caller's seat NUMBER at the table (`table.players[].seat`, 2-max, Magic's), or null
|
|
30
|
+
* while unseated or for a game type with no 2-seat table at all. A non-Magic game type reads
|
|
31
|
+
* its own seat list off `view`'s generic member data instead of this field.
|
|
32
|
+
*/
|
|
33
|
+
seat: number | null;
|
|
34
|
+
isLeader: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** The room's game has started: a match is running, or (for a pod game type) the deal happened. */
|
|
37
|
+
underway: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What a game type renders inside the platform room screen: its setup before the start, its game
|
|
41
|
+
* after.
|
|
42
|
+
*
|
|
43
|
+
* `setup` is what a player sees ABOVE the seats before the room is underway — Magic's format,
|
|
44
|
+
* mode and deck chooser. A game type that offers no pre-start configuration (today, none) leaves
|
|
45
|
+
* it absent, and the room screen draws nothing in its place.
|
|
46
|
+
*
|
|
47
|
+
* `game` is the game type's own placeholder for "the game" once the room is playing it — Magic's
|
|
48
|
+
* board/pod card inside the room (the actual match is a screen of its own, reached by
|
|
49
|
+
* navigation); Bomberman's `<BundleSlot>`. Required: every registered game type draws SOMETHING
|
|
50
|
+
* once underway, even if it is nothing more than a status line.
|
|
51
|
+
*/
|
|
52
|
+
export interface GameRoomUi {
|
|
53
|
+
setup?: (p: GameSetupProps) => ReactNode;
|
|
54
|
+
game: (p: GameSetupProps) => ReactNode;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Registers (or replaces) the UI a `gameType` renders inside the room screen. Called once, at
|
|
58
|
+
* module scope, from the game type's own module — every registrant, Magic's `draft` and
|
|
59
|
+
* `constructed-1v1` included.
|
|
60
|
+
*/
|
|
61
|
+
export declare function registerGameRoomUi(gameType: string, ui: GameRoomUi): void;
|
|
62
|
+
/** The UI registered for a `gameType`, or null for one nothing has registered. */
|
|
63
|
+
export declare function gameRoomUiFor(gameType: string): GameRoomUi | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The seam between the platform room screen and a game type's own UI.
|
|
3
|
+
*
|
|
4
|
+
* The room screen owns join, password, leader, members, spectators, seats, ready and start —
|
|
5
|
+
* every room, whatever it plays. What a game type draws INSIDE that room is registered here, by
|
|
6
|
+
* its `gameType` string, so the screen never imports a game's own file to find out what to
|
|
7
|
+
* render.
|
|
8
|
+
*
|
|
9
|
+
* `view` is nullable because the room record and the room's table are two separate reads: a
|
|
10
|
+
* table can answer before the room record does, or the room record can fail while the table
|
|
11
|
+
* still holds a seat list. A game's `setup`/`game` must handle `view === null` exactly as the
|
|
12
|
+
* room screen already does elsewhere (optional chaining, never a crash) rather than assume the
|
|
13
|
+
* two reads land together.
|
|
14
|
+
*
|
|
15
|
+
* This file is `platform`: it imports no game's own code, Magic's included. A game registers
|
|
16
|
+
* itself by calling `registerGameRoomUi` from ITS OWN module, once, at import — Magic's `draft`
|
|
17
|
+
* and `constructed-1v1` do this from `screens/magic-room-ui.tsx`, the same way bomberman's own
|
|
18
|
+
* module does, reading the room's injected clients from `rooms/game-clients.tsx` rather than
|
|
19
|
+
* closing over `RoomTableScreen`'s props.
|
|
20
|
+
*/
|
|
21
|
+
const registry = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Registers (or replaces) the UI a `gameType` renders inside the room screen. Called once, at
|
|
24
|
+
* module scope, from the game type's own module — every registrant, Magic's `draft` and
|
|
25
|
+
* `constructed-1v1` included.
|
|
26
|
+
*/
|
|
27
|
+
export function registerGameRoomUi(gameType, ui) {
|
|
28
|
+
registry.set(gameType, ui);
|
|
29
|
+
}
|
|
30
|
+
/** The UI registered for a `gameType`, or null for one nothing has registered. */
|
|
31
|
+
export function gameRoomUiFor(gameType) {
|
|
32
|
+
return registry.get(gameType) ?? null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MatchChannel } from '@wolffm/rooms-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* A `MatchChannel` plus the host's own word that the match ended — the room's, never the
|
|
4
|
+
* bundle's: `winners` are the seat numbers of the `{ t: 'over', winners }` that ended it (the
|
|
5
|
+
* bundle's own `ctx.match` numbering), or null when every seat left. By the time a handler
|
|
6
|
+
* hears it, this channel has already sent its join again: the room's next match is the one it
|
|
7
|
+
* speaks in from then on (`relay-socket.ts`, "A room's next match").
|
|
8
|
+
*/
|
|
9
|
+
export interface RelayChannel extends MatchChannel {
|
|
10
|
+
onEnded(handler: (winners: readonly number[] | null) => void): () => void;
|
|
11
|
+
/**
|
|
12
|
+
* The room's last result, for the room to show: the winners when a match ends (live, or the
|
|
13
|
+
* join answering for a match that ended before this screen loaded), then null once the next
|
|
14
|
+
* match is under way (the first message this channel sends or hears after that).
|
|
15
|
+
*/
|
|
16
|
+
onResult(handler: (winners: readonly number[] | null) => void): () => void;
|
|
17
|
+
}
|
|
18
|
+
export interface RelayChannelOptions {
|
|
19
|
+
/** The server's origin, e.g. `http://localhost:9008`. Omitted: same origin (production). */
|
|
20
|
+
url?: string;
|
|
21
|
+
/** socket.io path. Defaults to the bundle's own `/cardtable/socket.io/`. */
|
|
22
|
+
path?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Opens one relay connection for `matchId` (a relay-runtime room's own id — there is no separate
|
|
26
|
+
* match id for this kind of room; see `rooms/BundleSlot.tsx`'s own doc) and returns it as a
|
|
27
|
+
* `MatchChannel`. `close()` disconnects the socket for good; call it once, on unmount.
|
|
28
|
+
*/
|
|
29
|
+
export declare function openRelayChannel(matchId: string, options?: RelayChannelOptions): RelayChannel;
|