@ksaa-nlp/gamehub-sdk 0.9.0 → 3.5.0

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.
Files changed (74) hide show
  1. package/README.md +154 -374
  2. package/SPEC.md +865 -0
  3. package/dist/gamehub-sdk.js +164 -1191
  4. package/dist/gamehub-sdk.js.map +3 -3
  5. package/dist/src/api-client.d.ts +15 -5
  6. package/dist/src/api-client.d.ts.map +1 -1
  7. package/dist/src/api-client.js +21 -5
  8. package/dist/src/api-client.js.map +1 -1
  9. package/dist/src/bridge.d.ts +31 -14
  10. package/dist/src/bridge.d.ts.map +1 -1
  11. package/dist/src/bridge.js +148 -159
  12. package/dist/src/bridge.js.map +1 -1
  13. package/dist/src/constants.d.ts +8 -6
  14. package/dist/src/constants.d.ts.map +1 -1
  15. package/dist/src/constants.js +8 -6
  16. package/dist/src/constants.js.map +1 -1
  17. package/dist/src/init.d.ts +18 -12
  18. package/dist/src/init.d.ts.map +1 -1
  19. package/dist/src/init.js +23 -156
  20. package/dist/src/init.js.map +1 -1
  21. package/dist/src/main.d.ts +45 -85
  22. package/dist/src/main.d.ts.map +1 -1
  23. package/dist/src/main.js +27 -52
  24. package/dist/src/main.js.map +1 -1
  25. package/dist/src/match-context.d.ts.map +1 -1
  26. package/dist/src/match-context.js +0 -14
  27. package/dist/src/match-context.js.map +1 -1
  28. package/dist/src/server-dev-harness.d.ts +85 -0
  29. package/dist/src/server-dev-harness.d.ts.map +1 -0
  30. package/dist/src/server-dev-harness.js +233 -0
  31. package/dist/src/server-dev-harness.js.map +1 -0
  32. package/dist/src/server-entry.d.ts +127 -0
  33. package/dist/src/server-entry.d.ts.map +1 -0
  34. package/dist/src/server-entry.js +26 -0
  35. package/dist/src/server-entry.js.map +1 -0
  36. package/dist/src/session.d.ts +16 -9
  37. package/dist/src/session.d.ts.map +1 -1
  38. package/dist/src/session.js +38 -27
  39. package/dist/src/session.js.map +1 -1
  40. package/dist/src/state.d.ts +17 -55
  41. package/dist/src/state.d.ts.map +1 -1
  42. package/dist/src/state.js +13 -32
  43. package/dist/src/state.js.map +1 -1
  44. package/dist/src/utils.d.ts +3 -14
  45. package/dist/src/utils.d.ts.map +1 -1
  46. package/dist/src/utils.js +3 -31
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/types/bootstrap.d.ts +56 -36
  49. package/dist/types/bootstrap.d.ts.map +1 -1
  50. package/dist/types/question.d.ts +36 -0
  51. package/dist/types/question.d.ts.map +1 -0
  52. package/dist/types/question.js +21 -0
  53. package/dist/types/question.js.map +1 -0
  54. package/dist/types/session.d.ts +23 -20
  55. package/dist/types/session.d.ts.map +1 -1
  56. package/package.json +14 -4
  57. package/CHANGELOG.md +0 -545
  58. package/MIGRATION.md +0 -322
  59. package/dist/src/multiplayer-match.d.ts +0 -42
  60. package/dist/src/multiplayer-match.d.ts.map +0 -1
  61. package/dist/src/multiplayer-match.js +0 -551
  62. package/dist/src/multiplayer-match.js.map +0 -1
  63. package/dist/src/multiplayer.d.ts +0 -96
  64. package/dist/src/multiplayer.d.ts.map +0 -1
  65. package/dist/src/multiplayer.js +0 -536
  66. package/dist/src/multiplayer.js.map +0 -1
  67. package/dist/types/multiplayer-match.d.ts +0 -204
  68. package/dist/types/multiplayer-match.d.ts.map +0 -1
  69. package/dist/types/multiplayer-match.js +0 -15
  70. package/dist/types/multiplayer-match.js.map +0 -1
  71. package/dist/types/multiplayer.d.ts +0 -194
  72. package/dist/types/multiplayer.d.ts.map +0 -1
  73. package/dist/types/multiplayer.js +0 -2
  74. package/dist/types/multiplayer.js.map +0 -1
