@hadoku/game-ui 0.1.254 → 0.1.256
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/dist/components/ConnectionBanner.d.ts +1 -1
- package/dist/components/ConnectionBanner.js +1 -1
- package/dist/components/connection-state.d.ts +23 -0
- package/dist/components/connection-state.js +89 -1
- package/dist/rooms/relay-channel.d.ts +3 -0
- package/dist/rooms/relay-channel.js +37 -6
- package/dist/rooms/screen/AskButton.d.ts +11 -0
- package/dist/rooms/screen/AskButton.js +35 -0
- package/dist/rooms/screen/CloseRoom.d.ts +8 -0
- package/dist/rooms/screen/CloseRoom.js +17 -0
- package/dist/rooms/screen/PlatformRoomScreen.d.ts +5 -2
- package/dist/rooms/screen/PlatformRoomScreen.js +13 -8
- package/dist/rooms/screen/RoomShell.d.ts +1 -2
- package/dist/rooms/screen/RoomShell.js +4 -39
- package/dist/rooms/screen/roomSounds.d.ts +13 -0
- package/dist/rooms/screen/roomSounds.js +41 -0
- package/dist/track-connection.d.ts +14 -0
- package/dist/track-connection.js +41 -0
- package/package.json +4 -4
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* So this component renders the one thing the app was not saying. It holds no
|
|
15
15
|
* state and starts no timers: it takes a `ConnectionState` computed by
|
|
16
|
-
* `
|
|
16
|
+
* `connectionState` (`./connection-state.ts`) from facts the driver already tracks, which is why the
|
|
17
17
|
* banner can be tested without a socket and cannot drift from what the socket
|
|
18
18
|
* is actually doing.
|
|
19
19
|
*
|
|
@@ -14,7 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
*
|
|
15
15
|
* So this component renders the one thing the app was not saying. It holds no
|
|
16
16
|
* state and starts no timers: it takes a `ConnectionState` computed by
|
|
17
|
-
* `
|
|
17
|
+
* `connectionState` (`./connection-state.ts`) from facts the driver already tracks, which is why the
|
|
18
18
|
* banner can be tested without a socket and cannot drift from what the socket
|
|
19
19
|
* is actually doing.
|
|
20
20
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SeqVerdict } from '@wolffm/rooms-protocol';
|
|
1
2
|
export type ConnectionPhase =
|
|
2
3
|
/** No connection has ever been established. */
|
|
3
4
|
'connecting'
|
|
@@ -32,3 +33,25 @@ export interface ConnectionState {
|
|
|
32
33
|
}
|
|
33
34
|
/** Whether the banner has anything worth showing. `live` is silence. */
|
|
34
35
|
export declare function isWorthShowing(state: ConnectionState): boolean;
|
|
36
|
+
/** Everything a phase is decided from. All of it already exists on the driver. */
|
|
37
|
+
export interface ConnectionFacts {
|
|
38
|
+
connected: boolean;
|
|
39
|
+
/** Whether a connection has EVER been established. Distinguishes first-connect from a drop. */
|
|
40
|
+
everConnected: boolean;
|
|
41
|
+
/** The drop followed the server's own restart notice and is inside its quiet window. */
|
|
42
|
+
serverUpdating: boolean;
|
|
43
|
+
/** Join messages sent. `> 1` means at least one reconnect has happened. */
|
|
44
|
+
joins: number;
|
|
45
|
+
/** Payloads applied, in total. */
|
|
46
|
+
applied: number;
|
|
47
|
+
/** `applied` as it stood when the most recent RE-join went out. */
|
|
48
|
+
appliedAtLastJoin: number;
|
|
49
|
+
/** A resync request is outstanding and unanswered. */
|
|
50
|
+
resyncPending: boolean;
|
|
51
|
+
/** The seat this client holds, or null while spectating or unseated. */
|
|
52
|
+
seatId: number | null;
|
|
53
|
+
/** The verdict on the most recent envelope. Diagnostic only. */
|
|
54
|
+
lastVerdict: SeqVerdict | null;
|
|
55
|
+
}
|
|
56
|
+
/** What the connection is doing, and what to say about it. */
|
|
57
|
+
export declare function connectionState(facts: ConnectionFacts): ConnectionState;
|
|
@@ -1,5 +1,93 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/*
|
|
2
|
+
* What a connection is doing, as `./ConnectionBanner.tsx` shows it: `connectionState` over facts a
|
|
3
|
+
* driver already tracks (`../track-connection.ts`), never a second copy of "are we connected".
|
|
4
|
+
*
|
|
5
|
+
* ## The one derived counter
|
|
6
|
+
*
|
|
7
|
+
* Telling "reconnected, waiting" from "reconnected, back in business" needs to
|
|
8
|
+
* know whether a payload has landed SINCE the re-join, which no single counter
|
|
9
|
+
* answers. `appliedAtLastJoin` is `stats.applied` sampled when the re-join goes
|
|
10
|
+
* out; the difference is the answer. It is one number in the driver rather than
|
|
11
|
+
* a timer in a component, because a timer makes the banner untestable and lies
|
|
12
|
+
* on a slow connection.
|
|
13
|
+
*
|
|
14
|
+
* `recovered` is deliberately BOUNDED to the first payload after the re-join.
|
|
15
|
+
* An unbounded one would leave "Reconnected" on screen for the remaining forty
|
|
16
|
+
* minutes of the draft, which is noise, and noise is what gets banners ignored.
|
|
17
|
+
*/
|
|
2
18
|
/** Whether the banner has anything worth showing. `live` is silence. */
|
|
3
19
|
export function isWorthShowing(state) {
|
|
4
20
|
return state.phase !== 'live';
|
|
5
21
|
}
|
|
22
|
+
/** How many payloads after a re-join still count as "recovered". */
|
|
23
|
+
const RECOVERY_WINDOW = 1;
|
|
24
|
+
function seatPhrase(seatId) {
|
|
25
|
+
return seatId === null ? 'Your place' : `Seat ${seatId}`;
|
|
26
|
+
}
|
|
27
|
+
/** What the connection is doing, and what to say about it. */
|
|
28
|
+
export function connectionState(facts) {
|
|
29
|
+
const seated = facts.seatId !== null;
|
|
30
|
+
if (!facts.connected && !facts.everConnected) {
|
|
31
|
+
return {
|
|
32
|
+
phase: 'connecting',
|
|
33
|
+
seatHeld: false,
|
|
34
|
+
stalled: true,
|
|
35
|
+
label: 'Connecting',
|
|
36
|
+
detail: 'Joining…',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (!facts.connected && facts.serverUpdating) {
|
|
40
|
+
return {
|
|
41
|
+
phase: 'updating',
|
|
42
|
+
seatHeld: seated,
|
|
43
|
+
stalled: true,
|
|
44
|
+
label: 'Updating…',
|
|
45
|
+
detail: seated ? 'Server updating — seat held.' : 'Server updating.',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (!facts.connected) {
|
|
49
|
+
return {
|
|
50
|
+
phase: 'offline',
|
|
51
|
+
seatHeld: seated,
|
|
52
|
+
stalled: true,
|
|
53
|
+
label: seated ? `${seatPhrase(facts.seatId)} is held for you` : 'Disconnected',
|
|
54
|
+
detail: seated ? 'Connection dropped — seat held. Reconnecting.' : 'The connection dropped. Reconnecting.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (facts.resyncPending) {
|
|
58
|
+
return {
|
|
59
|
+
phase: 'resyncing',
|
|
60
|
+
seatHeld: false,
|
|
61
|
+
stalled: true,
|
|
62
|
+
label: 'Catching up',
|
|
63
|
+
detail: 'Resyncing.',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const sinceJoin = facts.applied - facts.appliedAtLastJoin;
|
|
67
|
+
const reconnected = facts.joins > 1;
|
|
68
|
+
if (reconnected && sinceJoin <= 0) {
|
|
69
|
+
return {
|
|
70
|
+
phase: 'reconnecting',
|
|
71
|
+
seatHeld: false,
|
|
72
|
+
stalled: true,
|
|
73
|
+
label: 'Reconnected — waiting for the table',
|
|
74
|
+
detail: 'Reconnected — resyncing.',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (reconnected && sinceJoin <= RECOVERY_WINDOW) {
|
|
78
|
+
return {
|
|
79
|
+
phase: 'recovered',
|
|
80
|
+
seatHeld: false,
|
|
81
|
+
stalled: false,
|
|
82
|
+
label: seated ? `Back in ${seatPhrase(facts.seatId).toLowerCase()}` : 'Back',
|
|
83
|
+
detail: 'Recovered.',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
phase: 'live',
|
|
88
|
+
seatHeld: false,
|
|
89
|
+
stalled: false,
|
|
90
|
+
label: 'Live',
|
|
91
|
+
detail: 'Connected.',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MatchChannel } from '@wolffm/rooms-protocol';
|
|
2
|
+
import type { ConnectionFacts } from '../components/connection-state.js';
|
|
2
3
|
/**
|
|
3
4
|
* A `MatchChannel` plus the host's own word that the match ended — the room's, never the
|
|
4
5
|
* bundle's: `winners` are the seat numbers of the `{ t: 'over', winners }` that ended it (the
|
|
@@ -14,6 +15,8 @@ export interface RelayChannel extends MatchChannel {
|
|
|
14
15
|
* match is under way (the first message this channel sends or hears after that).
|
|
15
16
|
*/
|
|
16
17
|
onResult(handler: (winners: readonly number[] | null) => void): () => void;
|
|
18
|
+
/** What the connection is doing, told on every change: a drop, a planned restart, a rejoin and its answer. */
|
|
19
|
+
onConnection(handler: (facts: ConnectionFacts) => void): () => void;
|
|
17
20
|
}
|
|
18
21
|
export interface RelayChannelOptions {
|
|
19
22
|
/** The server's origin, e.g. `http://localhost:9008`. Omitted: same origin (production). */
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Ordering and at-most-once delivery are `runtimes/relay.ts`'s `RelaySession`'s own guarantees;
|
|
13
13
|
* this file adds nothing to either — it only opens the connection, joins, rejoins on every
|
|
14
|
-
* reconnect and after every match's end,
|
|
14
|
+
* reconnect and after every match's end, relays `relay:message` both ways, and says what its connection is doing. A watcher's own `send` is a silent no-op from
|
|
15
15
|
* out here too, but only because the SERVER drops it without an error — nothing here tracks
|
|
16
16
|
* whether this socket holds a seat.
|
|
17
17
|
*/
|
|
18
18
|
import { defaultSocketPath, openSocket, socketOptions } from "../room/socket-options.js";
|
|
19
|
+
import { trackConnection } from "../track-connection.js";
|
|
19
20
|
/**
|
|
20
21
|
* Mirrors `packages/game-server/src/play/relay-socket.ts`'s own `RELAY_EVENTS`. The client has no package
|
|
21
22
|
* of the server's to import these from (the server is not a dependency of the UI bundle), so the
|
|
@@ -39,7 +40,9 @@ export function openRelayChannel(matchId, options = {}) {
|
|
|
39
40
|
const handlers = new Set();
|
|
40
41
|
const endedHandlers = new Set();
|
|
41
42
|
const resultHandlers = new Set();
|
|
43
|
+
const connectionHandlers = new Set();
|
|
42
44
|
let closed = false;
|
|
45
|
+
let rejoining = false;
|
|
43
46
|
/** A result is shown: the next message sent or heard clears it. */
|
|
44
47
|
let showing = false;
|
|
45
48
|
const tellResult = (winners) => {
|
|
@@ -56,14 +59,35 @@ export function openRelayChannel(matchId, options = {}) {
|
|
|
56
59
|
return;
|
|
57
60
|
// A match that ended before this join answers with its result (`relay-socket.ts`'s ack).
|
|
58
61
|
socket.emit(RELAY_EVENTS.join, { matchId }, (ack) => {
|
|
59
|
-
if (closed || ack?.ok !== true
|
|
62
|
+
if (closed || ack?.ok !== true)
|
|
60
63
|
return;
|
|
61
|
-
|
|
64
|
+
const answered = rejoining;
|
|
65
|
+
rejoining = false;
|
|
66
|
+
if (answered)
|
|
67
|
+
tellConnection();
|
|
68
|
+
if (ack.ended !== undefined)
|
|
69
|
+
tellResult(winnersOf(ack.ended.winners));
|
|
62
70
|
});
|
|
63
71
|
};
|
|
64
|
-
//
|
|
65
|
-
// again on the new one
|
|
66
|
-
socket
|
|
72
|
+
// The first join goes out at once (socket.io holds it until the connection opens); a reconnect (a
|
|
73
|
+
// dropped network, a deploy) joins again on the new one, as a brand new peer to `relay-socket.ts`.
|
|
74
|
+
const connection = trackConnection(socket, {
|
|
75
|
+
onRejoin: () => {
|
|
76
|
+
rejoining = true;
|
|
77
|
+
join();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
// With no snapshot to wait for, a rejoin (`rejoining`: sent on a new connection, not yet answered) is
|
|
81
|
+
// the whole of coming back, so no "back" line stays over a quiet room. The seats are the room's to show.
|
|
82
|
+
const tellConnection = () => {
|
|
83
|
+
if (closed)
|
|
84
|
+
return;
|
|
85
|
+
const facts = { connected: connection.connected, everConnected: connection.everConnected, serverUpdating: connection.serverUpdating, joins: rejoining ? connection.joins : 1, applied: 0, appliedAtLastJoin: 0, resyncPending: false, seatId: null, lastVerdict: null };
|
|
86
|
+
for (const handler of [...connectionHandlers])
|
|
87
|
+
handler(facts);
|
|
88
|
+
};
|
|
89
|
+
connection.subscribe(tellConnection);
|
|
90
|
+
join();
|
|
67
91
|
socket.on(RELAY_EVENTS.message, (msg) => {
|
|
68
92
|
if (closed)
|
|
69
93
|
return;
|
|
@@ -97,6 +121,12 @@ export function openRelayChannel(matchId, options = {}) {
|
|
|
97
121
|
resultHandlers.add(handler);
|
|
98
122
|
return () => resultHandlers.delete(handler);
|
|
99
123
|
},
|
|
124
|
+
onConnection(handler) {
|
|
125
|
+
if (closed)
|
|
126
|
+
return () => { };
|
|
127
|
+
connectionHandlers.add(handler);
|
|
128
|
+
return () => connectionHandlers.delete(handler);
|
|
129
|
+
},
|
|
100
130
|
send(msg) {
|
|
101
131
|
if (closed)
|
|
102
132
|
return;
|
|
@@ -116,6 +146,7 @@ export function openRelayChannel(matchId, options = {}) {
|
|
|
116
146
|
handlers.clear();
|
|
117
147
|
endedHandlers.clear();
|
|
118
148
|
resultHandlers.clear();
|
|
149
|
+
connectionHandlers.clear();
|
|
119
150
|
socket.disconnect();
|
|
120
151
|
},
|
|
121
152
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '../../components/Button.css';
|
|
2
|
+
export interface AskButtonProps {
|
|
3
|
+
className: string;
|
|
4
|
+
testId: string;
|
|
5
|
+
label: string;
|
|
6
|
+
confirm?: string;
|
|
7
|
+
act: () => Promise<string | null>;
|
|
8
|
+
/** Told as the ask opens and folds, so a row of asks can put one question at a time. */
|
|
9
|
+
onAsking?: (asking: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function AskButton({ className, testId, label, confirm, act, onAsking }: AskButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A press that asks once more before it acts (Leave when it costs an event, Close, Magic's Reset):
|
|
4
|
+
* Cancel, focused, and a danger confirm that runs `act`. `act` answers null once done (the ask folds)
|
|
5
|
+
* or the sentence to show while the ask stays. No `confirm`: the press acts at once. Testids are
|
|
6
|
+
* `<testId>` and `-ask|-no|-yes|-error`; the pair wears `<className>__ask`, the confirm
|
|
7
|
+
* `<className>--danger`, and nothing wraps them, so they sit directly in the caller's row.
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
import '../../components/Button.css';
|
|
11
|
+
export function AskButton({ className, testId, label, confirm, act, onAsking }) {
|
|
12
|
+
const [asking, setAsking] = useState(false);
|
|
13
|
+
const [busy, setBusy] = useState(false);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const ask = (next) => {
|
|
16
|
+
setAsking(next);
|
|
17
|
+
setError(null);
|
|
18
|
+
onAsking?.(next);
|
|
19
|
+
};
|
|
20
|
+
const run = () => {
|
|
21
|
+
setBusy(true);
|
|
22
|
+
setError(null);
|
|
23
|
+
void act().then((message) => {
|
|
24
|
+
setBusy(false);
|
|
25
|
+
if (message === null)
|
|
26
|
+
ask(false);
|
|
27
|
+
else
|
|
28
|
+
setError(message);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const button = (id, words, onClick, danger = false, focus = false) => (_jsx("button", { type: "button", className: danger ? `${className} ${className}--danger ct-action ct-action--danger` : `${className} ct-action`, "data-testid": id, autoFocus: focus, disabled: busy, onClick: onClick, children: _jsx("span", { className: "ct-action__label", children: words }) }));
|
|
32
|
+
if (!asking)
|
|
33
|
+
return button(testId, label, () => (confirm === undefined ? run() : ask(true)));
|
|
34
|
+
return (_jsxs("span", { className: `${className}__ask`, "data-testid": `${testId}-ask`, children: [button(`${testId}-no`, 'Cancel', () => ask(false), false, true), button(`${testId}-yes`, confirm, run, true), error !== null && (_jsx("span", { className: "ct-error", role: "alert", "data-testid": `${testId}-error`, children: error }))] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RoomEndOutcome } from '../room-core-client.js';
|
|
2
|
+
/** The game's close for a room. */
|
|
3
|
+
export type CloseRoomCall = (roomId: string) => Promise<RoomEndOutcome>;
|
|
4
|
+
export declare function CloseRoom({ roomId, close, onAsking }: {
|
|
5
|
+
roomId: string;
|
|
6
|
+
close: CloseRoomCall;
|
|
7
|
+
onAsking?: (asking: boolean) => void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* The room leader's Close (the operator, 2026-10-19: *"lobby owner needs to be able to 'close' a
|
|
4
|
+
* tournament"*): asked once more, then the room ends for everyone and this screen goes to the lobby.
|
|
5
|
+
* A refusal stays asked, in the server's words. Its size is `.room-close`, in the app's one stylesheet.
|
|
6
|
+
*/
|
|
7
|
+
import { navigate } from "../../screens/route.js";
|
|
8
|
+
import { AskButton } from "./AskButton.js";
|
|
9
|
+
function closed(r) {
|
|
10
|
+
if (!r.ok)
|
|
11
|
+
return r.message;
|
|
12
|
+
navigate({ kind: 'lobby' });
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export function CloseRoom({ roomId, close, onAsking }) {
|
|
16
|
+
return _jsx(AskButton, { className: "room-close", testId: "room-close", label: "Close", confirm: "Close room", act: () => close(roomId).then(closed), onAsking: onAsking });
|
|
17
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type RoomViewBase } from '../game-setup.js';
|
|
3
|
+
import { type CloseRoomCall } from './CloseRoom.js';
|
|
3
4
|
import { type LeaveRoom } from './room-exit.js';
|
|
4
5
|
import type { RoomJoin } from './useRoomJoin.js';
|
|
5
6
|
export interface PlatformRoomScreenProps<R extends RoomViewBase> {
|
|
6
7
|
/** The host's read of the room. */
|
|
7
8
|
join: RoomJoin<R>;
|
|
8
|
-
/** What the host draws in the head row beside Leave
|
|
9
|
+
/** What the host draws in the head row beside Leave and Close: Settings. */
|
|
9
10
|
headerTools?: ReactNode;
|
|
11
|
+
/** The game's close for a room; given, the room's leader gets Close. */
|
|
12
|
+
close?: CloseRoomCall;
|
|
10
13
|
/** The game's `/leave` for this room; absent, the head row draws no Leave. */
|
|
11
14
|
leave?: LeaveRoom;
|
|
12
15
|
/** Told each time the game says a match is, or is no longer, live. */
|
|
13
16
|
onLive?: (live: boolean) => void;
|
|
14
17
|
}
|
|
15
|
-
export declare function PlatformRoomScreen<R extends RoomViewBase>({ join, headerTools, leave, onLive }: PlatformRoomScreenProps<R>): import("react").JSX.Element;
|
|
18
|
+
export declare function PlatformRoomScreen<R extends RoomViewBase>({ join, headerTools, close, leave, onLive }: PlatformRoomScreenProps<R>): import("react").JSX.Element;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
3
|
* The room screen for a game type the platform hosts: the shell every room has (`RoomShell`), drawn
|
|
4
4
|
* from the host's one read of the room (`useRoomJoin`), with the game type's own parts from the
|
|
5
5
|
* registry (`../game-setup.ts`) in its body.
|
|
6
6
|
*
|
|
7
|
-
* What it draws: the room's name, Leave (where the host has a way home), the
|
|
8
|
-
* password gate while the join is refused, the join's refusal
|
|
9
|
-
* and `game` for the room's `gameType`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* What it draws: the room's name, Leave (where the host has a way home), the leader's Close (where the
|
|
8
|
+
* host passes one), the host's tools, the password gate while the join is refused, the join's refusal
|
|
9
|
+
* in words, and the registered `setup` and `game` for the room's `gameType`. It plays the room's
|
|
10
|
+
* comings and goings (`./roomSounds.ts`) as its reads report them. Seats, spectators and options
|
|
11
|
+
* are the game's own, drawn in its `setup`. The host calls `useRoomJoin` itself and passes the
|
|
12
|
+
* result, so it can decide which screen to draw from the same read.
|
|
12
13
|
*
|
|
13
14
|
* While the game says a match is live (`GameSetupProps.onLive`), the head row steps aside; the game
|
|
14
15
|
* offers the way out itself (`GameSetupProps.leave`).
|
|
@@ -16,14 +17,18 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
16
17
|
import { useState } from 'react';
|
|
17
18
|
import { useChromeShell } from '@wolffm/ui-shell/chrome/shell';
|
|
18
19
|
import { gameRoomUiFor } from "../game-setup.js";
|
|
20
|
+
import { CloseRoom } from "./CloseRoom.js";
|
|
19
21
|
import { leaveRoomThen, useRoomHome } from "./room-exit.js";
|
|
22
|
+
import { useRoomSounds } from "./roomSounds.js";
|
|
20
23
|
import { RoomShell } from "./RoomShell.js";
|
|
21
|
-
export function PlatformRoomScreen({ join, headerTools, leave, onLive }) {
|
|
24
|
+
export function PlatformRoomScreen({ join, headerTools, close, leave, onLive }) {
|
|
22
25
|
const shellRef = useChromeShell('fit');
|
|
23
26
|
const home = useRoomHome();
|
|
24
27
|
const [live, setLive] = useState(false);
|
|
25
28
|
const { view } = join;
|
|
26
29
|
const ui = view === null ? null : gameRoomUiFor(view.gameType);
|
|
30
|
+
// The room's own record says who is in it, not who is ready: readiness is the game's.
|
|
31
|
+
useRoomSounds(view === null ? null : { others: view.members.filter((m) => m.id !== view.you.id).map((m) => m.id).sort(), ready: [], readySource: view.gameType });
|
|
27
32
|
const gameProps = {
|
|
28
33
|
view,
|
|
29
34
|
me: { userId: view?.you.id ?? '', seat: null, isLeader: view?.you.leader === true },
|
|
@@ -35,5 +40,5 @@ export function PlatformRoomScreen({ join, headerTools, leave, onLive }) {
|
|
|
35
40
|
},
|
|
36
41
|
...(home === null ? {} : { leave: () => void leaveRoomThen(home) }),
|
|
37
42
|
};
|
|
38
|
-
return (_jsxs(RoomShell, { shellRef: shellRef, dataMembers: view?.members.length, roomTitle: view?.name, settled: join.settled, leave: leave, headerTools: headerTools, resolved: join.resolved, pending: !join.resolved && !join.settled, locked: join.locked, password: join.password, onPasswordChange: join.setPassword, onPasswordSubmit: join.submitPassword, roomMissingMessage: join.joinError, live: live, children: [ui?.setup?.(gameProps), ui?.game(gameProps)] }));
|
|
43
|
+
return (_jsxs(RoomShell, { shellRef: shellRef, dataMembers: view?.members.length, roomTitle: view?.name, settled: join.settled, leave: leave, headerTools: _jsxs(_Fragment, { children: [close !== undefined && view?.you.leader === true && _jsx(CloseRoom, { roomId: view.id, close: close }), headerTools] }), resolved: join.resolved, pending: !join.resolved && !join.settled, locked: join.locked, password: join.password, onPasswordChange: join.setPassword, onPasswordSubmit: join.submitPassword, roomMissingMessage: join.joinError, live: live, children: [ui?.setup?.(gameProps), ui?.game(gameProps)] }));
|
|
39
44
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReactNode, RefCallback } from 'react';
|
|
2
2
|
import { type LeaveRoom } from './room-exit.js';
|
|
3
|
-
import '../../components/Button.css';
|
|
4
3
|
import './RoomShell.css';
|
|
5
4
|
export interface RoomShellProps {
|
|
6
5
|
shellRef?: RefCallback<HTMLElement>;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
* The room screen's own chrome: the shell, the title, the header's tool row, the streamed/builtin
|
|
4
|
-
* split, the password gate, and the one message a room that could not be read gets. Every room
|
|
5
|
-
* has this, whatever it plays — a game type's own content is a slot (`children`), never something
|
|
6
|
-
* this file knows the shape of.
|
|
7
|
-
*
|
|
8
|
-
* Nothing here is Magic's: no deck, no mode, no table. What a game type puts in the header
|
|
9
|
-
* (Magic's own settings panel, say) arrives already built, as `headerTools`; what it puts in the
|
|
10
|
-
* room's body arrives as `children`, rendered only once `resolved` is true and the room is not
|
|
11
|
-
* streamed — a streamed room draws `streamedBody` instead, and neither draws until the room record
|
|
12
|
-
* has answered.
|
|
13
|
-
*
|
|
14
|
-
* Only the member count, the title, `resolved` and the body are always given. Every other prop is
|
|
15
|
-
* off when absent: no tools, no streamed mode, no loading body, no password gate, no missing-room
|
|
16
|
-
* message. A game with none of those passes nothing for them.
|
|
17
|
-
*
|
|
18
|
-
* While the game in the body says a match is live (`live`), the head row is not drawn at all —
|
|
19
|
-
* no title, no Leave, no tools — so the game has the room to itself, and its own menu offers the
|
|
20
|
-
* way out (`GameSetupProps.leave`). It comes back the moment `live` is false again. The room's
|
|
21
|
-
* leave stays registered throughout, so the page's top bar still leaves through it.
|
|
22
|
-
*/
|
|
23
|
-
import { useState } from 'react';
|
|
2
|
+
import { AskButton } from "./AskButton.js";
|
|
24
3
|
import { leaveRoomThen, useRoomHome, useRoomLeave } from "./room-exit.js";
|
|
25
|
-
import '../../components/Button.css';
|
|
26
4
|
import './RoomShell.css';
|
|
27
5
|
export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled = false, leave, leaveAsks, headerTools = null, streamed = false, streamedSubLine = null, resolved, pending = false, pendingBody = null, streamedBody = null, locked = null, password = '', onPasswordChange, onPasswordSubmit, roomMissingMessage = null, live = false, children, }) {
|
|
28
6
|
useRoomLeave(leaveAsks === undefined ? (leave ?? null) : null);
|
|
@@ -34,20 +12,7 @@ export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settle
|
|
|
34
12
|
}
|
|
35
13
|
/** The head row's Leave. A leave that costs an event (`asks`) is asked once more, by its name, before it leaves. */
|
|
36
14
|
function RoomLeave({ leave, asks, home }) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return (_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave", disabled: leaving, onClick: () => {
|
|
41
|
-
if (asks !== undefined) {
|
|
42
|
-
setAsking(true);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
setLeaving(true);
|
|
46
|
-
void leaveRoomThen(home);
|
|
47
|
-
}, children: _jsx("span", { className: "ct-action__label", children: asks ?? 'Leave' }) }));
|
|
48
|
-
}
|
|
49
|
-
return (_jsxs("span", { className: "room-leave__ask", "data-testid": "room-leave-ask", children: [_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave-no", autoFocus: true, disabled: leaving, onClick: () => setAsking(false), children: _jsx("span", { className: "ct-action__label", children: "Cancel" }) }), _jsx("button", { type: "button", className: "room-leave ct-action ct-action--danger", "data-testid": "room-leave-yes", disabled: leaving, onClick: () => {
|
|
50
|
-
setLeaving(true);
|
|
51
|
-
void leave().finally(home);
|
|
52
|
-
}, children: _jsx("span", { className: "ct-action__label", children: asks }) })] }));
|
|
15
|
+
// Asked, it is this leave (the top bar only goes home); unasked, the one the shell registered.
|
|
16
|
+
const left = () => (asks === undefined ? leaveRoomThen(home) : leave().finally(home));
|
|
17
|
+
return (_jsx(AskButton, { className: "room-leave", testId: "room-leave", label: asks ?? 'Leave', confirm: asks, act: () => left().then(() => null) }));
|
|
53
18
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What the room looks like for its sounds: who is in it besides you, and who is ready. */
|
|
2
|
+
export interface RoomPresence {
|
|
3
|
+
/** Every member's id except the viewer's own. */
|
|
4
|
+
others: readonly string[];
|
|
5
|
+
/** A key per ready member or seat. */
|
|
6
|
+
ready: readonly string[];
|
|
7
|
+
/** What the ready keys are read from; a change of source rebaselines readiness rather than sounding. */
|
|
8
|
+
readySource: string;
|
|
9
|
+
}
|
|
10
|
+
/** The roles one change of the room plays, in order: joins, leaves, then readies. */
|
|
11
|
+
export declare function presenceRoles(before: RoomPresence, after: RoomPresence): string[];
|
|
12
|
+
/** Sounds each change of `presence`; `null` while the room has not been read, which sounds nothing and resets the baseline. */
|
|
13
|
+
export declare function useRoomSounds(presence: RoomPresence | null): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The room's comings and goings (the operator, 2026-11-08: "a sound for when someone joins a card table
|
|
3
|
+
* room and also a sound for when they ready up", and one for leaving). Another member arriving plays
|
|
4
|
+
* `ui.room-join`, one going `ui.room-leave`, and anyone readying, you included, `ui.room-ready`. Every
|
|
5
|
+
* screen in the room hears the same changes, as the room's own reads report them.
|
|
6
|
+
*
|
|
7
|
+
* A screen hears only changes it saw happen: the first snapshot it reads is the baseline, and so is the
|
|
8
|
+
* first after the readiness it reads from changes source (a mode switch, the Gauntlet's state arriving).
|
|
9
|
+
* One update plays each role at most once, so a pod filling in one read is one join, not five.
|
|
10
|
+
* Each role is the game's to voice (Magic's falls back to a sound it already had until one is assigned).
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect, useRef } from 'react';
|
|
13
|
+
import { playRole } from "../../sound/index.js";
|
|
14
|
+
/** The roles one change of the room plays, in order: joins, leaves, then readies. */
|
|
15
|
+
export function presenceRoles(before, after) {
|
|
16
|
+
const roles = [];
|
|
17
|
+
const was = new Set(before.others);
|
|
18
|
+
const is = new Set(after.others);
|
|
19
|
+
if (after.others.some((id) => !was.has(id)))
|
|
20
|
+
roles.push('ui.room-join');
|
|
21
|
+
if (before.others.some((id) => !is.has(id)))
|
|
22
|
+
roles.push('ui.room-leave');
|
|
23
|
+
if (before.readySource === after.readySource) {
|
|
24
|
+
const wasReady = new Set(before.ready);
|
|
25
|
+
if (after.ready.some((key) => !wasReady.has(key)))
|
|
26
|
+
roles.push('ui.room-ready');
|
|
27
|
+
}
|
|
28
|
+
return roles;
|
|
29
|
+
}
|
|
30
|
+
/** Sounds each change of `presence`; `null` while the room has not been read, which sounds nothing and resets the baseline. */
|
|
31
|
+
export function useRoomSounds(presence) {
|
|
32
|
+
const last = useRef(null);
|
|
33
|
+
const key = presence === null ? null : JSON.stringify(presence);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const now = key === null ? null : JSON.parse(key);
|
|
36
|
+
if (now !== null && last.current !== null)
|
|
37
|
+
for (const role of presenceRoles(last.current, now))
|
|
38
|
+
playRole(role);
|
|
39
|
+
last.current = now;
|
|
40
|
+
}, [key]);
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { watchRestart } from './restart-notice.js';
|
|
2
|
+
export type TrackedConnection = ReturnType<typeof trackConnection>;
|
|
3
|
+
export declare function trackConnection(transport: Parameters<typeof watchRestart>[0], { onRejoin }?: {
|
|
4
|
+
onRejoin?: () => void;
|
|
5
|
+
}): {
|
|
6
|
+
connected: boolean;
|
|
7
|
+
everConnected: boolean;
|
|
8
|
+
/** Dropped by a planned restart, inside its quiet window (`./restart-notice.ts`). */
|
|
9
|
+
serverUpdating: boolean;
|
|
10
|
+
/** 1 for the caller's first join, one more for each rejoin. */
|
|
11
|
+
joins: number;
|
|
12
|
+
/** Told after every change, the rejoin already sent. Returns the unsubscribe. */
|
|
13
|
+
subscribe(fn: () => void): () => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* One socket's connection, as the facts a connection banner is drawn from (`./components/connection-state.ts`). The caller joins
|
|
2
|
+
* once at the start (socket.io holds an emit until the connection opens) and again in `onRejoin`, on every connect after the first. */
|
|
3
|
+
import { watchRestart } from "./restart-notice.js";
|
|
4
|
+
export function trackConnection(transport, { onRejoin } = {}) {
|
|
5
|
+
const listeners = new Set();
|
|
6
|
+
const tell = () => listeners.forEach((fn) => fn());
|
|
7
|
+
const state = {
|
|
8
|
+
connected: false,
|
|
9
|
+
everConnected: false,
|
|
10
|
+
/** Dropped by a planned restart, inside its quiet window (`./restart-notice.ts`). */
|
|
11
|
+
serverUpdating: false,
|
|
12
|
+
/** 1 for the caller's first join, one more for each rejoin. */
|
|
13
|
+
joins: 1,
|
|
14
|
+
/** Told after every change, the rejoin already sent. Returns the unsubscribe. */
|
|
15
|
+
subscribe(fn) {
|
|
16
|
+
listeners.add(fn);
|
|
17
|
+
return () => void listeners.delete(fn);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
// Registered first, so a connect or a drop has settled `updating` before its own handler below
|
|
21
|
+
// tells anyone; only the quiet window running out is told from here.
|
|
22
|
+
watchRestart(transport, (updating, back) => {
|
|
23
|
+
state.serverUpdating = updating;
|
|
24
|
+
if (!state.connected && !back)
|
|
25
|
+
tell();
|
|
26
|
+
});
|
|
27
|
+
transport.on('connect', () => {
|
|
28
|
+
const rejoin = state.everConnected;
|
|
29
|
+
state.connected = state.everConnected = true;
|
|
30
|
+
if (rejoin) {
|
|
31
|
+
state.joins += 1;
|
|
32
|
+
onRejoin?.();
|
|
33
|
+
}
|
|
34
|
+
tell();
|
|
35
|
+
});
|
|
36
|
+
transport.on('disconnect', () => {
|
|
37
|
+
state.connected = false;
|
|
38
|
+
tell();
|
|
39
|
+
});
|
|
40
|
+
return state;
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-ui",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.256",
|
|
4
|
+
"gitHead": "c702ab6e78d9e2f3bc68a89a9a28a3cf3396b6e5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"react-dom": "^19.2.8"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
57
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
56
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.260",
|
|
57
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.260",
|
|
58
58
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.4",
|
|
59
59
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.158",
|
|
60
60
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.158",
|