@ksaa-nlp/gamehub-react-native-sdk 0.0.0-stage → 1.1.1
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 +272 -2
- package/SPEC.md +265 -0
- package/dist/src/api-client.d.ts +7 -0
- package/dist/src/api-client.d.ts.map +1 -0
- package/dist/src/api-client.js +123 -0
- package/dist/src/api-client.js.map +1 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +45 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content.d.ts +7 -0
- package/dist/src/content.d.ts.map +1 -0
- package/dist/src/content.js +70 -0
- package/dist/src/content.js.map +1 -0
- package/dist/src/host-events.d.ts +7 -0
- package/dist/src/host-events.d.ts.map +1 -0
- package/dist/src/host-events.js +20 -0
- package/dist/src/host-events.js.map +1 -0
- package/dist/src/identity.d.ts +10 -0
- package/dist/src/identity.d.ts.map +1 -0
- package/dist/src/identity.js +27 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +54 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/launch.d.ts +16 -0
- package/dist/src/launch.d.ts.map +1 -0
- package/dist/src/launch.js +115 -0
- package/dist/src/launch.js.map +1 -0
- package/dist/src/lobby-request.d.ts +4 -0
- package/dist/src/lobby-request.d.ts.map +1 -0
- package/dist/src/lobby-request.js +46 -0
- package/dist/src/lobby-request.js.map +1 -0
- package/dist/src/lobby.d.ts +33 -0
- package/dist/src/lobby.d.ts.map +1 -0
- package/dist/src/lobby.js +308 -0
- package/dist/src/lobby.js.map +1 -0
- package/dist/src/match-context.d.ts +10 -0
- package/dist/src/match-context.d.ts.map +1 -0
- package/dist/src/match-context.js +41 -0
- package/dist/src/match-context.js.map +1 -0
- package/dist/src/multiplayer-client.d.ts +27 -0
- package/dist/src/multiplayer-client.d.ts.map +1 -0
- package/dist/src/multiplayer-client.js +163 -0
- package/dist/src/multiplayer-client.js.map +1 -0
- package/dist/src/multiplayer-react.d.ts +4 -0
- package/dist/src/multiplayer-react.d.ts.map +1 -0
- package/dist/src/multiplayer-react.js +8 -0
- package/dist/src/multiplayer-react.js.map +1 -0
- package/dist/src/multiplayer-storage.d.ts +22 -0
- package/dist/src/multiplayer-storage.d.ts.map +1 -0
- package/dist/src/multiplayer-storage.js +65 -0
- package/dist/src/multiplayer-storage.js.map +1 -0
- package/dist/src/multiplayer-types.d.ts +54 -0
- package/dist/src/multiplayer-types.d.ts.map +1 -0
- package/dist/src/multiplayer-types.js +2 -0
- package/dist/src/multiplayer-types.js.map +1 -0
- package/dist/src/multiplayer.d.ts +5 -0
- package/dist/src/multiplayer.d.ts.map +1 -0
- package/dist/src/multiplayer.js +4 -0
- package/dist/src/multiplayer.js.map +1 -0
- package/dist/src/react.d.ts +11 -0
- package/dist/src/react.d.ts.map +1 -0
- package/dist/src/react.js +20 -0
- package/dist/src/react.js.map +1 -0
- package/dist/src/score.d.ts +9 -0
- package/dist/src/score.d.ts.map +1 -0
- package/dist/src/score.js +168 -0
- package/dist/src/score.js.map +1 -0
- package/dist/src/session-view.d.ts +4 -0
- package/dist/src/session-view.d.ts.map +1 -0
- package/dist/src/session-view.js +276 -0
- package/dist/src/session-view.js.map +1 -0
- package/dist/src/session.d.ts +10 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +142 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/settings.d.ts +4 -0
- package/dist/src/settings.d.ts.map +1 -0
- package/dist/src/settings.js +40 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/types.d.ts +125 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +5 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +16 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
- package/dist/vendor/colyseus-schemas/clock.js +67 -0
- package/dist/vendor/colyseus-schemas/common.d.ts +35 -0
- package/dist/vendor/colyseus-schemas/common.js +15 -0
- package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
- package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
- package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
- package/dist/vendor/colyseus-schemas/ugc.js +124 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +200 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.js +289 -0
- package/dist/vendor/match.d.ts +37 -0
- package/dist/vendor/match.d.ts.map +1 -0
- package/dist/vendor/match.js +2 -0
- package/dist/vendor/match.js.map +1 -0
- package/dist/vendor/multiplayer-client.d.ts +50 -0
- package/dist/vendor/multiplayer-client.d.ts.map +1 -0
- package/dist/vendor/multiplayer-client.js +268 -0
- package/dist/vendor/multiplayer-client.js.map +1 -0
- package/dist/vendor/multiplayer-session.d.ts +82 -0
- package/dist/vendor/multiplayer-session.d.ts.map +1 -0
- package/dist/vendor/multiplayer-session.js +2 -0
- package/dist/vendor/multiplayer-session.js.map +1 -0
- package/dist/vendor/question.d.ts +35 -0
- package/dist/vendor/question.d.ts.map +1 -0
- package/dist/vendor/question.js +20 -0
- package/dist/vendor/question.js.map +1 -0
- package/dist/vendor/session.d.ts +158 -0
- package/dist/vendor/session.d.ts.map +1 -0
- package/dist/vendor/session.js +2 -0
- package/dist/vendor/session.js.map +1 -0
- package/dist/vendor/word.d.ts +147 -0
- package/dist/vendor/word.d.ts.map +1 -0
- package/dist/vendor/word.js +15 -0
- package/dist/vendor/word.js.map +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/** Plain-data v2 wire contract. This entry must remain dependency and side-effect free. */
|
|
2
|
+
export const LAUNCH_VERSION = 2;
|
|
3
|
+
export const MULTIPLAYER_CAPABILITY = 'multiplayer.launch.v2';
|
|
4
|
+
export const MULTIPLAYER_LOBBY_CAPABILITY = 'multiplayer.lobby.v2';
|
|
5
|
+
export const CONTROL_TIMEOUT_MS = 10000;
|
|
6
|
+
export const ARRIVAL_WINDOW_MS = 90000;
|
|
7
|
+
export const RECOVERY_GRACE_MS = 60000;
|
|
8
|
+
export const RESERVATION_LEASE_MS = 15000;
|
|
9
|
+
export const BOT_LEVELS = ['easy', 'medium', 'hard'];
|
|
10
|
+
/** Bots stored before levels existed play at `medium`. */
|
|
11
|
+
export const DEFAULT_BOT_LEVEL = 'medium';
|
|
12
|
+
export const isBotLevel = (value) => BOT_LEVELS.includes(value);
|
|
13
|
+
/** UGC bots are game-owned; quiz bots are played by the built-in engine. Relay has none. */
|
|
14
|
+
export const BOT_ENGINES = ['ugc', 'quiz-template'];
|
|
15
|
+
/** Missing policy identifies an existing two-human v2 package/round. */
|
|
16
|
+
export function playerPolicy(binding) {
|
|
17
|
+
return (binding.playerPolicy ?? {
|
|
18
|
+
minPlayers: 2,
|
|
19
|
+
maxPlayers: 2,
|
|
20
|
+
minHumanPlayers: 1,
|
|
21
|
+
maxBots: 0,
|
|
22
|
+
maxSpectators: 16,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function parsePlayerPolicy(manifest, ceiling = 256) {
|
|
26
|
+
const minPlayers = manifest.minPlayers;
|
|
27
|
+
const maxPlayers = manifest.maxPlayers;
|
|
28
|
+
const minHumanPlayers = (manifest.minHumanPlayers ?? 1);
|
|
29
|
+
const maxBots = (manifest.maxBots ?? 0);
|
|
30
|
+
if (![minPlayers, maxPlayers, minHumanPlayers, maxBots].every(Number.isSafeInteger) ||
|
|
31
|
+
minPlayers < 1 ||
|
|
32
|
+
maxPlayers < minPlayers ||
|
|
33
|
+
maxPlayers > ceiling ||
|
|
34
|
+
minHumanPlayers < 1 ||
|
|
35
|
+
minHumanPlayers > maxPlayers ||
|
|
36
|
+
maxBots < 0 ||
|
|
37
|
+
maxBots > maxPlayers - minHumanPlayers ||
|
|
38
|
+
typeof manifest.spectators !== 'boolean' ||
|
|
39
|
+
(maxBots > 0 && !BOT_ENGINES.includes(manifest.engine)))
|
|
40
|
+
throw new MultiplayerFault('PROTOCOL_UNSUPPORTED');
|
|
41
|
+
return {
|
|
42
|
+
minPlayers,
|
|
43
|
+
maxPlayers,
|
|
44
|
+
minHumanPlayers,
|
|
45
|
+
maxBots,
|
|
46
|
+
maxSpectators: manifest.spectators ? 16 : 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export const ERROR_CODES = [
|
|
50
|
+
'INVALID_REQUEST',
|
|
51
|
+
'UNAUTHORIZED',
|
|
52
|
+
'LOGIN_REQUIRED',
|
|
53
|
+
'FORBIDDEN',
|
|
54
|
+
'NOT_FOUND',
|
|
55
|
+
'GAME_MISMATCH',
|
|
56
|
+
'GAME_UNAVAILABLE',
|
|
57
|
+
'NO_QUESTIONS',
|
|
58
|
+
'PROTOCOL_UNSUPPORTED',
|
|
59
|
+
'PASSCODE_REQUIRED',
|
|
60
|
+
'INVALID_PASSCODE',
|
|
61
|
+
'ROOM_FULL',
|
|
62
|
+
'SEAT_REMOVED',
|
|
63
|
+
'SEAT_LEFT',
|
|
64
|
+
'ROSTER_FROZEN',
|
|
65
|
+
'NOT_HOST',
|
|
66
|
+
'STALE_REVISION',
|
|
67
|
+
'NOT_READY',
|
|
68
|
+
'STALE_ATTEMPT',
|
|
69
|
+
'STALE_GENERATION',
|
|
70
|
+
'ALREADY_CONNECTED',
|
|
71
|
+
'LAUNCH_PENDING',
|
|
72
|
+
'LAUNCH_EXPIRED',
|
|
73
|
+
'ARRIVAL_TIMEOUT',
|
|
74
|
+
'RECOVERY_EXPIRED',
|
|
75
|
+
'INTERRUPTED',
|
|
76
|
+
'ROUND_TERMINAL',
|
|
77
|
+
'RESULT_CONFLICT',
|
|
78
|
+
'INVALID_RESULT',
|
|
79
|
+
'RATE_LIMITED',
|
|
80
|
+
'UNAVAILABLE',
|
|
81
|
+
'CANCELLED',
|
|
82
|
+
'STORAGE_UNAVAILABLE',
|
|
83
|
+
];
|
|
84
|
+
export class MultiplayerFault extends Error {
|
|
85
|
+
constructor(code, retryable = false, status = 409) {
|
|
86
|
+
super(errorMessage(code));
|
|
87
|
+
this.code = code;
|
|
88
|
+
this.retryable = retryable;
|
|
89
|
+
this.status = status;
|
|
90
|
+
}
|
|
91
|
+
toJSON() {
|
|
92
|
+
return {
|
|
93
|
+
code: this.code,
|
|
94
|
+
message: this.message,
|
|
95
|
+
retryable: this.retryable,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export const terminalRound = (phase) => ['completed', 'aborted', 'interrupted'].includes(phase);
|
|
100
|
+
const transitions = {
|
|
101
|
+
preparing: ['loading', 'aborted'],
|
|
102
|
+
loading: ['playing', 'aborted'],
|
|
103
|
+
playing: ['finishing', 'interrupted'],
|
|
104
|
+
finishing: ['completed', 'interrupted'],
|
|
105
|
+
completed: [],
|
|
106
|
+
aborted: [],
|
|
107
|
+
interrupted: [],
|
|
108
|
+
};
|
|
109
|
+
export function canTransition(from, to) {
|
|
110
|
+
return transitions[from]?.includes(to) ?? false;
|
|
111
|
+
}
|
|
112
|
+
export function isRecord(value) {
|
|
113
|
+
return (!!value &&
|
|
114
|
+
typeof value === 'object' &&
|
|
115
|
+
!Array.isArray(value) &&
|
|
116
|
+
(Object.getPrototypeOf(value) === Object.prototype ||
|
|
117
|
+
Object.getPrototypeOf(value) === null));
|
|
118
|
+
}
|
|
119
|
+
export function isBoundedId(value) {
|
|
120
|
+
return typeof value === 'string' && /^[a-zA-Z0-9_-]{1,160}$/.test(value);
|
|
121
|
+
}
|
|
122
|
+
export function isLaunchReference(value) {
|
|
123
|
+
if (!isRecord(value) ||
|
|
124
|
+
value.version !== 2 ||
|
|
125
|
+
(value.recoveryGraceMs !== undefined &&
|
|
126
|
+
(!Number.isSafeInteger(value.recoveryGraceMs) ||
|
|
127
|
+
Number(value.recoveryGraceMs) < 1000 ||
|
|
128
|
+
Number(value.recoveryGraceMs) > 120000)))
|
|
129
|
+
return false;
|
|
130
|
+
return ([
|
|
131
|
+
'multiplayerSessionId',
|
|
132
|
+
'roundId',
|
|
133
|
+
'attemptId',
|
|
134
|
+
'seatId',
|
|
135
|
+
'hostInstanceId',
|
|
136
|
+
].every((k) => isBoundedId(value[k])) &&
|
|
137
|
+
typeof value.gameUrl === 'string' &&
|
|
138
|
+
value.gameUrl.startsWith('/games/') &&
|
|
139
|
+
value.gameUrl.length < 2048 &&
|
|
140
|
+
(value.scoreAuthority === 'server' || value.scoreAuthority === 'unverified'));
|
|
141
|
+
}
|
|
142
|
+
export function isLaunchOutcome(value) {
|
|
143
|
+
if (!isRecord(value))
|
|
144
|
+
return false;
|
|
145
|
+
if (value.status === 'reserved')
|
|
146
|
+
return (isLaunchReference(value.launch) &&
|
|
147
|
+
isRecord(value.reservation) &&
|
|
148
|
+
['name', 'roomId', 'sessionId'].every((k) => isBoundedId(value.reservation[k])) &&
|
|
149
|
+
typeof value.wsEndpoint === 'string' &&
|
|
150
|
+
/^wss?:\/\//.test(value.wsEndpoint) &&
|
|
151
|
+
value.wsEndpoint.length < 2048 &&
|
|
152
|
+
Number.isSafeInteger(value.generation) &&
|
|
153
|
+
Number(value.generation) > 0 &&
|
|
154
|
+
Number.isSafeInteger(value.expiresAt));
|
|
155
|
+
return ((value.status === 'terminal' || value.status === 'recoverable') &&
|
|
156
|
+
isRecord(value.error) &&
|
|
157
|
+
ERROR_CODES.includes(value.error.code) &&
|
|
158
|
+
typeof value.error.retryable === 'boolean' &&
|
|
159
|
+
typeof value.error.message === 'string' &&
|
|
160
|
+
value.error.message.length <= 1000);
|
|
161
|
+
}
|
|
162
|
+
export function parseResultProposal(value, participantSeatIds) {
|
|
163
|
+
if (!isRecord(value) ||
|
|
164
|
+
value.version !== 2 ||
|
|
165
|
+
!isRecord(value.scores) ||
|
|
166
|
+
!Array.isArray(value.winnerSeatIds) ||
|
|
167
|
+
!['win', 'draw', 'forfeit', 'abort'].includes(String(value.reason)))
|
|
168
|
+
throw new MultiplayerFault('INVALID_RESULT');
|
|
169
|
+
const allowed = new Set(participantSeatIds);
|
|
170
|
+
if (allowed.size !== participantSeatIds.length || !allowed.size)
|
|
171
|
+
throw new MultiplayerFault('INVALID_RESULT');
|
|
172
|
+
const scores = {};
|
|
173
|
+
for (const [seat, score] of Object.entries(value.scores)) {
|
|
174
|
+
if (!allowed.has(seat) ||
|
|
175
|
+
typeof score !== 'number' ||
|
|
176
|
+
!Number.isFinite(score) ||
|
|
177
|
+
Math.abs(score) > 1000000000)
|
|
178
|
+
throw new MultiplayerFault('INVALID_RESULT');
|
|
179
|
+
scores[seat] = score;
|
|
180
|
+
}
|
|
181
|
+
if (Object.keys(scores).length !== allowed.size ||
|
|
182
|
+
new Set(value.winnerSeatIds).size !== value.winnerSeatIds.length ||
|
|
183
|
+
value.winnerSeatIds.some((id) => typeof id !== 'string' || !allowed.has(id)) ||
|
|
184
|
+
(value.reason === 'draw' && value.winnerSeatIds.length !== 0) ||
|
|
185
|
+
(value.reason === 'win' && value.winnerSeatIds.length === 0))
|
|
186
|
+
throw new MultiplayerFault('INVALID_RESULT');
|
|
187
|
+
let metadata;
|
|
188
|
+
if (value.metadata !== undefined) {
|
|
189
|
+
if (!isRecord(value.metadata) ||
|
|
190
|
+
JSON.stringify(value.metadata).length > 4096 ||
|
|
191
|
+
Object.keys(value.metadata).length > 32 ||
|
|
192
|
+
Object.values(value.metadata).some((v) => (v !== null && !['string', 'number', 'boolean'].includes(typeof v)) ||
|
|
193
|
+
(typeof v === 'number' && !Number.isFinite(v))))
|
|
194
|
+
throw new MultiplayerFault('INVALID_RESULT');
|
|
195
|
+
metadata = value.metadata;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
version: 2,
|
|
199
|
+
scores,
|
|
200
|
+
winnerSeatIds: [...value.winnerSeatIds].sort(),
|
|
201
|
+
reason: value.reason,
|
|
202
|
+
...(metadata ? { metadata } : {}),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** Stable, bounded canonical JSON; callers validate their domain payload first. */
|
|
206
|
+
export function canonicalJson(value) {
|
|
207
|
+
if (Array.isArray(value))
|
|
208
|
+
return '[' + value.map(canonicalJson).join(',') + ']';
|
|
209
|
+
if (isRecord(value))
|
|
210
|
+
return ('{' +
|
|
211
|
+
Object.keys(value)
|
|
212
|
+
.sort()
|
|
213
|
+
.map((k) => JSON.stringify(k) + ':' + canonicalJson(value[k]))
|
|
214
|
+
.join(',') +
|
|
215
|
+
'}');
|
|
216
|
+
const encoded = JSON.stringify(value);
|
|
217
|
+
if (encoded === undefined)
|
|
218
|
+
throw new MultiplayerFault('INVALID_REQUEST');
|
|
219
|
+
return encoded;
|
|
220
|
+
}
|
|
221
|
+
export function normalizeError(error) {
|
|
222
|
+
if (error instanceof MultiplayerFault)
|
|
223
|
+
return error.toJSON();
|
|
224
|
+
const numeric = {
|
|
225
|
+
4210: 'ROUND_TERMINAL',
|
|
226
|
+
4211: 'SEAT_REMOVED',
|
|
227
|
+
4212: 'STALE_GENERATION',
|
|
228
|
+
4213: 'ALREADY_CONNECTED',
|
|
229
|
+
4214: 'RECOVERY_EXPIRED',
|
|
230
|
+
4215: 'ARRIVAL_TIMEOUT',
|
|
231
|
+
4216: 'INTERRUPTED',
|
|
232
|
+
4217: 'GAME_UNAVAILABLE',
|
|
233
|
+
4218: 'INVALID_RESULT',
|
|
234
|
+
4219: 'NOT_READY',
|
|
235
|
+
4220: 'LOGIN_REQUIRED',
|
|
236
|
+
4221: 'UNAVAILABLE',
|
|
237
|
+
522: 'LAUNCH_EXPIRED',
|
|
238
|
+
};
|
|
239
|
+
const raw = isRecord(error)
|
|
240
|
+
? error
|
|
241
|
+
: error instanceof Error
|
|
242
|
+
? {
|
|
243
|
+
code: error.code,
|
|
244
|
+
message: error.message,
|
|
245
|
+
}
|
|
246
|
+
: {};
|
|
247
|
+
const code = typeof raw.code === 'number'
|
|
248
|
+
? numeric[raw.code]
|
|
249
|
+
: ERROR_CODES.includes(raw.code)
|
|
250
|
+
? raw.code
|
|
251
|
+
: undefined;
|
|
252
|
+
return {
|
|
253
|
+
code: code ?? 'UNAVAILABLE',
|
|
254
|
+
message: code
|
|
255
|
+
? errorMessage(code)
|
|
256
|
+
: 'Connection unavailable. Check your network and retry.',
|
|
257
|
+
retryable: !code ||
|
|
258
|
+
['LAUNCH_EXPIRED', 'UNAVAILABLE', 'LAUNCH_PENDING'].includes(code),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export function errorMessage(code) {
|
|
262
|
+
const messages = {
|
|
263
|
+
UNAUTHORIZED: 'Sign in, or rejoin with this host’s original guest session.',
|
|
264
|
+
LOGIN_REQUIRED: 'Sign in to play or spectate this game.',
|
|
265
|
+
GAME_MISMATCH: 'This invitation belongs to a different game. Open its invitation link.',
|
|
266
|
+
GAME_UNAVAILABLE: 'This game or its approved package is unavailable. Return to the lobby.',
|
|
267
|
+
NO_QUESTIONS: 'The selected profile has no published questions. Add questions or choose another profile.',
|
|
268
|
+
PROTOCOL_UNSUPPORTED: 'This game and host do not support the same multiplayer version.',
|
|
269
|
+
PASSCODE_REQUIRED: 'Enter the room passcode to join, including as a spectator.',
|
|
270
|
+
INVALID_PASSCODE: 'The passcode is incorrect. Check it and retry.',
|
|
271
|
+
ROOM_FULL: 'There are no free seats of this type.',
|
|
272
|
+
NOT_HOST: 'Only the current lobby host can start or rematch.',
|
|
273
|
+
NOT_READY: 'Meet the required player counts and keep human players connected. Confirm readiness only when this lobby requires it.',
|
|
274
|
+
STALE_REVISION: 'The lobby changed. Refresh its status and retry.',
|
|
275
|
+
ROSTER_FROZEN: 'This round has already selected its players. Join as a spectator or wait for a rematch.',
|
|
276
|
+
LAUNCH_PENDING: 'Your launch is being prepared. Retry shortly.',
|
|
277
|
+
LAUNCH_EXPIRED: 'The reservation expired. Request a fresh launch.',
|
|
278
|
+
ALREADY_CONNECTED: 'This seat is already connected in another tab. Return to that tab.',
|
|
279
|
+
ARRIVAL_TIMEOUT: 'A required player did not arrive in time. Return to the lobby and rematch.',
|
|
280
|
+
RECOVERY_EXPIRED: 'The reconnect window ended. Return to the lobby for a new round.',
|
|
281
|
+
SEAT_REMOVED: 'This seat has left or was removed and cannot reconnect.',
|
|
282
|
+
SEAT_LEFT: 'Your lobby membership ended. Rejoin the room if it is still available.',
|
|
283
|
+
INTERRUPTED: 'The round was interrupted before its result was saved. Return to the lobby.',
|
|
284
|
+
ROUND_TERMINAL: 'This round has ended. Return to the lobby.',
|
|
285
|
+
RATE_LIMITED: 'Too many requests. Wait a moment and retry.',
|
|
286
|
+
UNAVAILABLE: 'The service is temporarily unavailable. Retry or leave the session.',
|
|
287
|
+
};
|
|
288
|
+
return messages[code] ?? code;
|
|
289
|
+
}
|
|
@@ -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":["../../vendor/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":["../../vendor/match.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MultiplayerState } from '#colyseus-schemas/multiplayer';
|
|
2
|
+
import { type LaunchReference, type MultiplayerError } from '#multiplayer-contracts';
|
|
3
|
+
export type ConnectionStatus = 'disconnected' | 'connecting' | 'loading' | 'playing' | 'reconnecting' | 'finishing' | 'completed' | 'failed';
|
|
4
|
+
export interface LaunchHost {
|
|
5
|
+
requestMultiplayerLaunch(): Promise<unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface TokenStorage {
|
|
8
|
+
getItem(key: string): string | null;
|
|
9
|
+
setItem(key: string, value: string): void;
|
|
10
|
+
removeItem(key: string): void;
|
|
11
|
+
}
|
|
12
|
+
export interface MultiplayerSnapshot {
|
|
13
|
+
status: ConnectionStatus;
|
|
14
|
+
error: MultiplayerError | null;
|
|
15
|
+
storageAvailable: boolean;
|
|
16
|
+
state: MultiplayerState | null;
|
|
17
|
+
}
|
|
18
|
+
/** Game-owned socket. One adapter per active document/round; no credentials go to parent pages. */
|
|
19
|
+
export declare class MultiplayerClient {
|
|
20
|
+
private readonly host;
|
|
21
|
+
readonly launch: LaunchReference;
|
|
22
|
+
private readonly storage?;
|
|
23
|
+
private readonly makeClient;
|
|
24
|
+
private room;
|
|
25
|
+
private operation;
|
|
26
|
+
private generation;
|
|
27
|
+
private disposed;
|
|
28
|
+
private recoverUntil;
|
|
29
|
+
private cancelRetry;
|
|
30
|
+
private unsubscribers;
|
|
31
|
+
private listeners;
|
|
32
|
+
private token;
|
|
33
|
+
private endpoint;
|
|
34
|
+
private clockNow;
|
|
35
|
+
private snapshot;
|
|
36
|
+
private readonly storageKey;
|
|
37
|
+
constructor(host: LaunchHost, launch: LaunchReference, storage?: TokenStorage | undefined, makeClient?: (endpoint: string) => import("@colyseus/sdk").ColyseusSDK<any, any>);
|
|
38
|
+
getSnapshot(): MultiplayerSnapshot;
|
|
39
|
+
subscribe(listener: (state: MultiplayerSnapshot) => void): () => void;
|
|
40
|
+
serverNow(): number;
|
|
41
|
+
connect(): Promise<void>;
|
|
42
|
+
private join;
|
|
43
|
+
send<T>(type: string, payload: T): boolean;
|
|
44
|
+
leave(): Promise<void>;
|
|
45
|
+
private detach;
|
|
46
|
+
private remember;
|
|
47
|
+
private clearToken;
|
|
48
|
+
private update;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=multiplayer-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplayer-client.d.ts","sourceRoot":"","sources":["../../vendor/multiplayer-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAIL,KAAK,eAAe,EAEpB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAChC,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,YAAY,GACZ,SAAS,GACT,SAAS,GACT,cAAc,GACd,WAAW,GACX,WAAW,GACX,QAAQ,CAAC;AACb,MAAM,WAAW,UAAU;IACzB,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AACD,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AACD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC;AACD,mGAAmG;AACnG,qBAAa,iBAAiB;IAoB1B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,QAAQ,CAAC,MAAM,EAAE,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAtB7B,OAAO,CAAC,IAAI,CAA4C;IACxD,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,QAAQ,CAKd;IACF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAEjB,IAAI,EAAE,UAAU,EACxB,MAAM,EAAE,eAAe,EACf,OAAO,CAAC,EAAE,YAAY,YAAA,EACtB,UAAU,IAAI,UAAU,MAAM,kDAAyB;IAY1E,WAAW,IAAI,mBAAmB;IAGlC,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAAG,MAAM,IAAI;IAKrE,SAAS,IAAI,MAAM;IAGnB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAmCV,IAAI;IA2IlB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO;IAWpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,MAAM;IAGd,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,MAAM;CAIf"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Client } from '@colyseus/sdk';
|
|
2
|
+
import { attachServerClock } from '#colyseus-schemas/clock';
|
|
3
|
+
import { MultiplayerState } from '#colyseus-schemas/multiplayer';
|
|
4
|
+
import { isLaunchOutcome, normalizeError, RECOVERY_GRACE_MS, } from '#multiplayer-contracts';
|
|
5
|
+
/** Game-owned socket. One adapter per active document/round; no credentials go to parent pages. */
|
|
6
|
+
export class MultiplayerClient {
|
|
7
|
+
constructor(host, launch, storage, makeClient = (endpoint) => new Client(endpoint)) {
|
|
8
|
+
this.host = host;
|
|
9
|
+
this.launch = launch;
|
|
10
|
+
this.storage = storage;
|
|
11
|
+
this.makeClient = makeClient;
|
|
12
|
+
this.room = null;
|
|
13
|
+
this.operation = null;
|
|
14
|
+
this.generation = 0;
|
|
15
|
+
this.disposed = false;
|
|
16
|
+
this.recoverUntil = 0;
|
|
17
|
+
this.cancelRetry = null;
|
|
18
|
+
this.unsubscribers = [];
|
|
19
|
+
this.listeners = new Set();
|
|
20
|
+
this.token = null;
|
|
21
|
+
this.endpoint = null;
|
|
22
|
+
this.clockNow = () => Date.now();
|
|
23
|
+
this.snapshot = {
|
|
24
|
+
status: 'disconnected',
|
|
25
|
+
error: null,
|
|
26
|
+
storageAvailable: true,
|
|
27
|
+
state: null,
|
|
28
|
+
};
|
|
29
|
+
this.storageKey = [
|
|
30
|
+
// Also the SDK Usage Report's implementation marker; keep the literal.
|
|
31
|
+
'gamehub.mp.v2',
|
|
32
|
+
launch.hostInstanceId,
|
|
33
|
+
launch.multiplayerSessionId,
|
|
34
|
+
launch.roundId,
|
|
35
|
+
launch.seatId,
|
|
36
|
+
].join(':');
|
|
37
|
+
if (!storage)
|
|
38
|
+
this.snapshot.storageAvailable = false;
|
|
39
|
+
}
|
|
40
|
+
getSnapshot() {
|
|
41
|
+
return this.snapshot;
|
|
42
|
+
}
|
|
43
|
+
subscribe(listener) {
|
|
44
|
+
this.listeners.add(listener);
|
|
45
|
+
listener(this.snapshot);
|
|
46
|
+
return () => this.listeners.delete(listener);
|
|
47
|
+
}
|
|
48
|
+
serverNow() {
|
|
49
|
+
return this.clockNow();
|
|
50
|
+
}
|
|
51
|
+
connect() {
|
|
52
|
+
if (this.disposed || this.snapshot.status === 'completed')
|
|
53
|
+
return Promise.resolve();
|
|
54
|
+
if (this.operation)
|
|
55
|
+
return this.operation;
|
|
56
|
+
if (this.room)
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
const generation = this.generation;
|
|
59
|
+
const operation = (async () => {
|
|
60
|
+
do {
|
|
61
|
+
await this.join(generation);
|
|
62
|
+
if (generation !== this.generation ||
|
|
63
|
+
this.snapshot.status !== 'failed' ||
|
|
64
|
+
!this.snapshot.error?.retryable ||
|
|
65
|
+
Date.now() >= this.recoverUntil)
|
|
66
|
+
break;
|
|
67
|
+
this.update({ status: 'reconnecting' });
|
|
68
|
+
await new Promise((resolve) => {
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
this.cancelRetry = null;
|
|
71
|
+
resolve();
|
|
72
|
+
}, 1000);
|
|
73
|
+
this.cancelRetry = () => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
this.cancelRetry = null;
|
|
76
|
+
resolve();
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
} while (generation === this.generation && !this.disposed);
|
|
80
|
+
})().finally(() => {
|
|
81
|
+
if (this.operation === operation)
|
|
82
|
+
this.operation = null;
|
|
83
|
+
});
|
|
84
|
+
this.operation = operation;
|
|
85
|
+
return operation;
|
|
86
|
+
}
|
|
87
|
+
async join(generation) {
|
|
88
|
+
this.update({
|
|
89
|
+
status: this.token ? 'reconnecting' : 'connecting',
|
|
90
|
+
error: null,
|
|
91
|
+
});
|
|
92
|
+
try {
|
|
93
|
+
let room = null;
|
|
94
|
+
if (!this.token) {
|
|
95
|
+
try {
|
|
96
|
+
const raw = this.storage?.getItem(this.storageKey);
|
|
97
|
+
const saved = raw ? JSON.parse(raw) : null;
|
|
98
|
+
if (saved &&
|
|
99
|
+
typeof saved.token === 'string' &&
|
|
100
|
+
typeof saved.endpoint === 'string' &&
|
|
101
|
+
/^wss?:\/\//.test(saved.endpoint) &&
|
|
102
|
+
saved.expiresAt > Date.now()) {
|
|
103
|
+
this.token = saved.token;
|
|
104
|
+
this.endpoint = saved.endpoint;
|
|
105
|
+
this.recoverUntil =
|
|
106
|
+
Date.now() + (this.launch.recoveryGraceMs ?? RECOVERY_GRACE_MS);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
this.update({ storageAvailable: false });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (this.token && this.endpoint) {
|
|
114
|
+
try {
|
|
115
|
+
room = await this.makeClient(this.endpoint).reconnect(this.token, MultiplayerState);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (!normalizeError(error).retryable)
|
|
119
|
+
this.clearToken();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (generation !== this.generation) {
|
|
123
|
+
await room?.leave();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!room) {
|
|
127
|
+
const result = await this.host.requestMultiplayerLaunch();
|
|
128
|
+
if (generation !== this.generation)
|
|
129
|
+
return;
|
|
130
|
+
if (!isLaunchOutcome(result))
|
|
131
|
+
throw new Error('Invalid launch response');
|
|
132
|
+
const outcome = result;
|
|
133
|
+
if (outcome.status !== 'reserved') {
|
|
134
|
+
this.update({ status: 'failed', error: outcome.error });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if ([
|
|
138
|
+
'roundId',
|
|
139
|
+
'attemptId',
|
|
140
|
+
'seatId',
|
|
141
|
+
'multiplayerSessionId',
|
|
142
|
+
'hostInstanceId',
|
|
143
|
+
].some((k) => outcome.launch[k] !==
|
|
144
|
+
this.launch[k]))
|
|
145
|
+
throw new Error('Stale launch response');
|
|
146
|
+
this.endpoint = outcome.wsEndpoint;
|
|
147
|
+
room = await this.makeClient(outcome.wsEndpoint).consumeSeatReservation(outcome.reservation, MultiplayerState);
|
|
148
|
+
}
|
|
149
|
+
if (generation !== this.generation) {
|
|
150
|
+
await room.leave();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.room = room;
|
|
154
|
+
// Recovery is owned here, not by a second SDK reconnect loop.
|
|
155
|
+
room.reconnection.enabled = false;
|
|
156
|
+
this.clockNow = attachServerClock(room);
|
|
157
|
+
this.remember(room);
|
|
158
|
+
const sync = () => {
|
|
159
|
+
if (generation !== this.generation)
|
|
160
|
+
return;
|
|
161
|
+
const phase = room.state?.roundPhase;
|
|
162
|
+
const status = phase === 'playing'
|
|
163
|
+
? 'playing'
|
|
164
|
+
: phase === 'completed'
|
|
165
|
+
? 'completed'
|
|
166
|
+
: phase === 'finishing'
|
|
167
|
+
? 'finishing'
|
|
168
|
+
: 'loading';
|
|
169
|
+
this.update({ state: room.state, status });
|
|
170
|
+
if (status === 'completed')
|
|
171
|
+
this.clearToken();
|
|
172
|
+
};
|
|
173
|
+
room.onStateChange(sync);
|
|
174
|
+
this.unsubscribers.push(() => room.onStateChange.remove(sync));
|
|
175
|
+
this.unsubscribers.push(room.onMessage('mp:status', (message) => {
|
|
176
|
+
if (message.phase === 'finishing')
|
|
177
|
+
this.update({ status: 'finishing' });
|
|
178
|
+
if (message.phase === 'completed') {
|
|
179
|
+
this.clearToken();
|
|
180
|
+
this.update({ status: 'completed' });
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
183
|
+
this.unsubscribers.push(room.onMessage('error', (error) => this.update({ error: normalizeError(error) })));
|
|
184
|
+
const onLeave = (code) => {
|
|
185
|
+
this.room = null;
|
|
186
|
+
this.detach();
|
|
187
|
+
if (generation !== this.generation || this.disposed)
|
|
188
|
+
return;
|
|
189
|
+
if (this.snapshot.status === 'completed')
|
|
190
|
+
return;
|
|
191
|
+
if (code >= 4200 || code === 1000) {
|
|
192
|
+
this.clearToken();
|
|
193
|
+
this.update({ status: 'failed', error: normalizeError({ code }) });
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.recoverUntil =
|
|
197
|
+
Date.now() + (this.launch.recoveryGraceMs ?? RECOVERY_GRACE_MS);
|
|
198
|
+
this.update({ status: 'reconnecting' });
|
|
199
|
+
queueMicrotask(() => {
|
|
200
|
+
void this.connect();
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
room.onLeave(onLeave);
|
|
204
|
+
this.unsubscribers.push(() => room.onLeave.remove(onLeave));
|
|
205
|
+
sync();
|
|
206
|
+
room.send('mp:ready');
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (generation === this.generation)
|
|
210
|
+
this.update({ status: 'failed', error: normalizeError(error) });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
send(type, payload) {
|
|
214
|
+
if (this.snapshot.status !== 'playing' ||
|
|
215
|
+
!this.room ||
|
|
216
|
+
type.startsWith('mp:') ||
|
|
217
|
+
type.startsWith('clock:'))
|
|
218
|
+
return false;
|
|
219
|
+
this.room.send('mp:action', { type, payload });
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
async leave() {
|
|
223
|
+
++this.generation;
|
|
224
|
+
this.disposed = true;
|
|
225
|
+
this.cancelRetry?.();
|
|
226
|
+
this.clearToken();
|
|
227
|
+
const room = this.room;
|
|
228
|
+
this.room = null;
|
|
229
|
+
// Clock cleanup receives onLeave before removing the adapter's own listeners.
|
|
230
|
+
if (room)
|
|
231
|
+
await room.leave();
|
|
232
|
+
this.detach();
|
|
233
|
+
this.update({ status: 'disconnected', state: null });
|
|
234
|
+
this.listeners.clear();
|
|
235
|
+
}
|
|
236
|
+
detach() {
|
|
237
|
+
for (const off of this.unsubscribers.splice(0))
|
|
238
|
+
off();
|
|
239
|
+
}
|
|
240
|
+
remember(room) {
|
|
241
|
+
this.token = room.reconnectionToken;
|
|
242
|
+
try {
|
|
243
|
+
this.storage?.setItem(this.storageKey, JSON.stringify({
|
|
244
|
+
token: this.token,
|
|
245
|
+
endpoint: this.endpoint,
|
|
246
|
+
expiresAt: Date.now() + 86400000,
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
this.update({ storageAvailable: false });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
clearToken() {
|
|
254
|
+
this.token = null;
|
|
255
|
+
try {
|
|
256
|
+
this.storage?.removeItem(this.storageKey);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
this.update({ storageAvailable: false });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
update(change) {
|
|
263
|
+
this.snapshot = { ...this.snapshot, ...change };
|
|
264
|
+
for (const listener of this.listeners)
|
|
265
|
+
listener(this.snapshot);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=multiplayer-client.js.map
|