@ksaa-nlp/gamehub-sdk 0.7.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -374
- package/SPEC.md +865 -0
- package/dist/gamehub-sdk.js +164 -1163
- package/dist/gamehub-sdk.js.map +3 -3
- package/dist/src/api-client.d.ts +15 -5
- package/dist/src/api-client.d.ts.map +1 -1
- package/dist/src/api-client.js +21 -5
- package/dist/src/api-client.js.map +1 -1
- package/dist/src/bridge.d.ts +31 -14
- package/dist/src/bridge.d.ts.map +1 -1
- package/dist/src/bridge.js +148 -159
- package/dist/src/bridge.js.map +1 -1
- package/dist/src/constants.d.ts +8 -6
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -6
- package/dist/src/constants.js.map +1 -1
- package/dist/src/init.d.ts +18 -12
- package/dist/src/init.d.ts.map +1 -1
- package/dist/src/init.js +23 -156
- package/dist/src/init.js.map +1 -1
- package/dist/src/main.d.ts +45 -85
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +27 -52
- package/dist/src/main.js.map +1 -1
- package/dist/src/match-context.d.ts.map +1 -1
- package/dist/src/match-context.js +0 -14
- package/dist/src/match-context.js.map +1 -1
- package/dist/src/server-dev-harness.d.ts +85 -0
- package/dist/src/server-dev-harness.d.ts.map +1 -0
- package/dist/src/server-dev-harness.js +233 -0
- package/dist/src/server-dev-harness.js.map +1 -0
- package/dist/src/server-entry.d.ts +127 -0
- package/dist/src/server-entry.d.ts.map +1 -0
- package/dist/src/server-entry.js +26 -0
- package/dist/src/server-entry.js.map +1 -0
- package/dist/src/session.d.ts +16 -9
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +38 -27
- package/dist/src/session.js.map +1 -1
- package/dist/src/state.d.ts +17 -55
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/state.js +13 -32
- package/dist/src/state.js.map +1 -1
- package/dist/src/utils.d.ts +3 -14
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -31
- package/dist/src/utils.js.map +1 -1
- package/dist/types/bootstrap.d.ts +56 -36
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/question.d.ts +36 -0
- package/dist/types/question.d.ts.map +1 -0
- package/dist/types/question.js +21 -0
- package/dist/types/question.js.map +1 -0
- package/dist/types/session.d.ts +23 -20
- package/dist/types/session.d.ts.map +1 -1
- package/package.json +14 -4
- package/CHANGELOG.md +0 -467
- package/MIGRATION.md +0 -322
- package/dist/src/multiplayer-match.d.ts +0 -42
- package/dist/src/multiplayer-match.d.ts.map +0 -1
- package/dist/src/multiplayer-match.js +0 -551
- package/dist/src/multiplayer-match.js.map +0 -1
- package/dist/src/multiplayer.d.ts +0 -96
- package/dist/src/multiplayer.d.ts.map +0 -1
- package/dist/src/multiplayer.js +0 -495
- package/dist/src/multiplayer.js.map +0 -1
- package/dist/types/multiplayer-match.d.ts +0 -204
- package/dist/types/multiplayer-match.d.ts.map +0 -1
- package/dist/types/multiplayer-match.js +0 -15
- package/dist/types/multiplayer-match.js.map +0 -1
- package/dist/types/multiplayer.d.ts +0 -157
- package/dist/types/multiplayer.d.ts.map +0 -1
- package/dist/types/multiplayer.js +0 -2
- package/dist/types/multiplayer.js.map +0 -1
package/MIGRATION.md
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
# Migration guide
|
|
2
|
-
|
|
3
|
-
Each section below covers one consumption pattern. Pick whichever describes how your project used the previous version of `@ksaa-nlp/gamehub-sdk` and follow only that section.
|
|
4
|
-
|
|
5
|
-
This guide covers the cumulative migration from **v0.1 → v0.4.0**. The intermediate v0.2.0 and v0.3.0 releases are referenced where they changed something you can still observe; if you're upgrading directly from v0.1, you don't need to apply intermediate changes separately — they're all rolled in.
|
|
6
|
-
|
|
7
|
-
## TL;DR by consumer type
|
|
8
|
-
|
|
9
|
-
| You consume the SDK via... | Action required |
|
|
10
|
-
| --- | --- |
|
|
11
|
-
| A `<script>` tag in a host page | None. `window.GameHubSDK` and auto-init are unchanged. |
|
|
12
|
-
| `import sdk from '@ksaa-nlp/gamehub-sdk'` (default-import singleton) | Switch to `import { createSdk } from '@ksaa-nlp/gamehub-sdk'` and call `createSdk()`. Nothing happens on import — call `await sdk.ready()` to boot. |
|
|
13
|
-
| Angular / SSR / Node | Same as above. **New in v0.3.0:** importing the package no longer touches `window` or `document`, so SSR builds no longer crash on import. |
|
|
14
|
-
| `import type { ... } from '@ksaa-nlp/gamehub-sdk'` | Type names are unchanged; they're now real ESM named exports rather than members of a `gamehubSdk` namespace import. Most code keeps working as-is. |
|
|
15
|
-
| Source-level access to `GameHub.X.*` (forking, patching, vendoring) | Replace each `GameHub.Foo.bar` reference with a named `import` from the matching module file. |
|
|
16
|
-
|
|
17
|
-
## 1. `<script>`-tag consumers
|
|
18
|
-
|
|
19
|
-
No migration required. The compiled UMD bundle still:
|
|
20
|
-
|
|
21
|
-
- Attaches `sdk` to `window.GameHubSDK` on load.
|
|
22
|
-
- Runs `autoInit()` once the DOM is ready (or immediately if it already is).
|
|
23
|
-
- Sends `READY` to the host via postMessage.
|
|
24
|
-
- Auto-joins any pending multiplayer room signalled by URL params or bootstrap.
|
|
25
|
-
|
|
26
|
-
Existing host pages and existing games using `window.GameHubSDK.submitScore(...)` need no changes.
|
|
27
|
-
|
|
28
|
-
> **What's different under the hood:** in v0.3.0 the IIFE that does this work moved from [src/main.ts](./src/main.ts) into a dedicated [src/browser-entry.ts](./src/browser-entry.ts). This split is invisible to script-tag end users — the published `gamehub-sdk.js` continues to do exactly the same thing — but it matters if you build the SDK from source (see [Build pipeline](#build-pipeline) below).
|
|
29
|
-
|
|
30
|
-
## 2. Default-import singleton consumers
|
|
31
|
-
|
|
32
|
-
### Before (v0.1)
|
|
33
|
-
|
|
34
|
-
The package shipped a hand-written shim ([scripts/emit-module-entry.mjs](./scripts/emit-module-entry.mjs)) that imported the IIFE for its side effect and re-exported `window.GameHubSDK` as the default export:
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
// v0.1
|
|
38
|
-
import sdk from '@ksaa-nlp/gamehub-sdk';
|
|
39
|
-
|
|
40
|
-
await sdk.ready();
|
|
41
|
-
sdk.submitScore(100);
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
// CommonJS variant
|
|
46
|
-
const sdk = require('@ksaa-nlp/gamehub-sdk');
|
|
47
|
-
sdk.notifyComplete({ score: 100 });
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Both forms returned the same singleton that the IIFE had attached to the window.
|
|
51
|
-
|
|
52
|
-
### After (v0.3.0)
|
|
53
|
-
|
|
54
|
-
The default-import singleton shape is gone. The SDK now exposes a named `createSdk` factory:
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
// v0.3.0
|
|
58
|
-
import { createSdk, type Sdk } from '@ksaa-nlp/gamehub-sdk';
|
|
59
|
-
|
|
60
|
-
const sdk: Sdk = createSdk();
|
|
61
|
-
await sdk.ready();
|
|
62
|
-
sdk.submitScore(100);
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
// CommonJS variant (once the dual build lands — see "Build pipeline" below)
|
|
67
|
-
const { createSdk } = require('@ksaa-nlp/gamehub-sdk');
|
|
68
|
-
const sdk = createSdk();
|
|
69
|
-
sdk.notifyComplete({ score: 100 });
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The `Sdk` interface, every result type (`StartSessionResult`, `SubmitScoreResult`, ...), and every payload type (`BootstrapData`, `MatchContext`, `RoomInfo`, ...) are exported as named ESM types from the package root.
|
|
73
|
-
|
|
74
|
-
### Lifecycle: nothing happens until you call something
|
|
75
|
-
|
|
76
|
-
In v0.1, importing the package immediately ran environment detection, registered a `window.addEventListener('message', ...)` handler, and started the bootstrap handshake. In v0.3.0 none of that runs at import time. Concretely:
|
|
77
|
-
|
|
78
|
-
- `import { createSdk } from '@ksaa-nlp/gamehub-sdk'` — no side effects.
|
|
79
|
-
- `createSdk()` — builds and returns a plain SDK object. No DOM access.
|
|
80
|
-
- `await sdk.ready()` — **this** is the point where `detectEnvironment()` runs (resolving the API base URL), the host message listener installs, and the bootstrap / auth handshake fires. Both `detectEnvironment` and the listener installation are idempotent, so calling `ready()` multiple times is safe.
|
|
81
|
-
|
|
82
|
-
If you previously relied on the act of importing the package being enough to populate `window.GameHubSDK` — for example, an HTML host page that does `import('@ksaa-nlp/gamehub-sdk')` and then expects `window.GameHubSDK.submitScore(...)` to work — that no longer happens. Use `createSdk()` and keep your own reference, or load the script-tag bundle.
|
|
83
|
-
|
|
84
|
-
### Why we dropped the singleton default
|
|
85
|
-
|
|
86
|
-
The v0.1 default-import returned a shared mutable instance attached to `window`. That made it impossible to use the SDK in environments without a `window` (Node, Angular SSR), and it tied your module's state to whichever script tag had loaded the IIFE. With `createSdk()`, callers control lifecycle explicitly.
|
|
87
|
-
|
|
88
|
-
### Angular SSR / Node module consumers (new in v0.3.0)
|
|
89
|
-
|
|
90
|
-
In v0.1 and v0.2.0, `import '@ksaa-nlp/gamehub-sdk'` would crash an SSR build with `ReferenceError: window is not defined` — the IIFE ran at module evaluation time. **In v0.3.0 the import is pure**, and every method on the returned `Sdk` is callable in a non-browser environment without throwing:
|
|
91
|
-
|
|
92
|
-
- Read-only methods (`isInitialized`, `isAuthenticated`, `hasActiveSession`, `isInIframe`, `getGameSlug`, `getBootstrap`, `multiplayer.getRoom`, `multiplayer.getPeers`, `multiplayer.isConnected`, `multiplayer.getRole`, `multiplayer.isHost`, `multiplayer.isViewer`, `multiplayer.selfId`) return sensible defaults (`null`, `false`, `[]`).
|
|
93
|
-
- Side-effect methods (`notifyComplete`, `requestClose`, `logEvent`) silently no-op.
|
|
94
|
-
- `await sdk.ready()` resolves to `false` instead of throwing.
|
|
95
|
-
|
|
96
|
-
This means an Angular service can be straightforward:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
import { Injectable } from '@angular/core';
|
|
100
|
-
import { createSdk, type Sdk } from '@ksaa-nlp/gamehub-sdk';
|
|
101
|
-
|
|
102
|
-
@Injectable({ providedIn: 'root' })
|
|
103
|
-
export class GameHubService {
|
|
104
|
-
// Safe to construct on either platform — no window access happens here.
|
|
105
|
-
private readonly sdk: Sdk = createSdk();
|
|
106
|
-
|
|
107
|
-
// Boot lazily. On the server this resolves to `false` and skips the
|
|
108
|
-
// bootstrap handshake; in the browser it runs the full auto-init flow.
|
|
109
|
-
ready() {
|
|
110
|
-
return this.sdk.ready();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
submitScore(score: number) {
|
|
114
|
-
return this.sdk.submitScore(score);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
You don't need `isPlatformBrowser` gates around the import or the `createSdk()` call. You only need to gate calls whose semantics genuinely require a browser (multiplayer / WebSocket-backed methods will still throw if the WebSocket constructor isn't present).
|
|
120
|
-
|
|
121
|
-
> **Stable in v0.4.0:** the `package.json` `exports` map, the dual build pipeline, and the dropped CJS path are all in place. Importing the package via `import { createSdk } from '@ksaa-nlp/gamehub-sdk'` works under Node's native ESM loader without a bundler, under Angular CLI, Vite, webpack, esbuild, Bun, and Rollup. The `scripts/emit-module-entry.mjs` shim is gone.
|
|
122
|
-
|
|
123
|
-
## 3. Type-only consumers
|
|
124
|
-
|
|
125
|
-
### Before
|
|
126
|
-
|
|
127
|
-
The previous `dist/index.d.ts` exposed types as members of a single namespace import:
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
import type sdkTypes = require('@ksaa-nlp/gamehub-sdk');
|
|
131
|
-
type Bootstrap = sdkTypes.BootstrapData;
|
|
132
|
-
type Score = sdkTypes.SubmitScoreResult;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Or, depending on `esModuleInterop`:
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
import type gamehubSdk from '@ksaa-nlp/gamehub-sdk';
|
|
139
|
-
type Bootstrap = gamehubSdk.BootstrapData; // worked through `declare namespace gamehubSdk`
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### After
|
|
143
|
-
|
|
144
|
-
Every public type is now a real top-level named export:
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
import type {
|
|
148
|
-
Sdk,
|
|
149
|
-
BootstrapData,
|
|
150
|
-
MatchContext,
|
|
151
|
-
RoomInfo,
|
|
152
|
-
SubmitScoreResult,
|
|
153
|
-
StartSessionResult,
|
|
154
|
-
CreateRoomResult,
|
|
155
|
-
JoinOptions,
|
|
156
|
-
JoinRoomResult,
|
|
157
|
-
ScoreMetadata,
|
|
158
|
-
Question,
|
|
159
|
-
QuestionOptions,
|
|
160
|
-
} from '@ksaa-nlp/gamehub-sdk';
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Type names are unchanged from v0.1, so a project-wide find-and-replace from `gamehubSdk.<TypeName>` to `<TypeName>` plus the named `import type` is usually all that's needed. v0.3.0 adds no new type changes on top of the v0.2.0 conversion.
|
|
164
|
-
|
|
165
|
-
## 4. Source-level / vendored consumers
|
|
166
|
-
|
|
167
|
-
If your project forks or vendors the SDK source (e.g. a monorepo path import, or `link:` install), every cross-file reference needs to switch from namespace lookup to a named import.
|
|
168
|
-
|
|
169
|
-
### State access
|
|
170
|
-
|
|
171
|
-
The single biggest change: `GameHub.State` is no longer a namespace of mutable `export let`s. It's a single object exported from `src/state.ts`.
|
|
172
|
-
|
|
173
|
-
```ts
|
|
174
|
-
// Before
|
|
175
|
-
GameHub.State.gameSlug = 'my-game';
|
|
176
|
-
const token = GameHub.State.authToken;
|
|
177
|
-
|
|
178
|
-
// After
|
|
179
|
-
import { state } from './state';
|
|
180
|
-
state.gameSlug = 'my-game';
|
|
181
|
-
const token = state.authToken;
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Every field name on `state` matches the previous `GameHub.State.*` field exactly.
|
|
185
|
-
|
|
186
|
-
### Function references
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
// Before
|
|
190
|
-
GameHub.Session.startSession();
|
|
191
|
-
GameHub.Multiplayer.joinRoom(code);
|
|
192
|
-
GameHub.Bridge.sendToParent('LOG_EVENT', payload);
|
|
193
|
-
GameHub.Utils.warn('something');
|
|
194
|
-
GameHub.Api.apiRequest('/sessions/start', { method: 'POST' });
|
|
195
|
-
|
|
196
|
-
// After
|
|
197
|
-
import * as Session from './session';
|
|
198
|
-
import * as Multiplayer from './multiplayer';
|
|
199
|
-
import { sendToParent } from './bridge';
|
|
200
|
-
import { warn } from './utils';
|
|
201
|
-
import { apiRequest } from './api-client';
|
|
202
|
-
|
|
203
|
-
Session.startSession();
|
|
204
|
-
Multiplayer.joinRoom(code);
|
|
205
|
-
sendToParent('LOG_EVENT', payload);
|
|
206
|
-
warn('something');
|
|
207
|
-
apiRequest('/sessions/start', { method: 'POST' });
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
Either style works — namespace import (`import * as Session from './session'`) reads similarly to the old `GameHub.Session.*`; named imports tree-shake better.
|
|
211
|
-
|
|
212
|
-
### Constants
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
// Before
|
|
216
|
-
GameHub.SDK_VERSION;
|
|
217
|
-
GameHub.MESSAGE_PREFIX;
|
|
218
|
-
GameHub.MP_MAX_RECONNECT_ATTEMPTS;
|
|
219
|
-
|
|
220
|
-
// After
|
|
221
|
-
import {
|
|
222
|
-
SDK_VERSION,
|
|
223
|
-
MESSAGE_PREFIX,
|
|
224
|
-
MP_MAX_RECONNECT_ATTEMPTS,
|
|
225
|
-
} from './constants';
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### Types
|
|
229
|
-
|
|
230
|
-
```ts
|
|
231
|
-
// Before — types lived in the same `namespace GameHub` block as constants/state
|
|
232
|
-
const ctx: GameHub.MatchContext = ...;
|
|
233
|
-
const opts: GameHub.JoinOptions = ...;
|
|
234
|
-
|
|
235
|
-
// After — types live in `types/*.ts` and import like any other module
|
|
236
|
-
import type { MatchContext } from '../types/match';
|
|
237
|
-
import type { JoinOptions } from '../types/multiplayer';
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### Public surface
|
|
241
|
-
|
|
242
|
-
```ts
|
|
243
|
-
// Before
|
|
244
|
-
GameHub.Public.create();
|
|
245
|
-
type Sdk = GameHub.Public.Sdk;
|
|
246
|
-
|
|
247
|
-
// After
|
|
248
|
-
import { createSdk, type Sdk } from './main';
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Module map
|
|
252
|
-
|
|
253
|
-
| Old namespace | New module path |
|
|
254
|
-
| --- | --- |
|
|
255
|
-
| `GameHub` (constants) | [`src/constants.ts`](./src/constants.ts) |
|
|
256
|
-
| `GameHub.State` | `state` object exported from [`src/state.ts`](./src/state.ts) |
|
|
257
|
-
| `GameHub.Utils` | [`src/utils.ts`](./src/utils.ts) (now also exports `isBrowser()` for SSR guards) |
|
|
258
|
-
| `GameHub.Api` | [`src/api-client.ts`](./src/api-client.ts) (function `apiRequest`) |
|
|
259
|
-
| `GameHub.Bridge` | [`src/bridge.ts`](./src/bridge.ts) |
|
|
260
|
-
| `GameHub.MatchCtx` | [`src/match-context.ts`](./src/match-context.ts) |
|
|
261
|
-
| `GameHub.Session` | [`src/session.ts`](./src/session.ts) |
|
|
262
|
-
| `GameHub.Multiplayer` | [`src/multiplayer.ts`](./src/multiplayer.ts) |
|
|
263
|
-
| `GameHub.Init` | [`src/init.ts`](./src/init.ts) |
|
|
264
|
-
| `GameHub.Public.create` / `GameHub.Public.Sdk` | `createSdk` / `Sdk` from [`src/main.ts`](./src/main.ts) |
|
|
265
|
-
| Bootstrap IIFE (v0.1: bottom of `main.ts` script bundle) | [`src/browser-entry.ts`](./src/browser-entry.ts) — new in v0.3.0 |
|
|
266
|
-
| Type definitions (`MatchContext`, `BootstrapData`, ...) | [`types/*.ts`](./types) |
|
|
267
|
-
|
|
268
|
-
## Build pipeline
|
|
269
|
-
|
|
270
|
-
The SDK has **two entry points** built by **two tools**, both wired up in [package.json](./package.json) under `npm run build`:
|
|
271
|
-
|
|
272
|
-
| Entry | Built by | Output | Purpose |
|
|
273
|
-
| --- | --- | --- | --- |
|
|
274
|
-
| [src/main.ts](./src/main.ts) | `tsc` (per-file ESM emit) | `dist/src/main.js` + `.d.ts` | npm / Angular / Node ESM consumers. No side effects on import. |
|
|
275
|
-
| [src/browser-entry.ts](./src/browser-entry.ts) | `esbuild` (single IIFE bundle) | `dist/gamehub-sdk.js` | `<script>`-tag distribution. Self-contained 40 KB IIFE that attaches `window.GameHubSDK`. |
|
|
276
|
-
|
|
277
|
-
```jsonc
|
|
278
|
-
// package.json scripts
|
|
279
|
-
"build:tsc": "tsc -p ./tsconfig.json",
|
|
280
|
-
"build:bundle": "esbuild src/browser-entry.ts --bundle --format=iife --platform=browser --target=es2020 --outfile=dist/gamehub-sdk.js --sourcemap",
|
|
281
|
-
"build": "npm run build:tsc && npm run build:bundle",
|
|
282
|
-
"prepack": "npm run build"
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
`tsc` alone can't bundle (it does per-file emit only), so the script-tag artifact needs `esbuild`. `prepack` ensures `npm pack` / `npm publish` always rebuild from source — no stale `dist/` ships.
|
|
286
|
-
|
|
287
|
-
### Resulting dist layout
|
|
288
|
-
|
|
289
|
-
```
|
|
290
|
-
dist/
|
|
291
|
-
├── gamehub-sdk.js ← 40 KB IIFE for <script src="...">
|
|
292
|
-
├── gamehub-sdk.js.map
|
|
293
|
-
└── src/
|
|
294
|
-
├── main.js ← exports map "." entry (npm/Angular/Node)
|
|
295
|
-
├── main.d.ts
|
|
296
|
-
├── browser-entry.js ← exports map "./browser" entry
|
|
297
|
-
└── *.js + *.d.ts + *.map ← per-file ESM
|
|
298
|
-
└── types/
|
|
299
|
-
└── *.d.ts ← shared type declarations
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### `package.json` exports map
|
|
303
|
-
|
|
304
|
-
```jsonc
|
|
305
|
-
"type": "module",
|
|
306
|
-
"exports": {
|
|
307
|
-
".": { "types": "./dist/src/main.d.ts", "import": "./dist/src/main.js" },
|
|
308
|
-
"./browser": { "types": "./dist/src/browser-entry.d.ts", "import": "./dist/src/browser-entry.js" },
|
|
309
|
-
"./gamehub-sdk.js": "./dist/gamehub-sdk.js",
|
|
310
|
-
"./package.json": "./package.json"
|
|
311
|
-
}
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Source-level invariants
|
|
315
|
-
|
|
316
|
-
- **Every relative import in [src/](./src) and [types/](./types) ends in `.js`** — even when importing a `.ts` file. TypeScript with `moduleResolution: NodeNext` resolves `./foo.js` to `./foo.ts` at compile time and preserves the `.js` extension in the emitted output. This is the standard Node-ESM pattern; without it the dist won't load under Node's native ESM loader.
|
|
317
|
-
- **`src/main.ts` has no side effects.** All side-effecting boot code lives in [src/browser-entry.ts](./src/browser-entry.ts). Don't add IIFE / top-level DOM access to `main.ts` or any of its transitive imports.
|
|
318
|
-
- **Use `isBrowser()` from [src/utils.ts](./src/utils.ts)** for any new code that touches `window` / `document` / `WebSocket`. Top-level type references to those globals are fine (TS-only); top-level value reads will break SSR.
|
|
319
|
-
|
|
320
|
-
## Questions / problems?
|
|
321
|
-
|
|
322
|
-
If something in your migration isn't covered here, please open an issue with a code snippet of the previous usage and we'll add it to this guide.
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host-authoritative match coordinator.
|
|
3
|
-
*
|
|
4
|
-
* One Match per room. The Match owns:
|
|
5
|
-
* - the peer-ready handshake (auto-fired on first boot when `autoReady`)
|
|
6
|
-
* - host election + the start broadcast (always retained)
|
|
7
|
-
* - per-event routing: guest intents → host hostHandle → host broadcast
|
|
8
|
-
* → all peers' apply (idempotent via `idKey`)
|
|
9
|
-
* - matchId scoping (frames from previous matches are dropped)
|
|
10
|
-
* - lifecycle transitions: waiting → starting → active → aborted/ended
|
|
11
|
-
*
|
|
12
|
-
* Game code declares the event map and per-event hostHandle/apply pairs;
|
|
13
|
-
* everything else lives here.
|
|
14
|
-
*/
|
|
15
|
-
import type { Peer } from '../types/multiplayer.js';
|
|
16
|
-
import type { Match, MatchOptions, MatchScopedPayload } from '../types/multiplayer-match.js';
|
|
17
|
-
/**
|
|
18
|
-
* Build a host-authoritative Match coordinator. Must be called after the
|
|
19
|
-
* SDK has joined a room. Throws if no room is active or another Match is
|
|
20
|
-
* still alive — call `match.destroy()` first to start a new one.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createMatch<TMap extends {
|
|
23
|
-
[K in keyof TMap]: MatchScopedPayload;
|
|
24
|
-
}, TStart extends MatchScopedPayload>(options: MatchOptions<TMap, TStart>): Match<TMap>;
|
|
25
|
-
/**
|
|
26
|
-
* Deterministic seat assignment. Sorts peers as: host first, then
|
|
27
|
-
* lexicographically ascending by peerId. Assigns each `seatNames[i]` to
|
|
28
|
-
* the i-th peer. Extra peers (when `peers.length > seatNames.length`)
|
|
29
|
-
* receive `null` — treat them as spectators.
|
|
30
|
-
*/
|
|
31
|
-
export declare function assignSeats<TSeat extends string>(peers: readonly Peer[], seatNames: readonly TSeat[], hostPeerId: string | null): {
|
|
32
|
-
bySeat: Record<TSeat, string>;
|
|
33
|
-
byPeer: Record<string, TSeat | null>;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Resolves once `peers.length >= n`. Useful before constructing a Match
|
|
37
|
-
* when you don't want to render anything until everyone is present.
|
|
38
|
-
*
|
|
39
|
-
* @param timeoutMs optional timeout — rejects with `waitForPeers: timeout`.
|
|
40
|
-
*/
|
|
41
|
-
export declare function waitForPeers(n: number, timeoutMs?: number): Promise<Peer[]>;
|
|
42
|
-
//# sourceMappingURL=multiplayer-match.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multiplayer-match.d.ts","sourceRoot":"","sources":["../../src/multiplayer-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EACV,KAAK,EAML,YAAY,EACZ,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AAevC;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,SAAS;KAAG,CAAC,IAAI,MAAM,IAAI,GAAG,kBAAkB;CAAE,EACtD,MAAM,SAAS,kBAAkB,EACjC,OAAO,EAAE,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAkhBlD;AAID;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,SAAS,MAAM,EAC9C,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,SAAS,EAAE,SAAS,KAAK,EAAE,EAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB;IACD,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;CACtC,CAqBA;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EAAE,MAAM,EACT,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,EAAE,CAAC,CAqCjB"}
|