@ksaa-nlp/gamehub-sdk 0.9.0 → 3.6.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 +158 -373
- package/SPEC.md +869 -0
- package/dist/gamehub-sdk.js +168 -1191
- 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 +33 -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 +46 -20
- package/dist/types/session.d.ts.map +1 -1
- package/package.json +14 -4
- package/CHANGELOG.md +0 -545
- 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 -536
- 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 -194
- 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/bridge.d.ts
CHANGED
|
@@ -1,35 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-origin communication layer between the game iframe and its host page.
|
|
3
3
|
*
|
|
4
|
-
* Messages are namespaced with `MESSAGE_PREFIX` so we don't pick up
|
|
5
|
-
* postMessage traffic. The host
|
|
6
|
-
*
|
|
4
|
+
* Messages are namespaced with `MESSAGE_PREFIX` so we don't pick up
|
|
5
|
+
* unrelated postMessage traffic. The host implements a small protocol:
|
|
6
|
+
* - `BOOTSTRAP_REQUEST` ⇄ `BOOTSTRAP` (initial config + multiplayer)
|
|
7
|
+
* - `AUTH_REQUEST` ⇄ `AUTH_RESPONSE` (refresh the bearer token)
|
|
8
|
+
* - `READY` / `INIT` / `SESSION_STARTED` / `SCORE_SUBMITTED` / etc.
|
|
9
|
+
* (one-way SDK → host signals)
|
|
7
10
|
*/
|
|
8
11
|
import type { BootstrapConfig } from '../types/bootstrap.js';
|
|
12
|
+
import type { ApiResponse, ApiRequestOptions } from '../types/api.js';
|
|
9
13
|
/**
|
|
10
14
|
* Fold a {@link BootstrapConfig} from the host into internal state. Accepts
|
|
11
|
-
* partial configs: only
|
|
12
|
-
*
|
|
15
|
+
* partial configs: only fields the host explicitly set (including explicit
|
|
16
|
+
* `null`s used to clear a value) are applied.
|
|
13
17
|
*/
|
|
14
18
|
export declare function mergeBootstrapConfig(config?: BootstrapConfig): void;
|
|
15
19
|
/**
|
|
16
20
|
* Ask the host for its bootstrap payload. Resolves `null` if the game is
|
|
17
|
-
* standalone (no parent)
|
|
18
|
-
* if we're not in an iframe.
|
|
21
|
+
* standalone (no parent) or the host doesn't reply within the timeout.
|
|
19
22
|
*
|
|
20
|
-
* Subsequent calls after a successful bootstrap short-circuit to the
|
|
21
|
-
* state snapshot.
|
|
23
|
+
* Subsequent calls after a successful bootstrap short-circuit to the
|
|
24
|
+
* cached state snapshot.
|
|
22
25
|
*/
|
|
23
26
|
export declare function requestBootstrapFromParent(): Promise<BootstrapConfig | null>;
|
|
24
27
|
/**
|
|
25
|
-
* Ask the host for a fresh auth token. The host may also use the response
|
|
26
|
-
* override league/match context — when it does, we prefer its values
|
|
27
|
-
* whatever was on the URL.
|
|
28
|
+
* Ask the host for a fresh auth token. The host may also use the response
|
|
29
|
+
* to override league/match context — when it does, we prefer its values.
|
|
28
30
|
*/
|
|
29
31
|
export declare function getAuthTokenFromParent(): Promise<string | null>;
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
+
* Proxy an HTTP request to the GameHub backend through the host page.
|
|
34
|
+
*
|
|
35
|
+
* The host frame is same-origin with the GameHub API, so it performs the
|
|
36
|
+
* real `fetch` and posts the parsed JSON envelope back. This keeps the SDK
|
|
37
|
+
* (and the game it lives in) from ever issuing a cross-origin request to the
|
|
38
|
+
* backend — which would otherwise fail CORS when the game is served from a
|
|
39
|
+
* different domain than GameHub.
|
|
40
|
+
*
|
|
41
|
+
* The protocol mirrors the bootstrap/auth handshakes: a `messageId`-keyed
|
|
42
|
+
* `API_REQUEST` is answered by exactly one `API_RESPONSE`. Resolves with the
|
|
43
|
+
* parsed {@link ApiResponse}; rejects on host-reported failure or timeout so
|
|
44
|
+
* the existing per-call `try/catch` degradation paths fire unchanged.
|
|
45
|
+
*/
|
|
46
|
+
export declare function requestApiFromParent(endpoint: string, options?: ApiRequestOptions): Promise<ApiResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Fire a namespaced message up to the host window. Silently no-ops when
|
|
49
|
+
* we aren't inside an iframe.
|
|
33
50
|
*/
|
|
34
51
|
export declare function sendToParent(type: string, data: Record<string, any>): void;
|
|
35
52
|
//# sourceMappingURL=bridge.d.ts.map
|
package/dist/src/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA+BtE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,eAAoB,GAAG,IAAI,CA4CvE;AAmBD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA4D5E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0C/D;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,WAAW,CAAC,CAkDtB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAU1E"}
|
package/dist/src/bridge.js
CHANGED
|
@@ -1,169 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-origin communication layer between the game iframe and its host page.
|
|
3
3
|
*
|
|
4
|
-
* Messages are namespaced with `MESSAGE_PREFIX` so we don't pick up
|
|
5
|
-
* postMessage traffic. The host
|
|
6
|
-
*
|
|
4
|
+
* Messages are namespaced with `MESSAGE_PREFIX` so we don't pick up
|
|
5
|
+
* unrelated postMessage traffic. The host implements a small protocol:
|
|
6
|
+
* - `BOOTSTRAP_REQUEST` ⇄ `BOOTSTRAP` (initial config + multiplayer)
|
|
7
|
+
* - `AUTH_REQUEST` ⇄ `AUTH_RESPONSE` (refresh the bearer token)
|
|
8
|
+
* - `READY` / `INIT` / `SESSION_STARTED` / `SCORE_SUBMITTED` / etc.
|
|
9
|
+
* (one-way SDK → host signals)
|
|
7
10
|
*/
|
|
8
11
|
import { state } from './state.js';
|
|
9
|
-
import { MESSAGE_PREFIX, PARENT_REQUEST_TIMEOUT_MS } from './constants.js';
|
|
12
|
+
import { MESSAGE_PREFIX, PARENT_REQUEST_TIMEOUT_MS, HOST_API_TIMEOUT_MS, } from './constants.js';
|
|
10
13
|
import { isBrowser } from './utils.js';
|
|
14
|
+
function trimToNullable(value) {
|
|
15
|
+
if (value === null)
|
|
16
|
+
return null;
|
|
17
|
+
if (typeof value !== 'string')
|
|
18
|
+
return undefined;
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
return trimmed ? trimmed : null;
|
|
21
|
+
}
|
|
22
|
+
function parseMultiplayer(value) {
|
|
23
|
+
if (value === null)
|
|
24
|
+
return null;
|
|
25
|
+
if (!value || typeof value !== 'object')
|
|
26
|
+
return undefined;
|
|
27
|
+
const { reservation, wsEndpoint } = value;
|
|
28
|
+
if (!reservation ||
|
|
29
|
+
typeof reservation !== 'object' ||
|
|
30
|
+
typeof reservation.name !== 'string' ||
|
|
31
|
+
typeof reservation.sessionId !== 'string' ||
|
|
32
|
+
typeof reservation.roomId !== 'string' ||
|
|
33
|
+
typeof wsEndpoint !== 'string') {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
reservation,
|
|
38
|
+
wsEndpoint: wsEndpoint.trim(),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
11
41
|
/**
|
|
12
42
|
* Fold a {@link BootstrapConfig} from the host into internal state. Accepts
|
|
13
|
-
* partial configs: only
|
|
14
|
-
*
|
|
43
|
+
* partial configs: only fields the host explicitly set (including explicit
|
|
44
|
+
* `null`s used to clear a value) are applied.
|
|
15
45
|
*/
|
|
16
46
|
export function mergeBootstrapConfig(config = {}) {
|
|
17
47
|
if (!config || typeof config !== 'object')
|
|
18
48
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
state
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
state.
|
|
45
|
-
}
|
|
46
|
-
if (typeof config.participant1Id === 'string' &&
|
|
47
|
-
config.participant1Id.trim()) {
|
|
48
|
-
state.participant1Id = config.participant1Id.trim();
|
|
49
|
-
}
|
|
50
|
-
else if (config.participant1Id === null) {
|
|
51
|
-
state.participant1Id = null;
|
|
52
|
-
}
|
|
53
|
-
if (typeof config.participant2Id === 'string' &&
|
|
54
|
-
config.participant2Id.trim()) {
|
|
55
|
-
state.participant2Id = config.participant2Id.trim();
|
|
56
|
-
}
|
|
57
|
-
else if (config.participant2Id === null) {
|
|
58
|
-
state.participant2Id = null;
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(config.participant1MemberIds)) {
|
|
61
|
-
state.participant1MemberIds = config.participant1MemberIds.filter(Boolean);
|
|
62
|
-
}
|
|
63
|
-
if (Array.isArray(config.participant2MemberIds)) {
|
|
64
|
-
state.participant2MemberIds = config.participant2MemberIds.filter(Boolean);
|
|
65
|
-
}
|
|
66
|
-
if (typeof config.playerName === 'string' && config.playerName.trim()) {
|
|
67
|
-
state.bootstrapPlayerName = config.playerName.trim();
|
|
68
|
-
}
|
|
69
|
-
else if (config.playerName === null) {
|
|
70
|
-
state.bootstrapPlayerName = null;
|
|
71
|
-
}
|
|
72
|
-
if (typeof config.peerId === 'string' && config.peerId.trim()) {
|
|
73
|
-
state.bootstrapPeerId = config.peerId.trim();
|
|
74
|
-
}
|
|
75
|
-
else if (config.peerId === null) {
|
|
76
|
-
state.bootstrapPeerId = null;
|
|
77
|
-
}
|
|
78
|
-
// `room` is an object on the wire so roomCode/shareId/maxPlayers and
|
|
79
|
-
// optional live join credentials stay grouped — but SDK state keeps them
|
|
80
|
-
// flat to avoid allocating a fresh object on every merge and to keep
|
|
81
|
-
// URL-seeded values (e.g. from `?roomCode=`) in the same place.
|
|
82
|
-
if (config.room && typeof config.room === 'object') {
|
|
83
|
-
const room = config.room;
|
|
84
|
-
if (typeof room.roomCode === 'string' && room.roomCode.trim()) {
|
|
85
|
-
state.bootstrapRoomCode = room.roomCode.trim().toUpperCase();
|
|
86
|
-
}
|
|
87
|
-
else if (room.roomCode === null) {
|
|
88
|
-
state.bootstrapRoomCode = null;
|
|
89
|
-
}
|
|
90
|
-
if (typeof room.shareId === 'string' && room.shareId.trim()) {
|
|
91
|
-
state.bootstrapShareId = room.shareId.trim();
|
|
92
|
-
}
|
|
93
|
-
else if (room.shareId === null) {
|
|
94
|
-
state.bootstrapShareId = null;
|
|
95
|
-
}
|
|
96
|
-
if (typeof room.maxPlayers === 'number' &&
|
|
97
|
-
Number.isFinite(room.maxPlayers)) {
|
|
98
|
-
state.bootstrapMaxPlayers = room.maxPlayers;
|
|
99
|
-
}
|
|
100
|
-
else if (room.maxPlayers === null) {
|
|
101
|
-
state.bootstrapMaxPlayers = null;
|
|
102
|
-
}
|
|
103
|
-
if (typeof room.role === 'string' && room.role.trim()) {
|
|
104
|
-
state.bootstrapRoomRole = room.role.trim();
|
|
105
|
-
}
|
|
106
|
-
else if (room.role === null) {
|
|
107
|
-
state.bootstrapRoomRole = null;
|
|
108
|
-
}
|
|
109
|
-
if (typeof room.roomToken === 'string' && room.roomToken.trim()) {
|
|
110
|
-
state.bootstrapRoomToken = room.roomToken.trim();
|
|
111
|
-
}
|
|
112
|
-
else if (room.roomToken === null) {
|
|
113
|
-
state.bootstrapRoomToken = null;
|
|
114
|
-
}
|
|
115
|
-
if (typeof room.wsUrl === 'string' && room.wsUrl.trim()) {
|
|
116
|
-
state.bootstrapWsUrl = room.wsUrl.trim();
|
|
117
|
-
}
|
|
118
|
-
else if (room.wsUrl === null) {
|
|
119
|
-
state.bootstrapWsUrl = null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else if (config.room === null) {
|
|
123
|
-
state.bootstrapRoomCode = null;
|
|
124
|
-
state.bootstrapShareId = null;
|
|
125
|
-
state.bootstrapMaxPlayers = null;
|
|
126
|
-
state.bootstrapRoomRole = null;
|
|
127
|
-
state.bootstrapRoomToken = null;
|
|
128
|
-
state.bootstrapWsUrl = null;
|
|
49
|
+
const apply = (key, raw) => {
|
|
50
|
+
const next = trimToNullable(raw);
|
|
51
|
+
if (next === undefined)
|
|
52
|
+
return;
|
|
53
|
+
state[key] = next;
|
|
54
|
+
};
|
|
55
|
+
apply('gameSlug', config.gameSlug);
|
|
56
|
+
apply('authToken', config.authToken);
|
|
57
|
+
apply('leagueId', config.leagueId);
|
|
58
|
+
apply('gameId', config.gameId);
|
|
59
|
+
apply('matchId', config.matchId);
|
|
60
|
+
const applyBootstrap = (key, raw) => {
|
|
61
|
+
const next = trimToNullable(raw);
|
|
62
|
+
if (next === undefined)
|
|
63
|
+
return;
|
|
64
|
+
state[key] = next;
|
|
65
|
+
};
|
|
66
|
+
applyBootstrap('bootstrapMode', config.mode);
|
|
67
|
+
applyBootstrap('bootstrapPlayerName', config.playerName);
|
|
68
|
+
applyBootstrap('bootstrapPlayerCount', config.playerCount);
|
|
69
|
+
applyBootstrap('bootstrapTeamOneName', config.teamOneName);
|
|
70
|
+
applyBootstrap('bootstrapTeamTwoName', config.teamTwoName);
|
|
71
|
+
applyBootstrap('bootstrapProfileId', config.profileId);
|
|
72
|
+
const mp = parseMultiplayer(config.multiplayer);
|
|
73
|
+
if (mp !== undefined) {
|
|
74
|
+
state.bootstrapMultiplayer = mp;
|
|
129
75
|
}
|
|
130
76
|
}
|
|
77
|
+
function snapshotBootstrap() {
|
|
78
|
+
return {
|
|
79
|
+
gameSlug: state.gameSlug,
|
|
80
|
+
authToken: state.authToken,
|
|
81
|
+
leagueId: state.leagueId,
|
|
82
|
+
gameId: state.gameId,
|
|
83
|
+
matchId: state.matchId,
|
|
84
|
+
mode: state.bootstrapMode,
|
|
85
|
+
playerName: state.bootstrapPlayerName,
|
|
86
|
+
playerCount: state.bootstrapPlayerCount,
|
|
87
|
+
teamOneName: state.bootstrapTeamOneName,
|
|
88
|
+
teamTwoName: state.bootstrapTeamTwoName,
|
|
89
|
+
profileId: state.bootstrapProfileId,
|
|
90
|
+
multiplayer: state.bootstrapMultiplayer,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
131
93
|
/**
|
|
132
94
|
* Ask the host for its bootstrap payload. Resolves `null` if the game is
|
|
133
|
-
* standalone (no parent)
|
|
134
|
-
* if we're not in an iframe.
|
|
95
|
+
* standalone (no parent) or the host doesn't reply within the timeout.
|
|
135
96
|
*
|
|
136
|
-
* Subsequent calls after a successful bootstrap short-circuit to the
|
|
137
|
-
* state snapshot.
|
|
97
|
+
* Subsequent calls after a successful bootstrap short-circuit to the
|
|
98
|
+
* cached state snapshot.
|
|
138
99
|
*/
|
|
139
100
|
export function requestBootstrapFromParent() {
|
|
140
101
|
if (!isBrowser() || window.parent === window) {
|
|
141
102
|
return Promise.resolve(null);
|
|
142
103
|
}
|
|
143
104
|
if (state.bootstrapReceived) {
|
|
144
|
-
return Promise.resolve(
|
|
145
|
-
gameSlug: state.gameSlug,
|
|
146
|
-
authToken: state.authToken,
|
|
147
|
-
leagueId: state.leagueId,
|
|
148
|
-
gameId: state.gameId,
|
|
149
|
-
matchId: state.matchId,
|
|
150
|
-
participant1Id: state.participant1Id,
|
|
151
|
-
participant2Id: state.participant2Id,
|
|
152
|
-
participant1MemberIds: state.participant1MemberIds,
|
|
153
|
-
participant2MemberIds: state.participant2MemberIds,
|
|
154
|
-
playerName: state.bootstrapPlayerName,
|
|
155
|
-
peerId: state.bootstrapPeerId,
|
|
156
|
-
room: state.bootstrapRoomCode
|
|
157
|
-
? {
|
|
158
|
-
roomCode: state.bootstrapRoomCode,
|
|
159
|
-
shareId: state.bootstrapShareId,
|
|
160
|
-
maxPlayers: state.bootstrapMaxPlayers,
|
|
161
|
-
role: state.bootstrapRoomRole,
|
|
162
|
-
roomToken: state.bootstrapRoomToken,
|
|
163
|
-
wsUrl: state.bootstrapWsUrl,
|
|
164
|
-
}
|
|
165
|
-
: null,
|
|
166
|
-
});
|
|
105
|
+
return Promise.resolve(snapshotBootstrap());
|
|
167
106
|
}
|
|
168
107
|
if (state.bootstrapRequestPromise) {
|
|
169
108
|
return state.bootstrapRequestPromise;
|
|
@@ -209,9 +148,8 @@ export function requestBootstrapFromParent() {
|
|
|
209
148
|
return state.bootstrapRequestPromise;
|
|
210
149
|
}
|
|
211
150
|
/**
|
|
212
|
-
* Ask the host for a fresh auth token. The host may also use the response
|
|
213
|
-
* override league/match context — when it does, we prefer its values
|
|
214
|
-
* whatever was on the URL.
|
|
151
|
+
* Ask the host for a fresh auth token. The host may also use the response
|
|
152
|
+
* to override league/match context — when it does, we prefer its values.
|
|
215
153
|
*/
|
|
216
154
|
export function getAuthTokenFromParent() {
|
|
217
155
|
return new Promise((resolve) => {
|
|
@@ -233,23 +171,12 @@ export function getAuthTokenFromParent() {
|
|
|
233
171
|
if (timeoutId)
|
|
234
172
|
clearTimeout(timeoutId);
|
|
235
173
|
state.parentOrigin = event.origin;
|
|
236
|
-
// Host-supplied context wins over URL params.
|
|
237
174
|
if (event.data.leagueId)
|
|
238
175
|
state.leagueId = event.data.leagueId;
|
|
239
176
|
if (event.data.gameId)
|
|
240
177
|
state.gameId = event.data.gameId;
|
|
241
178
|
if (event.data.matchId)
|
|
242
179
|
state.matchId = event.data.matchId;
|
|
243
|
-
if (event.data.participant1Id)
|
|
244
|
-
state.participant1Id = event.data.participant1Id;
|
|
245
|
-
if (event.data.participant2Id)
|
|
246
|
-
state.participant2Id = event.data.participant2Id;
|
|
247
|
-
if (Array.isArray(event.data.participant1MemberIds))
|
|
248
|
-
state.participant1MemberIds =
|
|
249
|
-
event.data.participant1MemberIds.filter(Boolean);
|
|
250
|
-
if (Array.isArray(event.data.participant2MemberIds))
|
|
251
|
-
state.participant2MemberIds =
|
|
252
|
-
event.data.participant2MemberIds.filter(Boolean);
|
|
253
180
|
resolve(event.data.token || null);
|
|
254
181
|
}
|
|
255
182
|
};
|
|
@@ -264,9 +191,71 @@ export function getAuthTokenFromParent() {
|
|
|
264
191
|
}, PARENT_REQUEST_TIMEOUT_MS);
|
|
265
192
|
});
|
|
266
193
|
}
|
|
194
|
+
/** Monotonic counter so concurrent API proxy requests get distinct ids. */
|
|
195
|
+
let apiRequestSeq = 0;
|
|
196
|
+
/**
|
|
197
|
+
* Proxy an HTTP request to the GameHub backend through the host page.
|
|
198
|
+
*
|
|
199
|
+
* The host frame is same-origin with the GameHub API, so it performs the
|
|
200
|
+
* real `fetch` and posts the parsed JSON envelope back. This keeps the SDK
|
|
201
|
+
* (and the game it lives in) from ever issuing a cross-origin request to the
|
|
202
|
+
* backend — which would otherwise fail CORS when the game is served from a
|
|
203
|
+
* different domain than GameHub.
|
|
204
|
+
*
|
|
205
|
+
* The protocol mirrors the bootstrap/auth handshakes: a `messageId`-keyed
|
|
206
|
+
* `API_REQUEST` is answered by exactly one `API_RESPONSE`. Resolves with the
|
|
207
|
+
* parsed {@link ApiResponse}; rejects on host-reported failure or timeout so
|
|
208
|
+
* the existing per-call `try/catch` degradation paths fire unchanged.
|
|
209
|
+
*/
|
|
210
|
+
export function requestApiFromParent(endpoint, options = {}) {
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
if (!isBrowser() || window.parent === window) {
|
|
213
|
+
reject(new Error('Host bridge unavailable: not running in an iframe'));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const messageId = 'api_' + Date.now().toString() + '_' + ++apiRequestSeq;
|
|
217
|
+
let settled = false;
|
|
218
|
+
let timeoutId = null;
|
|
219
|
+
const handler = (event) => {
|
|
220
|
+
if (!event.data ||
|
|
221
|
+
event.data.type !== MESSAGE_PREFIX + '_API_RESPONSE' ||
|
|
222
|
+
event.data.messageId !== messageId) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (settled)
|
|
226
|
+
return;
|
|
227
|
+
settled = true;
|
|
228
|
+
window.removeEventListener('message', handler);
|
|
229
|
+
if (timeoutId)
|
|
230
|
+
clearTimeout(timeoutId);
|
|
231
|
+
state.parentOrigin = event.origin;
|
|
232
|
+
if (event.data.ok) {
|
|
233
|
+
resolve((event.data.result ?? {}));
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
reject(new Error(event.data.error || 'Host API request failed'));
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
window.addEventListener('message', handler);
|
|
240
|
+
window.parent.postMessage({
|
|
241
|
+
type: MESSAGE_PREFIX + '_API_REQUEST',
|
|
242
|
+
messageId,
|
|
243
|
+
endpoint,
|
|
244
|
+
method: options.method || 'GET',
|
|
245
|
+
body: options.body ?? null,
|
|
246
|
+
}, state.parentOrigin || '*');
|
|
247
|
+
timeoutId = setTimeout(() => {
|
|
248
|
+
if (settled)
|
|
249
|
+
return;
|
|
250
|
+
settled = true;
|
|
251
|
+
window.removeEventListener('message', handler);
|
|
252
|
+
reject(new Error('Host API request timed out'));
|
|
253
|
+
}, HOST_API_TIMEOUT_MS);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
267
256
|
/**
|
|
268
|
-
* Fire a namespaced message up to the host window. Silently no-ops when
|
|
269
|
-
* aren't inside an iframe.
|
|
257
|
+
* Fire a namespaced message up to the host window. Silently no-ops when
|
|
258
|
+
* we aren't inside an iframe.
|
|
270
259
|
*/
|
|
271
260
|
export function sendToParent(type, data) {
|
|
272
261
|
if (!isBrowser() || window.parent === window)
|
package/dist/src/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOvC,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,C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
* Bundle version reported by the SDK. Bumped at release time.
|
|
3
3
|
*/
|
|
4
|
-
export declare const SDK_VERSION = "
|
|
4
|
+
export declare const SDK_VERSION = "3.6.0";
|
|
5
5
|
/**
|
|
6
6
|
* Prefix applied to every cross-origin postMessage the SDK emits and accepts.
|
|
7
7
|
* Keeps our messages isolated from unrelated frames on the same page.
|
|
@@ -9,10 +9,12 @@ export declare const SDK_VERSION = "0.7.0";
|
|
|
9
9
|
export declare const MESSAGE_PREFIX = "GAMEHUB_SDK";
|
|
10
10
|
/** How long to wait for the host to reply to bootstrap/auth requests. */
|
|
11
11
|
export declare const PARENT_REQUEST_TIMEOUT_MS = 2000;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
13
|
+
* How long to wait for the host to proxy an HTTP API request back to the
|
|
14
|
+
* SDK. Larger than {@link PARENT_REQUEST_TIMEOUT_MS} because this round-trip
|
|
15
|
+
* includes the host's real network call to the GameHub backend.
|
|
16
|
+
*/
|
|
17
|
+
export declare const HOST_API_TIMEOUT_MS = 15000;
|
|
18
|
+
/** Upper bound on questions returned per `getQuestions` call. */
|
|
17
19
|
export declare const QUESTIONS_LIMIT_CAP = 100;
|
|
18
20
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC;;;GAGG;AACH,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC;;;GAGG;AACH,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
|
package/dist/src/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundle version reported by the SDK. Bumped at release time.
|
|
3
3
|
*/
|
|
4
|
-
export const SDK_VERSION = '
|
|
4
|
+
export const SDK_VERSION = '3.6.0';
|
|
5
5
|
/**
|
|
6
6
|
* Prefix applied to every cross-origin postMessage the SDK emits and accepts.
|
|
7
7
|
* Keeps our messages isolated from unrelated frames on the same page.
|
|
@@ -9,10 +9,12 @@ export const SDK_VERSION = '0.7.0';
|
|
|
9
9
|
export const MESSAGE_PREFIX = 'GAMEHUB_SDK';
|
|
10
10
|
/** How long to wait for the host to reply to bootstrap/auth requests. */
|
|
11
11
|
export const PARENT_REQUEST_TIMEOUT_MS = 2000;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
13
|
+
* How long to wait for the host to proxy an HTTP API request back to the
|
|
14
|
+
* SDK. Larger than {@link PARENT_REQUEST_TIMEOUT_MS} because this round-trip
|
|
15
|
+
* includes the host's real network call to the GameHub backend.
|
|
16
|
+
*/
|
|
17
|
+
export const HOST_API_TIMEOUT_MS = 15000;
|
|
18
|
+
/** Upper bound on questions returned per `getQuestions` call. */
|
|
17
19
|
export const QUESTIONS_LIMIT_CAP = 100;
|
|
18
20
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAE5C,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAE5C,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC"}
|
package/dist/src/init.d.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
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
|
/**
|
|
11
|
-
* One-off environment detection. Should be called exactly once at SDK
|
|
12
|
-
* time, before any other
|
|
13
|
-
*
|
|
16
|
+
* One-off environment detection. Should be called exactly once at SDK
|
|
17
|
+
* boot time, before any other init function. Idempotent and safe to call
|
|
18
|
+
* outside a browser (no-op).
|
|
14
19
|
*/
|
|
15
20
|
export declare function detectEnvironment(): void;
|
|
16
21
|
/**
|
|
17
22
|
* Orchestrates the full SDK boot sequence:
|
|
18
23
|
* 1. Request bootstrap config from the host (seeds slug + context).
|
|
19
24
|
* 2. Exchange for an auth token if we don't already have one.
|
|
20
|
-
* 3. Notify the host that we've booted
|
|
21
|
-
* 4. Open a session if we can, and
|
|
25
|
+
* 3. Notify the host that we've booted.
|
|
26
|
+
* 4. Open a session if we can, and reconnect to the Colyseus room when
|
|
27
|
+
* the host gave us a `multiplayer` block.
|
|
22
28
|
*
|
|
23
29
|
* Safe to call multiple times — concurrent callers share a single promise.
|
|
24
30
|
*/
|
|
@@ -29,8 +35,8 @@ export declare function autoInit(): Promise<boolean>;
|
|
|
29
35
|
*/
|
|
30
36
|
export declare function ensureInitialized(): Promise<boolean>;
|
|
31
37
|
/**
|
|
32
|
-
* Wires up the ambient message listener the host uses to push updates
|
|
33
|
-
* the running SDK (fresh bootstrap, rotated auth, pause/resume
|
|
38
|
+
* Wires up the ambient message listener the host uses to push updates
|
|
39
|
+
* into the running SDK (fresh bootstrap, rotated auth, pause/resume).
|
|
34
40
|
*/
|
|
35
41
|
export declare function installHostMessageListener(): void;
|
|
36
42
|
//# sourceMappingURL=init.d.ts.map
|
package/dist/src/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CA2DxC;AAED;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,CAkDjD;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAK1D;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAyCjD"}
|