@ksaa-nlp/gamehub-sdk 4.0.0 → 4.3.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 +75 -1
- package/SPEC.md +131 -6
- package/dist/gamehub-sdk.js +354 -11
- package/dist/gamehub-sdk.js.map +4 -4
- package/dist/src/bridge.d.ts +0 -14
- package/dist/src/bridge.d.ts.map +1 -1
- package/dist/src/bridge.js +57 -1
- package/dist/src/bridge.js.map +1 -1
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/init.d.ts +0 -14
- package/dist/src/init.d.ts.map +1 -1
- package/dist/src/init.js +7 -1
- package/dist/src/init.js.map +1 -1
- package/dist/src/main.d.ts +17 -20
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +20 -1
- package/dist/src/main.js.map +1 -1
- package/dist/src/multiplayer-session.d.ts +8 -0
- package/dist/src/multiplayer-session.d.ts.map +1 -0
- package/dist/src/multiplayer-session.js +216 -0
- package/dist/src/multiplayer-session.js.map +1 -0
- package/dist/src/multiplayer.d.ts +4 -0
- package/dist/src/multiplayer.d.ts.map +1 -0
- package/dist/src/multiplayer.js +91 -0
- package/dist/src/multiplayer.js.map +1 -0
- package/dist/src/server-entry.d.ts +15 -5
- package/dist/src/server-entry.d.ts.map +1 -1
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +6 -0
- package/dist/src/session.js.map +1 -1
- package/dist/src/settings.d.ts +7 -0
- package/dist/src/settings.d.ts.map +1 -0
- package/dist/src/settings.js +49 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/state.d.ts +7 -1
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/state.js +5 -9
- package/dist/src/state.js.map +1 -1
- package/dist/types/bootstrap.d.ts +44 -0
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/multiplayer-session.d.ts +76 -0
- package/dist/types/multiplayer-session.d.ts.map +1 -0
- package/dist/types/multiplayer-session.js +2 -0
- package/dist/types/multiplayer-session.js.map +1 -0
- package/package.json +1 -1
package/dist/gamehub-sdk.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
3
|
// src/constants.ts
|
|
4
|
-
var SDK_VERSION = "4.
|
|
4
|
+
var SDK_VERSION = "4.3.0";
|
|
5
5
|
var MESSAGE_PREFIX = "GAMEHUB_SDK";
|
|
6
6
|
var PARENT_REQUEST_TIMEOUT_MS = 2e3;
|
|
7
7
|
var HOST_API_TIMEOUT_MS = 15e3;
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
// src/state.ts
|
|
12
12
|
var state = {
|
|
13
|
+
multiplayerEntry: null,
|
|
14
|
+
gameSettings: { musicEnabled: false },
|
|
15
|
+
settingsListeners: /* @__PURE__ */ new Set(),
|
|
16
|
+
bootstrapLaunch: null,
|
|
17
|
+
bootstrapCapabilities: [],
|
|
13
18
|
sdkOrigin: "",
|
|
14
19
|
sdkPathPrefix: "",
|
|
15
20
|
runtimeBasePath: "",
|
|
@@ -41,6 +46,207 @@
|
|
|
41
46
|
matchContextPromise: null
|
|
42
47
|
};
|
|
43
48
|
|
|
49
|
+
// src/multiplayer-session.ts
|
|
50
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
51
|
+
var empty = {
|
|
52
|
+
session: null,
|
|
53
|
+
busy: false,
|
|
54
|
+
error: null,
|
|
55
|
+
disconnected: false
|
|
56
|
+
};
|
|
57
|
+
var current = empty;
|
|
58
|
+
var id = (value) => typeof value === "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(value);
|
|
59
|
+
function parseLobbyState(value) {
|
|
60
|
+
if (!value || typeof value !== "object") return null;
|
|
61
|
+
const v = value;
|
|
62
|
+
if (typeof v.busy !== "boolean" || typeof v.disconnected !== "boolean")
|
|
63
|
+
return null;
|
|
64
|
+
const error2 = v.error;
|
|
65
|
+
if (error2 !== null && (!error2 || !id(error2.code) || typeof error2.message !== "string" || error2.message.length > 1e3 || typeof error2.retryable !== "boolean"))
|
|
66
|
+
return null;
|
|
67
|
+
const s = v.session;
|
|
68
|
+
if (s !== null) {
|
|
69
|
+
if (!s || ![s.multiplayerSessionId, s.hostSeatId, s.ownSeatId].every(id) || typeof s.gameSlug !== "string" || !/^[a-z0-9-]{1,100}$/.test(s.gameSlug) || !/^\d{6}$/.test(s.roomCode) || !["waiting", "in_round", "completed", "closed"].includes(s.phase) || !Number.isSafeInteger(s.revision) || s.revision < 0 || typeof s.rematchAllowed !== "boolean" || !Array.isArray(s.seats) || s.seats.length > 272)
|
|
70
|
+
return null;
|
|
71
|
+
for (const url of [s.invitationUrl, s.spectatorInvitationUrl]) {
|
|
72
|
+
if (url !== void 0 && (typeof url !== "string" || url.length > 2048 || !/^https?:\/\//.test(url)))
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const p = s.playerPolicy;
|
|
76
|
+
if (!p || ![
|
|
77
|
+
p.minPlayers,
|
|
78
|
+
p.maxPlayers,
|
|
79
|
+
p.minHumanPlayers,
|
|
80
|
+
p.maxBots,
|
|
81
|
+
p.maxSpectators
|
|
82
|
+
].every((n) => Number.isSafeInteger(n) && n >= 0 && n <= 256) || p.minPlayers < 1 || p.minHumanPlayers < 1 || p.maxPlayers < p.minPlayers || p.minHumanPlayers > p.maxPlayers || p.maxBots > p.maxPlayers - p.minHumanPlayers || p.maxSpectators > 16)
|
|
83
|
+
return null;
|
|
84
|
+
if (!s.seats.every(
|
|
85
|
+
(seat) => seat && id(seat.seatId) && typeof seat.displayName === "string" && seat.displayName.length <= 80 && ["human", "bot"].includes(seat.kind) && ["player", "spectator"].includes(seat.type) && typeof seat.ready === "boolean" && typeof seat.online === "boolean"
|
|
86
|
+
))
|
|
87
|
+
return null;
|
|
88
|
+
if (s.round !== null && (!s.round || !id(s.round.roundId) || ![
|
|
89
|
+
"preparing",
|
|
90
|
+
"loading",
|
|
91
|
+
"playing",
|
|
92
|
+
"finishing",
|
|
93
|
+
"completed",
|
|
94
|
+
"aborted",
|
|
95
|
+
"interrupted"
|
|
96
|
+
].includes(s.round.phase) || s.round.reason !== null && (typeof s.round.reason !== "string" || s.round.reason.length > 1e3)))
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
busy: v.busy,
|
|
101
|
+
disconnected: v.disconnected,
|
|
102
|
+
error: error2 ? { code: error2.code, message: error2.message, retryable: error2.retryable } : null,
|
|
103
|
+
session: s ? {
|
|
104
|
+
...s.invitationUrl ? { invitationUrl: s.invitationUrl } : {},
|
|
105
|
+
...s.spectatorInvitationUrl ? { spectatorInvitationUrl: s.spectatorInvitationUrl } : {},
|
|
106
|
+
multiplayerSessionId: s.multiplayerSessionId,
|
|
107
|
+
gameSlug: s.gameSlug,
|
|
108
|
+
roomCode: s.roomCode,
|
|
109
|
+
phase: s.phase,
|
|
110
|
+
revision: s.revision,
|
|
111
|
+
hostSeatId: s.hostSeatId,
|
|
112
|
+
ownSeatId: s.ownSeatId,
|
|
113
|
+
rematchAllowed: s.rematchAllowed,
|
|
114
|
+
playerPolicy: {
|
|
115
|
+
minPlayers: s.playerPolicy.minPlayers,
|
|
116
|
+
maxPlayers: s.playerPolicy.maxPlayers,
|
|
117
|
+
minHumanPlayers: s.playerPolicy.minHumanPlayers,
|
|
118
|
+
maxBots: s.playerPolicy.maxBots,
|
|
119
|
+
maxSpectators: s.playerPolicy.maxSpectators
|
|
120
|
+
},
|
|
121
|
+
seats: s.seats.map((seat) => ({
|
|
122
|
+
seatId: seat.seatId,
|
|
123
|
+
displayName: seat.displayName,
|
|
124
|
+
kind: seat.kind,
|
|
125
|
+
type: seat.type,
|
|
126
|
+
ready: seat.ready,
|
|
127
|
+
online: seat.online
|
|
128
|
+
})),
|
|
129
|
+
round: s.round ? {
|
|
130
|
+
roundId: s.round.roundId,
|
|
131
|
+
phase: s.round.phase,
|
|
132
|
+
reason: s.round.reason
|
|
133
|
+
} : null
|
|
134
|
+
} : null
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function acceptLobbyState(value) {
|
|
138
|
+
const parsed = parseLobbyState(value);
|
|
139
|
+
if (!parsed) return;
|
|
140
|
+
current = parsed;
|
|
141
|
+
for (const listener of listeners) {
|
|
142
|
+
try {
|
|
143
|
+
listener(structuredClone(current));
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function lobbySnapshot() {
|
|
149
|
+
return structuredClone(current);
|
|
150
|
+
}
|
|
151
|
+
function onMultiplayerSessionChange(listener) {
|
|
152
|
+
const subscription = (value) => listener(value);
|
|
153
|
+
listeners.add(subscription);
|
|
154
|
+
try {
|
|
155
|
+
subscription(lobbySnapshot());
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
return () => {
|
|
159
|
+
listeners.delete(subscription);
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function requestMultiplayerSession(request) {
|
|
163
|
+
if (!state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
|
|
164
|
+
return {
|
|
165
|
+
success: false,
|
|
166
|
+
error: {
|
|
167
|
+
code: "PROTOCOL_UNSUPPORTED",
|
|
168
|
+
message: "This host does not support multiplayer lobby controls",
|
|
169
|
+
retryable: false
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const slug = state.gameSlug;
|
|
173
|
+
const launch = state.bootstrapLaunch;
|
|
174
|
+
try {
|
|
175
|
+
const response = await requestApiFromParent("/multiplayer/session", {
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: request
|
|
178
|
+
});
|
|
179
|
+
if (slug !== state.gameSlug || launch !== state.bootstrapLaunch)
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
error: {
|
|
183
|
+
code: "STALE_ATTEMPT",
|
|
184
|
+
message: "The multiplayer context changed",
|
|
185
|
+
retryable: false
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const parsed = response.success ? parseLobbyState(response.data) : null;
|
|
189
|
+
if (parsed && (!parsed.session || parsed.session.gameSlug === slug)) {
|
|
190
|
+
acceptLobbyState(parsed);
|
|
191
|
+
return { success: true, data: lobbySnapshot() };
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
error: {
|
|
196
|
+
code: response.error?.code ?? "UNAVAILABLE",
|
|
197
|
+
message: response.error?.message ?? "Lobby request failed",
|
|
198
|
+
retryable: response.error?.details?.terminal !== true
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
} catch {
|
|
202
|
+
return {
|
|
203
|
+
success: false,
|
|
204
|
+
error: {
|
|
205
|
+
code: "UNAVAILABLE",
|
|
206
|
+
message: "Lobby request timed out; refresh status before retrying",
|
|
207
|
+
retryable: true
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/settings.ts
|
|
214
|
+
function getSettings() {
|
|
215
|
+
return { ...state.gameSettings };
|
|
216
|
+
}
|
|
217
|
+
function notify(listener) {
|
|
218
|
+
try {
|
|
219
|
+
listener(getSettings());
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function onSettingsChange(listener) {
|
|
224
|
+
if (typeof listener !== "function") return () => {
|
|
225
|
+
};
|
|
226
|
+
const subscription = (settings) => listener(settings);
|
|
227
|
+
state.settingsListeners.add(subscription);
|
|
228
|
+
notify(subscription);
|
|
229
|
+
return () => {
|
|
230
|
+
state.settingsListeners.delete(subscription);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function mergeSettings(value) {
|
|
234
|
+
if (value === void 0) return;
|
|
235
|
+
let musicEnabled;
|
|
236
|
+
if (value === null) {
|
|
237
|
+
musicEnabled = false;
|
|
238
|
+
} else if (typeof value === "object" && !Array.isArray(value) && typeof value.musicEnabled === "boolean") {
|
|
239
|
+
musicEnabled = value.musicEnabled;
|
|
240
|
+
} else {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (musicEnabled === state.gameSettings.musicEnabled) return;
|
|
244
|
+
state.gameSettings = { musicEnabled };
|
|
245
|
+
for (const listener of [...state.settingsListeners]) {
|
|
246
|
+
if (state.settingsListeners.has(listener)) notify(listener);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
44
250
|
// src/utils.ts
|
|
45
251
|
function isBrowser() {
|
|
46
252
|
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -208,7 +414,26 @@
|
|
|
208
414
|
};
|
|
209
415
|
}
|
|
210
416
|
function mergeBootstrapConfig(config = {}) {
|
|
211
|
-
if (!config || typeof config !== "object") return;
|
|
417
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
418
|
+
mergeSettings(config.settings);
|
|
419
|
+
if (config.multiplayerSession !== void 0)
|
|
420
|
+
acceptLobbyState(
|
|
421
|
+
config.multiplayerSession ?? {
|
|
422
|
+
session: null,
|
|
423
|
+
busy: false,
|
|
424
|
+
error: null,
|
|
425
|
+
disconnected: false
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
if (config.multiplayerEntry === null) state.multiplayerEntry = null;
|
|
429
|
+
else if (config.multiplayerEntry && ["create", "join"].includes(config.multiplayerEntry.action)) {
|
|
430
|
+
const entry = config.multiplayerEntry;
|
|
431
|
+
state.multiplayerEntry = {
|
|
432
|
+
action: entry.action,
|
|
433
|
+
...typeof entry.roomCode === "string" && /^\d{6}$/.test(entry.roomCode) ? { roomCode: entry.roomCode } : {},
|
|
434
|
+
...entry.type === "player" || entry.type === "spectator" ? { type: entry.type } : {}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
212
437
|
const apply = (key, raw) => {
|
|
213
438
|
const next = trimToNullable(raw);
|
|
214
439
|
if (next === void 0) return;
|
|
@@ -235,6 +460,20 @@
|
|
|
235
460
|
applyBootstrap("bootstrapTeamOneName", config.teamOneName);
|
|
236
461
|
applyBootstrap("bootstrapTeamTwoName", config.teamTwoName);
|
|
237
462
|
applyBootstrap("bootstrapProfileId", config.profileId);
|
|
463
|
+
if (Array.isArray(config.capabilities))
|
|
464
|
+
state.bootstrapCapabilities = config.capabilities.filter((c) => typeof c === "string" && c.length <= 100).slice(0, 32);
|
|
465
|
+
const launch = config.multiplayerLaunch;
|
|
466
|
+
if (launch === null) state.bootstrapLaunch = null;
|
|
467
|
+
else if (launch && launch.version === 2 && (launch.recoveryGraceMs === void 0 || Number.isSafeInteger(launch.recoveryGraceMs) && launch.recoveryGraceMs >= 1e3 && launch.recoveryGraceMs <= 12e4) && [
|
|
468
|
+
"multiplayerSessionId",
|
|
469
|
+
"roundId",
|
|
470
|
+
"attemptId",
|
|
471
|
+
"seatId",
|
|
472
|
+
"hostInstanceId"
|
|
473
|
+
].every(
|
|
474
|
+
(k) => typeof launch[k] === "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(String(launch[k]))
|
|
475
|
+
) && typeof launch.gameUrl === "string" && launch.gameUrl.startsWith("/games/") && launch.gameUrl.length < 2048 && ["server", "unverified"].includes(launch.scoreAuthority))
|
|
476
|
+
state.bootstrapLaunch = { ...launch };
|
|
238
477
|
const mp = parseMultiplayer(config.multiplayer);
|
|
239
478
|
if (mp !== void 0) {
|
|
240
479
|
state.bootstrapMultiplayer = mp;
|
|
@@ -242,6 +481,9 @@
|
|
|
242
481
|
}
|
|
243
482
|
function snapshotBootstrap() {
|
|
244
483
|
return {
|
|
484
|
+
multiplayerEntry: state.multiplayerEntry,
|
|
485
|
+
multiplayerSession: lobbySnapshot(),
|
|
486
|
+
settings: getSettings(),
|
|
245
487
|
gameSlug: state.gameSlug,
|
|
246
488
|
authToken: state.authToken,
|
|
247
489
|
leagueId: state.leagueId,
|
|
@@ -254,7 +496,9 @@
|
|
|
254
496
|
teamOneName: state.bootstrapTeamOneName,
|
|
255
497
|
teamTwoName: state.bootstrapTeamTwoName,
|
|
256
498
|
profileId: state.bootstrapProfileId,
|
|
257
|
-
multiplayer: state.bootstrapMultiplayer
|
|
499
|
+
multiplayer: state.bootstrapMultiplayer,
|
|
500
|
+
multiplayerLaunch: state.bootstrapLaunch,
|
|
501
|
+
capabilities: state.bootstrapCapabilities
|
|
258
502
|
};
|
|
259
503
|
}
|
|
260
504
|
function requestBootstrapFromParent() {
|
|
@@ -594,6 +838,8 @@
|
|
|
594
838
|
}
|
|
595
839
|
}
|
|
596
840
|
async function startSession() {
|
|
841
|
+
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
|
|
842
|
+
return { success: false, error: "Multiplayer rounds own their results" };
|
|
597
843
|
if (state.sessionToken) return { success: true, token: state.sessionToken };
|
|
598
844
|
if (state.sessionStartPromise) return await state.sessionStartPromise;
|
|
599
845
|
const promise = performStartSession();
|
|
@@ -654,14 +900,14 @@
|
|
|
654
900
|
}
|
|
655
901
|
return failedResult(code, message, code === "SERVER_ERROR");
|
|
656
902
|
}
|
|
657
|
-
async function performSubmission(
|
|
903
|
+
async function performSubmission(pending2) {
|
|
658
904
|
let outcome;
|
|
659
905
|
try {
|
|
660
906
|
const response = await apiRequest("/sessions/submit", {
|
|
661
907
|
method: "POST",
|
|
662
|
-
body:
|
|
908
|
+
body: pending2.body
|
|
663
909
|
});
|
|
664
|
-
outcome = normalizeSubmissionResult(response,
|
|
910
|
+
outcome = normalizeSubmissionResult(response, pending2.token);
|
|
665
911
|
} catch (err) {
|
|
666
912
|
outcome = failedResult(
|
|
667
913
|
"TRANSPORT_ERROR",
|
|
@@ -671,7 +917,7 @@
|
|
|
671
917
|
}
|
|
672
918
|
if (outcome.success) {
|
|
673
919
|
sendToParent("SCORE_SUBMITTED", {
|
|
674
|
-
score:
|
|
920
|
+
score: pending2.body.score,
|
|
675
921
|
sessionId: outcome.sessionId,
|
|
676
922
|
status: outcome.status,
|
|
677
923
|
terminal: outcome.terminal,
|
|
@@ -687,6 +933,12 @@
|
|
|
687
933
|
}
|
|
688
934
|
async function submitScore(score, meta = {}) {
|
|
689
935
|
await ensureInitialized();
|
|
936
|
+
if (state.bootstrapLaunch || state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
|
|
937
|
+
return failedResult(
|
|
938
|
+
"FORBIDDEN",
|
|
939
|
+
"Multiplayer rounds own their results",
|
|
940
|
+
false
|
|
941
|
+
);
|
|
690
942
|
if (!state.isInitialized) {
|
|
691
943
|
return failedResult(
|
|
692
944
|
"SDK_NOT_INITIALIZED",
|
|
@@ -717,8 +969,8 @@
|
|
|
717
969
|
}
|
|
718
970
|
const prepared = prepareSubmission(state.sessionToken, score, meta);
|
|
719
971
|
if (!prepared.ok) return prepared.result;
|
|
720
|
-
const
|
|
721
|
-
if (
|
|
972
|
+
const pending2 = state.pendingSubmission;
|
|
973
|
+
if (pending2 && (pending2.token !== state.sessionToken || pending2.canonicalPayload !== prepared.canonicalPayload)) {
|
|
722
974
|
return failedResult(
|
|
723
975
|
"CONCURRENT_SUBMISSION_CONFLICT",
|
|
724
976
|
"A different payload is already bound to the active session",
|
|
@@ -726,7 +978,7 @@
|
|
|
726
978
|
);
|
|
727
979
|
}
|
|
728
980
|
if (state.submissionPromise) return await state.submissionPromise;
|
|
729
|
-
const activePending =
|
|
981
|
+
const activePending = pending2 ?? {
|
|
730
982
|
token: state.sessionToken,
|
|
731
983
|
canonicalPayload: prepared.canonicalPayload,
|
|
732
984
|
body: prepared.body
|
|
@@ -907,7 +1159,7 @@
|
|
|
907
1159
|
state.isAutoInitializing = false;
|
|
908
1160
|
return false;
|
|
909
1161
|
}
|
|
910
|
-
if (!state.authToken) {
|
|
1162
|
+
if (!state.authToken && !state.bootstrapLaunch && !state.bootstrapCapabilities.includes("multiplayer.lobby.v2")) {
|
|
911
1163
|
state.authToken = await getAuthTokenFromParent();
|
|
912
1164
|
}
|
|
913
1165
|
state.isInitialized = true;
|
|
@@ -950,6 +1202,8 @@
|
|
|
950
1202
|
state.bootstrapReceived = true;
|
|
951
1203
|
mergeBootstrapConfig(data.payload);
|
|
952
1204
|
}
|
|
1205
|
+
if (type === MESSAGE_PREFIX + "_MULTIPLAYER_SESSION" && state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
|
|
1206
|
+
acceptLobbyState(data.payload);
|
|
953
1207
|
if (type === MESSAGE_PREFIX + "_SET_AUTH") {
|
|
954
1208
|
state.authToken = data.token;
|
|
955
1209
|
if (state.gameSlug && !state.sessionToken && !state.sessionStartPromise && (state.authToken || state.leagueId && state.gameId && state.matchId)) {
|
|
@@ -968,6 +1222,79 @@
|
|
|
968
1222
|
});
|
|
969
1223
|
}
|
|
970
1224
|
|
|
1225
|
+
// src/multiplayer.ts
|
|
1226
|
+
var pending = null;
|
|
1227
|
+
function requestMultiplayerLaunch() {
|
|
1228
|
+
if (!state.bootstrapLaunch || !state.bootstrapCapabilities.includes("multiplayer.launch.v2"))
|
|
1229
|
+
return Promise.resolve({
|
|
1230
|
+
status: "terminal",
|
|
1231
|
+
error: {
|
|
1232
|
+
code: "PROTOCOL_UNSUPPORTED",
|
|
1233
|
+
message: "This host does not support multiplayer launch v2",
|
|
1234
|
+
retryable: false
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
if (pending) return pending;
|
|
1238
|
+
const launch = state.bootstrapLaunch;
|
|
1239
|
+
const operation = (async () => {
|
|
1240
|
+
try {
|
|
1241
|
+
const response = await requestApiFromParent("/multiplayer/launch", {
|
|
1242
|
+
method: "POST",
|
|
1243
|
+
body: {}
|
|
1244
|
+
});
|
|
1245
|
+
if (state.bootstrapLaunch !== launch)
|
|
1246
|
+
return {
|
|
1247
|
+
status: "terminal",
|
|
1248
|
+
error: {
|
|
1249
|
+
code: "STALE_ATTEMPT",
|
|
1250
|
+
message: "Launch context changed",
|
|
1251
|
+
retryable: false
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
const data = response.data;
|
|
1255
|
+
if (response.success && data) {
|
|
1256
|
+
if (data.status === "reserved" && data.launch && [
|
|
1257
|
+
"multiplayerSessionId",
|
|
1258
|
+
"roundId",
|
|
1259
|
+
"attemptId",
|
|
1260
|
+
"seatId",
|
|
1261
|
+
"hostInstanceId"
|
|
1262
|
+
].every(
|
|
1263
|
+
(k) => data.launch[k] === launch[k]
|
|
1264
|
+
) && data.reservation && ["name", "roomId", "sessionId"].every(
|
|
1265
|
+
(k) => typeof data.reservation[k] === "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(
|
|
1266
|
+
String(data.reservation[k])
|
|
1267
|
+
)
|
|
1268
|
+
) && /^wss?:\/\//.test(data.wsEndpoint) && data.wsEndpoint.length < 2048 && Number.isSafeInteger(data.generation) && data.generation > 0 && Number.isSafeInteger(data.expiresAt))
|
|
1269
|
+
return data;
|
|
1270
|
+
if ((data.status === "recoverable" || data.status === "terminal") && data.error && typeof data.error.code === "string" && data.error.code.length <= 100 && typeof data.error.message === "string" && data.error.message.length <= 1e3 && typeof data.error.retryable === "boolean")
|
|
1271
|
+
return data;
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
status: "recoverable",
|
|
1275
|
+
error: {
|
|
1276
|
+
code: response.error?.code ?? "UNAVAILABLE",
|
|
1277
|
+
message: response.error?.message ?? "Launch unavailable",
|
|
1278
|
+
retryable: true
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
} catch {
|
|
1282
|
+
return {
|
|
1283
|
+
status: "recoverable",
|
|
1284
|
+
error: {
|
|
1285
|
+
code: "UNAVAILABLE",
|
|
1286
|
+
message: "Launch request failed; retry",
|
|
1287
|
+
retryable: true
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
})().finally(() => {
|
|
1292
|
+
if (pending === operation) pending = null;
|
|
1293
|
+
});
|
|
1294
|
+
pending = operation;
|
|
1295
|
+
return operation;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
971
1298
|
// src/match-context.ts
|
|
972
1299
|
async function fetchMatchContext() {
|
|
973
1300
|
if (!state.leagueId || !state.matchId) return null;
|
|
@@ -1002,6 +1329,12 @@
|
|
|
1002
1329
|
hasActiveSession() {
|
|
1003
1330
|
return !!state.sessionToken;
|
|
1004
1331
|
},
|
|
1332
|
+
requestMultiplayerLaunch,
|
|
1333
|
+
requestMultiplayerSession,
|
|
1334
|
+
onMultiplayerSessionChange(listener) {
|
|
1335
|
+
installHostMessageListener();
|
|
1336
|
+
return onMultiplayerSessionChange(listener);
|
|
1337
|
+
},
|
|
1005
1338
|
async startSession() {
|
|
1006
1339
|
await ensureInitialized();
|
|
1007
1340
|
if (state.sessionStartPromise) return await state.sessionStartPromise;
|
|
@@ -1063,8 +1396,16 @@
|
|
|
1063
1396
|
async ready() {
|
|
1064
1397
|
return await ensureInitialized();
|
|
1065
1398
|
},
|
|
1399
|
+
getSettings,
|
|
1400
|
+
onSettingsChange(listener) {
|
|
1401
|
+
installHostMessageListener();
|
|
1402
|
+
return onSettingsChange(listener);
|
|
1403
|
+
},
|
|
1066
1404
|
getBootstrap() {
|
|
1067
1405
|
return {
|
|
1406
|
+
multiplayerEntry: state.multiplayerEntry,
|
|
1407
|
+
multiplayerSession: lobbySnapshot(),
|
|
1408
|
+
settings: getSettings(),
|
|
1068
1409
|
gameSlug: state.gameSlug,
|
|
1069
1410
|
authToken: state.authToken,
|
|
1070
1411
|
leagueId: state.leagueId,
|
|
@@ -1078,6 +1419,8 @@
|
|
|
1078
1419
|
teamTwoName: state.bootstrapTeamTwoName,
|
|
1079
1420
|
profileId: state.bootstrapProfileId,
|
|
1080
1421
|
multiplayer: state.bootstrapMultiplayer,
|
|
1422
|
+
multiplayerLaunch: state.bootstrapLaunch,
|
|
1423
|
+
capabilities: [...state.bootstrapCapabilities],
|
|
1081
1424
|
isBootstrapped: state.bootstrapReceived
|
|
1082
1425
|
};
|
|
1083
1426
|
},
|