@ksaa-nlp/gamehub-sdk 4.3.0 → 5.0.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 +75 -46
- package/SPEC.md +130 -59
- package/dist/gamehub-sdk.js +15 -30
- package/dist/gamehub-sdk.js.map +3 -3
- package/dist/src/bot-driver.d.ts +54 -0
- package/dist/src/bot-driver.d.ts.map +1 -0
- package/dist/src/bot-driver.js +104 -0
- package/dist/src/bot-driver.js.map +1 -0
- package/dist/src/bridge.d.ts.map +1 -1
- package/dist/src/bridge.js +0 -35
- package/dist/src/bridge.js.map +1 -1
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/init.js +7 -7
- package/dist/src/init.js.map +1 -1
- package/dist/src/main.d.ts +1 -1
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +3 -4
- package/dist/src/main.js.map +1 -1
- package/dist/src/multiplayer-client.d.ts +50 -0
- package/dist/src/multiplayer-client.d.ts.map +1 -0
- package/dist/src/multiplayer-client.js +268 -0
- package/dist/src/multiplayer-client.js.map +1 -0
- package/dist/src/multiplayer-entry.d.ts +9 -0
- package/dist/src/multiplayer-entry.d.ts.map +1 -0
- package/dist/src/multiplayer-entry.js +9 -0
- package/dist/src/multiplayer-entry.js.map +1 -0
- package/dist/src/multiplayer-session.d.ts.map +1 -1
- package/dist/src/multiplayer-session.js +5 -1
- package/dist/src/multiplayer-session.js.map +1 -1
- package/dist/src/multiplayer.d.ts.map +1 -1
- package/dist/src/multiplayer.js +2 -1
- package/dist/src/multiplayer.js.map +1 -1
- package/dist/src/server-entry.d.ts +10 -4
- package/dist/src/server-entry.d.ts.map +1 -1
- package/dist/src/server-entry.js +7 -5
- package/dist/src/server-entry.js.map +1 -1
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +3 -2
- package/dist/src/session.js.map +1 -1
- package/dist/src/state.d.ts +1 -2
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/state.js +0 -1
- package/dist/src/state.js.map +1 -1
- package/dist/types/bootstrap.d.ts +6 -45
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/multiplayer-session.d.ts +13 -7
- package/dist/types/multiplayer-session.d.ts.map +1 -1
- package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
- package/dist/vendor/colyseus-schemas/clock.js +67 -0
- package/dist/vendor/colyseus-schemas/common.d.ts +17 -0
- package/dist/vendor/colyseus-schemas/common.js +12 -0
- package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
- package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
- package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
- package/dist/vendor/colyseus-schemas/ugc.js +124 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +176 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.js +287 -0
- package/package.json +33 -3
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ bs.playerCount; // free-form, e.g. '4'
|
|
|
93
93
|
bs.teamOneName; // free-form
|
|
94
94
|
bs.teamTwoName; // free-form
|
|
95
95
|
bs.profileId; // string | null — game profile chosen in the pre-start picker
|
|
96
|
-
bs.
|
|
96
|
+
bs.multiplayerLaunch; // bound multiplayer round, or null (see Multiplayer below)
|
|
97
97
|
bs.isBootstrapped; // true after the host has replied at least once
|
|
98
98
|
```
|
|
99
99
|
|
|
@@ -252,40 +252,12 @@ Both are optional. The SDK doesn't pause anything itself; it just delivers the s
|
|
|
252
252
|
|
|
253
253
|
## Multiplayer
|
|
254
254
|
|
|
255
|
-
The
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const { multiplayer } = sdk.getBootstrap();
|
|
263
|
-
if (!multiplayer) {
|
|
264
|
-
startSoloMode();
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const client = new Client(multiplayer.wsEndpoint);
|
|
269
|
-
const room = await client.consumeSeatReservation<UgcState>(
|
|
270
|
-
multiplayer.reservation
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
const serverNow = attachServerClock(room);
|
|
274
|
-
|
|
275
|
-
room.onStateChange((state) => render(state));
|
|
276
|
-
room.onMessage('fx:answer', (msg) => playSound(msg));
|
|
277
|
-
room.send('answer:submit', { answer: 'B' });
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
`multiplayer.reservation` is a Colyseus `SeatReservation` (the `{ room, sessionId }` envelope) — feed it straight to `consumeSeatReservation`, which performs the clean first join. No reconnection-token handoff crosses the host→game boundary; after joining, the server mints `room.reconnectionToken` for the game to keep if it wants to reconnect later.
|
|
281
|
-
|
|
282
|
-
External embeds also provide `roomCode`, `role`, and `connectionScope` when
|
|
283
|
-
available. If the game persists its server-issued reconnection token, include
|
|
284
|
-
`connectionScope` in that storage key so two publisher tabs cannot reuse each
|
|
285
|
-
other's reconnect state. These fields are opaque launch context; the SDK never
|
|
286
|
-
opens a socket or writes reconnection data.
|
|
287
|
-
|
|
288
|
-
The returned `room` is a stock `@colyseus/sdk` `Room` — see <https://docs.colyseus.io/client/room/> for its full API. Install `@colyseus/sdk`, `@colyseus/schema`, and `@ksaa-nlp/colyseus-schemas` in your game; the SDK doesn't pull them in. This works the same inside a native WebView host — the game opens its own socket from inside the WebView; the SDK never proxies realtime traffic over the native bridge.
|
|
255
|
+
The main entry and the script-tag bundle never open a WebSocket. Multiplayer
|
|
256
|
+
games read `sdk.getBootstrap().multiplayerLaunch`, request their bound seat with
|
|
257
|
+
`requestMultiplayerLaunch()` and connect with `MultiplayerClient` from the
|
|
258
|
+
opt-in `@ksaa-nlp/gamehub-sdk/multiplayer` subpath. See
|
|
259
|
+
[Multiplayer (SDK 4.2)](#multiplayer-sdk-42) below and the
|
|
260
|
+
[multiplayer reference](../../specs/multiplayer.md).
|
|
289
261
|
|
|
290
262
|
## API summary
|
|
291
263
|
|
|
@@ -293,7 +265,7 @@ The returned `room` is a stock `@colyseus/sdk` `Room` — see <https://docs.coly
|
|
|
293
265
|
const sdk = createSdk();
|
|
294
266
|
|
|
295
267
|
// Lifecycle
|
|
296
|
-
sdk.version; // '
|
|
268
|
+
sdk.version; // '5.0.0'
|
|
297
269
|
sdk.ready(); // Promise<boolean>
|
|
298
270
|
sdk.isInitialized(); // boolean
|
|
299
271
|
sdk.isAuthenticated(); // boolean
|
|
@@ -336,7 +308,7 @@ import type {
|
|
|
336
308
|
Sdk,
|
|
337
309
|
BootstrapData,
|
|
338
310
|
BootstrapConfig,
|
|
339
|
-
|
|
311
|
+
MultiplayerLaunchContext,
|
|
340
312
|
ScoreMetadata,
|
|
341
313
|
SubmitScoreResult,
|
|
342
314
|
StartSessionResult,
|
|
@@ -370,11 +342,35 @@ The full nested `Word` shape and its sub-interfaces (`WordSense`, `WordForm`, `L
|
|
|
370
342
|
|
|
371
343
|
For games with authoritative server logic running in the Colyseus UGC sandbox, the SDK ships two extra subpaths, separate from the browser runtime:
|
|
372
344
|
|
|
373
|
-
- `@ksaa-nlp/gamehub-sdk/server` —
|
|
345
|
+
- `@ksaa-nlp/gamehub-sdk/server` — types (`GuestModule`, `Ctx`, `PeerInfo`, …) for writing the guest module, plus the optional `createBotDriver` helper.
|
|
374
346
|
- `@ksaa-nlp/gamehub-sdk/server/dev` — `runLocal(guest, opts)`, a pure-Node harness to unit-test a guest bundle against a simulated room without `isolated-vm`.
|
|
375
347
|
|
|
376
348
|
See [SPEC.md §21bis](./SPEC.md#21bis-ugc-server-bundle-subpath) for the full contract.
|
|
377
349
|
|
|
350
|
+
### Bot players (SDK 4.5)
|
|
351
|
+
|
|
352
|
+
When the host adds bots, `opts.seededPlayers` contains `kind: 'bot'` rows with a
|
|
353
|
+
`botLevel` (`easy`/`medium`/`hard`). `createBotDriver` plays them from your rules:
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
import { createBotDriver } from '@ksaa-nlp/gamehub-sdk/server';
|
|
357
|
+
|
|
358
|
+
const bots = createBotDriver<Move>({
|
|
359
|
+
legalMoves: (ctx, seatId) => movesFor(ctx.state, seatId),
|
|
360
|
+
apply: (ctx, seatId, move) => play(ctx, seatId, move), // same path as humans
|
|
361
|
+
isTurn: (ctx, seatId) => ctx.state.turn === seatId,
|
|
362
|
+
isOver: (ctx) => ctx.state.finished,
|
|
363
|
+
score: (ctx, seatId, move) => evaluate(ctx.state, seatId, move), // optional
|
|
364
|
+
});
|
|
365
|
+
// onCreate: bots.setBots(opts.seededPlayers)
|
|
366
|
+
// onStart and after every state change: bots.schedule(ctx)
|
|
367
|
+
// onMessage: ignore messages from bots.isBot(peer.peerId)
|
|
368
|
+
// onDispose: bots.cancel(ctx)
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Easy plays randomly, medium uses `score` half the time, hard always picks the
|
|
372
|
+
best-scored move. See SPEC "Bot driver (4.5.0)" and `examples/take-twenty-one`.
|
|
373
|
+
|
|
378
374
|
## Specification
|
|
379
375
|
|
|
380
376
|
[SPEC.md](./SPEC.md) is the authoritative contract — postMessage taxonomy, state model, REST endpoints, error semantics, boundary rules, versioning policy. Read that before changing SDK internals or adding a new feature area.
|
|
@@ -412,17 +408,50 @@ The example host toggles music during gameplay; the game uses a separate gain
|
|
|
412
408
|
node for background music so sound effects remain independent. This is a
|
|
413
409
|
local integration demo; the GameHub profile is the production preference editor.
|
|
414
410
|
|
|
415
|
-
## Multiplayer
|
|
411
|
+
## Multiplayer (SDK 4.2)
|
|
416
412
|
|
|
417
413
|
Use `await sdk.ready()` before reading `sdk.getBootstrap().multiplayerLaunch`.
|
|
418
414
|
`requestMultiplayerLaunch()` requests only that already-bound launch from a
|
|
419
415
|
capable trusted host and accepts no room/game override. It returns reserved,
|
|
420
|
-
recoverable or terminal. The
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
416
|
+
recoverable or terminal. The main entry owns no realtime connection or
|
|
417
|
+
persistent token; `MultiplayerClient` handles socket, state, clock and recovery
|
|
418
|
+
lifecycle:
|
|
419
|
+
|
|
420
|
+
```sh
|
|
421
|
+
npm install @ksaa-nlp/gamehub-sdk @colyseus/sdk
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
import { createSdk } from '@ksaa-nlp/gamehub-sdk';
|
|
426
|
+
import { MultiplayerClient } from '@ksaa-nlp/gamehub-sdk/multiplayer';
|
|
427
|
+
const sdk = createSdk();
|
|
428
|
+
await sdk.ready();
|
|
429
|
+
const launch = sdk.getBootstrap().multiplayerLaunch;
|
|
430
|
+
if (!launch) throw new Error('Open this game from a GameHub v2 lobby');
|
|
431
|
+
let storage;
|
|
432
|
+
try {
|
|
433
|
+
storage = window.sessionStorage;
|
|
434
|
+
} catch {}
|
|
435
|
+
const game = new MultiplayerClient(sdk, launch, storage);
|
|
436
|
+
const unsubscribe = game.subscribe(({ status, state, error }) => {
|
|
437
|
+
// Render progress, synchronized state and actionable failure/retry.
|
|
438
|
+
});
|
|
439
|
+
await game.connect();
|
|
440
|
+
game.send('take', { amount: 1 });
|
|
441
|
+
// On explicit exit:
|
|
442
|
+
unsubscribe();
|
|
443
|
+
await game.leave();
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
`@colyseus/sdk` (and the `@colyseus/schema` it brings) are optional peers: only
|
|
447
|
+
this subpath needs them. The room's state classes and every multiplayer wire
|
|
448
|
+
type (bot levels, error codes, launch and result validators) ship inside the
|
|
449
|
+
SDK and are re-exported from this subpath. A saved result comes from server
|
|
450
|
+
acknowledgement, not a local `endMatch` call. The [Take Twenty-One starter](../../examples/take-twenty-one/README.md)
|
|
451
|
+
contains a complete authoring/build/upload example. Native hosts do not
|
|
452
|
+
advertise multiplayer. Server-authoritative rounds use `ctx.endMatch` version 2
|
|
453
|
+
instead of browser `submitScore`/`submitMatchResult`. The manifest and full
|
|
454
|
+
contract are in the [multiplayer reference](../../specs/multiplayer.md#3-package-manifest-gamehubmultiplayerjson).
|
|
426
455
|
|
|
427
456
|
## Create and join inside your game (SDK 4.3)
|
|
428
457
|
|
|
@@ -453,6 +482,6 @@ Use `multiplayerEntry` to prefill invitation code and spectator intent. Public
|
|
|
453
482
|
session snapshots contain invitation URLs, limits, roster and current round
|
|
454
483
|
phase. Rematch availability follows terminal round phases, not only eventual
|
|
455
484
|
session retirement. Start transitions to a newly mounted pinned game document;
|
|
456
|
-
read `multiplayerLaunch` there and connect
|
|
485
|
+
read `multiplayerLaunch` there and connect `MultiplayerClient`. Lobby menus
|
|
457
486
|
cannot start/submit ordinary client scores. See the starter for ready/start,
|
|
458
487
|
bots, leave and rematch controls.
|
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# GameHub SDK — Specification
|
|
2
2
|
|
|
3
|
-
Version:
|
|
3
|
+
Version: 5.0.0
|
|
4
4
|
Status: Authoritative. Supersedes README/MIGRATION/CHANGELOG where they conflict.
|
|
5
5
|
|
|
6
6
|
This document is the single source of truth for the GameHub SDK. Code, tests, and consumer docs follow this spec; if a behaviour is observed in code but not described here, treat it as undocumented and revisit before relying on it.
|
|
@@ -11,13 +11,13 @@ This document is the single source of truth for the GameHub SDK. Code, tests, an
|
|
|
11
11
|
|
|
12
12
|
The GameHub SDK is the client library that GameHub-hosted games use to talk to the GameHub platform. It is a thin, transport-agnostic adapter providing five capabilities:
|
|
13
13
|
|
|
14
|
-
1. **Bootstrap pipeline.** A cross-origin `postMessage` handshake with the host page to discover the active game, the user's auth context, and (when applicable)
|
|
14
|
+
1. **Bootstrap pipeline.** A cross-origin `postMessage` handshake with the host page to discover the active game, the user's auth context, and (when applicable) the bound multiplayer launch or lobby context.
|
|
15
15
|
2. **Sessions and scoring.** HTTP wrappers that open a session token and submit scores, with auto-init of the session when a submit is the first call.
|
|
16
16
|
3. **Questions.** HTTP wrapper for the questions endpoint, used by quiz-style games.
|
|
17
17
|
4. **League-match HTTP.** Wrappers for the league-match context fetch and the match-result submit endpoint.
|
|
18
18
|
5. **Game settings.** Read account-wide preferences and subscribe to trusted host updates; games implement their own audio behavior.
|
|
19
19
|
|
|
20
|
-
The
|
|
20
|
+
The main entry and script-tag bundle are not coupled to any realtime transport. Multiplayer games request their bound launch through the SDK and open their own socket with `MultiplayerClient` from the opt-in `./multiplayer` subpath (§21ter), whose realtime packages are optional peers; see [the multiplayer reference](../../specs/multiplayer.md).
|
|
21
21
|
|
|
22
22
|
## 2. Scope and non-goals
|
|
23
23
|
|
|
@@ -30,20 +30,21 @@ The SDK is not coupled to any realtime transport. When the host attaches a multi
|
|
|
30
30
|
- Fetch questions (`getQuestions`) and words (`getWords`).
|
|
31
31
|
- Request the host's report dialog for a question (`reportQuestion`) or word (`reportWord`).
|
|
32
32
|
- Surface a bootstrap snapshot (`getBootstrap()`) including the trusted
|
|
33
|
-
`sessionMode` and
|
|
33
|
+
`sessionMode` and multiplayer launch/lobby context.
|
|
34
34
|
- Forward player-visible host commands (`pause`, `resume`) to optional `window.onGameHubPause` / `onGameHubResume` callbacks.
|
|
35
|
-
- Type definitions for authoring UGC server bundles (`./server` subpath,
|
|
35
|
+
- Type definitions for authoring UGC server bundles (`./server` subpath), plus the optional bundled `createBotDriver` helper.
|
|
36
36
|
- Node-only dev harness (`./server/dev` subpath) for unit-testing a guest bundle against a simulated `ctx`.
|
|
37
|
+
- The game-owned Colyseus connection for a bound v2 round (`./multiplayer` subpath, §21ter), opt-in and outside the main entry and the IIFE bundle.
|
|
37
38
|
|
|
38
39
|
### Out of scope
|
|
39
40
|
|
|
40
|
-
- Opening or managing WebSocket / WebRTC / SSE connections.
|
|
41
|
-
- Maintaining live realtime room state, peer rosters, message routing, or reconnection.
|
|
42
|
-
- Server-side authority for **browser-side** game logic. The `./server` subpath
|
|
41
|
+
- Opening or managing WebSocket / WebRTC / SSE connections from the main entry, `./browser` or the IIFE bundle. Only the `./multiplayer` subpath opens a socket (§21ter).
|
|
42
|
+
- Maintaining live realtime room state, peer rosters, message routing, or reconnection outside the `./multiplayer` subpath.
|
|
43
|
+
- Server-side authority for **browser-side** game logic. The `./server` subpath holds types and the pure `createBotDriver` helper; authoritative server logic for UGC games runs inside the colyseus UGC sandbox (`packages/colyseus/src/rooms/ugc/`).
|
|
43
44
|
- Persistent storage. The SDK keeps everything in memory; refresh resets it.
|
|
44
45
|
- UI. The SDK never renders or injects DOM.
|
|
45
46
|
- Analytics. `logEvent` forwards a payload to the host via postMessage; the SDK does not POST to any analytics endpoint itself.
|
|
46
|
-
- Realtime time-sync.
|
|
47
|
+
- Realtime time-sync in the main entry. The server-clock helper's source is `@ksaa-nlp/colyseus-schemas/clock`; only `./multiplayer` ships a copy (§21ter).
|
|
47
48
|
- Multi-tenant or multi-game state. The SDK assumes one game slug per page load.
|
|
48
49
|
|
|
49
50
|
## 3. Architecture
|
|
@@ -67,11 +68,13 @@ The package is laid out flat under `src/` and `types/`. No subdirectories.
|
|
|
67
68
|
| `src/constants.ts` | `SDK_VERSION`, `MESSAGE_PREFIX`, `PARENT_REQUEST_TIMEOUT_MS`, `QUESTIONS_LIMIT_CAP`, `WORDS_LIMIT_CAP`. |
|
|
68
69
|
| `src/utils.ts` | `isBrowser`, `warn`, `error`, `unwrapResult`, `readQueryParam`. |
|
|
69
70
|
| `types/api.ts` | `ApiResponse`, `ApiRequestOptions`. |
|
|
70
|
-
| `types/bootstrap.ts` | `
|
|
71
|
+
| `types/bootstrap.ts` | `BootstrapConfig`, `BootstrapData`, `MultiplayerLaunchContext` (alias of the contracts' `LaunchReference`), `SdkSeatReservation`. |
|
|
71
72
|
| `types/session.ts` | `Question`, `QuestionOptions`, `ScoreMetadata`, `EventData`, `GameCompleteData`, `StartSessionResult`, `SubmitScoreResult`, `WordOptions`, `ReportWordData`, `ReportableWord` (re-exports `Word`). |
|
|
72
73
|
| `types/word.ts` | `Word` + sub-interfaces (`WordSense`, `WordForm`, `Lookup`, `Synset`, `FormRepresentation`, `DynamicProp`, …) — Words Bank feature. |
|
|
73
74
|
| `types/match.ts` | `MatchParticipantMember`, `MatchParticipant`, `MatchContext`, `MatchResultPayload`. |
|
|
74
|
-
| `src/server-entry.ts` | `./server` subpath. Types
|
|
75
|
+
| `src/server-entry.ts` | `./server` subpath. Types (`GuestModule`, `Ctx`, `PeerInfo`, `BroadcastOptions`, `EndMatchPayload`, `CreateOptions`) plus `createBotDriver` from `src/bot-driver.ts`, its only runtime code. No imports from the browser SDK; safe for tooling that compiles the bundle on Node. |
|
|
76
|
+
| `src/multiplayer-entry.ts` | `./multiplayer` subpath. Re-exports `MultiplayerClient` and its types plus all of `@ksaa-nlp/gamehub-multiplayer-contracts`. Never imported by `main.ts` or `browser-entry.ts`. |
|
|
77
|
+
| `src/multiplayer-client.ts` | `MultiplayerClient`: the game-owned Colyseus connection, reconnect-token handling and recovery (§21ter). The only module importing `@colyseus/sdk` and the copied schemas (`#colyseus-schemas/*`). |
|
|
75
78
|
| `src/server-dev-harness.ts` | `./server/dev` subpath. `runLocal(guest, opts)` returns a `LocalRoom` that simulates the colyseus host (`join`, `send`, `leave`, `advance`, etc.) and records every bridge call to `outbox`. Pure Node — does not import `isolated-vm` or anything browser. |
|
|
76
79
|
|
|
77
80
|
### 3.2 Singleton model
|
|
@@ -101,10 +104,13 @@ This is the only place in the package that does work on import. Module / npm con
|
|
|
101
104
|
| `dist/src/main.js` | ESM entry. Pure on import. |
|
|
102
105
|
| `dist/src/main.d.ts` | Public type surface. |
|
|
103
106
|
| `dist/src/browser-entry.js` | ESM entry that performs the same side effects as the IIFE bundle. Used by frameworks that want a tree-shakeable side-effectful import. |
|
|
107
|
+
| `dist/src/multiplayer-entry.js` | ESM `./multiplayer` subpath. Pure on import; resolves the optional peers `@colyseus/sdk` and `@colyseus/schema`. |
|
|
108
|
+
| `dist/vendor/gamehub-multiplayer-contracts/` | Build-time copy of the private contracts workspace's `index` (`.js`, `.d.ts`), resolved through the `#multiplayer-contracts` import map (§21ter). |
|
|
109
|
+
| `dist/vendor/colyseus-schemas/` | Build-time copy of the private schemas workspace's `clock`, `common`, `multiplayer` and `ugc` (`.js`, `.d.ts`), resolved through the `#colyseus-schemas/*` import map (§21ter). |
|
|
104
110
|
| `dist/gamehub-sdk.js` | IIFE bundle for `<script>` tag use, target ES2020, no external deps. Includes `browser-entry.ts`. Marked `sideEffects: true`. |
|
|
105
111
|
| `dist/gamehub-sdk.js.map` | Source map for the IIFE bundle. The app-served JS and map are refreshed together under `packages/gamehub/public/sdk/`. |
|
|
106
112
|
|
|
107
|
-
`build:tsc` emits ESM with `.js` extensions in imports (NodeNext) and full `.d.ts` files. `build:bundle` runs esbuild over `src/browser-entry.ts` to produce the IIFE.
|
|
113
|
+
`build:vendor` rebuilds `packages/gamehub-multiplayer-contracts` and `packages/colyseus-schemas` and copies their shipped modules into `dist/vendor/` (`scripts/vendor-workspace.mjs`); `build:tsc` runs it first. `build:tsc` emits ESM with `.js` extensions in imports (NodeNext) and full `.d.ts` files. `build:bundle` runs esbuild over `src/browser-entry.ts` to produce the IIFE.
|
|
108
114
|
|
|
109
115
|
### 4.2 Package metadata
|
|
110
116
|
|
|
@@ -113,15 +119,18 @@ This is the only place in the package that does work on import. Module / npm con
|
|
|
113
119
|
- `exports`:
|
|
114
120
|
- `"."` → `./dist/src/main.js` (pure entry).
|
|
115
121
|
- `"./browser"` → `./dist/src/browser-entry.js` (side-effectful entry).
|
|
122
|
+
- `"./multiplayer"` → `./dist/src/multiplayer-entry.js` (game-owned realtime connection, §21ter).
|
|
123
|
+
- `"./server"`, `"./server/dev"` → UGC server-bundle types and dev harness (§21bis).
|
|
116
124
|
- `"./gamehub-sdk.js"` → `./dist/gamehub-sdk.js` (raw IIFE).
|
|
117
125
|
- `"./package.json"` → `./package.json`.
|
|
118
126
|
- `sideEffects`: `["./dist/src/browser-entry.js", "./dist/gamehub-sdk.js"]` — everything else is tree-shakeable.
|
|
119
127
|
- `files`: only `dist/**/*`, `README.md`, `CHANGELOG.md`, `MIGRATION.md` are published.
|
|
120
|
-
- `dependencies`: none.
|
|
121
|
-
- `peerDependencies`:
|
|
122
|
-
- `
|
|
128
|
+
- `dependencies`: none. Workspace contracts and schemas ship as copies under `dist/vendor/`.
|
|
129
|
+
- `peerDependencies`: `@colyseus/sdk` ^0.18.5 and `@colyseus/schema` ^5.0.36, both marked optional in `peerDependenciesMeta`. Only `./multiplayer` imports them; games that use it install `@colyseus/sdk`, which depends on `@colyseus/schema`, so one copy serves both the decoder and the copied state classes.
|
|
130
|
+
- `imports`: `#multiplayer-contracts` → `./dist/vendor/gamehub-multiplayer-contracts/index`, `#colyseus-schemas/*` → `./dist/vendor/colyseus-schemas/*` (`types` and `default`). The private workspace packages are never dependencies.
|
|
131
|
+
- `devDependencies`: the two peers (for building and testing the subpath), `esbuild`, `typescript`.
|
|
123
132
|
|
|
124
|
-
|
|
133
|
+
Adding a runtime dependency or another peer, or making a peer required, is a deliberate decision and a major-version bump (§20.4).
|
|
125
134
|
|
|
126
135
|
### 4.3 Target environments
|
|
127
136
|
|
|
@@ -222,14 +231,6 @@ On the **native** transport there is no web origin: inbound `HostMessage.origin`
|
|
|
222
231
|
- Empty string after trim → `null`.
|
|
223
232
|
- Explicit `null` in the payload → `null`.
|
|
224
233
|
- Non-string and non-null → ignored (field left as-is).
|
|
225
|
-
- `multiplayer`:
|
|
226
|
-
- Explicit `null` → `null`.
|
|
227
|
-
- Object with a `reservation` object (string `name`, `sessionId`, `roomId` — the `SdkSeatReservation` shape) and a string `wsEndpoint` → only `wsEndpoint` is trimmed; the `reservation` object is stored as-is.
|
|
228
|
-
- Optional `roomCode`, `role`, and `connectionScope` strings are copied only
|
|
229
|
-
when non-empty and bounded. `connectionScope` lets a game partition its own
|
|
230
|
-
reconnect storage by public embed and outer-host instance; the SDK neither
|
|
231
|
-
stores nor interprets it.
|
|
232
|
-
- Any other shape → ignored (field left as-is).
|
|
233
234
|
- `sessionMode` accepts only `'authenticated'`, `'embed-guest'`,
|
|
234
235
|
`'league-guest'`, or explicit `null`; every other value is ignored. The
|
|
235
236
|
trusted host, not uploaded game code, selects this authority mode.
|
|
@@ -323,7 +324,7 @@ interface GameHubNativeHost {
|
|
|
323
324
|
- The SDK installs `receive` when the transport is constructed. The native app calls `window.GameHubNativeHost.receive(env)` to deliver every host → SDK envelope (`BOOTSTRAP`, `AUTH_RESPONSE`, `API_RESPONSE`, `SET_AUTH`, `COMMAND`).
|
|
324
325
|
- Envelope shapes, `messageId` correlation, and timeouts (§6.3) are identical to the postMessage transport. The native host must therefore echo the `messageId` on `BOOTSTRAP`/`AUTH_RESPONSE`/`API_RESPONSE` exactly as an iframe host does.
|
|
325
326
|
- The native host is responsible for the same protocol an iframe host implements: replying to `BOOTSTRAP_REQUEST`/`AUTH_REQUEST`, proxying `API_REQUEST` (performing the real HTTPS call natively and preserving parseable backend failure envelopes with `ok: true` — see §6.6), and reacting to one-way signals (`REQUEST_CLOSE`, `QUESTION_REPORT`, `WORD_REPORT`, accepted-only `SCORE_SUBMITTED`, `GAME_COMPLETE`, `LOG_EVENT`).
|
|
326
|
-
-
|
|
327
|
+
- Native hosts advertise no multiplayer capability. The SDK never proxies realtime traffic over the bridge (§19.1).
|
|
327
328
|
|
|
328
329
|
## 7. Authentication
|
|
329
330
|
|
|
@@ -564,8 +565,6 @@ interface SdkState {
|
|
|
564
565
|
bootstrapTeamOneName: string | null;
|
|
565
566
|
bootstrapTeamTwoName: string | null;
|
|
566
567
|
|
|
567
|
-
// Multiplayer block (opaque to the SDK)
|
|
568
|
-
bootstrapMultiplayer: BootstrapMultiplayer | null;
|
|
569
568
|
bootstrapReceived: boolean;
|
|
570
569
|
|
|
571
570
|
// Init lifecycle
|
|
@@ -695,14 +694,6 @@ interface SdkSeatReservation {
|
|
|
695
694
|
devMode?: boolean;
|
|
696
695
|
}
|
|
697
696
|
|
|
698
|
-
interface BootstrapMultiplayer {
|
|
699
|
-
reservation: SdkSeatReservation;
|
|
700
|
-
wsEndpoint: string;
|
|
701
|
-
roomCode?: string;
|
|
702
|
-
role?: string;
|
|
703
|
-
connectionScope?: string;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
697
|
interface GameSettings {
|
|
707
698
|
readonly musicEnabled: boolean;
|
|
708
699
|
}
|
|
@@ -721,7 +712,6 @@ interface BootstrapConfig {
|
|
|
721
712
|
teamOneName?: string | null;
|
|
722
713
|
teamTwoName?: string | null;
|
|
723
714
|
profileId?: string | null;
|
|
724
|
-
multiplayer?: BootstrapMultiplayer | null;
|
|
725
715
|
}
|
|
726
716
|
|
|
727
717
|
interface BootstrapData {
|
|
@@ -738,7 +728,6 @@ interface BootstrapData {
|
|
|
738
728
|
teamOneName: string | null;
|
|
739
729
|
teamTwoName: string | null;
|
|
740
730
|
profileId: string | null;
|
|
741
|
-
multiplayer: BootstrapMultiplayer | null;
|
|
742
731
|
isBootstrapped: boolean;
|
|
743
732
|
}
|
|
744
733
|
|
|
@@ -929,20 +918,20 @@ The SDK expects (but tolerates absence of) a `{ success, data, token?, error? }`
|
|
|
929
918
|
|
|
930
919
|
These rules exist because of a real prior regression where transport-related cleanup deleted unrelated HTTP plumbing. They are tight on purpose.
|
|
931
920
|
|
|
932
|
-
### 19.1
|
|
921
|
+
### 19.1 Realtime only in `./multiplayer`
|
|
933
922
|
|
|
934
|
-
- The
|
|
935
|
-
-
|
|
936
|
-
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
- The
|
|
923
|
+
- The main entry, `./browser`, `./server`, `./server/dev` and the IIFE bundle must not import any realtime client (`@colyseus/sdk`, `@colyseus/schema`, `#colyseus-schemas/*`, `ws`, `socket.io-client`, …) and must not open a `WebSocket`, `EventSource`, or `RTCPeerConnection`.
|
|
924
|
+
- `src/multiplayer-client.ts` is the only module that imports `@colyseus/sdk` and `#colyseus-schemas/*`; it is reachable only through `./multiplayer`. No other transport is added there.
|
|
925
|
+
- Multiplayer launch context and reservations are validated as bounded opaque
|
|
926
|
+
data by the main entry and consumed only by `MultiplayerClient`.
|
|
927
|
+
- The server-clock helper (`attachServerClock`) is maintained in `@ksaa-nlp/colyseus-schemas/clock`; the SDK only ships its copy. `MultiplayerClient` attaches it and exposes `serverNow()`.
|
|
928
|
+
- The copied schema modules are never edited or bundled: they import only each other, `@colyseus/schema` and (type-only) `@colyseus/sdk`.
|
|
940
929
|
|
|
941
930
|
### 19.2 HTTP plumbing is transport-agnostic
|
|
942
931
|
|
|
943
932
|
- `submitMatchResult`, `getMatchContext`, `MatchContext`, and `MatchResultPayload` are **not** part of any realtime stack.
|
|
944
933
|
- A future cleanup that removes realtime support **must not** delete league-match HTTP code as collateral.
|
|
945
|
-
- The match-context endpoint is plain HTTP and continues to work
|
|
934
|
+
- The match-context endpoint is plain HTTP and continues to work without any multiplayer bootstrap context.
|
|
946
935
|
|
|
947
936
|
### 19.3 No DOM injection
|
|
948
937
|
|
|
@@ -951,7 +940,7 @@ These rules exist because of a real prior regression where transport-related cle
|
|
|
951
940
|
|
|
952
941
|
### 19.4 No storage
|
|
953
942
|
|
|
954
|
-
- The SDK must not call `localStorage`, `sessionStorage`, `IndexedDB`, or cookies.
|
|
943
|
+
- The SDK must not call `localStorage`, `sessionStorage`, `IndexedDB`, or cookies. `MultiplayerClient` reads and writes reconnect tokens only through the `TokenStorage` object the game passes in; it never reaches for a global store.
|
|
955
944
|
- Tokens (auth and session) live in memory only; refresh resets them. Persistent identity is the host page's responsibility.
|
|
956
945
|
|
|
957
946
|
### 19.5 Singleton
|
|
@@ -974,9 +963,9 @@ These rules exist because of a real prior regression where transport-related cle
|
|
|
974
963
|
|
|
975
964
|
The IIFE bundle (`dist/gamehub-sdk.js`) must remain under **52 KiB raw** and **12 KiB gzip**. SDK 4.3 deliberately raises the previous 44/10 KiB limits to include bounded lobby-state validation, typed host controls and independent subscriptions. Runtime dependencies remain empty; the distribution test checks the built and served bytes and both budgets.
|
|
976
965
|
|
|
977
|
-
### 20.4
|
|
966
|
+
### 20.4 Runtime dependencies
|
|
978
967
|
|
|
979
|
-
`
|
|
968
|
+
`dependencies` must stay empty: the private `@ksaa-nlp/gamehub-multiplayer-contracts` and `@ksaa-nlp/colyseus-schemas` workspaces ship as build-time copies (§21ter), never as dependencies. `peerDependencies` contains only the optional realtime peers of `./multiplayer` (§4.2). Adding any dependency or other peer, or making a peer required, is a major-version event and requires updating §2 (non-goals) and §19 (boundary rules). The distribution test enforces this.
|
|
980
969
|
|
|
981
970
|
## 21. Testing acceptance criteria
|
|
982
971
|
|
|
@@ -1041,8 +1030,8 @@ The SDK ships focused Node tests for transport trust-boundary behavior. Every ch
|
|
|
1041
1030
|
|
|
1042
1031
|
### 21.6 Boundary
|
|
1043
1032
|
|
|
1044
|
-
- `
|
|
1045
|
-
- `
|
|
1033
|
+
- Built `main.js`, `browser-entry.js` and `server-entry.js` contain no import of `@colyseus/*` or `#colyseus-schemas/*`, and the IIFE bundle contains neither Colyseus nor `MultiplayerClient` (distribution test).
|
|
1034
|
+
- `package.json` `dependencies` is empty and both peers are optional (distribution test).
|
|
1046
1035
|
|
|
1047
1036
|
### 21.7 SDK Usage Intelligence Report synchronization
|
|
1048
1037
|
|
|
@@ -1077,7 +1066,7 @@ The `./server` and `./server/dev` subpaths are separate from the browser SDK. Im
|
|
|
1077
1066
|
|
|
1078
1067
|
### 21bis.1 `./server` — types
|
|
1079
1068
|
|
|
1080
|
-
`@ksaa-nlp/gamehub-sdk/server` exports types
|
|
1069
|
+
`@ksaa-nlp/gamehub-sdk/server` exports types plus one runtime helper, `createBotDriver` (see "Bot driver (4.5.0)"), which bundlers include only when a guest calls it. Authors use the types from TypeScript:
|
|
1081
1070
|
|
|
1082
1071
|
```ts
|
|
1083
1072
|
import type { GuestModule, Ctx, PeerInfo } from '@ksaa-nlp/gamehub-sdk/server';
|
|
@@ -1131,10 +1120,9 @@ expect(room.outbox).toContainEqual({
|
|
|
1131
1120
|
|
|
1132
1121
|
## 22. Glossary
|
|
1133
1122
|
|
|
1134
|
-
- **Bootstrap.** The set of context the host gives the iframe at load: slug, IDs, auth, multiplayer
|
|
1123
|
+
- **Bootstrap.** The set of context the host gives the iframe at load: slug, IDs, auth, multiplayer launch/lobby context, display strings.
|
|
1135
1124
|
- **Session.** A server-issued token representing a single playthrough. Used to authenticate `submitScore`.
|
|
1136
1125
|
- **League match.** A scheduled game between two participants tracked by GameHub's league system. Has its own session endpoint that allows guest submitters.
|
|
1137
|
-
- **Multiplayer block.** The opaque `{ reservation, wsEndpoint }` pair the host provides for the game to open its own realtime connection, where `reservation` is the Colyseus seat-reservation (`SdkSeatReservation`).
|
|
1138
1126
|
- **Host.** The GameHub-served page that frames the game in an iframe. Owns auth, matchmaking, and the bootstrap pipeline.
|
|
1139
1127
|
- **Game.** The iframe-hosted application that consumes this SDK.
|
|
1140
1128
|
- **Standalone.** A game loaded outside an iframe. `isInIframe()` returns false; the bootstrap pipeline is skipped.
|
|
@@ -1142,8 +1130,7 @@ expect(room.outbox).toContainEqual({
|
|
|
1142
1130
|
## Launch v2 (4.2.0)
|
|
1143
1131
|
|
|
1144
1132
|
The authoritative cross-package contract is [multiplayer v2](../../specs/multiplayer.md).
|
|
1145
|
-
Optional bootstrap `capabilities` and `multiplayerLaunch`
|
|
1146
|
-
unchanged required v1 `multiplayer.reservation` shape. `requestMultiplayerLaunch()`
|
|
1133
|
+
Optional bootstrap `capabilities` and `multiplayerLaunch` carry the bound round. `requestMultiplayerLaunch()`
|
|
1147
1134
|
is a no-argument, single-flight request to the trusted host for its already-bound
|
|
1148
1135
|
round. It validates bounded replies and fences a changed launch context. It owns
|
|
1149
1136
|
no socket or persistent storage. Old/native hosts do not advertise v2 and return
|
|
@@ -1153,15 +1140,15 @@ no socket or persistent storage. Old/native hosts do not advertise v2 and return
|
|
|
1153
1140
|
bootstrap suppresses unrelated client-scored session creation; the host permits
|
|
1154
1141
|
only the bound launch request and the backend rejects browser ownership of
|
|
1155
1142
|
server-multiplayer PlayerSessions. Solo and legacy HTTP methods retain their
|
|
1156
|
-
existing semantics.
|
|
1157
|
-
|
|
1143
|
+
existing semantics. `MultiplayerClient` (`./multiplayer`, §21ter) owns Colyseus
|
|
1144
|
+
state, clock and recovery tokens.
|
|
1158
1145
|
|
|
1159
1146
|
Server `EndMatchPayload` adds optional version 2, per-seat scores, winner seat IDs
|
|
1160
1147
|
and bounded metadata. The v2 room requires the v2 result shape and enriches it
|
|
1161
1148
|
with trusted provenance. `ctx.endMatch` is a proposal, not a saved acknowledgement.
|
|
1162
1149
|
Legacy endMatch payloads remain valid in legacy rooms.
|
|
1163
1150
|
|
|
1164
|
-
SDK_VERSION, npm version and served JS/map are
|
|
1151
|
+
SDK_VERSION, npm version and served JS/map are 5.0.0. The distribution gate is
|
|
1165
1152
|
52 KiB raw / 12 KiB gzip (the raw increase covers v2 validation and game settings); runtime
|
|
1166
1153
|
dependencies remain empty. Scanner version 3 includes requestMultiplayerLaunch,
|
|
1167
1154
|
endMatch, seededPlayers and the static-only game-settings APIs; version-2 scans
|
|
@@ -1173,6 +1160,39 @@ observation is not successful admission; see the
|
|
|
1173
1160
|
|
|
1174
1161
|
`SeededPlayer` adds optional `kind: human|bot`, `seatId` and `peerId`. Missing kind means human for legacy hosts. V2 always supplies these fields; userId/seatId/peerId are the same opaque stable seat ID, never a bot/account credential. Bots do not connect or receive `onJoin`; the UGC bundle owns their legal moves using normal state/rules and `ctx.setTimeout`. All roster players, including bots, belong in endMatch scores. No realtime dependency is introduced. SDK Usage scanner 3 represents the widened data capability as `seededPlayers`: static identifiers are possible evidence; a trusted first UGC round-start acknowledgement confirms roster delivery. It does not prove a game consumed the field or that its bot algorithm acted. See the report specification.
|
|
1175
1162
|
|
|
1163
|
+
## Bot driver (4.5.0)
|
|
1164
|
+
|
|
1165
|
+
`@ksaa-nlp/gamehub-sdk/server` exports `createBotDriver<Move>(options)`, the
|
|
1166
|
+
only runtime code in the server entry. It is plain JS bundled into the game's
|
|
1167
|
+
UGC server bundle and uses only the injected `ctx` (`setTimeout`,
|
|
1168
|
+
`clearTimeout`, seeded `random`), so it adds no sandbox surface or dependency
|
|
1169
|
+
and does not affect the browser IIFE bundle.
|
|
1170
|
+
|
|
1171
|
+
The game supplies its rules: `legalMoves(ctx, seatId)` and `apply(ctx, seatId,
|
|
1172
|
+
move)` (required; `apply` should use the same path as human messages), plus
|
|
1173
|
+
optional `isTurn` (default always; simultaneous games must return false once
|
|
1174
|
+
the bot has acted for the step), `isOver` (default never), `score` (higher is
|
|
1175
|
+
better), `choose` (replaces the default choice) and `delayMs` (fixed number or
|
|
1176
|
+
per-level `[min, max]`; defaults `DEFAULT_BOT_DELAYS`: easy 1.5–3 s, medium
|
|
1177
|
+
0.9–1.8 s, hard 0.5–1 s).
|
|
1178
|
+
|
|
1179
|
+
The returned `BotDriver` has `setBots(opts.seededPlayers)` (bot seats with
|
|
1180
|
+
`botLevel`, missing → `medium`), `bots`, `isBot(seatId)`, `schedule(ctx)` and
|
|
1181
|
+
`cancel(ctx)`. Call `schedule` after `onStart` and after every state change; it
|
|
1182
|
+
keeps at most one pending timer per bot and, when a timer fires, re-checks
|
|
1183
|
+
`isOver`/`isTurn`, skips an empty move list, applies the chosen move and
|
|
1184
|
+
schedules again. Call `cancel` on finish or in `onDispose`. Default choice:
|
|
1185
|
+
easy is uniformly random; medium uses the best `score` half the time and is
|
|
1186
|
+
random otherwise; hard always takes the best `score` (ties broken randomly).
|
|
1187
|
+
Without `score` every level is random. `BotDriver.kind` is the stable literal
|
|
1188
|
+
`"gamehub-sdk:createBotDriver"` used by the SDK usage report (scanner 5,
|
|
1189
|
+
static-only, detected in the private server bundle). Take Twenty-One is the
|
|
1190
|
+
reference integration.
|
|
1191
|
+
|
|
1192
|
+
## Bot levels (4.4.0)
|
|
1193
|
+
|
|
1194
|
+
`SeededPlayer.botLevel` (`easy|medium|hard`) is present on bot seats from v2 hosts; treat a bot without it as `medium` (older hosts). Humans never carry it. `MultiplayerSessionRequest` `add-bot` accepts an optional `level` (host default `medium`), and lobby roster seats expose `botLevel` on bots only; `parseLobbyState` rejects unknown levels or a level on a human seat. Games decide what each level means for their own rules. This widens existing capabilities (`seededPlayers`, lobby control) and adds no new usage-report feature.
|
|
1195
|
+
|
|
1176
1196
|
## Lobby control v2 (4.3.0)
|
|
1177
1197
|
|
|
1178
1198
|
The optional capability `multiplayer.lobby.v2` enables game-owned lobby UI.
|
|
@@ -1202,9 +1222,60 @@ and prohibit ordinary session creation/submission, even with a stale cached solo
|
|
|
1202
1222
|
token. A loading round is a new pinned document with the existing launch contract;
|
|
1203
1223
|
`requestMultiplayerLaunch()` semantics remain unchanged. In-flight lobby replies
|
|
1204
1224
|
are fenced against a changed slug/launch. Hosts retain all storage and sockets
|
|
1205
|
-
remain in
|
|
1225
|
+
remain in `MultiplayerClient` (§21ter).
|
|
1206
1226
|
|
|
1207
1227
|
SDK Usage scanner 4 includes both new APIs, with Arabic admin/filter/CSV support.
|
|
1208
1228
|
Successful validated host lobby requests observe `requestMultiplayerSession`;
|
|
1209
1229
|
`onMultiplayerSessionChange` is static-only because delivered state does not prove
|
|
1210
1230
|
a subscription. Observations do not prove admission or a started round.
|
|
1231
|
+
|
|
1232
|
+
## Legacy multiplayer block removed (5.0.0)
|
|
1233
|
+
|
|
1234
|
+
Breaking: `BootstrapMultiplayer`, `BootstrapConfig.multiplayer` and
|
|
1235
|
+
`BootstrapData.multiplayer` are removed. No GameHub host had populated the
|
|
1236
|
+
block since generic v1 multiplayer was retired; a `multiplayer` field sent by an
|
|
1237
|
+
older host is ignored. Games use `multiplayerLaunch`, `requestMultiplayerLaunch()`
|
|
1238
|
+
and `MultiplayerClient` from `./multiplayer` (§21ter; see
|
|
1239
|
+
[the multiplayer reference](../../specs/multiplayer.md)). `SdkSeatReservation`
|
|
1240
|
+
remains as the reserved-launch reservation type.
|
|
1241
|
+
|
|
1242
|
+
## 21ter. Multiplayer subpath (5.0.0)
|
|
1243
|
+
|
|
1244
|
+
- **`@ksaa-nlp/gamehub-sdk/multiplayer`** exports `MultiplayerClient`,
|
|
1245
|
+
`ConnectionStatus`, `LaunchHost`, `MultiplayerSnapshot`, `TokenStorage` and
|
|
1246
|
+
re-exports every contract. The full API, storage and recovery contract is §10 of
|
|
1247
|
+
[the multiplayer reference](../../specs/multiplayer.md#10-game-adapter-ksaa-nlpgamehub-sdkmultiplayer).
|
|
1248
|
+
`MultiplayerClient` accepts any `LaunchHost` (an object with
|
|
1249
|
+
`requestMultiplayerLaunch()`), normally the `Sdk` itself.
|
|
1250
|
+
- **Contracts copy.** The private `@ksaa-nlp/gamehub-multiplayer-contracts`
|
|
1251
|
+
workspace holds the wire contracts. The SDK build rebuilds it and copies
|
|
1252
|
+
`index` into `dist/vendor/gamehub-multiplayer-contracts/`; every SDK module
|
|
1253
|
+
imports it as `#multiplayer-contracts`, and `./multiplayer` re-exports all of
|
|
1254
|
+
it. The copy must stay import-free. The SDK's own lobby and launch types take `BotLevel`, `SeatType`, `SessionPhase`,
|
|
1255
|
+
`ParticipantKind`, `LaunchReference` and both capability strings from it
|
|
1256
|
+
instead of redeclaring them; `createBotDriver`'s `BotLevel` and level list come
|
|
1257
|
+
from it too.
|
|
1258
|
+
- **Schema copy.** `@ksaa-nlp/colyseus-schemas` is a private workspace. The
|
|
1259
|
+
same `build:vendor` step rebuilds it and copies `clock`, `common`, `multiplayer` and `ugc`
|
|
1260
|
+
into `dist/vendor/colyseus-schemas/`; `multiplayer-client.ts` imports them as
|
|
1261
|
+
`#colyseus-schemas/clock` and `#colyseus-schemas/multiplayer`, and the
|
|
1262
|
+
`package.json` `imports` map resolves that path inside the SDK for both this
|
|
1263
|
+
build and consumers (TypeScript `moduleResolution` `node16`, `nodenext` or
|
|
1264
|
+
`bundler`, which `./multiplayer` already requires). The distribution test
|
|
1265
|
+
checks the copy is byte-identical to the schemas `dist/` minus source-map
|
|
1266
|
+
comments, imports only siblings, `@colyseus/schema` and `@colyseus/sdk`, and
|
|
1267
|
+
that nothing in `dist/` names either private package. A contracts or schema
|
|
1268
|
+
change therefore ships as an SDK release; the SDK has no runtime
|
|
1269
|
+
dependencies.
|
|
1270
|
+
- **Peers.** `@colyseus/sdk` ^0.18.5 and `@colyseus/schema` ^5.0.36 are optional
|
|
1271
|
+
peers. A game importing `./multiplayer` installs `@colyseus/sdk`, which brings
|
|
1272
|
+
the single `@colyseus/schema` copy that both the decoder and the copied
|
|
1273
|
+
classes use; solo games and script-tag users need neither. The IIFE bundle
|
|
1274
|
+
does not change.
|
|
1275
|
+
|
|
1276
|
+
**Usage report.** `MultiplayerClient` is feature `MultiplayerClient`, static-only
|
|
1277
|
+
(the game's own socket crosses no host boundary the report can observe).
|
|
1278
|
+
Scanner version 6 detects it through the `"gamehub.mp.v2"` reconnect-token
|
|
1279
|
+
namespace literal the class always builds, which survives minification and
|
|
1280
|
+
is tree-shaken with the class. A bare `MultiplayerClient` identifier is only `possible`. See
|
|
1281
|
+
[the usage report](../../specs/sdk-usage-report.md).
|