@ksaa-nlp/gamehub-sdk 4.5.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 +50 -45
- package/SPEC.md +93 -55
- package/dist/gamehub-sdk.js +14 -30
- package/dist/gamehub-sdk.js.map +3 -3
- package/dist/src/bot-driver.d.ts +2 -1
- package/dist/src/bot-driver.d.ts.map +1 -1
- package/dist/src/bot-driver.js +11 -1
- package/dist/src/bot-driver.js.map +1 -1
- 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 +3 -3
- 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/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 +9 -8
- 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,
|
|
@@ -436,17 +408,50 @@ The example host toggles music during gameplay; the game uses a separate gain
|
|
|
436
408
|
node for background music so sound effects remain independent. This is a
|
|
437
409
|
local integration demo; the GameHub profile is the production preference editor.
|
|
438
410
|
|
|
439
|
-
## Multiplayer
|
|
411
|
+
## Multiplayer (SDK 4.2)
|
|
440
412
|
|
|
441
413
|
Use `await sdk.ready()` before reading `sdk.getBootstrap().multiplayerLaunch`.
|
|
442
414
|
`requestMultiplayerLaunch()` requests only that already-bound launch from a
|
|
443
415
|
capable trusted host and accepts no room/game override. It returns reserved,
|
|
444
|
-
recoverable or terminal. The
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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).
|
|
450
455
|
|
|
451
456
|
## Create and join inside your game (SDK 4.3)
|
|
452
457
|
|
|
@@ -477,6 +482,6 @@ Use `multiplayerEntry` to prefill invitation code and spectator intent. Public
|
|
|
477
482
|
session snapshots contain invitation URLs, limits, roster and current round
|
|
478
483
|
phase. Rematch availability follows terminal round phases, not only eventual
|
|
479
484
|
session retirement. Start transitions to a newly mounted pinned game document;
|
|
480
|
-
read `multiplayerLaunch` there and connect
|
|
485
|
+
read `multiplayerLaunch` there and connect `MultiplayerClient`. Lobby menus
|
|
481
486
|
cannot start/submit ordinary client scores. See the starter for ready/start,
|
|
482
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
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.
|
|
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.
|
|
42
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
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
|
|
|
@@ -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
|
|
@@ -1235,9 +1222,60 @@ and prohibit ordinary session creation/submission, even with a stale cached solo
|
|
|
1235
1222
|
token. A loading round is a new pinned document with the existing launch contract;
|
|
1236
1223
|
`requestMultiplayerLaunch()` semantics remain unchanged. In-flight lobby replies
|
|
1237
1224
|
are fenced against a changed slug/launch. Hosts retain all storage and sockets
|
|
1238
|
-
remain in
|
|
1225
|
+
remain in `MultiplayerClient` (§21ter).
|
|
1239
1226
|
|
|
1240
1227
|
SDK Usage scanner 4 includes both new APIs, with Arabic admin/filter/CSV support.
|
|
1241
1228
|
Successful validated host lobby requests observe `requestMultiplayerSession`;
|
|
1242
1229
|
`onMultiplayerSessionChange` is static-only because delivered state does not prove
|
|
1243
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).
|
package/dist/gamehub-sdk.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
3
|
// src/constants.ts
|
|
4
|
-
var SDK_VERSION = "
|
|
4
|
+
var SDK_VERSION = "5.0.0";
|
|
5
5
|
var MESSAGE_PREFIX = "GAMEHUB_SDK";
|
|
6
6
|
var PARENT_REQUEST_TIMEOUT_MS = 2e3;
|
|
7
7
|
var HOST_API_TIMEOUT_MS = 15e3;
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
bootstrapTeamOneName: null,
|
|
33
33
|
bootstrapTeamTwoName: null,
|
|
34
34
|
bootstrapProfileId: null,
|
|
35
|
-
bootstrapMultiplayer: null,
|
|
36
35
|
bootstrapReceived: false,
|
|
37
36
|
isInitialized: false,
|
|
38
37
|
isAutoInitializing: false,
|
|
@@ -46,6 +45,12 @@
|
|
|
46
45
|
matchContextPromise: null
|
|
47
46
|
};
|
|
48
47
|
|
|
48
|
+
// dist/vendor/gamehub-multiplayer-contracts/index.js
|
|
49
|
+
var MULTIPLAYER_CAPABILITY = "multiplayer.launch.v2";
|
|
50
|
+
var MULTIPLAYER_LOBBY_CAPABILITY = "multiplayer.lobby.v2";
|
|
51
|
+
var BOT_LEVELS = ["easy", "medium", "hard"];
|
|
52
|
+
var isBotLevel = (value) => BOT_LEVELS.includes(value);
|
|
53
|
+
|
|
49
54
|
// src/multiplayer-session.ts
|
|
50
55
|
var listeners = /* @__PURE__ */ new Set();
|
|
51
56
|
var empty = {
|
|
@@ -82,7 +87,7 @@
|
|
|
82
87
|
].every((n) => Number.isSafeInteger(n) && n >= 0 && n <= 256) || p.minPlayers < 1 || p.minHumanPlayers < 1 || p.maxPlayers < p.minPlayers || p.minHumanPlayers > p.maxPlayers || p.maxBots > p.maxPlayers - p.minHumanPlayers || p.maxSpectators > 16)
|
|
83
88
|
return null;
|
|
84
89
|
if (!s.seats.every(
|
|
85
|
-
(seat) => seat && id(seat.seatId) && typeof seat.displayName === "string" && seat.displayName.length <= 80 && ["human", "bot"].includes(seat.kind) && (seat.botLevel === void 0 || seat.kind === "bot" &&
|
|
90
|
+
(seat) => seat && id(seat.seatId) && typeof seat.displayName === "string" && seat.displayName.length <= 80 && ["human", "bot"].includes(seat.kind) && (seat.botLevel === void 0 || seat.kind === "bot" && isBotLevel(seat.botLevel)) && ["player", "spectator"].includes(seat.type) && typeof seat.ready === "boolean" && typeof seat.online === "boolean"
|
|
86
91
|
))
|
|
87
92
|
return null;
|
|
88
93
|
if (s.round !== null && (!s.round || !id(s.round.roundId) || ![
|
|
@@ -161,7 +166,7 @@
|
|
|
161
166
|
};
|
|
162
167
|
}
|
|
163
168
|
async function requestMultiplayerSession(request) {
|
|
164
|
-
if (!state.bootstrapCapabilities.includes(
|
|
169
|
+
if (!state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
|
|
165
170
|
return {
|
|
166
171
|
success: false,
|
|
167
172
|
error: {
|
|
@@ -399,21 +404,6 @@
|
|
|
399
404
|
const trimmed = value.trim();
|
|
400
405
|
return trimmed ? trimmed : null;
|
|
401
406
|
}
|
|
402
|
-
function parseMultiplayer(value) {
|
|
403
|
-
if (value === null) return null;
|
|
404
|
-
if (!value || typeof value !== "object") return void 0;
|
|
405
|
-
const { reservation, wsEndpoint, roomCode, role, connectionScope } = value;
|
|
406
|
-
if (!reservation || typeof reservation !== "object" || typeof reservation.name !== "string" || typeof reservation.sessionId !== "string" || typeof reservation.roomId !== "string" || typeof wsEndpoint !== "string") {
|
|
407
|
-
return void 0;
|
|
408
|
-
}
|
|
409
|
-
return {
|
|
410
|
-
reservation,
|
|
411
|
-
wsEndpoint: wsEndpoint.trim(),
|
|
412
|
-
...typeof roomCode === "string" && /^[A-Za-z0-9]{4,12}$/.test(roomCode) ? { roomCode: roomCode.toUpperCase() } : {},
|
|
413
|
-
...role === "host" || role === "player" || role === "spectator" ? { role } : {},
|
|
414
|
-
...typeof connectionScope === "string" && connectionScope.length > 0 && connectionScope.length <= 160 ? { connectionScope } : {}
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
407
|
function mergeBootstrapConfig(config = {}) {
|
|
418
408
|
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
419
409
|
mergeSettings(config.settings);
|
|
@@ -475,10 +465,6 @@
|
|
|
475
465
|
(k) => typeof launch[k] === "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(String(launch[k]))
|
|
476
466
|
) && typeof launch.gameUrl === "string" && launch.gameUrl.startsWith("/games/") && launch.gameUrl.length < 2048 && ["server", "unverified"].includes(launch.scoreAuthority))
|
|
477
467
|
state.bootstrapLaunch = { ...launch };
|
|
478
|
-
const mp = parseMultiplayer(config.multiplayer);
|
|
479
|
-
if (mp !== void 0) {
|
|
480
|
-
state.bootstrapMultiplayer = mp;
|
|
481
|
-
}
|
|
482
468
|
}
|
|
483
469
|
function snapshotBootstrap() {
|
|
484
470
|
return {
|
|
@@ -497,7 +483,6 @@
|
|
|
497
483
|
teamOneName: state.bootstrapTeamOneName,
|
|
498
484
|
teamTwoName: state.bootstrapTeamTwoName,
|
|
499
485
|
profileId: state.bootstrapProfileId,
|
|
500
|
-
multiplayer: state.bootstrapMultiplayer,
|
|
501
486
|
multiplayerLaunch: state.bootstrapLaunch,
|
|
502
487
|
capabilities: state.bootstrapCapabilities
|
|
503
488
|
};
|
|
@@ -839,7 +824,7 @@
|
|
|
839
824
|
}
|
|
840
825
|
}
|
|
841
826
|
async function startSession() {
|
|
842
|
-
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(
|
|
827
|
+
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
|
|
843
828
|
return { success: false, error: "Multiplayer rounds own their results" };
|
|
844
829
|
if (state.sessionToken) return { success: true, token: state.sessionToken };
|
|
845
830
|
if (state.sessionStartPromise) return await state.sessionStartPromise;
|
|
@@ -934,7 +919,7 @@
|
|
|
934
919
|
}
|
|
935
920
|
async function submitScore(score, meta = {}) {
|
|
936
921
|
await ensureInitialized();
|
|
937
|
-
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(
|
|
922
|
+
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
|
|
938
923
|
return failedResult(
|
|
939
924
|
"FORBIDDEN",
|
|
940
925
|
"Multiplayer rounds own their results",
|
|
@@ -1160,7 +1145,7 @@
|
|
|
1160
1145
|
state.isAutoInitializing = false;
|
|
1161
1146
|
return false;
|
|
1162
1147
|
}
|
|
1163
|
-
if (!state.authToken && !state.bootstrapLaunch && !state.bootstrapCapabilities.includes(
|
|
1148
|
+
if (!state.authToken && !state.bootstrapLaunch && !state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY)) {
|
|
1164
1149
|
state.authToken = await getAuthTokenFromParent();
|
|
1165
1150
|
}
|
|
1166
1151
|
state.isInitialized = true;
|
|
@@ -1203,7 +1188,7 @@
|
|
|
1203
1188
|
state.bootstrapReceived = true;
|
|
1204
1189
|
mergeBootstrapConfig(data.payload);
|
|
1205
1190
|
}
|
|
1206
|
-
if (type === MESSAGE_PREFIX + "_MULTIPLAYER_SESSION" && state.bootstrapCapabilities.includes(
|
|
1191
|
+
if (type === MESSAGE_PREFIX + "_MULTIPLAYER_SESSION" && state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
|
|
1207
1192
|
acceptLobbyState(data.payload);
|
|
1208
1193
|
if (type === MESSAGE_PREFIX + "_SET_AUTH") {
|
|
1209
1194
|
state.authToken = data.token;
|
|
@@ -1226,7 +1211,7 @@
|
|
|
1226
1211
|
// src/multiplayer.ts
|
|
1227
1212
|
var pending = null;
|
|
1228
1213
|
function requestMultiplayerLaunch() {
|
|
1229
|
-
if (!state.bootstrapLaunch || !state.bootstrapCapabilities.includes(
|
|
1214
|
+
if (!state.bootstrapLaunch || !state.bootstrapCapabilities.includes(MULTIPLAYER_CAPABILITY))
|
|
1230
1215
|
return Promise.resolve({
|
|
1231
1216
|
status: "terminal",
|
|
1232
1217
|
error: {
|
|
@@ -1419,7 +1404,6 @@
|
|
|
1419
1404
|
teamOneName: state.bootstrapTeamOneName,
|
|
1420
1405
|
teamTwoName: state.bootstrapTeamTwoName,
|
|
1421
1406
|
profileId: state.bootstrapProfileId,
|
|
1422
|
-
multiplayer: state.bootstrapMultiplayer,
|
|
1423
1407
|
multiplayerLaunch: state.bootstrapLaunch,
|
|
1424
1408
|
capabilities: [...state.bootstrapCapabilities],
|
|
1425
1409
|
isBootstrapped: state.bootstrapReceived
|