@ksaa-nlp/gamehub-sdk 0.1.0 → 0.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/CHANGELOG.md +294 -0
- package/MIGRATION.md +322 -0
- package/README.md +121 -182
- package/dist/gamehub-sdk.js +1202 -1670
- package/dist/gamehub-sdk.js.map +7 -0
- package/dist/src/api-client.d.ts +11 -0
- package/dist/src/api-client.d.ts.map +1 -0
- package/dist/src/api-client.js +27 -0
- package/dist/src/api-client.js.map +1 -0
- package/dist/src/bridge.d.ts +35 -0
- package/dist/src/bridge.d.ts.map +1 -0
- package/dist/src/bridge.js +280 -0
- package/dist/src/bridge.js.map +1 -0
- package/dist/src/browser-entry.d.ts +19 -0
- package/dist/src/browser-entry.d.ts.map +1 -0
- package/dist/src/browser-entry.js +49 -0
- package/dist/src/browser-entry.js.map +1 -0
- package/dist/src/constants.d.ts +18 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +18 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/init.d.ts +36 -0
- package/dist/src/init.d.ts.map +1 -0
- package/dist/src/init.js +317 -0
- package/dist/src/init.js.map +1 -0
- package/dist/src/main.d.ts +101 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +126 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/match-context.d.ts +11 -0
- package/dist/src/match-context.d.ts.map +1 -0
- package/dist/src/match-context.js +51 -0
- package/dist/src/match-context.js.map +1 -0
- package/dist/src/multiplayer.d.ts +82 -0
- package/dist/src/multiplayer.d.ts.map +1 -0
- package/dist/src/multiplayer.js +461 -0
- package/dist/src/multiplayer.js.map +1 -0
- package/dist/src/session.d.ts +35 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +206 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/state.d.ts +71 -0
- package/dist/src/state.d.ts.map +1 -0
- package/dist/src/state.js +55 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/utils.d.ts +36 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +73 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/types/api.d.ts +21 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/{types/bootstrap.ts → dist/types/bootstrap.d.ts} +26 -29
- package/dist/types/bootstrap.d.ts.map +1 -0
- package/dist/types/bootstrap.js +2 -0
- package/dist/types/bootstrap.js.map +1 -0
- package/dist/types/match.d.ts +37 -0
- package/dist/types/match.d.ts.map +1 -0
- package/dist/types/match.js +2 -0
- package/dist/types/match.js.map +1 -0
- package/dist/types/multiplayer.d.ts +138 -0
- package/dist/types/multiplayer.d.ts.map +1 -0
- package/dist/types/multiplayer.js +2 -0
- package/dist/types/multiplayer.js.map +1 -0
- package/{types/session.ts → dist/types/session.d.ts} +24 -30
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +2 -0
- package/dist/types/session.js.map +1 -0
- package/package.json +34 -18
- package/dist/gamehub-sdk.d.ts +0 -694
- package/dist/index.d.ts +0 -56
- package/dist/index.mjs +0 -6
- package/scripts/emit-module-entry.mjs +0 -96
- package/src/api-client.ts +0 -33
- package/src/bridge.ts +0 -312
- package/src/constants.ts +0 -24
- package/src/init.ts +0 -335
- package/src/main.ts +0 -287
- package/src/match-context.ts +0 -52
- package/src/multiplayer.ts +0 -525
- package/src/session.ts +0 -240
- package/src/state.ts +0 -78
- package/src/utils.ts +0 -68
- package/tsconfig.json +0 -33
- package/types/api.ts +0 -21
- package/types/match.ts +0 -41
- package/types/multiplayer.ts +0 -118
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { state } from './state.js';
|
|
2
|
+
import { QUESTIONS_LIMIT_CAP } from './constants.js';
|
|
3
|
+
import { apiRequest } from './api-client.js';
|
|
4
|
+
import { unwrapResult, warn } from './utils.js';
|
|
5
|
+
import { sendToParent } from './bridge.js';
|
|
6
|
+
import { ensureInitialized } from './init.js';
|
|
7
|
+
/**
|
|
8
|
+
* Starts a new game session and caches the returned session token. Safe to
|
|
9
|
+
* call multiple times — the cached token short-circuits subsequent calls.
|
|
10
|
+
*
|
|
11
|
+
* Endpoint is selected from the active context:
|
|
12
|
+
* - league + game + match → scoped match session
|
|
13
|
+
* - league + game → scoped league session
|
|
14
|
+
* - otherwise → standalone session (requires auth)
|
|
15
|
+
*/
|
|
16
|
+
export async function startSession() {
|
|
17
|
+
if (!state.gameSlug)
|
|
18
|
+
return { success: false, error: 'Game slug not set' };
|
|
19
|
+
const isLeagueMatchSession = Boolean(state.leagueId && state.gameId && state.matchId);
|
|
20
|
+
if (!state.authToken && !isLeagueMatchSession) {
|
|
21
|
+
return { success: false, error: 'User not authenticated' };
|
|
22
|
+
}
|
|
23
|
+
if (state.sessionToken)
|
|
24
|
+
return { success: true, token: state.sessionToken };
|
|
25
|
+
try {
|
|
26
|
+
let endpoint = '/sessions/start';
|
|
27
|
+
let body = { gameSlug: state.gameSlug };
|
|
28
|
+
if (state.leagueId && state.gameId && state.matchId) {
|
|
29
|
+
endpoint =
|
|
30
|
+
'/leagues/' +
|
|
31
|
+
state.leagueId +
|
|
32
|
+
'/matches/' +
|
|
33
|
+
state.matchId +
|
|
34
|
+
'/session';
|
|
35
|
+
body = { gameId: state.gameId };
|
|
36
|
+
}
|
|
37
|
+
else if (state.leagueId && state.gameId) {
|
|
38
|
+
endpoint = '/leagues/' + state.leagueId + '/sessions';
|
|
39
|
+
body = { gameId: state.gameId };
|
|
40
|
+
}
|
|
41
|
+
const result = await apiRequest(endpoint, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
body,
|
|
44
|
+
});
|
|
45
|
+
const data = unwrapResult(result);
|
|
46
|
+
if (result.success || data?.token) {
|
|
47
|
+
state.sessionToken = data?.token || result?.token || null;
|
|
48
|
+
sendToParent('SESSION_STARTED', { token: state.sessionToken });
|
|
49
|
+
return { success: true, token: state.sessionToken };
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
error: result.error?.message || 'Failed to start session',
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return { success: false, error: err.message };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Submit a score to the current session. If no session exists yet we try to
|
|
62
|
+
* open one (re-using any in-flight start attempt).
|
|
63
|
+
*/
|
|
64
|
+
export async function submitScore(score, meta = {}) {
|
|
65
|
+
await ensureInitialized();
|
|
66
|
+
if (!state.isInitialized) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: 'SDK could not initialize. Is game slug set?',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Online-mode gate: when the SDK is joined to a multiplayer room, only the
|
|
73
|
+
// host is allowed to submit. Guests and viewers short-circuit with
|
|
74
|
+
// `{ skipped: true }` so games can call `submitScore` from shared code
|
|
75
|
+
// without double-counting the match.
|
|
76
|
+
if (state.mpRoom && state.mpRoom.role !== 'host') {
|
|
77
|
+
warn('submitScore skipped: only the multiplayer host may submit scores');
|
|
78
|
+
return { success: true, skipped: true };
|
|
79
|
+
}
|
|
80
|
+
if (!state.sessionToken) {
|
|
81
|
+
if (state.sessionStartPromise) {
|
|
82
|
+
await state.sessionStartPromise;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const sessionResult = await startSession();
|
|
86
|
+
if (!sessionResult.success) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: sessionResult.error || 'Could not start session',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!state.sessionToken) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: 'No active session. User may not be authenticated.',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (typeof score !== 'number' || score < 0) {
|
|
101
|
+
return { success: false, error: 'Score must be a non-negative number' };
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const result = await apiRequest('/sessions/submit', {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
body: {
|
|
107
|
+
token: state.sessionToken,
|
|
108
|
+
score: Math.floor(score),
|
|
109
|
+
meta,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const data = unwrapResult(result);
|
|
113
|
+
if (result.success || data?.accepted) {
|
|
114
|
+
sendToParent('SCORE_SUBMITTED', {
|
|
115
|
+
score,
|
|
116
|
+
accepted: data?.accepted,
|
|
117
|
+
timeTaken: data?.timeTaken,
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
accepted: data?.accepted,
|
|
122
|
+
timeTaken: data?.timeTaken,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
error: result.error?.message || 'Score rejected',
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
return { success: false, error: err.message };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convenience wrapper that tags a score with the current league match
|
|
136
|
+
* context. Fails early if there's no matchId — a plain `submitScore` is the
|
|
137
|
+
* right call in that case.
|
|
138
|
+
*/
|
|
139
|
+
export async function submitMatchScore(score, meta = {}) {
|
|
140
|
+
if (!state.matchId) {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
error: 'No matchId found for this game session',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return await submitScore(score, {
|
|
147
|
+
...(meta || {}),
|
|
148
|
+
matchId: state.matchId,
|
|
149
|
+
leagueId: state.leagueId || meta.leagueId,
|
|
150
|
+
gameId: state.gameId || meta.gameId,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Submit a match result (winner, scores, etc.) with a zero placeholder
|
|
155
|
+
* score — the server derives the real leaderboard entries from the result
|
|
156
|
+
* payload.
|
|
157
|
+
*/
|
|
158
|
+
export async function submitMatchResult(result = {}) {
|
|
159
|
+
if (!result || typeof result !== 'object') {
|
|
160
|
+
return { success: false, error: 'match result payload is required' };
|
|
161
|
+
}
|
|
162
|
+
return await submitMatchScore(0, { matchResult: result });
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Fetch questions for this game. Returns an empty array on any failure or
|
|
166
|
+
* invalid input — callers can treat "no questions" as the degraded state.
|
|
167
|
+
*/
|
|
168
|
+
export async function getQuestions(options = {}) {
|
|
169
|
+
await ensureInitialized();
|
|
170
|
+
const gameIdentifier = state.gameId || state.gameSlug;
|
|
171
|
+
if (!gameIdentifier)
|
|
172
|
+
return [];
|
|
173
|
+
const { difficulty, category, limit } = options;
|
|
174
|
+
if (difficulty && !['easy', 'medium', 'hard'].includes(difficulty)) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
if (limit !== undefined && (typeof limit !== 'number' || limit < 1)) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const params = new URLSearchParams({
|
|
182
|
+
limit: String(Math.min(limit || QUESTIONS_LIMIT_CAP, QUESTIONS_LIMIT_CAP)),
|
|
183
|
+
random: 'true',
|
|
184
|
+
});
|
|
185
|
+
if (state.gameId)
|
|
186
|
+
params.set('gameId', state.gameId);
|
|
187
|
+
if (difficulty)
|
|
188
|
+
params.set('difficulty', difficulty);
|
|
189
|
+
if (category)
|
|
190
|
+
params.set('category', String(category));
|
|
191
|
+
const result = await apiRequest('/games/' +
|
|
192
|
+
encodeURIComponent(gameIdentifier) +
|
|
193
|
+
'/questions?' +
|
|
194
|
+
params.toString(), { method: 'GET' });
|
|
195
|
+
const data = unwrapResult(result);
|
|
196
|
+
if (Array.isArray(data))
|
|
197
|
+
return data;
|
|
198
|
+
if (!data || !Array.isArray(data.questions))
|
|
199
|
+
return [];
|
|
200
|
+
return data.questions;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAU9C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,CAAC,KAAK,CAAC,QAAQ;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAE3E,MAAM,oBAAoB,GAAG,OAAO,CAClC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAChD,CAAC;IACF,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC;IAC7D,CAAC;IACD,IAAI,KAAK,CAAC,YAAY;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;IAE5E,IAAI,CAAC;QACH,IAAI,QAAQ,GAAG,iBAAiB,CAAC;QACjC,IAAI,IAAI,GAAwB,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QAE7D,IAAI,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f,CAAC,CAAC;QACH,IAAI,KAAK,CAAC,MAAM;YAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,UAAU;YAAE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACrD,IAAI,QAAQ;YAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAC7B,SAAS;YACP,kBAAkB,CAAC,cAAc,CAAC;YAClC,aAAa;YACb,MAAM,CAAC,QAAQ,EAAE,EACnB,EAAE,MAAM,EAAE,KAAK,EAAE,CAClB,CAAC;QAEF,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACrC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,OAAO,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralised mutable state for the SDK singleton.
|
|
3
|
+
*
|
|
4
|
+
* Everything here lives on a single `state` object so the various feature
|
|
5
|
+
* modules can mutate it (`state.foo = bar`). ES modules don't allow
|
|
6
|
+
* reassigning imported `let` bindings from the consumer side, so a single
|
|
7
|
+
* shared object is the cleanest replacement for the previous namespace-with-
|
|
8
|
+
* `export let` pattern.
|
|
9
|
+
*/
|
|
10
|
+
import type { MatchContext } from '../types/match.js';
|
|
11
|
+
import type { BootstrapConfig } from '../types/bootstrap.js';
|
|
12
|
+
import type { StartSessionResult } from '../types/session.js';
|
|
13
|
+
import type { MpRoom, MpJoinRequest, Peer, MpEventHandler } from '../types/multiplayer.js';
|
|
14
|
+
export interface SdkState {
|
|
15
|
+
sdkOrigin: string;
|
|
16
|
+
sdkPathPrefix: string;
|
|
17
|
+
runtimeBasePath: string;
|
|
18
|
+
apiBase: string;
|
|
19
|
+
gameSlug: string | null;
|
|
20
|
+
sessionToken: string | null;
|
|
21
|
+
authToken: string | null;
|
|
22
|
+
leagueId: string | null;
|
|
23
|
+
gameId: string | null;
|
|
24
|
+
matchId: string | null;
|
|
25
|
+
participant1Id: string | null;
|
|
26
|
+
participant2Id: string | null;
|
|
27
|
+
participant1MemberIds: string[];
|
|
28
|
+
participant2MemberIds: string[];
|
|
29
|
+
matchContext: MatchContext | null;
|
|
30
|
+
matchContextPromise: Promise<MatchContext | null> | null;
|
|
31
|
+
bootstrapShareId: string | null;
|
|
32
|
+
bootstrapRoomCode: string | null;
|
|
33
|
+
bootstrapRoomRole: string | null;
|
|
34
|
+
bootstrapRoomToken: string | null;
|
|
35
|
+
bootstrapWsUrl: string | null;
|
|
36
|
+
bootstrapPlayerName: string | null;
|
|
37
|
+
bootstrapPeerId: string | null;
|
|
38
|
+
bootstrapMaxPlayers: number | null;
|
|
39
|
+
bootstrapReceived: boolean;
|
|
40
|
+
isInitialized: boolean;
|
|
41
|
+
isAutoInitializing: boolean;
|
|
42
|
+
autoInitPromise: Promise<boolean> | null;
|
|
43
|
+
bootstrapRequestPromise: Promise<BootstrapConfig | null> | null;
|
|
44
|
+
parentOrigin: string | null;
|
|
45
|
+
sessionStartPromise: Promise<StartSessionResult> | null;
|
|
46
|
+
lastAutoJoinShareId: string | null;
|
|
47
|
+
lastAutoJoinRoomCode: string | null;
|
|
48
|
+
mpSocket: WebSocket | null;
|
|
49
|
+
mpReconnectTimer: ReturnType<typeof setTimeout> | null;
|
|
50
|
+
mpReconnectAttempts: number;
|
|
51
|
+
mpExpectedClose: boolean;
|
|
52
|
+
mpRoom: MpRoom | null;
|
|
53
|
+
mpLastJoinRequest: MpJoinRequest | null;
|
|
54
|
+
readonly mpPeers: Map<string, Peer>;
|
|
55
|
+
readonly mpHandlers: Map<string, Set<MpEventHandler>>;
|
|
56
|
+
/**
|
|
57
|
+
* Highest `seq` we've already delivered to game code, per sending peer.
|
|
58
|
+
* Used to drop late/duplicate `game_event` frames so a reconnect or a
|
|
59
|
+
* buffered message can't double-advance game state.
|
|
60
|
+
*/
|
|
61
|
+
readonly mpLastSeqByPeer: Map<string, number>;
|
|
62
|
+
/**
|
|
63
|
+
* Local override for view-only guests. The server doesn't know about
|
|
64
|
+
* viewers — this is a client-side flag the SDK flips when the game joins
|
|
65
|
+
* with `{ asViewer: true }`. It gates outbound `send` / `broadcast` and
|
|
66
|
+
* score submission.
|
|
67
|
+
*/
|
|
68
|
+
mpViewerOverride: boolean;
|
|
69
|
+
}
|
|
70
|
+
export declare const state: SdkState;
|
|
71
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,IAAI,EACJ,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,QAAQ;IAEvB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAGhB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,I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AAG,IAAI,CAAC;IAC3B,gBAAgB,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC;IACvD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,aAAa,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IACtD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,KAAK,EAAE,QAiDnB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralised mutable state for the SDK singleton.
|
|
3
|
+
*
|
|
4
|
+
* Everything here lives on a single `state` object so the various feature
|
|
5
|
+
* modules can mutate it (`state.foo = bar`). ES modules don't allow
|
|
6
|
+
* reassigning imported `let` bindings from the consumer side, so a single
|
|
7
|
+
* shared object is the cleanest replacement for the previous namespace-with-
|
|
8
|
+
* `export let` pattern.
|
|
9
|
+
*/
|
|
10
|
+
export const state = {
|
|
11
|
+
sdkOrigin: '',
|
|
12
|
+
sdkPathPrefix: '',
|
|
13
|
+
runtimeBasePath: '',
|
|
14
|
+
apiBase: '',
|
|
15
|
+
gameSlug: null,
|
|
16
|
+
sessionToken: null,
|
|
17
|
+
authToken: null,
|
|
18
|
+
leagueId: null,
|
|
19
|
+
gameId: null,
|
|
20
|
+
matchId: null,
|
|
21
|
+
participant1Id: null,
|
|
22
|
+
participant2Id: null,
|
|
23
|
+
participant1MemberIds: [],
|
|
24
|
+
participant2MemberIds: [],
|
|
25
|
+
matchContext: null,
|
|
26
|
+
matchContextPromise: null,
|
|
27
|
+
bootstrapShareId: null,
|
|
28
|
+
bootstrapRoomCode: null,
|
|
29
|
+
bootstrapRoomRole: null,
|
|
30
|
+
bootstrapRoomToken: null,
|
|
31
|
+
bootstrapWsUrl: null,
|
|
32
|
+
bootstrapPlayerName: null,
|
|
33
|
+
bootstrapPeerId: null,
|
|
34
|
+
bootstrapMaxPlayers: null,
|
|
35
|
+
bootstrapReceived: false,
|
|
36
|
+
isInitialized: false,
|
|
37
|
+
isAutoInitializing: false,
|
|
38
|
+
autoInitPromise: null,
|
|
39
|
+
bootstrapRequestPromise: null,
|
|
40
|
+
parentOrigin: null,
|
|
41
|
+
sessionStartPromise: null,
|
|
42
|
+
lastAutoJoinShareId: null,
|
|
43
|
+
lastAutoJoinRoomCode: null,
|
|
44
|
+
mpSocket: null,
|
|
45
|
+
mpReconnectTimer: null,
|
|
46
|
+
mpReconnectAttempts: 0,
|
|
47
|
+
mpExpectedClose: false,
|
|
48
|
+
mpRoom: null,
|
|
49
|
+
mpLastJoinRequest: null,
|
|
50
|
+
mpPeers: new Map(),
|
|
51
|
+
mpHandlers: new Map(),
|
|
52
|
+
mpLastSeqByPeer: new Map(),
|
|
53
|
+
mpViewerOverride: false,
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgFH,MAAM,CAAC,MAAM,KAAK,GAAa;IAC7B,SAAS,EAAE,EAAE;IACb,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,EAAE;IACnB,OAAO,EAAE,EAAE;IAEX,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,qBAAqB,EAAE,EAAE;IACzB,qBAAqB,EAAE,EAAE;IAEzB,YAAY,EAAE,IAAI;IAClB,mBAAmB,EAAE,IAAI;IAEzB,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,kBAAkB,EAAE,IAAI;IACxB,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,IAAI;IACzB,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,IAAI;IACzB,iBAAiB,EAAE,KAAK;IAExB,aAAa,EAAE,KAAK;IACpB,kBAAkB,EAAE,KAAK;IACzB,eAAe,EAAE,IAAI;IACrB,uBAAuB,EAAE,IAAI;IAC7B,YAAY,EAAE,IAAI;IAClB,mBAAmB,EAAE,IAAI;IACzB,mBAAmB,EAAE,IAAI;IACzB,oBAAoB,EAAE,IAAI;IAE1B,QAAQ,EAAE,IAAI;IACd,gBAAgB,EAAE,IAAI;IACtB,mBAAmB,EAAE,CAAC;IACtB,eAAe,EAAE,KAAK;IACtB,MAAM,EAAE,IAAI;IACZ,iBAAiB,EAAE,IAAI;IACvB,OAAO,EAAE,IAAI,GAAG,EAAE;IAClB,UAAU,EAAE,IAAI,GAAG,EAAE;IACrB,eAAe,EAAE,IAAI,GAAG,EAAE;IAC1B,gBAAgB,EAAE,KAAK;CACxB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* True when running in a browser-like environment (has both `window` and
|
|
4
|
+
* `document`). Used to short-circuit DOM-touching helpers so the package
|
|
5
|
+
* can be imported under Node / Angular SSR without throwing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBrowser(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Logs with a consistent `[GameHubSDK]` prefix so host-page developers can
|
|
10
|
+
* easily filter SDK messages in their console.
|
|
11
|
+
*/
|
|
12
|
+
export declare function warn(message: string, ...rest: any[]): void;
|
|
13
|
+
export declare function error(message: string, ...rest: any[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Flattens the standard `{ success, data }` envelope returned by our REST API
|
|
16
|
+
* down to the inner `data` payload, or returns the raw response if it isn't
|
|
17
|
+
* shaped that way.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unwrapResult(result: ApiResponse | null | undefined): any;
|
|
20
|
+
/**
|
|
21
|
+
* Extracts a share ID from either:
|
|
22
|
+
* - a full multiplayer URL (`/join?mp=<shareId>`), or
|
|
23
|
+
* - a short path where the last segment is the share ID itself.
|
|
24
|
+
* Returns null if the link can't be parsed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractShareIdFromLink(link: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Safely read a query-string parameter, falling back to a regex scan when
|
|
29
|
+
* URLSearchParams is unavailable (very old browsers / odd runtimes).
|
|
30
|
+
*/
|
|
31
|
+
export declare function readQueryParam(name: string): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Reads a CSV query parameter and returns the trimmed, non-empty values.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readCsvQueryParam(name: string): string[];
|
|
36
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE1D;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAIxE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASlE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMxD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when running in a browser-like environment (has both `window` and
|
|
3
|
+
* `document`). Used to short-circuit DOM-touching helpers so the package
|
|
4
|
+
* can be imported under Node / Angular SSR without throwing.
|
|
5
|
+
*/
|
|
6
|
+
export function isBrowser() {
|
|
7
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Logs with a consistent `[GameHubSDK]` prefix so host-page developers can
|
|
11
|
+
* easily filter SDK messages in their console.
|
|
12
|
+
*/
|
|
13
|
+
export function warn(message, ...rest) {
|
|
14
|
+
console.warn('[GameHubSDK] ' + message, ...rest);
|
|
15
|
+
}
|
|
16
|
+
export function error(message, ...rest) {
|
|
17
|
+
console.error('[GameHubSDK] ' + message, ...rest);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Flattens the standard `{ success, data }` envelope returned by our REST API
|
|
21
|
+
* down to the inner `data` payload, or returns the raw response if it isn't
|
|
22
|
+
* shaped that way.
|
|
23
|
+
*/
|
|
24
|
+
export function unwrapResult(result) {
|
|
25
|
+
if (!result)
|
|
26
|
+
return null;
|
|
27
|
+
if (result.success && result.data)
|
|
28
|
+
return result.data;
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extracts a share ID from either:
|
|
33
|
+
* - a full multiplayer URL (`/join?mp=<shareId>`), or
|
|
34
|
+
* - a short path where the last segment is the share ID itself.
|
|
35
|
+
* Returns null if the link can't be parsed.
|
|
36
|
+
*/
|
|
37
|
+
export function extractShareIdFromLink(link) {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = new URL(link, window.location.origin);
|
|
40
|
+
const mp = parsed.searchParams.get('mp');
|
|
41
|
+
if (mp)
|
|
42
|
+
return mp;
|
|
43
|
+
return parsed.pathname.split('/').pop() || null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Safely read a query-string parameter, falling back to a regex scan when
|
|
51
|
+
* URLSearchParams is unavailable (very old browsers / odd runtimes).
|
|
52
|
+
*/
|
|
53
|
+
export function readQueryParam(name) {
|
|
54
|
+
try {
|
|
55
|
+
const params = new URLSearchParams(window.location.search);
|
|
56
|
+
return params.get(name);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
const match = window.location.search.match(new RegExp('[?&]' + name + '=([^&]+)'));
|
|
60
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Reads a CSV query parameter and returns the trimmed, non-empty values.
|
|
65
|
+
*/
|
|
66
|
+
export function readCsvQueryParam(name) {
|
|
67
|
+
const raw = readQueryParam(name) || '';
|
|
68
|
+
return raw
|
|
69
|
+
.split(',')
|
|
70
|
+
.map((value) => value.trim())
|
|
71
|
+
.filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CA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CAAC;QACP,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CACxC,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC,CACvC,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACvC,OAAO,GAAG;SACP,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The envelope returned by the GameHub REST API.
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiResponse {
|
|
5
|
+
success: boolean;
|
|
6
|
+
data?: any;
|
|
7
|
+
token?: string;
|
|
8
|
+
error?: {
|
|
9
|
+
message?: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Options accepted by `apiRequest`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ApiRequestOptions {
|
|
16
|
+
method?: string;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
body?: any;
|
|
19
|
+
credentials?: RequestCredentials;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../types/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../types/api.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export interface BootstrapRoom {
|
|
1
|
+
import type { MatchContext } from './match.js';
|
|
2
|
+
/**
|
|
3
|
+
* Static room metadata supplied by the host during bootstrap.
|
|
4
|
+
*
|
|
5
|
+
* Peer counts and peer lists are deliberately excluded because they'd be
|
|
6
|
+
* stale by the time the game reads them. Use `multiplayer.getPeers()` and
|
|
7
|
+
* the `room_joined` / `peer_joined` / `peer_left` events for live state.
|
|
8
|
+
*/
|
|
9
|
+
export interface BootstrapRoom {
|
|
11
10
|
roomCode: string | null;
|
|
12
11
|
shareId: string | null;
|
|
13
12
|
maxPlayers: number | null;
|
|
14
13
|
role: string | null;
|
|
15
14
|
roomToken: string | null;
|
|
16
15
|
wsUrl: string | null;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export interface BootstrapConfig {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The configuration the host sends via postMessage to seed SDK state.
|
|
19
|
+
*/
|
|
20
|
+
export interface BootstrapConfig {
|
|
23
21
|
gameSlug?: string | null;
|
|
24
22
|
authToken?: string | null;
|
|
25
23
|
leagueId?: string | null;
|
|
@@ -31,20 +29,19 @@ namespace GameHub {
|
|
|
31
29
|
participant2MemberIds?: string[];
|
|
32
30
|
playerName?: string | null;
|
|
33
31
|
/** The peerId the server assigned to this player. Use
|
|
34
|
-
*
|
|
32
|
+
* `multiplayer.selfId()` after join for the live value. */
|
|
35
33
|
peerId?: string | null;
|
|
36
34
|
room?: Partial<BootstrapRoom> | null;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export interface BootstrapData {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Snapshot of the SDK's bootstrap-sourced state, returned by
|
|
38
|
+
* `sdk.getBootstrap()`.
|
|
39
|
+
*
|
|
40
|
+
* This snapshot contains only static session metadata. For the live room
|
|
41
|
+
* and peer state, use `multiplayer.getRoom()`, `multiplayer.getPeers()`,
|
|
42
|
+
* and the `room_joined` / `peer_joined` / `peer_left` events.
|
|
43
|
+
*/
|
|
44
|
+
export interface BootstrapData {
|
|
48
45
|
gameSlug: string | null;
|
|
49
46
|
authToken: string | null;
|
|
50
47
|
leagueId: string | null;
|
|
@@ -61,5 +58,5 @@ namespace GameHub {
|
|
|
61
58
|
/** Static room metadata. `null` for non-multiplayer sessions. */
|
|
62
59
|
room: BootstrapRoom | null;
|
|
63
60
|
isBootstrapped: boolean;
|
|
64
|
-
}
|
|
65
61
|
}
|
|
62
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../types/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,WAAW,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EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,qDAAqD;IACrD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iEAAiE;IACjE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../types/bootstrap.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single member belonging to a match participant (team player).
|
|
3
|
+
*/
|
|
4
|
+
export interface MatchParticipantMember {
|
|
5
|
+
leaguePlayerId: string;
|
|
6
|
+
fullname?: string;
|
|
7
|
+
avatar?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A participant (individual or team) in a league match.
|
|
11
|
+
*/
|
|
12
|
+
export interface MatchParticipant {
|
|
13
|
+
participantId: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
members?: MatchParticipantMember[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The full context for a league match this game is being played in.
|
|
19
|
+
*/
|
|
20
|
+
export interface MatchContext {
|
|
21
|
+
id: string;
|
|
22
|
+
leagueId: string;
|
|
23
|
+
gameId: string;
|
|
24
|
+
participant1: MatchParticipant;
|
|
25
|
+
participant2: MatchParticipant;
|
|
26
|
+
status: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Payload submitted via `submitMatchResult`.
|
|
30
|
+
*/
|
|
31
|
+
export interface MatchResultPayload {
|
|
32
|
+
winnerId?: string;
|
|
33
|
+
reason?: string;
|
|
34
|
+
scores?: Record<string, number>;
|
|
35
|
+
details?: Record<string, any>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../types/match.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../types/match.ts"],"names":[],"mappings":""}
|