@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/dist/src/init.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SDK discovery + auto-initialisation.
|
|
3
3
|
*
|
|
4
|
-
* Detects the API base URL (from the `<script>` tag or the page location)
|
|
5
|
-
* the active game slug,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Detects the API base URL (from the `<script>` tag or the page location)
|
|
5
|
+
* and the active game slug, then exchanges a few postMessages with the
|
|
6
|
+
* host to pick up an auth token and the bootstrap payload before opening
|
|
7
|
+
* a session.
|
|
8
|
+
*
|
|
9
|
+
* The SDK is transport-agnostic: when the bootstrap carries a
|
|
10
|
+
* `multiplayer` block, the values are exposed on
|
|
11
|
+
* `sdk.getBootstrap().multiplayer` for the game to open its own realtime
|
|
12
|
+
* connection (e.g. `new Client(wsEndpoint).reconnect(reconnectionToken)`
|
|
13
|
+
* via `@colyseus/sdk`). The SDK never opens a socket itself.
|
|
9
14
|
*/
|
|
10
15
|
import { state } from './state.js';
|
|
11
16
|
import { MESSAGE_PREFIX } from './constants.js';
|
|
12
|
-
import { isBrowser, readQueryParam,
|
|
17
|
+
import { isBrowser, readQueryParam, warn, error as logError } from './utils.js';
|
|
13
18
|
import { mergeBootstrapConfig, requestBootstrapFromParent, getAuthTokenFromParent, sendToParent, } from './bridge.js';
|
|
14
|
-
import * as Multiplayer from './multiplayer.js';
|
|
15
|
-
import * as MatchCtx from './match-context.js';
|
|
16
19
|
import * as Session from './session.js';
|
|
17
20
|
let environmentDetected = false;
|
|
18
21
|
let hostListenerInstalled = false;
|
|
19
22
|
/**
|
|
20
|
-
* One-off environment detection. Should be called exactly once at SDK
|
|
21
|
-
* time, before any other
|
|
22
|
-
*
|
|
23
|
+
* One-off environment detection. Should be called exactly once at SDK
|
|
24
|
+
* boot time, before any other init function. Idempotent and safe to call
|
|
25
|
+
* outside a browser (no-op).
|
|
23
26
|
*/
|
|
24
27
|
export function detectEnvironment() {
|
|
25
28
|
if (!isBrowser() || environmentDetected)
|
|
@@ -27,8 +30,8 @@ export function detectEnvironment() {
|
|
|
27
30
|
environmentDetected = true;
|
|
28
31
|
state.sdkOrigin = window.location.origin;
|
|
29
32
|
// Detect when the game is being served under /games/<slug>/ or
|
|
30
|
-
// /uploaded-games/<slug>/ —
|
|
31
|
-
//
|
|
33
|
+
// /uploaded-games/<slug>/ — used to infer the slug AND the mount point
|
|
34
|
+
// (which the API base URL is built from).
|
|
32
35
|
const runtimePathMatch = window.location.pathname.match(/^(.*)\/(?:uploaded-games|games)\/([a-z0-9-]+)(?:\/|$)/i);
|
|
33
36
|
let detectedSlug = null;
|
|
34
37
|
if (runtimePathMatch) {
|
|
@@ -40,10 +43,6 @@ export function detectEnvironment() {
|
|
|
40
43
|
state.leagueId = readQueryParam('leagueId');
|
|
41
44
|
state.gameId = readQueryParam('gameId');
|
|
42
45
|
state.matchId = readQueryParam('matchId');
|
|
43
|
-
state.participant1Id = readQueryParam('participant1Id');
|
|
44
|
-
state.participant2Id = readQueryParam('participant2Id');
|
|
45
|
-
state.participant1MemberIds = readCsvQueryParam('participant1MemberIds');
|
|
46
|
-
state.participant2MemberIds = readCsvQueryParam('participant2MemberIds');
|
|
47
46
|
// Locate our own <script> tag so we can honour `data-game-slug` and
|
|
48
47
|
// resolve the path prefix (needed when served from a subpath like /app).
|
|
49
48
|
const scripts = document.getElementsByTagName('script');
|
|
@@ -70,8 +69,6 @@ export function detectEnvironment() {
|
|
|
70
69
|
detectedSlug = slugAttr;
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
|
-
// Final fallback: look for a games slug in the path even if we didn't
|
|
74
|
-
// match the full pattern earlier.
|
|
75
72
|
if (!detectedSlug) {
|
|
76
73
|
const pathMatch = window.location.pathname.match(/\/(?:uploaded-games|games)\/([a-z0-9-]+)\//i);
|
|
77
74
|
if (pathMatch)
|
|
@@ -81,152 +78,28 @@ export function detectEnvironment() {
|
|
|
81
78
|
state.apiBase = state.sdkOrigin + effectiveBasePath + '/api';
|
|
82
79
|
state.gameSlug = detectedSlug;
|
|
83
80
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns the share ID we should auto-join on boot, if any. Bootstrap takes
|
|
86
|
-
* priority over URL params so hosts can override a stale link.
|
|
87
|
-
*/
|
|
88
|
-
function getPendingShareId() {
|
|
89
|
-
if (state.bootstrapShareId)
|
|
90
|
-
return state.bootstrapShareId;
|
|
91
|
-
return readQueryParam('mp');
|
|
92
|
-
}
|
|
93
|
-
/** Same as {@link getPendingShareId} but for room codes. */
|
|
94
|
-
function getPendingRoomCode() {
|
|
95
|
-
if (state.bootstrapRoomCode)
|
|
96
|
-
return state.bootstrapRoomCode;
|
|
97
|
-
const roomCode = readQueryParam('roomCode');
|
|
98
|
-
return roomCode ? roomCode.trim().toUpperCase() : null;
|
|
99
|
-
}
|
|
100
|
-
function getPendingRoomRole() {
|
|
101
|
-
if (state.bootstrapRoomRole)
|
|
102
|
-
return state.bootstrapRoomRole;
|
|
103
|
-
const role = readQueryParam('roomRole');
|
|
104
|
-
return role ? role.trim() : null;
|
|
105
|
-
}
|
|
106
|
-
function getPendingRoomToken() {
|
|
107
|
-
if (state.bootstrapRoomToken)
|
|
108
|
-
return state.bootstrapRoomToken;
|
|
109
|
-
const roomToken = readQueryParam('roomToken');
|
|
110
|
-
return roomToken ? roomToken.trim() : null;
|
|
111
|
-
}
|
|
112
|
-
function getPendingWsUrl() {
|
|
113
|
-
if (state.bootstrapWsUrl)
|
|
114
|
-
return state.bootstrapWsUrl;
|
|
115
|
-
const wsUrl = readQueryParam('wsUrl');
|
|
116
|
-
return wsUrl ? wsUrl.trim() : null;
|
|
117
|
-
}
|
|
118
|
-
/** Same as {@link getPendingShareId} but for the host-preferred display name. */
|
|
119
|
-
function getPendingPlayerName() {
|
|
120
|
-
if (state.bootstrapPlayerName)
|
|
121
|
-
return state.bootstrapPlayerName;
|
|
122
|
-
const playerName = readQueryParam('playerName');
|
|
123
|
-
return playerName ? playerName.trim() : undefined;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Resolve the peerId for "this player" — bootstrap wins over the URL so the
|
|
127
|
-
* host can correct a stale link. Populated opportunistically so games know
|
|
128
|
-
* their assigned peerId before the multiplayer WS has joined.
|
|
129
|
-
*/
|
|
130
|
-
function seedPeerIdFromUrl() {
|
|
131
|
-
if (state.bootstrapPeerId)
|
|
132
|
-
return;
|
|
133
|
-
const fromUrl = readQueryParam('peerId');
|
|
134
|
-
if (fromUrl)
|
|
135
|
-
state.bootstrapPeerId = fromUrl.trim();
|
|
136
|
-
}
|
|
137
|
-
function resumePendingRoomFromBootstrap() {
|
|
138
|
-
const roomCode = getPendingRoomCode();
|
|
139
|
-
const roomToken = getPendingRoomToken();
|
|
140
|
-
const wsUrl = getPendingWsUrl();
|
|
141
|
-
const peerId = state.bootstrapPeerId ||
|
|
142
|
-
readQueryParam('peerId')?.trim() ||
|
|
143
|
-
null;
|
|
144
|
-
if (!state.gameSlug || !roomCode || !roomToken || !wsUrl || !peerId) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
const role = getPendingRoomRole() || 'player';
|
|
148
|
-
state.mpViewerOverride = role === 'viewer';
|
|
149
|
-
state.mpRoom = {
|
|
150
|
-
roomCode,
|
|
151
|
-
shareId: state.bootstrapShareId || '',
|
|
152
|
-
peerId,
|
|
153
|
-
role,
|
|
154
|
-
gameSlug: state.gameSlug,
|
|
155
|
-
roomToken,
|
|
156
|
-
wsUrl,
|
|
157
|
-
};
|
|
158
|
-
state.mpLastJoinRequest = {
|
|
159
|
-
roomCode,
|
|
160
|
-
roomToken,
|
|
161
|
-
wsUrl,
|
|
162
|
-
gameSlug: state.gameSlug,
|
|
163
|
-
peerId,
|
|
164
|
-
};
|
|
165
|
-
Multiplayer.connect(state.mpLastJoinRequest);
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
async function autoJoinPendingShare() {
|
|
169
|
-
const shareId = getPendingShareId();
|
|
170
|
-
if (!shareId)
|
|
171
|
-
return;
|
|
172
|
-
if (state.lastAutoJoinShareId === shareId)
|
|
173
|
-
return;
|
|
174
|
-
try {
|
|
175
|
-
state.lastAutoJoinShareId = shareId;
|
|
176
|
-
await Multiplayer.joinRoomByLink(shareId, {
|
|
177
|
-
displayName: getPendingPlayerName(),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
state.lastAutoJoinShareId = null;
|
|
182
|
-
warn('Auto join by link failed: ' + (err?.message || err));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async function autoJoinPendingRoomCode() {
|
|
186
|
-
const roomCode = getPendingRoomCode();
|
|
187
|
-
if (!roomCode)
|
|
188
|
-
return;
|
|
189
|
-
if (state.lastAutoJoinRoomCode === roomCode)
|
|
190
|
-
return;
|
|
191
|
-
try {
|
|
192
|
-
state.lastAutoJoinRoomCode = roomCode;
|
|
193
|
-
if (resumePendingRoomFromBootstrap()) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
await Multiplayer.joinRoom(roomCode, {
|
|
197
|
-
displayName: getPendingPlayerName(),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
state.lastAutoJoinRoomCode = null;
|
|
202
|
-
warn('Auto join by room code failed: ' + (err?.message || err));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
81
|
/**
|
|
206
82
|
* Orchestrates the full SDK boot sequence:
|
|
207
83
|
* 1. Request bootstrap config from the host (seeds slug + context).
|
|
208
84
|
* 2. Exchange for an auth token if we don't already have one.
|
|
209
|
-
* 3. Notify the host that we've booted
|
|
210
|
-
* 4. Open a session if we can, and
|
|
85
|
+
* 3. Notify the host that we've booted.
|
|
86
|
+
* 4. Open a session if we can, and reconnect to the Colyseus room when
|
|
87
|
+
* the host gave us a `multiplayer` block.
|
|
211
88
|
*
|
|
212
89
|
* Safe to call multiple times — concurrent callers share a single promise.
|
|
213
90
|
*/
|
|
214
91
|
export async function autoInit() {
|
|
215
92
|
if (!isBrowser())
|
|
216
93
|
return false;
|
|
217
|
-
if (state.isInitialized || state.isAutoInitializing)
|
|
94
|
+
if (state.isInitialized || state.isAutoInitializing) {
|
|
218
95
|
return state.autoInitPromise;
|
|
219
|
-
|
|
220
|
-
// without going through the script-tag entry, so they may not have run
|
|
221
|
-
// these themselves. Both functions are idempotent — safe to call again
|
|
222
|
-
// when the script-tag entry has already invoked them.
|
|
96
|
+
}
|
|
223
97
|
detectEnvironment();
|
|
224
98
|
installHostMessageListener();
|
|
225
99
|
state.isAutoInitializing = true;
|
|
226
100
|
state.autoInitPromise = (async () => {
|
|
227
101
|
try {
|
|
228
102
|
await requestBootstrapFromParent();
|
|
229
|
-
seedPeerIdFromUrl();
|
|
230
103
|
if (!state.gameSlug) {
|
|
231
104
|
warn('Could not resolve game slug. Ensure the host page sends bootstrap config or serves the game under /games/{slug}.');
|
|
232
105
|
state.isAutoInitializing = false;
|
|
@@ -241,13 +114,10 @@ export async function autoInit() {
|
|
|
241
114
|
slug: state.gameSlug,
|
|
242
115
|
auto: true,
|
|
243
116
|
});
|
|
244
|
-
await MatchCtx.fetchMatchContext();
|
|
245
117
|
if (state.authToken ||
|
|
246
118
|
(state.leagueId && state.gameId && state.matchId)) {
|
|
247
119
|
state.sessionStartPromise = Session.startSession();
|
|
248
120
|
}
|
|
249
|
-
await autoJoinPendingShare();
|
|
250
|
-
await autoJoinPendingRoomCode();
|
|
251
121
|
return true;
|
|
252
122
|
}
|
|
253
123
|
catch (err) {
|
|
@@ -272,8 +142,8 @@ export async function ensureInitialized() {
|
|
|
272
142
|
return await autoInit();
|
|
273
143
|
}
|
|
274
144
|
/**
|
|
275
|
-
* Wires up the ambient message listener the host uses to push updates
|
|
276
|
-
* the running SDK (fresh bootstrap, rotated auth, pause/resume
|
|
145
|
+
* Wires up the ambient message listener the host uses to push updates
|
|
146
|
+
* into the running SDK (fresh bootstrap, rotated auth, pause/resume).
|
|
277
147
|
*/
|
|
278
148
|
export function installHostMessageListener() {
|
|
279
149
|
if (!isBrowser() || hostListenerInstalled)
|
|
@@ -287,9 +157,6 @@ export function installHostMessageListener() {
|
|
|
287
157
|
state.parentOrigin = event.origin;
|
|
288
158
|
state.bootstrapReceived = true;
|
|
289
159
|
mergeBootstrapConfig(event.data.payload);
|
|
290
|
-
if (state.isInitialized && state.bootstrapShareId && !state.mpRoom) {
|
|
291
|
-
autoJoinPendingShare();
|
|
292
|
-
}
|
|
293
160
|
}
|
|
294
161
|
if (type === MESSAGE_PREFIX + '_SET_AUTH') {
|
|
295
162
|
state.authToken = event.data.token;
|
package/dist/src/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAChC,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,SAAS,EAAE,IAAI,mBAAmB;QAAE,OAAO;IAChD,mBAAmB,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAEzC,+DAA+D;IAC/D,uEAAuE;IACvE,0CAA0C;IAC1C,MAAM,gBAAgB,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CACrD,wDAAwD,CACzD,CAAC;IACF,IAAI,YAAY,GAAkB,IAAI,CAAC;IACvC,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,eAAe,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAClD,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC7C,CAAC;IAED,uEAAuE;IACvE,wCAAwC;IACxC,KAAK,CAAC,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAC5C,KAAK,CAAC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,KAAK,UAAU,EACvC,CAAC;gBACD,CAAC,CAAC,eAAe,EAAE,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/src/main.d.ts
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public SDK module entry. Exports `createSdk` (the factory) and every
|
|
3
|
-
* public type.
|
|
4
|
-
* touch `window`, `document`, or run any boot logic.
|
|
3
|
+
* public type.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
* `window
|
|
5
|
+
* Importing this module has no side effects — it does not touch
|
|
6
|
+
* `window`, `document`, or run any boot logic. For the legacy
|
|
7
|
+
* `<script>`-tag distribution that auto-attaches `window.GameHubSDK`
|
|
8
|
+
* and runs `autoInit()`, see `./browser-entry.ts`.
|
|
9
|
+
*
|
|
10
|
+
* The SDK is transport-agnostic. Games that need realtime multiplayer
|
|
11
|
+
* read `sdk.getBootstrap().multiplayer` and open their own connection
|
|
12
|
+
* (e.g. via `@colyseus/sdk`'s `client.reconnect(...)`).
|
|
8
13
|
*/
|
|
9
14
|
import type { BootstrapData } from '../types/bootstrap.js';
|
|
15
|
+
import type { EventData, GameCompleteData, Question, QuestionOptions, ReportQuestionData, ScoreMetadata, StartSessionResult, SubmitScoreResult } from '../types/session.js';
|
|
10
16
|
import type { MatchContext, MatchResultPayload } from '../types/match.js';
|
|
11
|
-
import type { CreateRoomResult, JoinOptions, JoinRoomResult, MpEventHandler, Peer, RoomInfo, RoomOptions, SendOptions } from '../types/multiplayer.js';
|
|
12
|
-
import type { EventData, GameCompleteData, Question, QuestionOptions, ScoreMetadata, StartSessionResult, SubmitScoreResult } from '../types/session.js';
|
|
13
17
|
export type { ApiRequestOptions, ApiResponse } from '../types/api.js';
|
|
14
|
-
export type { BootstrapConfig, BootstrapData,
|
|
18
|
+
export type { BootstrapConfig, BootstrapData, BootstrapMultiplayer, } from '../types/bootstrap.js';
|
|
19
|
+
export type { EventData, GameCompleteData, Question, QuestionOptions, ReportQuestionData, ScoreMetadata, StartSessionResult, SubmitScoreResult, } from '../types/session.js';
|
|
15
20
|
export type { MatchContext, MatchParticipant, MatchParticipantMember, MatchResultPayload, } from '../types/match.js';
|
|
16
|
-
export type { CreateRoomResult, JoinInfo, JoinOptions, JoinRoomResult, MpEventHandler, MpJoinRequest, MpMessage, MpRoom, Peer, RoomInfo, RoomOptions, SendOptions, } from '../types/multiplayer.js';
|
|
17
|
-
export type { Match, MatchAbortReason, MatchBroadcastOptions, MatchCtx, MatchEventDef, MatchEventMap, MatchHostCtx, MatchOptions, MatchScopedPayload, MatchState, } from '../types/multiplayer-match.js';
|
|
18
|
-
export type { EventData, GameCompleteData, Question, QuestionOptions, ScoreMetadata, StartSessionResult, SubmitScoreResult, } from '../types/session.js';
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* Public shape of `window.GameHubSDK` and the value returned by
|
|
23
|
+
* `createSdk()`.
|
|
24
|
+
*
|
|
25
|
+
* Games that need realtime multiplayer read
|
|
26
|
+
* `sdk.getBootstrap().multiplayer` and open their own socket — typically
|
|
27
|
+
* via `new Client(wsEndpoint).reconnect(reconnectionToken)` from
|
|
28
|
+
* `@colyseus/sdk`. The SDK itself has no realtime dependency.
|
|
22
29
|
*/
|
|
23
30
|
export interface Sdk {
|
|
24
31
|
readonly version: string;
|
|
25
|
-
/** @returns true after auto-init has
|
|
32
|
+
/** @returns true after auto-init has resolved. */
|
|
26
33
|
isInitialized(): boolean;
|
|
27
34
|
/** @returns true when an auth token is currently known. */
|
|
28
35
|
isAuthenticated(): boolean;
|
|
@@ -34,17 +41,29 @@ export interface Sdk {
|
|
|
34
41
|
submitScore(score: number, meta?: ScoreMetadata): Promise<SubmitScoreResult>;
|
|
35
42
|
/** Submit a score attached to the active league match. */
|
|
36
43
|
submitMatchScore(score: number, meta?: ScoreMetadata): Promise<SubmitScoreResult>;
|
|
37
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Submit a league-match result (winner, per-participant scores, etc.).
|
|
46
|
+
* Use this instead of `submitMatchScore` for matches whose leaderboard
|
|
47
|
+
* is derived from the result payload rather than a single score.
|
|
48
|
+
*/
|
|
38
49
|
submitMatchResult(result?: MatchResultPayload): Promise<SubmitScoreResult>;
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Fetch the league-match context for the current bootstrap (leagueId +
|
|
52
|
+
* matchId). Memoised on first success; returns `null` outside a league
|
|
53
|
+
* match context or on transport error.
|
|
54
|
+
*/
|
|
55
|
+
getMatchContext(): Promise<MatchContext | null>;
|
|
44
56
|
/** Tell the host the game has finished (shows completion UI). */
|
|
45
57
|
notifyComplete(data?: GameCompleteData): void;
|
|
46
58
|
/** Ask the host to close the game/iframe and return to the lobby. */
|
|
47
59
|
requestClose(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Ask the host to open the "report this question" dialog. The host collects
|
|
62
|
+
* the reason, an optional message, and (for guests) name/email, then submits
|
|
63
|
+
* the report to the platform. No-ops when the game runs outside the host
|
|
64
|
+
* iframe.
|
|
65
|
+
*/
|
|
66
|
+
reportQuestion(data: ReportQuestionData): void;
|
|
48
67
|
/** Emit a custom analytics event to the host. */
|
|
49
68
|
logEvent(eventName: string, eventData?: EventData): void;
|
|
50
69
|
/** @returns the resolved game slug, or null if we never found one. */
|
|
@@ -55,75 +74,16 @@ export interface Sdk {
|
|
|
55
74
|
ready(): Promise<boolean>;
|
|
56
75
|
/** @returns a snapshot of bootstrap-sourced state for debugging. */
|
|
57
76
|
getBootstrap(): BootstrapData;
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Fetch questions for quiz-style games. Returns [] on failure.
|
|
79
|
+
* Pass `options.profileId` to select a game profile; if omitted, the
|
|
80
|
+
* bootstrap-supplied `profileId` is used, else the game's default profile.
|
|
81
|
+
*/
|
|
61
82
|
getQuestions(options?: QuestionOptions): Promise<Question[]>;
|
|
62
|
-
/** Multiplayer sub-API. */
|
|
63
|
-
multiplayer: {
|
|
64
|
-
createRoom(options?: RoomOptions): Promise<CreateRoomResult>;
|
|
65
|
-
joinRoom(roomCode: string, options?: JoinOptions): Promise<JoinRoomResult>;
|
|
66
|
-
joinRoomByLink(link: string, options?: JoinOptions): Promise<JoinRoomResult>;
|
|
67
|
-
leaveRoom(reason?: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Send a custom event to every peer in the room. Blocked for viewers.
|
|
70
|
-
* Pass `{ retain: true, retainKey }` (host only on the server side) to
|
|
71
|
-
* pin the latest frame so peers joining/reconnecting later receive it
|
|
72
|
-
* before live traffic.
|
|
73
|
-
*/
|
|
74
|
-
send(eventName: string, payload?: Record<string, any>, options?: SendOptions): boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Host-only send. No-ops for guests and viewers. Use this for
|
|
77
|
-
* authoritative state updates (grid shuffles, turn changes, round end).
|
|
78
|
-
* Pair with `{ retain: true, retainKey }` to make the latest snapshot
|
|
79
|
-
* automatically replay to late joiners and reconnecting peers.
|
|
80
|
-
*/
|
|
81
|
-
broadcast(eventName: string, payload?: Record<string, any>, options?: SendOptions): boolean;
|
|
82
|
-
on(eventName: string, handler: MpEventHandler): () => void;
|
|
83
|
-
getRoom(): RoomInfo | null;
|
|
84
|
-
getPeers(): Peer[];
|
|
85
|
-
isConnected(): boolean;
|
|
86
|
-
/** @returns the peer's role (`host`, `player`, `viewer`) or null. */
|
|
87
|
-
getRole(): string | null;
|
|
88
|
-
/** @returns true if this peer is the authoritative host. */
|
|
89
|
-
isHost(): boolean;
|
|
90
|
-
/** @returns true if this peer joined as a view-only guest. */
|
|
91
|
-
isViewer(): boolean;
|
|
92
|
-
/** @returns the peerId of the local player (self), or null. */
|
|
93
|
-
selfId(): string | null;
|
|
94
|
-
/**
|
|
95
|
-
* Server-clock timestamp in milliseconds. Use this — not
|
|
96
|
-
* `Date.now()` — for timer math compared across peers. Returns
|
|
97
|
-
* `Date.now()` before any frame has arrived; once frames flow, the
|
|
98
|
-
* offset is EMA-smoothed from incoming `sentAt` stamps.
|
|
99
|
-
*/
|
|
100
|
-
serverNow(): number;
|
|
101
|
-
/**
|
|
102
|
-
* Build a host-authoritative match coordinator. Owns the peer-ready
|
|
103
|
-
* handshake, host election, retained match-start broadcast, intent
|
|
104
|
-
* routing, matchId scoping, and idempotent reapply. Throws if not in
|
|
105
|
-
* a room or if a previous match hasn't been destroyed.
|
|
106
|
-
*/
|
|
107
|
-
match<TMap extends {
|
|
108
|
-
[K in keyof TMap]: import('../types/multiplayer-match.js').MatchScopedPayload;
|
|
109
|
-
}, TStart extends import('../types/multiplayer-match.js').MatchScopedPayload>(options: import('../types/multiplayer-match.js').MatchOptions<TMap, TStart>): import('../types/multiplayer-match.js').Match<TMap>;
|
|
110
|
-
/**
|
|
111
|
-
* Deterministic seat assignment. Sorts peers as `host first, then
|
|
112
|
-
* lex-asc by peerId`, then assigns `seatNames[i]` to the i-th peer.
|
|
113
|
-
* Extra peers map to `null` (treat as spectators).
|
|
114
|
-
*/
|
|
115
|
-
assignSeats<TSeat extends string>(peers: readonly Peer[], seatNames: readonly TSeat[], hostPeerId: string | null): {
|
|
116
|
-
bySeat: Record<TSeat, string>;
|
|
117
|
-
byPeer: Record<string, TSeat | null>;
|
|
118
|
-
};
|
|
119
|
-
/** Resolves once `peers.length >= n`. Optional timeout in milliseconds. */
|
|
120
|
-
waitForPeers(n: number, timeoutMs?: number): Promise<Peer[]>;
|
|
121
|
-
};
|
|
122
83
|
}
|
|
123
84
|
/**
|
|
124
|
-
*
|
|
125
|
-
* the internal modules
|
|
126
|
-
* freely refactorable.
|
|
85
|
+
* Build the public API object. Methods are thin adapters that route to
|
|
86
|
+
* the internal modules.
|
|
127
87
|
*/
|
|
128
88
|
export declare function createSdk(): Sdk;
|
|
129
89
|
//# sourceMappingURL=main.d.ts.map
|
package/dist/src/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,YAAY,EAGZ,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAI3B,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtE,YAAY,EACV,eAAe,EACf,aAAa,EACb,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;GAQG;AACH,MAAM,WAAW,GAAG;IAClB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,kDAAkD;IAClD,aAAa,IAAI,OAAO,CAAC;IACzB,2DAA2D;IAC3D,eAAe,IAAI,OAAO,CAAC;IAC3B,+DAA+D;IAC/D,gBAAgB,IAAI,OAAO,CAAC;IAE5B,kEAAkE;IAClE,YAAY,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAE5C,oDAAoD;IACpD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE7E,0DAA0D;IAC1D,gBAAgB,CACd,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9B;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE3E;;;;OAIG;IACH,eAAe,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAEhD,iEAAiE;IACjE,cAAc,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE9C,qEAAqE;IACrE,YAAY,IAAI,IAAI,CAAC;IAErB;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE/C,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAEzD,sEAAsE;IACtE,WAAW,IAAI,MAAM,GAAG,IAAI,CAAC;IAE7B,4DAA4D;IAC5D,UAAU,IAAI,OAAO,CAAC;IAEtB,4DAA4D;IAC5D,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1B,oEAAoE;IACpE,YAAY,IAAI,aAAa,CAAC;IAE9B;;;;OAIG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CAC9D;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAwG/B"}
|
package/dist/src/main.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public SDK module entry. Exports `createSdk` (the factory) and every
|
|
3
|
-
* public type.
|
|
4
|
-
* touch `window`, `document`, or run any boot logic.
|
|
3
|
+
* public type.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
* `window
|
|
5
|
+
* Importing this module has no side effects — it does not touch
|
|
6
|
+
* `window`, `document`, or run any boot logic. For the legacy
|
|
7
|
+
* `<script>`-tag distribution that auto-attaches `window.GameHubSDK`
|
|
8
|
+
* and runs `autoInit()`, see `./browser-entry.ts`.
|
|
9
|
+
*
|
|
10
|
+
* The SDK is transport-agnostic. Games that need realtime multiplayer
|
|
11
|
+
* read `sdk.getBootstrap().multiplayer` and open their own connection
|
|
12
|
+
* (e.g. via `@colyseus/sdk`'s `client.reconnect(...)`).
|
|
8
13
|
*/
|
|
9
14
|
import { SDK_VERSION } from './constants.js';
|
|
10
15
|
import { state } from './state.js';
|
|
@@ -13,12 +18,9 @@ import { ensureInitialized } from './init.js';
|
|
|
13
18
|
import { isBrowser } from './utils.js';
|
|
14
19
|
import * as Session from './session.js';
|
|
15
20
|
import * as MatchCtx from './match-context.js';
|
|
16
|
-
import * as Multiplayer from './multiplayer.js';
|
|
17
|
-
import * as MultiplayerMatch from './multiplayer-match.js';
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
20
|
-
* the internal modules
|
|
21
|
-
* freely refactorable.
|
|
22
|
+
* Build the public API object. Methods are thin adapters that route to
|
|
23
|
+
* the internal modules.
|
|
22
24
|
*/
|
|
23
25
|
export function createSdk() {
|
|
24
26
|
return {
|
|
@@ -47,9 +49,9 @@ export function createSdk() {
|
|
|
47
49
|
submitMatchResult(result = {}) {
|
|
48
50
|
return Session.submitMatchResult(result);
|
|
49
51
|
},
|
|
50
|
-
async
|
|
51
|
-
|
|
52
|
-
return
|
|
52
|
+
async getMatchContext() {
|
|
53
|
+
await ensureInitialized();
|
|
54
|
+
return await MatchCtx.fetchMatchContext();
|
|
53
55
|
},
|
|
54
56
|
notifyComplete(data = {}) {
|
|
55
57
|
sendToParent('GAME_COMPLETE', data);
|
|
@@ -57,6 +59,13 @@ export function createSdk() {
|
|
|
57
59
|
requestClose() {
|
|
58
60
|
sendToParent('REQUEST_CLOSE', {});
|
|
59
61
|
},
|
|
62
|
+
reportQuestion(data) {
|
|
63
|
+
sendToParent('QUESTION_REPORT', {
|
|
64
|
+
questionId: data.questionId,
|
|
65
|
+
prompt: data.prompt,
|
|
66
|
+
message: data.message,
|
|
67
|
+
});
|
|
68
|
+
},
|
|
60
69
|
logEvent(eventName, eventData = {}) {
|
|
61
70
|
sendToParent('LOG_EVENT', {
|
|
62
71
|
event: eventName,
|
|
@@ -79,53 +88,19 @@ export function createSdk() {
|
|
|
79
88
|
leagueId: state.leagueId,
|
|
80
89
|
gameId: state.gameId,
|
|
81
90
|
matchId: state.matchId,
|
|
82
|
-
|
|
83
|
-
participant1Id: state.participant1Id,
|
|
84
|
-
participant2Id: state.participant2Id,
|
|
85
|
-
participant1MemberIds: state.participant1MemberIds,
|
|
86
|
-
participant2MemberIds: state.participant2MemberIds,
|
|
91
|
+
mode: state.bootstrapMode,
|
|
87
92
|
playerName: state.bootstrapPlayerName,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
maxPlayers: state.bootstrapMaxPlayers,
|
|
94
|
-
role: state.bootstrapRoomRole,
|
|
95
|
-
roomToken: state.bootstrapRoomToken,
|
|
96
|
-
wsUrl: state.bootstrapWsUrl,
|
|
97
|
-
}
|
|
98
|
-
: null,
|
|
93
|
+
playerCount: state.bootstrapPlayerCount,
|
|
94
|
+
teamOneName: state.bootstrapTeamOneName,
|
|
95
|
+
teamTwoName: state.bootstrapTeamTwoName,
|
|
96
|
+
profileId: state.bootstrapProfileId,
|
|
97
|
+
multiplayer: state.bootstrapMultiplayer,
|
|
99
98
|
isBootstrapped: state.bootstrapReceived,
|
|
100
99
|
};
|
|
101
100
|
},
|
|
102
|
-
async getMatchContext() {
|
|
103
|
-
await ensureInitialized();
|
|
104
|
-
return await MatchCtx.fetchMatchContext();
|
|
105
|
-
},
|
|
106
101
|
getQuestions(options = {}) {
|
|
107
102
|
return Session.getQuestions(options);
|
|
108
103
|
},
|
|
109
|
-
multiplayer: {
|
|
110
|
-
createRoom: Multiplayer.createRoom,
|
|
111
|
-
joinRoom: Multiplayer.joinRoom,
|
|
112
|
-
joinRoomByLink: Multiplayer.joinRoomByLink,
|
|
113
|
-
leaveRoom: Multiplayer.leaveRoom,
|
|
114
|
-
send: Multiplayer.send,
|
|
115
|
-
broadcast: Multiplayer.broadcast,
|
|
116
|
-
on: Multiplayer.on,
|
|
117
|
-
getRoom: Multiplayer.getRoom,
|
|
118
|
-
getPeers: Multiplayer.getPeers,
|
|
119
|
-
isConnected: Multiplayer.isConnected,
|
|
120
|
-
getRole: Multiplayer.getRole,
|
|
121
|
-
isHost: Multiplayer.isHost,
|
|
122
|
-
isViewer: Multiplayer.isViewer,
|
|
123
|
-
selfId: Multiplayer.selfId,
|
|
124
|
-
serverNow: Multiplayer.serverNow,
|
|
125
|
-
match: MultiplayerMatch.createMatch,
|
|
126
|
-
assignSeats: MultiplayerMatch.assignSeats,
|
|
127
|
-
waitForPeers: MultiplayerMatch.waitForPeers,
|
|
128
|
-
},
|
|
129
104
|
};
|
|
130
105
|
}
|
|
131
106
|
//# sourceMappingURL=main.js.map
|
package/dist/src/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,QA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[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"match-context.d.ts","sourceRoot":"","sources":["../../src/match-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA0BtE"}
|
|
@@ -24,20 +24,6 @@ export async function fetchMatchContext() {
|
|
|
24
24
|
const data = unwrapResult(result);
|
|
25
25
|
if (result?.success && data) {
|
|
26
26
|
state.matchContext = data;
|
|
27
|
-
state.participant1Id =
|
|
28
|
-
data.participant1?.participantId || state.participant1Id;
|
|
29
|
-
state.participant2Id =
|
|
30
|
-
data.participant2?.participantId || state.participant2Id;
|
|
31
|
-
state.participant1MemberIds = Array.isArray(data.participant1?.members)
|
|
32
|
-
? data.participant1.members
|
|
33
|
-
.map((member) => member?.leaguePlayerId)
|
|
34
|
-
.filter(Boolean)
|
|
35
|
-
: state.participant1MemberIds;
|
|
36
|
-
state.participant2MemberIds = Array.isArray(data.participant2?.members)
|
|
37
|
-
? data.participant2.members
|
|
38
|
-
.map((member) => member?.leaguePlayerId)
|
|
39
|
-
.filter(Boolean)
|
|
40
|
-
: state.participant2MemberIds;
|
|
41
27
|
return state.matchContext;
|
|
42
28
|
}
|
|
43
29
|
return null;
|