@@ -1,204 +0,0 @@
1
- /**
2
- * Host-authoritative match coordinator types.
3
- *
4
- * The `multiplayer.match()` factory hides the boilerplate that every
5
- * multiplayer game otherwise reinvents: the peer-ready handshake, the
6
- * host-elected `match_start`, intent → resolve routing between guest and
7
- * host, matchId scoping, and idempotent reapply of broadcasts (including
8
- * server-replayed retained frames on reconnect).
9
- *
10
- * Games configure a Match by declaring (a) a typed event map, (b) per-event
11
- * `hostHandle` / `apply` pairs, and (c) a host-only `buildStart`. The
12
- * lifecycle, retain plumbing, and dedupe live in the SDK.
13
- */
14
- import type { Peer } from './multiplayer.js';
15
- /**
16
- * Every payload carried inside a Match must scope to a `matchId`. The SDK
17
- * auto-injects this field when sending and auto-verifies it on receive so
18
- * stragglers from a previous match are rejected before user code runs.
19
- *
20
- * `Omit<TPayload, 'matchId'>` is used at the call sites — `intent`,
21
- * `broadcast`, `buildStart` — so callers don't have to thread the id
22
- * around themselves.
23
- */
24
- export interface MatchScopedPayload {
25
- matchId: string;
26
- }
27
- /**
28
- * User-defined event map. Each value extends `MatchScopedPayload`.
29
- *
30
- * This alias is documentation, not a constraint: the actual `match()`
31
- * generics leave `TMap` unbounded so games can declare it as a fixed-keys
32
- * `interface` (which TypeScript otherwise refuses to assign to a
33
- * `Record<string, X>` because of the missing index signature). Per-event
34
- * payload safety still comes from `MatchEventDef<TPayload extends
35
- * MatchScopedPayload, TMap>` — providing an event whose payload doesn't
36
- * extend `MatchScopedPayload` fails to type-check at the events map.
37
- */
38
- export type MatchEventMap = Record<string, MatchScopedPayload>;
39
- /** Reasons a match can transition to `aborted`. */
40
- export type MatchAbortReason = 'room_closed' | 'disconnected' | 'kicked';
41
- /** State machine the Match advances through over its lifetime. */
42
- export type MatchState = 'waiting' | 'starting' | 'active' | 'aborted' | 'ended';
43
- /** Options passed to `multiplayer.broadcast(...)` from inside a Match ctx. */
44
- export interface MatchBroadcastOptions {
45
- /**
46
- * Pin this frame as a retained snapshot for this `retainKey`. The SDK
47
- * defaults to `false` — opt in per-event when reconnect/late-join peers
48
- * should automatically receive the latest payload for the key. The
49
- * match-start broadcast is always retained regardless.
50
- */
51
- retain?: boolean;
52
- /**
53
- * Override the retain key. Defaults to the event name when `retain: true`
54
- * and no override is supplied. Common pattern: derive from the payload,
55
- * e.g. `cell:${payload.cellId}`.
56
- */
57
- retainKey?: string;
58
- /**
59
- * Direct delivery — when set, the server routes this frame ONLY to the
60
- * listed peerIds. Use for private host→guest state (hints, per-player
61
- * power-up effects). Mutually exclusive with `retain` server-side; the
62
- * SDK won't apply locally either when targeted, since targeting implies
63
- * the host is sending state to specific other peers — not asserting it
64
- * as the local match's authoritative resolution.
65
- */
66
- to?: string | string[];
67
- }
68
- /** Context passed to event handlers (and exposed as `match.intent`/`broadcast`). */
69
- export interface MatchCtx<TMap> {
70
- readonly matchId: string;
71
- readonly isHost: boolean;
72
- readonly selfId: string;
73
- readonly peers: readonly Peer[];
74
- /**
75
- * True when the current handler is running for a server-replayed
76
- * retained frame (delivered to a reconnecting / late-joining peer),
77
- * false for live broadcasts and host-initiated calls. Use this to
78
- * suppress one-shot side effects (sounds, animations, confetti) that
79
- * would otherwise re-fire for state the peer is just catching up on.
80
- *
81
- * Always false on `intent()` / `broadcast()` callers — only meaningful
82
- * inside `apply` handlers triggered by replay.
83
- */
84
- readonly retained: boolean;
85
- /** Lookup helper: peer by id, or null if they've left the room. */
86
- peer(peerId: string): Peer | null;
87
- /**
88
- * Send an intent. From the host, short-circuits straight to local
89
- * `hostHandle` (no WS roundtrip). From a guest, sends through the WS for
90
- * the host to validate. `matchId` is auto-injected.
91
- */
92
- intent<K extends keyof TMap>(name: K, payload: Omit<TMap[K], 'matchId'>): boolean;
93
- /**
94
- * Host-only. Applies the resolution locally (idempotent via the event's
95
- * `idKey`), then broadcasts to peers. No-ops on guests with a console
96
- * warning. `matchId` is auto-injected.
97
- */
98
- broadcast<K extends keyof TMap>(name: K, payload: Omit<TMap[K], 'matchId'>, options?: MatchBroadcastOptions): boolean;
99
- }
100
- /** Narrowed ctx variant guaranteed inside `hostHandle`. */
101
- export interface MatchHostCtx<TMap> extends MatchCtx<TMap> {
102
- readonly isHost: true;
103
- }
104
- /** Per-event behaviour. At least one of `hostHandle` / `apply` must be set. */
105
- export interface MatchEventDef<TPayload extends MatchScopedPayload, TMap> {
106
- /**
107
- * Runs ONLY on the host, when an intent arrives from a guest (or when the
108
- * host calls `match.intent(...)` itself). Use to validate and call
109
- * `ctx.broadcast(...)` with the authoritative resolution.
110
- *
111
- * Omit for "broadcast-only" events (where guests cannot send the event
112
- * at all — only the host calls `ctx.broadcast`).
113
- */
114
- hostHandle?: (ctx: MatchHostCtx<TMap>, payload: TPayload, fromPeerId: string) => void | Promise<void>;
115
- /**
116
- * Runs on every peer (host included) when the broadcasted resolution
117
- * arrives. The only place game state should mutate. Guarded by `idKey`
118
- * for idempotency — same key → runs at most once per match.
119
- */
120
- apply?: (ctx: MatchCtx<TMap>, payload: TPayload, fromPeerId: string) => void;
121
- /**
122
- * Idempotency key. Defaults to `${eventName}:${matchId}:${seq}`. Override
123
- * when a single logical action can arrive under multiple seqs (e.g.
124
- * `cell_opened` keyed by cellId so a retained replay on reconnect is
125
- * deduped against the live frame the peer already applied).
126
- */
127
- idKey?: (payload: TPayload) => string;
128
- /**
129
- * When true, the host's `ctx.broadcast` of this event auto-pins it as a
130
- * retained frame so reconnecting peers receive the latest payload before
131
- * any live traffic. Defaults to false.
132
- */
133
- retain?: boolean;
134
- /**
135
- * Override the retain key when `retain: true`. Defaults to the event
136
- * name. Use a payload-derived key when multiple frames of the same event
137
- * type need to coexist as retained snapshots (e.g. one per cell).
138
- */
139
- retainKey?: (payload: TPayload) => string;
140
- }
141
- /** Match construction options. */
142
- export interface MatchOptions<TMap extends {
143
- [K in keyof TMap]: MatchScopedPayload;
144
- }, TStart extends MatchScopedPayload> {
145
- /** Wait until at least N peers are present AND ready. Default 2. */
146
- expectedPeers?: number;
147
- /**
148
- * If true (default), every peer auto-emits the ready handshake on first
149
- * boot. Set false when the game has its own ready gate (lobby UI, ready
150
- * button, character pick screen) and call `match.markReady()` manually.
151
- */
152
- autoReady?: boolean;
153
- /**
154
- * Host-only. Builds the match_start payload exactly once, when everyone
155
- * is ready. The SDK auto-injects `matchId` (uuid) before broadcasting —
156
- * leave it off the returned object. Use `peers` to derive seat
157
- * assignments deterministically.
158
- */
159
- buildStart: (peers: readonly Peer[]) => Omit<TStart, 'matchId'> | Promise<Omit<TStart, 'matchId'>>;
160
- /**
161
- * Runs on every peer when match_start arrives (live or retained replay).
162
- * Idempotent on `matchId` — re-broadcasts with the same id are dropped.
163
- */
164
- onStart: (ctx: MatchCtx<TMap>, payload: TStart) => void;
165
- /** Per-event hostHandle/apply pairs. Keys must be members of TMap. */
166
- events: {
167
- [K in keyof TMap]?: MatchEventDef<TMap[K], TMap>;
168
- };
169
- /** Local peer count vs `expectedPeers` changed before match_start. */
170
- onWaitingForPeers?: (waiting: boolean, present: number, expected: number) => void;
171
- /** A peer disconnected after match_start. Game decides what to do. */
172
- onPeerLeft?: (ctx: MatchCtx<TMap>, peerId: string) => void;
173
- /** Room WS died terminally (no reconnect possible). */
174
- onAborted?: (reason: MatchAbortReason, ctx: {
175
- matchId: string | null;
176
- }) => void;
177
- /** Internal event name for the start broadcast. Default 'match:start'. */
178
- startEventName?: string;
179
- /** Internal event name for the readiness handshake. Default 'match:peer_ready'. */
180
- readyEventName?: string;
181
- /** Retain key for the start broadcast. Default 'match:start'. */
182
- startRetainKey?: string;
183
- }
184
- /** Public Match handle. */
185
- export interface Match<TMap> {
186
- readonly state: MatchState;
187
- readonly matchId: string | null;
188
- /** Send an intent. Same as `ctx.intent` from inside handlers. */
189
- intent<K extends keyof TMap>(name: K, payload: Omit<TMap[K], 'matchId'>): boolean;
190
- /** Host-only broadcast. Same as `ctx.broadcast` from inside handlers. */
191
- broadcast<K extends keyof TMap>(name: K, payload: Omit<TMap[K], 'matchId'>, options?: MatchBroadcastOptions): boolean;
192
- /**
193
- * Manually mark this peer ready. No-op when `autoReady: true` (default)
194
- * or if the match has already started. Use with `autoReady: false`.
195
- */
196
- markReady(): void;
197
- /** Subscribe to lifecycle transitions. Returns unsubscribe. */
198
- onStateChange(handler: (state: MatchState) => void): () => void;
199
- /** Detach all subscriptions. Optionally also leaves the room. */
200
- destroy(opts?: {
201
- leaveRoom?: boolean;
202
- }): Promise<void>;
203
- }
204
- //# sourceMappingURL=multiplayer-match.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiplayer-match.d.ts","sourceRoot":"","sources":["../../types/multiplayer-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAE/D,mDAAmD;AACnD,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,cAAc,GAAG,QAAQ,CAAC;AAEzE,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,UAAU,GACV,QAAQ,GACR,SAAS,GACT,OAAO,CAAC;AAEZ,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACxB;AAED,oFAAoF;AACpF,MAAM,WAAW,QAAQ,CAAC,IAAI;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAEhC;;;;;;;;;OASG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,mEAAmE;IACnE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAElC;;;;OAIG;IACH,MAAM,CAAC,CAAC,SAAS,MAAM,IAAI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E,MAAM,GAAG,IAAI,CAAC;IAEhC,iEAAiE;IACjE,MAAM,CAAC,CAAC,SAAS,MAAM,IAAI,EACzB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,GAChC,OAAO,CAAC;IAEX,yEAAyE;IACzE,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,EAC5B,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EACjC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC;IAEX;;;OAGG;IACH,SAAS,IAAI,IAAI,CAAC;IAElB,+DAA+D;IAC/D,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAEhE,iEAAiE;IACjE,OAAO,CAAC,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Host-authoritative match coordinator types.
3
- *
4
- * The `multiplayer.match()` factory hides the boilerplate that every
5
- * multiplayer game otherwise reinvents: the peer-ready handshake, the
6
- * host-elected `match_start`, intent → resolve routing between guest and
7
- * host, matchId scoping, and idempotent reapply of broadcasts (including
8
- * server-replayed retained frames on reconnect).
9
- *
10
- * Games configure a Match by declaring (a) a typed event map, (b) per-event
11
- * `hostHandle` / `apply` pairs, and (c) a host-only `buildStart`. The
12
- * lifecycle, retain plumbing, and dedupe live in the SDK.
13
- */
14
- export {};
15
- //# sourceMappingURL=multiplayer-match.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiplayer-match.js","sourceRoot":"","sources":["../../types/multiplayer-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -1,194 +0,0 @@
1
- /**
2
- * Information needed to connect to a multiplayer room's WebSocket.
3
- */
4
- export interface JoinInfo {
5
- wsUrl: string;
6
- roomToken: string;
7
- gameSlug: string;
8
- roomCode: string;
9
- peerId: string;
10
- }
11
- /**
12
- * A peer in a multiplayer room. Identity fields beyond `peerId` are
13
- * populated from the JWT claims the platform mints — they're optional on
14
- * this type so games are robust to anonymous / passcode-joined peers.
15
- */
16
- export interface Peer {
17
- peerId: string;
18
- role?: string;
19
- userId?: string;
20
- guestId?: string;
21
- displayName?: string;
22
- avatar?: string | null;
23
- metadata?: Record<string, any>;
24
- /**
25
- * Server-side timestamp (ms since epoch) of the last frame or pong
26
- * received from this peer. Refreshed on every inbound message and on
27
- * the WS heartbeat. Useful for rendering "last seen 3s ago" or
28
- * dimming peers that have gone quiet.
29
- */
30
- lastSeenAt?: number;
31
- }
32
- /**
33
- * Public info about the current multiplayer room, returned by
34
- * `multiplayer.getRoom()`.
35
- */
36
- export interface RoomInfo {
37
- roomCode: string;
38
- shareId: string;
39
- shareUrl?: string;
40
- peerId: string;
41
- role: string;
42
- gameSlug: string;
43
- roomToken: string;
44
- wsUrl: string;
45
- }
46
- /**
47
- * Internal book-keeping for the currently-joined room.
48
- */
49
- export interface MpRoom {
50
- roomCode: string;
51
- shareId: string;
52
- shareUrl?: string;
53
- peerId: string;
54
- role: string;
55
- gameSlug: string;
56
- roomToken: string;
57
- wsUrl: string;
58
- }
59
- /**
60
- * Parameters used by `connect` to open / re-open a WS.
61
- */
62
- export interface MpJoinRequest {
63
- roomCode: string;
64
- roomToken: string;
65
- wsUrl: string;
66
- gameSlug: string;
67
- peerId: string;
68
- }
69
- /**
70
- * Listener for a single multiplayer event (or all events via `'*'`).
71
- */
72
- export type MpEventHandler = (payload: any) => void;
73
- /** Options accepted when creating a room. */
74
- export interface RoomOptions {
75
- maxPlayers?: number;
76
- passcode?: string;
77
- /**
78
- * Per-room realtime rate limit overrides. Server defaults are 20 frames
79
- * per 1000ms — fine for turn-based play. Real-time games (movement,
80
- * drawing, fast input) typically need a higher burst (e.g. 60–120) and
81
- * may keep the 1000ms window. Both fields are optional; unset fields
82
- * fall back to the server defaults.
83
- */
84
- rateBurst?: number;
85
- rateWindowMs?: number;
86
- /**
87
- * Opt-in: when the host disconnects past the reconnect grace window,
88
- * promote the earliest-joined remaining peer to host instead of
89
- * closing the room. The server emits a `host_changed` system event
90
- * `{ newHostPeerId, previousHostPeerId }` and updates `multiplayer.isHost()`
91
- * for the promoted peer automatically.
92
- *
93
- * Default false. Most match-style games (link-game, quizzes) should
94
- * leave this off — losing the host mid-match is correctly fatal
95
- * because the host owns authoritative state. Suitable for relay /
96
- * lobby / casual co-op games where any peer can keep play going.
97
- */
98
- autoMigrateHost?: boolean;
99
- }
100
- /** Options accepted when joining a room. */
101
- export interface JoinOptions {
102
- passcode?: string;
103
- displayName?: string;
104
- /**
105
- * When true, the SDK locally marks this peer as a view-only guest:
106
- * `multiplayer.send` and `multiplayer.broadcast` become no-ops and score
107
- * submission (`submitScore` / `submitMatchResult`) is blocked. The peer
108
- * still receives every broadcast so it can mirror host state.
109
- */
110
- asViewer?: boolean;
111
- }
112
- /**
113
- * Options accepted by `multiplayer.send` / `multiplayer.broadcast`.
114
- */
115
- export interface SendOptions {
116
- /**
117
- * When true, the server keeps the latest frame for `retainKey` (or the
118
- * event name if no key is given) and replays it to every peer that joins
119
- * the room afterwards — before any live traffic reaches that peer's
120
- * socket. Mirrors MQTT retained messages.
121
- *
122
- * Only the room's host may retain frames; the server silently drops the
123
- * `retain` flag from non-host senders. Targeted frames (with `to` set)
124
- * are never retained.
125
- */
126
- retain?: boolean;
127
- /**
128
- * Identifier under which the server stores the retained frame. Sending
129
- * another retained frame with the same key overwrites the previous value
130
- * but keeps its position in replay order. Defaults to the event name.
131
- * Must match `^[a-zA-Z0-9_.:-]{1,64}$`.
132
- */
133
- retainKey?: string;
134
- /**
135
- * Direct delivery — when set, the server routes this frame ONLY to the
136
- * listed peerIds (sender included if their id is in the list, but no
137
- * automatic sender-echo otherwise). Unknown peerIds are silently
138
- * skipped. Use for private host→guest hints, per-player power-ups, or
139
- * any state that shouldn't leak to spectators.
140
- *
141
- * Mutually exclusive with `retain`: a targeted frame is by definition
142
- * not a room-wide snapshot, so `retain` is dropped server-side when
143
- * `to` is also present.
144
- */
145
- to?: string | string[];
146
- /**
147
- * When true, the server drops the frame unless the sender is the room's
148
- * host, replying with a `system` `error` frame `{ code: 'HOST_ONLY' }`.
149
- * Set automatically by `multiplayer.broadcast` so authoritative game
150
- * state can't be forged by a guest. Application code generally does not
151
- * need to set this directly.
152
- */
153
- hostOnly?: boolean;
154
- }
155
- /**
156
- * Shape of the `message` event emitted for every peer-originated game event.
157
- */
158
- export interface MpMessage<T = any> {
159
- roomCode: string;
160
- fromPeerId: string;
161
- eventName: string;
162
- payload: T;
163
- seq: number;
164
- sentAt: number;
165
- /**
166
- * True when the frame is a server-replayed retained ("sticky") snapshot
167
- * delivered on join/reconnect. Game code can usually treat retained and
168
- * live frames identically — apply both via the same handler. Idempotent
169
- * appliers don't need to special-case this flag, but games that play
170
- * sounds/animations on a state change typically suppress them when
171
- * `retained` is true.
172
- */
173
- retained?: boolean;
174
- }
175
- /** Result returned by `multiplayer.createRoom`. */
176
- export interface CreateRoomResult {
177
- success: boolean;
178
- roomCode?: string;
179
- shareId?: string;
180
- shareUrl?: string;
181
- peerId?: string;
182
- roomToken?: string;
183
- error?: string;
184
- }
185
- /** Result returned by `multiplayer.joinRoom` / `joinRoomByLink`. */
186
- export interface JoinRoomResult {
187
- success: boolean;
188
- roomCode?: string;
189
- shareId?: string;
190
- peerId?: string;
191
- roomToken?: string;
192
- error?: string;
193
- }
194
- //# sourceMappingURL=multiplayer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiplayer.d.ts","sourceRoot":"","sources":["../../types/multiplayer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC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AC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=multiplayer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiplayer.js","sourceRoot":"","sources":["../../types/multiplayer.ts"],"names":[],"mappings":""}