@ksaa-nlp/gamehub-sdk 4.5.0 → 5.5.1
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 +103 -48
- package/SPEC.md +230 -57
- package/dist/gamehub-sdk.js +1 -1458
- package/dist/gamehub-sdk.js.map +4 -4
- package/dist/src/answers.d.ts +22 -0
- package/dist/src/answers.d.ts.map +1 -0
- package/dist/src/answers.js +139 -0
- package/dist/src/answers.js.map +1 -0
- 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 +2 -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/loading.d.ts +5 -0
- package/dist/src/loading.d.ts.map +1 -0
- package/dist/src/loading.js +54 -0
- package/dist/src/loading.js.map +1 -0
- package/dist/src/main.d.ts +14 -3
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +12 -4
- package/dist/src/main.js.map +1 -1
- package/dist/src/multiplayer-client.d.ts +52 -0
- package/dist/src/multiplayer-client.d.ts.map +1 -0
- package/dist/src/multiplayer-client.js +286 -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 +28 -7
- 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 +8 -45
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/loading.d.ts +6 -0
- package/dist/types/loading.d.ts.map +1 -0
- package/dist/types/loading.js +2 -0
- package/dist/types/loading.js.map +1 -0
- package/dist/types/multiplayer-session.d.ts +9 -8
- package/dist/types/multiplayer-session.d.ts.map +1 -1
- package/dist/types/question.d.ts +0 -1
- package/dist/types/question.d.ts.map +1 -1
- package/dist/types/question.js +0 -1
- package/dist/types/question.js.map +1 -1
- package/dist/types/session.d.ts +16 -0
- package/dist/types/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 +35 -0
- package/dist/vendor/colyseus-schemas/common.js +15 -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 +200 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.js +289 -0
- package/package.json +34 -4
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
|
|
|
@@ -239,53 +239,46 @@ sdk.reportWord({
|
|
|
239
239
|
|
|
240
240
|
All of these are fire-and-forget — they just signal the host (over whichever transport is active). `reportQuestion` / `reportWord` ask the host to open its report dialog (the host collects the reason + optional message for logged-in users and submits it; guests see a login prompt). Pass `questions` / `words` instead of a single id to have the host render a dropdown so the player chooses which item to report.
|
|
241
241
|
|
|
242
|
-
##
|
|
242
|
+
## Recording answers
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
Report each answered question so the platform can show which questions are
|
|
245
|
+
hardest, which wrong option players pick most, and how long answers take:
|
|
245
246
|
|
|
246
247
|
```ts
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
const shownAt = performance.now();
|
|
249
|
+
// …the player picks an option…
|
|
250
|
+
sdk.recordAnswer({
|
|
251
|
+
questionId: q.id, // the question-bank id, or your own stable id
|
|
252
|
+
correct: picked === q.answer,
|
|
253
|
+
choice: picked, // the option's text or its index — never typed text
|
|
254
|
+
timeMs: performance.now() - shownAt,
|
|
255
|
+
level: currentLevel,
|
|
256
|
+
});
|
|
249
257
|
```
|
|
250
258
|
|
|
251
|
-
|
|
259
|
+
It is fire-and-forget: answers are batched and sent before `submitScore`. Only
|
|
260
|
+
signed-in players' sessions send them, and the platform keeps them anonymously,
|
|
261
|
+
without the player. Invalid answers are dropped silently.
|
|
252
262
|
|
|
253
|
-
##
|
|
263
|
+
## Pause/resume from the host
|
|
254
264
|
|
|
255
|
-
The
|
|
265
|
+
The host can pause/resume the iframe by posting a command. Define globals to receive them:
|
|
256
266
|
|
|
257
267
|
```ts
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
import { attachServerClock } from '@ksaa-nlp/colyseus-schemas/clock';
|
|
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' });
|
|
268
|
+
window.onGameHubPause = () => pauseGameLoop();
|
|
269
|
+
window.onGameHubResume = () => resumeGameLoop();
|
|
278
270
|
```
|
|
279
271
|
|
|
280
|
-
|
|
272
|
+
Both are optional. The SDK doesn't pause anything itself; it just delivers the signal.
|
|
281
273
|
|
|
282
|
-
|
|
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.
|
|
274
|
+
## Multiplayer
|
|
287
275
|
|
|
288
|
-
The
|
|
276
|
+
The main entry and the script-tag bundle never open a WebSocket. Multiplayer
|
|
277
|
+
games read `sdk.getBootstrap().multiplayerLaunch`, request their bound seat with
|
|
278
|
+
`requestMultiplayerLaunch()` and connect with `MultiplayerClient` from the
|
|
279
|
+
opt-in `@ksaa-nlp/gamehub-sdk/multiplayer` subpath. See
|
|
280
|
+
[Multiplayer (SDK 4.2)](#multiplayer-sdk-42) below and the
|
|
281
|
+
[multiplayer reference](../../specs/multiplayer.md).
|
|
289
282
|
|
|
290
283
|
## API summary
|
|
291
284
|
|
|
@@ -293,7 +286,7 @@ The returned `room` is a stock `@colyseus/sdk` `Room` — see <https://docs.coly
|
|
|
293
286
|
const sdk = createSdk();
|
|
294
287
|
|
|
295
288
|
// Lifecycle
|
|
296
|
-
sdk.version; // '
|
|
289
|
+
sdk.version; // '5.0.0'
|
|
297
290
|
sdk.ready(); // Promise<boolean>
|
|
298
291
|
sdk.isInitialized(); // boolean
|
|
299
292
|
sdk.isAuthenticated(); // boolean
|
|
@@ -318,6 +311,7 @@ sdk.getWords({ difficulty, category, tags, limit, profileId }); // Promise<Word[
|
|
|
318
311
|
sdk.notifyComplete(data?); // void
|
|
319
312
|
sdk.requestClose(); // void
|
|
320
313
|
sdk.logEvent(name, data?); // void
|
|
314
|
+
sdk.recordAnswer({ questionId, correct, choice?, timeMs?, level? }); // void
|
|
321
315
|
sdk.reportQuestion({ questionId?, prompt?, message?, questions? }); // void
|
|
322
316
|
sdk.reportWord({ wordId?, lemma?, message?, words? }); // void
|
|
323
317
|
|
|
@@ -336,7 +330,7 @@ import type {
|
|
|
336
330
|
Sdk,
|
|
337
331
|
BootstrapData,
|
|
338
332
|
BootstrapConfig,
|
|
339
|
-
|
|
333
|
+
MultiplayerLaunchContext,
|
|
340
334
|
ScoreMetadata,
|
|
341
335
|
SubmitScoreResult,
|
|
342
336
|
StartSessionResult,
|
|
@@ -436,23 +430,58 @@ The example host toggles music during gameplay; the game uses a separate gain
|
|
|
436
430
|
node for background music so sound effects remain independent. This is a
|
|
437
431
|
local integration demo; the GameHub profile is the production preference editor.
|
|
438
432
|
|
|
439
|
-
## Multiplayer
|
|
433
|
+
## Multiplayer (SDK 4.2)
|
|
440
434
|
|
|
441
435
|
Use `await sdk.ready()` before reading `sdk.getBootstrap().multiplayerLaunch`.
|
|
442
436
|
`requestMultiplayerLaunch()` requests only that already-bound launch from a
|
|
443
437
|
capable trusted host and accepts no room/game override. It returns reserved,
|
|
444
|
-
recoverable or terminal. The
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
438
|
+
recoverable or terminal. The main entry owns no realtime connection or
|
|
439
|
+
persistent token; `MultiplayerClient` handles socket, state, clock and recovery
|
|
440
|
+
lifecycle:
|
|
441
|
+
|
|
442
|
+
```sh
|
|
443
|
+
npm install @ksaa-nlp/gamehub-sdk @colyseus/sdk
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
import { createSdk } from '@ksaa-nlp/gamehub-sdk';
|
|
448
|
+
import { MultiplayerClient } from '@ksaa-nlp/gamehub-sdk/multiplayer';
|
|
449
|
+
const sdk = createSdk();
|
|
450
|
+
await sdk.ready();
|
|
451
|
+
const launch = sdk.getBootstrap().multiplayerLaunch;
|
|
452
|
+
if (!launch) throw new Error('Open this game from a GameHub v2 lobby');
|
|
453
|
+
let storage;
|
|
454
|
+
try {
|
|
455
|
+
storage = window.sessionStorage;
|
|
456
|
+
} catch {}
|
|
457
|
+
const game = new MultiplayerClient(sdk, launch, storage);
|
|
458
|
+
const unsubscribe = game.subscribe(({ status, state, error }) => {
|
|
459
|
+
// Render progress, synchronized state and actionable failure/retry.
|
|
460
|
+
});
|
|
461
|
+
await game.connect();
|
|
462
|
+
game.send('take', { amount: 1 });
|
|
463
|
+
// On explicit exit:
|
|
464
|
+
unsubscribe();
|
|
465
|
+
await game.leave();
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
`@colyseus/sdk` (and the `@colyseus/schema` it brings) are optional peers: only
|
|
469
|
+
this subpath needs them. The room's state classes and every multiplayer wire
|
|
470
|
+
type (bot levels, error codes, launch and result validators) ship inside the
|
|
471
|
+
SDK and are re-exported from this subpath. A saved result comes from server
|
|
472
|
+
acknowledgement, not a local `endMatch` call. The [Take Twenty-One starter](../../examples/take-twenty-one/README.md)
|
|
473
|
+
contains a complete authoring/build/upload example. Native hosts do not
|
|
474
|
+
advertise multiplayer. Server-authoritative rounds use `ctx.endMatch` version 2
|
|
475
|
+
instead of browser `submitScore`/`submitMatchResult`. The manifest and full
|
|
476
|
+
contract are in the [multiplayer reference](../../specs/multiplayer.md#3-package-manifest-gamehubmultiplayerjson).
|
|
450
477
|
|
|
451
478
|
## Create and join inside your game (SDK 4.3)
|
|
452
479
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
480
|
+
The admin platform waiting-room setting enables normal multiplayer; TV support
|
|
481
|
+
independently enables AirConsole. Do not add `lobbyUi` to the manifest: it is retired.
|
|
482
|
+
The typed menu controls below remain available to existing game-owned session
|
|
483
|
+
hosts. Disabling the waiting-room setting disables new normal multiplayer entry;
|
|
484
|
+
it no longer selects a game-owned menu. Hosts retain authentication and session ownership.
|
|
456
485
|
|
|
457
486
|
```ts
|
|
458
487
|
await sdk.ready();
|
|
@@ -477,6 +506,32 @@ Use `multiplayerEntry` to prefill invitation code and spectator intent. Public
|
|
|
477
506
|
session snapshots contain invitation URLs, limits, roster and current round
|
|
478
507
|
phase. Rematch availability follows terminal round phases, not only eventual
|
|
479
508
|
session retirement. Start transitions to a newly mounted pinned game document;
|
|
480
|
-
read `multiplayerLaunch` there and connect
|
|
509
|
+
read `multiplayerLaunch` there and connect `MultiplayerClient`. Lobby menus
|
|
481
510
|
cannot start/submit ordinary client scores. See the starter for ready/start,
|
|
482
511
|
bots, leave and rematch controls.
|
|
512
|
+
|
|
513
|
+
### Shared platform loading screens
|
|
514
|
+
|
|
515
|
+
With SDK 5.2, games report loading state; GameHub renders the same loading UI
|
|
516
|
+
for solo, embedded, standard multiplayer and AirConsole gameplay:
|
|
517
|
+
|
|
518
|
+
```ts
|
|
519
|
+
const sdk = createSdk();
|
|
520
|
+
sdk.setLoading('loading'); // Queued until the trusted host bootstraps.
|
|
521
|
+
await sdk.ready();
|
|
522
|
+
try {
|
|
523
|
+
await loadGameAssets();
|
|
524
|
+
sdk.setLoading(null); // Reveal interactive instructions or gameplay.
|
|
525
|
+
} catch {
|
|
526
|
+
sdk.setLoading('failed'); // Platform retry UI.
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
For a game-specific wait, use `sdk.setLoading('waiting-for-players')`, then
|
|
531
|
+
`null` when it ends. Pass the SDK itself to `new MultiplayerClient(sdk, launch)`;
|
|
532
|
+
the updated adapter automatically reports connection, arrival, recovery and
|
|
533
|
+
finishing states through its independent channel. Do not draw a second loading
|
|
534
|
+
screen inside the game when hosted by GameHub. Clearing a custom loading state
|
|
535
|
+
does not clear an active connection wait. SDK `ready()` is not asset readiness.
|
|
536
|
+
Existing bundled adapters require rebuilding and republishing the game package;
|
|
537
|
+
the platform cannot infer every internal state from an older bundle.
|