@ksaa-nlp/gamehub-sdk 0.7.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.
- package/README.md +154 -374
- package/SPEC.md +865 -0
- package/dist/gamehub-sdk.js +164 -1163
- package/dist/gamehub-sdk.js.map +3 -3
- package/dist/src/api-client.d.ts +15 -5
- package/dist/src/api-client.d.ts.map +1 -1
- package/dist/src/api-client.js +21 -5
- package/dist/src/api-client.js.map +1 -1
- package/dist/src/bridge.d.ts +31 -14
- package/dist/src/bridge.d.ts.map +1 -1
- package/dist/src/bridge.js +148 -159
- package/dist/src/bridge.js.map +1 -1
- package/dist/src/constants.d.ts +8 -6
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -6
- package/dist/src/constants.js.map +1 -1
- package/dist/src/init.d.ts +18 -12
- package/dist/src/init.d.ts.map +1 -1
- package/dist/src/init.js +23 -156
- package/dist/src/init.js.map +1 -1
- package/dist/src/main.d.ts +45 -85
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +27 -52
- package/dist/src/main.js.map +1 -1
- package/dist/src/match-context.d.ts.map +1 -1
- package/dist/src/match-context.js +0 -14
- package/dist/src/match-context.js.map +1 -1
- package/dist/src/server-dev-harness.d.ts +85 -0
- package/dist/src/server-dev-harness.d.ts.map +1 -0
- package/dist/src/server-dev-harness.js +233 -0
- package/dist/src/server-dev-harness.js.map +1 -0
- package/dist/src/server-entry.d.ts +127 -0
- package/dist/src/server-entry.d.ts.map +1 -0
- package/dist/src/server-entry.js +26 -0
- package/dist/src/server-entry.js.map +1 -0
- package/dist/src/session.d.ts +16 -9
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +38 -27
- package/dist/src/session.js.map +1 -1
- package/dist/src/state.d.ts +17 -55
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/state.js +13 -32
- package/dist/src/state.js.map +1 -1
- package/dist/src/utils.d.ts +3 -14
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -31
- package/dist/src/utils.js.map +1 -1
- package/dist/types/bootstrap.d.ts +56 -36
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/question.d.ts +36 -0
- package/dist/types/question.d.ts.map +1 -0
- package/dist/types/question.js +21 -0
- package/dist/types/question.js.map +1 -0
- package/dist/types/session.d.ts +23 -20
- package/dist/types/session.d.ts.map +1 -1
- package/package.json +14 -4
- package/CHANGELOG.md +0 -467
- package/MIGRATION.md +0 -322
- package/dist/src/multiplayer-match.d.ts +0 -42
- package/dist/src/multiplayer-match.d.ts.map +0 -1
- package/dist/src/multiplayer-match.js +0 -551
- package/dist/src/multiplayer-match.js.map +0 -1
- package/dist/src/multiplayer.d.ts +0 -96
- package/dist/src/multiplayer.d.ts.map +0 -1
- package/dist/src/multiplayer.js +0 -495
- package/dist/src/multiplayer.js.map +0 -1
- package/dist/types/multiplayer-match.d.ts +0 -204
- package/dist/types/multiplayer-match.d.ts.map +0 -1
- package/dist/types/multiplayer-match.js +0 -15
- package/dist/types/multiplayer-match.js.map +0 -1
- package/dist/types/multiplayer.d.ts +0 -157
- package/dist/types/multiplayer.d.ts.map +0 -1
- package/dist/types/multiplayer.js +0 -2
- 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,Q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AAE,MAAM,GAAG,IAAI,CAAA;KAAE,KAC5B,IAAI,CAAC;IAIV,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,2BAA2B;AAC3B,MAAM,WAAW,KAAK,CAAC,IAAI;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,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,157 +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
|
-
/**
|
|
26
|
-
* Public info about the current multiplayer room, returned by
|
|
27
|
-
* `multiplayer.getRoom()`.
|
|
28
|
-
*/
|
|
29
|
-
export interface RoomInfo {
|
|
30
|
-
roomCode: string;
|
|
31
|
-
shareId: string;
|
|
32
|
-
shareUrl?: string;
|
|
33
|
-
peerId: string;
|
|
34
|
-
role: string;
|
|
35
|
-
gameSlug: string;
|
|
36
|
-
roomToken: string;
|
|
37
|
-
wsUrl: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Internal book-keeping for the currently-joined room.
|
|
41
|
-
*/
|
|
42
|
-
export interface MpRoom {
|
|
43
|
-
roomCode: string;
|
|
44
|
-
shareId: string;
|
|
45
|
-
shareUrl?: string;
|
|
46
|
-
peerId: string;
|
|
47
|
-
role: string;
|
|
48
|
-
gameSlug: string;
|
|
49
|
-
roomToken: string;
|
|
50
|
-
wsUrl: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Parameters used by `connect` to open / re-open a WS.
|
|
54
|
-
*/
|
|
55
|
-
export interface MpJoinRequest {
|
|
56
|
-
roomCode: string;
|
|
57
|
-
roomToken: string;
|
|
58
|
-
wsUrl: string;
|
|
59
|
-
gameSlug: string;
|
|
60
|
-
peerId: string;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Listener for a single multiplayer event (or all events via `'*'`).
|
|
64
|
-
*/
|
|
65
|
-
export type MpEventHandler = (payload: any) => void;
|
|
66
|
-
/** Options accepted when creating a room. */
|
|
67
|
-
export interface RoomOptions {
|
|
68
|
-
maxPlayers?: number;
|
|
69
|
-
passcode?: string;
|
|
70
|
-
}
|
|
71
|
-
/** Options accepted when joining a room. */
|
|
72
|
-
export interface JoinOptions {
|
|
73
|
-
passcode?: string;
|
|
74
|
-
displayName?: string;
|
|
75
|
-
/**
|
|
76
|
-
* When true, the SDK locally marks this peer as a view-only guest:
|
|
77
|
-
* `multiplayer.send` and `multiplayer.broadcast` become no-ops and score
|
|
78
|
-
* submission (`submitScore` / `submitMatchResult`) is blocked. The peer
|
|
79
|
-
* still receives every broadcast so it can mirror host state.
|
|
80
|
-
*/
|
|
81
|
-
asViewer?: boolean;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Options accepted by `multiplayer.send` / `multiplayer.broadcast`.
|
|
85
|
-
*/
|
|
86
|
-
export interface SendOptions {
|
|
87
|
-
/**
|
|
88
|
-
* When true, the server keeps the latest frame for `retainKey` (or the
|
|
89
|
-
* event name if no key is given) and replays it to every peer that joins
|
|
90
|
-
* the room afterwards — before any live traffic reaches that peer's
|
|
91
|
-
* socket. Mirrors MQTT retained messages.
|
|
92
|
-
*
|
|
93
|
-
* Only the room's host may retain frames; the server silently drops the
|
|
94
|
-
* `retain` flag from non-host senders. Targeted frames (with `to` set)
|
|
95
|
-
* are never retained.
|
|
96
|
-
*/
|
|
97
|
-
retain?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Identifier under which the server stores the retained frame. Sending
|
|
100
|
-
* another retained frame with the same key overwrites the previous value
|
|
101
|
-
* but keeps its position in replay order. Defaults to the event name.
|
|
102
|
-
* Must match `^[a-zA-Z0-9_.:-]{1,64}$`.
|
|
103
|
-
*/
|
|
104
|
-
retainKey?: string;
|
|
105
|
-
/**
|
|
106
|
-
* Direct delivery — when set, the server routes this frame ONLY to the
|
|
107
|
-
* listed peerIds (sender included if their id is in the list, but no
|
|
108
|
-
* automatic sender-echo otherwise). Unknown peerIds are silently
|
|
109
|
-
* skipped. Use for private host→guest hints, per-player power-ups, or
|
|
110
|
-
* any state that shouldn't leak to spectators.
|
|
111
|
-
*
|
|
112
|
-
* Mutually exclusive with `retain`: a targeted frame is by definition
|
|
113
|
-
* not a room-wide snapshot, so `retain` is dropped server-side when
|
|
114
|
-
* `to` is also present.
|
|
115
|
-
*/
|
|
116
|
-
to?: string | string[];
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Shape of the `message` event emitted for every peer-originated game event.
|
|
120
|
-
*/
|
|
121
|
-
export interface MpMessage<T = any> {
|
|
122
|
-
roomCode: string;
|
|
123
|
-
fromPeerId: string;
|
|
124
|
-
eventName: string;
|
|
125
|
-
payload: T;
|
|
126
|
-
seq: number;
|
|
127
|
-
sentAt: number;
|
|
128
|
-
/**
|
|
129
|
-
* True when the frame is a server-replayed retained ("sticky") snapshot
|
|
130
|
-
* delivered on join/reconnect. Game code can usually treat retained and
|
|
131
|
-
* live frames identically — apply both via the same handler. Idempotent
|
|
132
|
-
* appliers don't need to special-case this flag, but games that play
|
|
133
|
-
* sounds/animations on a state change typically suppress them when
|
|
134
|
-
* `retained` is true.
|
|
135
|
-
*/
|
|
136
|
-
retained?: boolean;
|
|
137
|
-
}
|
|
138
|
-
/** Result returned by `multiplayer.createRoom`. */
|
|
139
|
-
export interface CreateRoomResult {
|
|
140
|
-
success: boolean;
|
|
141
|
-
roomCode?: string;
|
|
142
|
-
shareId?: string;
|
|
143
|
-
shareUrl?: string;
|
|
144
|
-
peerId?: string;
|
|
145
|
-
roomToken?: string;
|
|
146
|
-
error?: string;
|
|
147
|
-
}
|
|
148
|
-
/** Result returned by `multiplayer.joinRoom` / `joinRoomByLink`. */
|
|
149
|
-
export interface JoinRoomResult {
|
|
150
|
-
success: boolean;
|
|
151
|
-
roomCode?: string;
|
|
152
|
-
shareId?: string;
|
|
153
|
-
peerId?: string;
|
|
154
|
-
roomToken?: string;
|
|
155
|
-
error?: string;
|
|
156
|
-
}
|
|
157
|
-
//# 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;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAA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