@caisual/kit 0.10.0 → 0.13.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/dist/kit.js +196 -24
- package/dist/node.js +77 -18
- package/dist/overlay.js +134 -35
- package/dist/runtime.js +79 -18
- package/dist/types/api.d.ts +1 -0
- package/dist/types/contracts/biglietto.d.ts +3 -2
- package/dist/types/contracts/immagine.d.ts +27 -0
- package/dist/types/contracts/index.d.ts +3 -0
- package/dist/types/contracts/manifest.d.ts +4 -1
- package/dist/types/contracts/match-result.d.ts +16 -0
- package/dist/types/contracts/overlay.d.ts +7 -1
- package/dist/types/contracts/versioni.d.ts +18 -0
- package/dist/types/daily.d.ts +14 -0
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/handshake.d.ts +2 -1
- package/dist/types/index.d.ts +10 -0
- package/dist/types/node/index.d.ts +4 -0
- package/dist/types/overlay/host-bridge.d.ts +6 -1
- package/dist/types/overlay/i18n.d.ts +9 -0
- package/dist/types/overlay/styles.d.ts +1 -1
- package/dist/types/overlay/ui-model.d.ts +4 -0
- package/dist/types/overlay/ui.d.ts +2 -0
- package/dist/types/protocollo.d.ts +8 -0
- package/dist/types/runtime/index.d.ts +4 -0
- package/dist/types/server/index.d.ts +12 -1
- package/dist/types/session/index.d.ts +1 -1
- package/dist/types/stanza/nucleo.d.ts +3 -0
- package/dist/types/stanza/tipi.d.ts +11 -0
- package/dist/types/stanza-client/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/kit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Caisual game kit v0.
|
|
1
|
+
// Caisual game kit v0.13.0
|
|
2
2
|
|
|
3
3
|
// ../contracts/src/slug.ts
|
|
4
4
|
var NOMI_RISERVATI = [
|
|
@@ -102,6 +102,8 @@ var CAMPI = /* @__PURE__ */ new Set([
|
|
|
102
102
|
"name",
|
|
103
103
|
"description",
|
|
104
104
|
"cover",
|
|
105
|
+
"card",
|
|
106
|
+
"icon",
|
|
105
107
|
"screenshots",
|
|
106
108
|
"tags",
|
|
107
109
|
"languages",
|
|
@@ -221,12 +223,21 @@ function validaManifest(valore) {
|
|
|
221
223
|
}
|
|
222
224
|
const description = stringaDefault(dati, "description", "", errori);
|
|
223
225
|
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
const immagini = { cover: "", card: "", icon: "" };
|
|
227
|
+
const usati = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const campo of ["cover", "card", "icon"]) {
|
|
229
|
+
const path = dati[campo];
|
|
230
|
+
if (path === void 0 || path === null) errori.push(`${campo}: is required.`);
|
|
231
|
+
else if (typeof path !== "string" || !percorsoRelativo(path)) errori.push(`${campo}: must be a relative file path inside client/ without query, fragment, or parent segments.`);
|
|
232
|
+
else {
|
|
233
|
+
if (!/\.(png|jpe?g|webp)$/i.test(path)) errori.push(`${campo}: must be a PNG, JPEG or WebP file.`);
|
|
234
|
+
const canonical = decodeURIComponent(path);
|
|
235
|
+
if (usati.has(canonical)) errori.push(`${campo}: each image must use a different file; cover, card and icon cannot share a path.`);
|
|
236
|
+
usati.add(canonical);
|
|
237
|
+
immagini[campo] = path;
|
|
238
|
+
}
|
|
229
239
|
}
|
|
240
|
+
const { cover, card, icon } = immagini;
|
|
230
241
|
const screenshots = [];
|
|
231
242
|
if (dati.screenshots !== void 0) {
|
|
232
243
|
if (!Array.isArray(dati.screenshots)) errori.push("screenshots: must be an array of relative file paths.");
|
|
@@ -256,8 +267,7 @@ function validaManifest(valore) {
|
|
|
256
267
|
errori.push("language: must be a BCP 47 language tag such as en, it, or pt-BR.");
|
|
257
268
|
}
|
|
258
269
|
const languages2 = [];
|
|
259
|
-
if (dati.languages ===
|
|
260
|
-
else if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
270
|
+
if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
261
271
|
errori.push("languages: must be a non-empty array of BCP 47 language tags.");
|
|
262
272
|
} else for (const [index, raw] of dati.languages.entries()) {
|
|
263
273
|
const tag = normalizeLanguage(raw);
|
|
@@ -265,6 +275,7 @@ function validaManifest(valore) {
|
|
|
265
275
|
else if (languages2.includes(tag)) errori.push(`languages[${index}]: duplicate language ${tag}.`);
|
|
266
276
|
else languages2.push(tag);
|
|
267
277
|
}
|
|
278
|
+
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
268
279
|
const language = languages2[0] ?? legacyLanguage;
|
|
269
280
|
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
270
281
|
errori.push("language: must match the first entry in languages when both are present.");
|
|
@@ -420,12 +431,14 @@ function validaManifest(valore) {
|
|
|
420
431
|
continue;
|
|
421
432
|
}
|
|
422
433
|
for (const campo of Object.keys(board)) {
|
|
423
|
-
if (!["source", "label", "periods"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
434
|
+
if (!["source", "label", "periods", "day"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
424
435
|
}
|
|
425
436
|
if (board.source !== "client" && board.source !== "server") {
|
|
426
437
|
errori.push(`boards.${id2}.source: must be "client" or "server".`);
|
|
427
438
|
valido = false;
|
|
428
439
|
}
|
|
440
|
+
if (board.day !== void 0 && board.day !== "submit" && board.day !== "start") errori.push(`boards.${id2}.day: must be "submit" or "start".`);
|
|
441
|
+
if (board.day === "start" && board.source !== "server") errori.push(`boards.${id2}.day: start requires source "server".`);
|
|
429
442
|
const label = testoFacoltativo(board, "label", 48, `boards.${id2}`, errori);
|
|
430
443
|
let periods = ["all-time"];
|
|
431
444
|
if (board.periods !== void 0) {
|
|
@@ -436,6 +449,7 @@ function validaManifest(valore) {
|
|
|
436
449
|
if (valido) Object.defineProperty(boards, id2, { value: {
|
|
437
450
|
source: board.source,
|
|
438
451
|
periods,
|
|
452
|
+
...board.day === void 0 ? {} : { day: board.day },
|
|
439
453
|
...label === void 0 ? {} : { label }
|
|
440
454
|
}, enumerable: true, configurable: true, writable: true });
|
|
441
455
|
}
|
|
@@ -632,6 +646,8 @@ function validaManifest(valore) {
|
|
|
632
646
|
name,
|
|
633
647
|
description,
|
|
634
648
|
cover,
|
|
649
|
+
card,
|
|
650
|
+
icon,
|
|
635
651
|
screenshots,
|
|
636
652
|
tags,
|
|
637
653
|
languages: languages2,
|
|
@@ -785,22 +801,27 @@ async function probeDevice(globals, timeoutMs = 1500) {
|
|
|
785
801
|
return { ...report, tier: deviceTier(report) };
|
|
786
802
|
}
|
|
787
803
|
|
|
804
|
+
// ../contracts/src/versioni.ts
|
|
805
|
+
function numeroVersione(value) {
|
|
806
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
807
|
+
}
|
|
808
|
+
|
|
788
809
|
// ../contracts/src/overlay.ts
|
|
789
|
-
function overlayConfiguration(manifest, coverUrl = null, invite = null) {
|
|
810
|
+
function overlayConfiguration(manifest, coverUrl = null, invite = null, iconUrl = null) {
|
|
790
811
|
const validated = validaManifest(manifest);
|
|
791
812
|
if (!validated.ok) throw new Error("The overlay manifest is invalid.");
|
|
792
|
-
return { manifest: validated.manifest, coverUrl, invite };
|
|
813
|
+
return { manifest: validated.manifest, coverUrl, iconUrl, invite };
|
|
793
814
|
}
|
|
794
815
|
function record(value) {
|
|
795
816
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
796
817
|
}
|
|
797
818
|
function validOverlayHello(value) {
|
|
798
819
|
const hello = record(value), config = record(hello?.configuration);
|
|
799
|
-
return hello?.v === 1 && typeof hello.epoch === "string" && hello.epoch.length > 0 && hello.epoch.length <= 128 && config !== null && (config.coverUrl === null || typeof config.coverUrl === "string") && (config.invite === null || typeof config.invite === "string" && /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(config.invite)) && validaManifest(config.manifest).ok;
|
|
820
|
+
return hello?.v === 1 && typeof hello.epoch === "string" && hello.epoch.length > 0 && hello.epoch.length <= 128 && config !== null && (config.coverUrl === null || typeof config.coverUrl === "string") && (config.iconUrl === null || typeof config.iconUrl === "string") && (config.invite === null || typeof config.invite === "string" && /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(config.invite)) && validaManifest(config.manifest).ok;
|
|
800
821
|
}
|
|
801
822
|
function normalizeOverlayHello(value) {
|
|
802
823
|
if (!validOverlayHello(value)) return null;
|
|
803
|
-
return { v: 1, epoch: value.epoch, configuration: overlayConfiguration(value.configuration.manifest, value.configuration.coverUrl, value.configuration.invite) };
|
|
824
|
+
return { v: 1, epoch: value.epoch, configuration: overlayConfiguration(value.configuration.manifest, value.configuration.coverUrl, value.configuration.invite, value.configuration.iconUrl) };
|
|
804
825
|
}
|
|
805
826
|
function validSafeArea(value) {
|
|
806
827
|
const area = record(value);
|
|
@@ -868,9 +889,37 @@ function validBoardDay(value) {
|
|
|
868
889
|
// ../contracts/src/room-limits.ts
|
|
869
890
|
var MESSAGGI_GIOCO_AL_SECONDO = 20;
|
|
870
891
|
|
|
892
|
+
// ../contracts/src/match-result.ts
|
|
893
|
+
function readMatchResult(value, playerIds) {
|
|
894
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
895
|
+
const result = object(value);
|
|
896
|
+
if (!result || !Array.isArray(result.standings)) return null;
|
|
897
|
+
const known = new Set(playerIds), seen = /* @__PURE__ */ new Set();
|
|
898
|
+
const standings = [];
|
|
899
|
+
for (const item of result.standings) {
|
|
900
|
+
const row = object(item);
|
|
901
|
+
if (!row || typeof row.playerId !== "string" || !known.has(row.playerId) || seen.has(row.playerId)) continue;
|
|
902
|
+
seen.add(row.playerId);
|
|
903
|
+
standings.push({
|
|
904
|
+
playerId: row.playerId,
|
|
905
|
+
...typeof row.score === "number" && Number.isFinite(row.score) ? { score: row.score } : {},
|
|
906
|
+
...typeof row.rank === "number" && Number.isSafeInteger(row.rank) && row.rank > 0 ? { rank: row.rank } : {}
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
if (!standings.length) return null;
|
|
910
|
+
return {
|
|
911
|
+
standings,
|
|
912
|
+
...Array.isArray(result.winners) ? { winners: [...new Set(result.winners.filter((id) => typeof id === "string" && seen.has(id)))] } : {},
|
|
913
|
+
...typeof result.draw === "boolean" ? { draw: result.draw } : {},
|
|
914
|
+
...typeof result.unit === "string" ? { unit: result.unit } : {}
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
871
918
|
// src/overlay/i18n.ts
|
|
872
919
|
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
873
920
|
var words = {
|
|
921
|
+
gameUpdated: ["This game was updated", "Questo gioco \xE8 stato aggiornato", "Este juego se ha actualizado", "Ce jeu a \xE9t\xE9 mis \xE0 jour", "Dieses Spiel wurde aktualisiert", "Este jogo foi atualizado"],
|
|
922
|
+
reloadGame: ["Reload game", "Ricarica il gioco", "Recargar el juego", "Recharger le jeu", "Spiel neu laden", "Recarregar o jogo"],
|
|
874
923
|
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
875
924
|
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
876
925
|
loadingSlow: ["This game is taking longer than expected. You can wait a little longer or try again.", "Il gioco ci sta mettendo pi\xF9 del previsto. Puoi aspettare ancora un po\u2019 o riprovare.", "El juego est\xE1 tardando m\xE1s de lo esperado. Puedes esperar un poco m\xE1s o volver a intentarlo.", "Le jeu met plus de temps que pr\xE9vu. Vous pouvez patienter encore un peu ou r\xE9essayer.", "Das Spiel braucht l\xE4nger als erwartet. Du kannst noch etwas warten oder es erneut versuchen.", "O jogo est\xE1 demorando mais do que o esperado. Voc\xEA pode esperar mais um pouco ou tentar novamente."],
|
|
@@ -913,6 +962,13 @@ var words = {
|
|
|
913
962
|
ended: ["Game finished", "Partita conclusa", "Partida terminada", "Partie termin\xE9e", "Spiel beendet", "Partida encerrada"],
|
|
914
963
|
rematchReady: ["{n}/{max} ready", "{n}/{max} pronti", "{n}/{max} listos", "{n}/{max} pr\xEAts", "{n}/{max} bereit", "{n}/{max} prontos"],
|
|
915
964
|
rematchStart: ["Start rematch", "Avvia rivincita", "Iniciar revancha", "Lancer la revanche", "Revanche starten", "Iniciar revanche"],
|
|
965
|
+
won: ["You won", "Hai vinto", "Has ganado", "Vous avez gagn\xE9", "Du hast gewonnen", "Voc\xEA venceu"],
|
|
966
|
+
lost: ["You lost", "Hai perso", "Has perdido", "Vous avez perdu", "Du hast verloren", "Voc\xEA perdeu"],
|
|
967
|
+
draw: ["Draw", "Pareggio", "Empate", "\xC9galit\xE9", "Unentschieden", "Empate"],
|
|
968
|
+
standings: ["Standings", "Piazzamenti", "Posiciones", "R\xE9sultats", "Platzierungen", "Coloca\xE7\xF5es"],
|
|
969
|
+
points: ["points", "punti", "puntos", "points", "Punkte", "pontos"],
|
|
970
|
+
time: ["time", "tempo", "tiempo", "temps", "Zeit", "tempo"],
|
|
971
|
+
distance: ["distance", "distanza", "distancia", "distance", "Distanz", "dist\xE2ncia"],
|
|
916
972
|
again: ["Play again", "Gioca ancora", "Jugar de nuevo", "Rejouer", "Erneut spielen", "Jogar novamente"],
|
|
917
973
|
newRoom: ["New room. Share the new invite.", "Nuova stanza. Condividi il nuovo invito.", "Nueva sala. Comparte la invitaci\xF3n.", "Nouvelle salle. Partagez le lien.", "Neuer Raum. Neue Einladung teilen.", "Nova sala. Compartilhe o convite."],
|
|
918
974
|
watching: ["Watching", "In osservazione", "Observando", "Spectateur", "Zuschauen", "Assistindo"],
|
|
@@ -1018,8 +1074,8 @@ function createTextLoader(fetcher, language, pathname = "/") {
|
|
|
1018
1074
|
}
|
|
1019
1075
|
|
|
1020
1076
|
// src/errors.ts
|
|
1021
|
-
function creaErrore(code, message) {
|
|
1022
|
-
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
1077
|
+
function creaErrore(code, message, version = {}) {
|
|
1078
|
+
return Object.assign(new Error(message), { name: "CaisualError", code, ...version });
|
|
1023
1079
|
}
|
|
1024
1080
|
function erroreOffline() {
|
|
1025
1081
|
return creaErrore("offline", "Caisual services are unavailable.");
|
|
@@ -1133,6 +1189,7 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1133
1189
|
function snapshot() {
|
|
1134
1190
|
const attached = current.kind === "room" || current.kind === "watch" ? current.room : null;
|
|
1135
1191
|
const configured = attached?.metadata.configuration;
|
|
1192
|
+
const result = attached ? readMatchResult(attached.result, attached.players.map((p) => p.id)) : null;
|
|
1136
1193
|
const fallback = manifest && attached && (attached.mode === null || manifest.modes.some((m) => m.id === attached.mode)) ? risolviModalita(manifest, attached.mode) : { players: { min: 1, max: 1 }, lobby: false };
|
|
1137
1194
|
return {
|
|
1138
1195
|
kind: pending ?? (current.kind === "idle" ? ready ? "home" : "boot" : current.kind),
|
|
@@ -1142,12 +1199,14 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1142
1199
|
ready,
|
|
1143
1200
|
capabilities: capabilities(),
|
|
1144
1201
|
room: attached ? {
|
|
1202
|
+
...attached.metadata.rematch?.keepSetup || attached.metadata.rematch?.autoStart ? { rematch: attached.metadata.rematch } : {},
|
|
1145
1203
|
code: attached.code,
|
|
1146
1204
|
mode: attached.mode,
|
|
1147
1205
|
status: attached.status,
|
|
1148
1206
|
host: attached.host,
|
|
1149
1207
|
you: current.kind === "room" ? current.room.you : null,
|
|
1150
1208
|
players: attached.players.map((p) => ({ id: p.id, name: p.name, guest: p.guest, role: p.role, team: p.team, ready: p.ready, connected: p.connected })),
|
|
1209
|
+
...result ? { result } : {},
|
|
1151
1210
|
countdownAt: attached.countdownAt,
|
|
1152
1211
|
connection: attached.connection,
|
|
1153
1212
|
closedCode: attached.metadata.closedCode,
|
|
@@ -1261,8 +1320,15 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1261
1320
|
}
|
|
1262
1321
|
}
|
|
1263
1322
|
const direct = base.room;
|
|
1323
|
+
const stopVersionErrors = direct.onError((error) => {
|
|
1324
|
+
if (!standard || disposed) return;
|
|
1325
|
+
if (error.code === "version_mismatch") direct.reload();
|
|
1326
|
+
else if (error.code === "version_outdated") notify(errorListeners, { sessionId: current.kind === "idle" ? null : current.id, error });
|
|
1327
|
+
});
|
|
1264
1328
|
const rooms = !standard ? direct : {
|
|
1265
1329
|
invited: direct.invited,
|
|
1330
|
+
reload: () => direct.reload(),
|
|
1331
|
+
onError: (listener) => direct.onError(listener),
|
|
1266
1332
|
create(options) {
|
|
1267
1333
|
if (manifest && modalitaLocale(manifest, options.mode)) return Promise.reject(creaErrore("invalid_request", "Local modes cannot create rooms."));
|
|
1268
1334
|
return run("attaching", options.mode, () => direct.create(options));
|
|
@@ -1475,6 +1541,7 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1475
1541
|
}
|
|
1476
1542
|
},
|
|
1477
1543
|
dispose() {
|
|
1544
|
+
stopVersionErrors();
|
|
1478
1545
|
cancel();
|
|
1479
1546
|
detach(true);
|
|
1480
1547
|
disposed = true;
|
|
@@ -1583,7 +1650,8 @@ async function leggiErrore(response) {
|
|
|
1583
1650
|
}
|
|
1584
1651
|
return creaErrore(
|
|
1585
1652
|
typeof corpo.error?.code === "string" ? corpo.error.code : response.status === 401 ? "invalid_ticket" : "internal_error",
|
|
1586
|
-
typeof corpo.error?.message === "string" ? corpo.error.message : `The request failed with status ${response.status}
|
|
1653
|
+
typeof corpo.error?.message === "string" ? corpo.error.message : `The request failed with status ${response.status}.`,
|
|
1654
|
+
{ currentVersion: corpo.error?.currentVersion, roomVersion: corpo.error?.roomVersion }
|
|
1587
1655
|
);
|
|
1588
1656
|
}
|
|
1589
1657
|
function creaRichiedente(origin, prefix, fetcher, biglietto) {
|
|
@@ -1683,6 +1751,53 @@ function creaClienteApi(appOrigin, fetcher, biglietto) {
|
|
|
1683
1751
|
|
|
1684
1752
|
// src/daily.ts
|
|
1685
1753
|
var DIVISORE_UINT32 = 4294967296;
|
|
1754
|
+
function prossimaMezzanotteUtc(ora) {
|
|
1755
|
+
return (Math.floor(ora / 864e5) + 1) * 864e5;
|
|
1756
|
+
}
|
|
1757
|
+
function creaDaily(initial, now, refresh) {
|
|
1758
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1759
|
+
let current = { ...initial }, timer, pending = false;
|
|
1760
|
+
function schedule() {
|
|
1761
|
+
if (!listeners.size || timer !== void 0 || pending) return;
|
|
1762
|
+
timer = setTimeout(check, Math.max(0, Math.min(2147483647, current.expiresAt - now())));
|
|
1763
|
+
timer.unref?.();
|
|
1764
|
+
}
|
|
1765
|
+
async function check() {
|
|
1766
|
+
timer = void 0;
|
|
1767
|
+
pending = true;
|
|
1768
|
+
try {
|
|
1769
|
+
const next = await refresh(), changed = next.day !== current.day;
|
|
1770
|
+
current = { ...next };
|
|
1771
|
+
if (changed) for (const listener of [...listeners]) {
|
|
1772
|
+
try {
|
|
1773
|
+
listener({ ...next });
|
|
1774
|
+
} catch {
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
} catch {
|
|
1778
|
+
} finally {
|
|
1779
|
+
pending = false;
|
|
1780
|
+
if (current.expiresAt <= now()) current.expiresAt = now() + 3e4;
|
|
1781
|
+
schedule();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
return {
|
|
1785
|
+
...initial,
|
|
1786
|
+
random: creaMulberry32(initial.seed),
|
|
1787
|
+
rng: () => creaMulberry32(initial.seed),
|
|
1788
|
+
onChange(listener) {
|
|
1789
|
+
listeners.add(listener);
|
|
1790
|
+
schedule();
|
|
1791
|
+
return () => {
|
|
1792
|
+
listeners.delete(listener);
|
|
1793
|
+
if (!listeners.size && timer !== void 0) {
|
|
1794
|
+
clearTimeout(timer);
|
|
1795
|
+
timer = void 0;
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1686
1801
|
function giornoUtc(ora) {
|
|
1687
1802
|
return new Date(ora).toISOString().slice(0, 10);
|
|
1688
1803
|
}
|
|
@@ -1741,7 +1856,7 @@ function attendiHandshake(finestra, appOrigin, timeoutMs = 3e3) {
|
|
|
1741
1856
|
if (!eTipo(evento.data, "caisual:hello")) return;
|
|
1742
1857
|
const dati = record2(evento.data);
|
|
1743
1858
|
const porta = evento.ports[0];
|
|
1744
|
-
if (typeof dati?.ticket !== "string" || porta === void 0) return;
|
|
1859
|
+
if (typeof dati?.ticket !== "string" || !numeroVersione(dati.n) || porta === void 0) return;
|
|
1745
1860
|
porta.start();
|
|
1746
1861
|
const overlay = normalizeOverlayHello(dati.overlay);
|
|
1747
1862
|
const tags = (value) => Array.isArray(value) ? value.map(normalizeLanguage).filter((tag) => tag !== null) : void 0;
|
|
@@ -1752,6 +1867,7 @@ function attendiHandshake(finestra, appOrigin, timeoutMs = 3e3) {
|
|
|
1752
1867
|
languagePreferences: tags(dati.languagePreferences),
|
|
1753
1868
|
gameLanguages: tags(dati.gameLanguages),
|
|
1754
1869
|
ticket: dati.ticket,
|
|
1870
|
+
n: dati.n,
|
|
1755
1871
|
live: leggiOrigine(dati.live),
|
|
1756
1872
|
invite: typeof dati.invite === "string" ? dati.invite : null,
|
|
1757
1873
|
porta
|
|
@@ -2783,7 +2899,20 @@ function applicaPatch(state, value) {
|
|
|
2783
2899
|
return { ok: true, state: risultato };
|
|
2784
2900
|
}
|
|
2785
2901
|
function creaApiLive(input) {
|
|
2786
|
-
const
|
|
2902
|
+
const richiedi = creaRichiedente(input.liveOrigin, "", input.fetcher, input.biglietto);
|
|
2903
|
+
const richiesta = async (path, method, body, renew) => {
|
|
2904
|
+
try {
|
|
2905
|
+
return await richiedi(path, method, { ...record3(body), n: input.n }, renew);
|
|
2906
|
+
} catch (error) {
|
|
2907
|
+
if (error instanceof Error && "code" in error && ["version_outdated", "version_mismatch"].includes(String(error.code))) {
|
|
2908
|
+
const value = record3(body);
|
|
2909
|
+
const code = typeof value?.code === "string" ? value.code.toUpperCase().replace(/[\s-]/g, "") : void 0;
|
|
2910
|
+
const roomId = typeof value?.roomId === "string" ? value.roomId : void 0;
|
|
2911
|
+
input.onVersionError?.(error, error.code === "version_mismatch" ? { code, roomId, watch: path === "/rooms/watch" } : void 0);
|
|
2912
|
+
}
|
|
2913
|
+
throw error;
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2787
2916
|
async function ingresso(path, body, rinnova = false) {
|
|
2788
2917
|
const value = await richiesta(path, "POST", body, rinnova);
|
|
2789
2918
|
if (!ingressoValido(value)) {
|
|
@@ -2936,6 +3065,7 @@ var StanzaClient = class {
|
|
|
2936
3065
|
host: room.host,
|
|
2937
3066
|
mode: room.mode,
|
|
2938
3067
|
countdownAt: room.countdownAt ?? null,
|
|
3068
|
+
rematch: room.rematch ?? null,
|
|
2939
3069
|
configuration: room.configuration ?? null,
|
|
2940
3070
|
connection: "connected",
|
|
2941
3071
|
closedCode: null
|
|
@@ -3336,6 +3466,7 @@ var StanzaClient = class {
|
|
|
3336
3466
|
this.ultimoInput = null;
|
|
3337
3467
|
}
|
|
3338
3468
|
this.metadataChanged({
|
|
3469
|
+
rematch: dati.rematch ?? null,
|
|
3339
3470
|
host: this.hostCorrente,
|
|
3340
3471
|
countdownAt: dati.countdownAt ?? (dati.status === "countdown" ? dati.at : null),
|
|
3341
3472
|
...dati.status === "ended" ? { connection: "ended", closedCode: 4004 } : {}
|
|
@@ -3431,8 +3562,11 @@ var StanzaClient = class {
|
|
|
3431
3562
|
this.segnalaStanza({ code: this.codice });
|
|
3432
3563
|
}
|
|
3433
3564
|
this.apri(ingresso.url);
|
|
3434
|
-
} catch {
|
|
3435
|
-
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
if (error instanceof Error && "code" in error && ["version_mismatch", "version_outdated", "room_not_found"].includes(String(error.code))) {
|
|
3567
|
+
this.notifica(this.errorListeners, { code: String(error.code), message: error.message });
|
|
3568
|
+
this.termina(4004, String(error.code));
|
|
3569
|
+
} else this.programmaRiconnessione();
|
|
3436
3570
|
}
|
|
3437
3571
|
}
|
|
3438
3572
|
fermaRiconnessione() {
|
|
@@ -3505,6 +3639,13 @@ var StanzaClient = class {
|
|
|
3505
3639
|
function creaStanzeOffline(invited = null) {
|
|
3506
3640
|
return {
|
|
3507
3641
|
invited,
|
|
3642
|
+
reload() {
|
|
3643
|
+
if (typeof window !== "undefined") window.location.reload();
|
|
3644
|
+
},
|
|
3645
|
+
onError() {
|
|
3646
|
+
return () => {
|
|
3647
|
+
};
|
|
3648
|
+
},
|
|
3508
3649
|
async create() {
|
|
3509
3650
|
throw erroreOffline();
|
|
3510
3651
|
},
|
|
@@ -3520,7 +3661,17 @@ function creaStanzeOffline(invited = null) {
|
|
|
3520
3661
|
};
|
|
3521
3662
|
}
|
|
3522
3663
|
function creaGestoreStanze(input, invited) {
|
|
3523
|
-
|
|
3664
|
+
let reloadTarget;
|
|
3665
|
+
const errors = /* @__PURE__ */ new Set();
|
|
3666
|
+
const api = creaApiLive({ ...input, onVersionError(error, target) {
|
|
3667
|
+
reloadTarget = target;
|
|
3668
|
+
for (const listener of errors) {
|
|
3669
|
+
try {
|
|
3670
|
+
listener(error);
|
|
3671
|
+
} catch {
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
} });
|
|
3524
3675
|
let haSegnalato = false;
|
|
3525
3676
|
let ultimoCodice = null;
|
|
3526
3677
|
const segnalaStanza = (room) => {
|
|
@@ -3711,6 +3862,15 @@ function creaGestoreStanze(input, invited) {
|
|
|
3711
3862
|
});
|
|
3712
3863
|
return {
|
|
3713
3864
|
invited,
|
|
3865
|
+
reload() {
|
|
3866
|
+
input.reload?.(reloadTarget);
|
|
3867
|
+
},
|
|
3868
|
+
onError(listener) {
|
|
3869
|
+
errors.add(listener);
|
|
3870
|
+
return () => {
|
|
3871
|
+
errors.delete(listener);
|
|
3872
|
+
};
|
|
3873
|
+
},
|
|
3714
3874
|
async create(options) {
|
|
3715
3875
|
return collega(await api.create(options.mode));
|
|
3716
3876
|
},
|
|
@@ -3804,12 +3964,15 @@ function creaSave(archivio, ora) {
|
|
|
3804
3964
|
};
|
|
3805
3965
|
}
|
|
3806
3966
|
async function creaStandalone(input, invited = null) {
|
|
3807
|
-
const
|
|
3967
|
+
const startedAt = input.ora(), day = giornoUtc(startedAt);
|
|
3808
3968
|
const seed = await calcolaSeed(input.hostname, day, input.subtle);
|
|
3809
3969
|
return {
|
|
3810
3970
|
connected: false,
|
|
3811
3971
|
player: { id: "local", name: "Guest", guest: true },
|
|
3812
|
-
daily: { day, seed,
|
|
3972
|
+
daily: creaDaily({ day, seed, expiresAt: prossimaMezzanotteUtc(startedAt) }, input.ora, async () => {
|
|
3973
|
+
const now = input.ora(), day2 = giornoUtc(now);
|
|
3974
|
+
return { day: day2, seed: await calcolaSeed(input.hostname, day2, input.subtle), expiresAt: prossimaMezzanotteUtc(now) };
|
|
3975
|
+
}),
|
|
3813
3976
|
time: { now: input.ora },
|
|
3814
3977
|
save: creaSave(input.archivio, input.ora),
|
|
3815
3978
|
board: {
|
|
@@ -3890,6 +4053,8 @@ async function connetti(input) {
|
|
|
3890
4053
|
const scartoOrario = me.serverTime - (prima + dopo) / 2;
|
|
3891
4054
|
const room = handshake.live === null ? creaStanzeOffline(handshake.invite) : creaGestoreStanze({
|
|
3892
4055
|
appOrigin,
|
|
4056
|
+
n: handshake.n,
|
|
4057
|
+
reload: (target) => handshake.porta.postMessage({ type: "caisual:reload", target }),
|
|
3893
4058
|
liveOrigin: handshake.live,
|
|
3894
4059
|
fetcher: input.fetcher,
|
|
3895
4060
|
biglietto: creaGestoreBiglietto(
|
|
@@ -3921,7 +4086,14 @@ async function connetti(input) {
|
|
|
3921
4086
|
const base = {
|
|
3922
4087
|
connected: true,
|
|
3923
4088
|
player: me.player,
|
|
3924
|
-
daily:
|
|
4089
|
+
daily: creaDaily(
|
|
4090
|
+
{ day: me.day, seed: me.seed, expiresAt: me.expiresAt ?? prossimaMezzanotteUtc(me.serverTime) },
|
|
4091
|
+
() => input.ora() + scartoOrario,
|
|
4092
|
+
async () => {
|
|
4093
|
+
const next = await api.me();
|
|
4094
|
+
return { day: next.day, seed: next.seed, expiresAt: next.expiresAt ?? prossimaMezzanotteUtc(next.serverTime) };
|
|
4095
|
+
}
|
|
4096
|
+
),
|
|
3925
4097
|
time: { now: () => input.ora() + scartoOrario },
|
|
3926
4098
|
save: {
|
|
3927
4099
|
set: (key, value) => api.saveSet(key, value),
|