@caisual/kit 0.12.0 → 0.14.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 +77 -12
- package/dist/overlay.js +34 -9
- package/dist/types/contracts/biglietto.d.ts +3 -2
- package/dist/types/contracts/index.d.ts +1 -0
- package/dist/types/contracts/manifest.d.ts +1 -1
- package/dist/types/contracts/versioni.d.ts +18 -0
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/handshake.d.ts +2 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/overlay/host-bridge.d.ts +6 -1
- package/dist/types/overlay/i18n.d.ts +2 -0
- package/dist/types/session/index.d.ts +1 -1
- 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.14.0
|
|
2
2
|
|
|
3
3
|
// ../contracts/src/slug.ts
|
|
4
4
|
var NOMI_RISERVATI = [
|
|
@@ -180,7 +180,7 @@ function testoFacoltativo(value, key, max, path, errors) {
|
|
|
180
180
|
}
|
|
181
181
|
return text2.trim();
|
|
182
182
|
};
|
|
183
|
-
const text = value[key], field = `${path}.${key}
|
|
183
|
+
const text = value[key], field = path ? `${path}.${key}` : key;
|
|
184
184
|
if (typeof text === "string") return check(text, field);
|
|
185
185
|
const translations = oggetto(text);
|
|
186
186
|
if (!translations || Object.keys(translations).length === 0) {
|
|
@@ -221,8 +221,7 @@ function validaManifest(valore) {
|
|
|
221
221
|
else if (typeof dati.name === "string" && (name.trim() === "" || name.length > 60)) {
|
|
222
222
|
errori.push("name: must contain 1-60 characters.");
|
|
223
223
|
}
|
|
224
|
-
const description =
|
|
225
|
-
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
224
|
+
const description = dati.description === "" ? "" : testoFacoltativo(dati, "description", 500, "", errori) ?? "";
|
|
226
225
|
const immagini = { cover: "", card: "", icon: "" };
|
|
227
226
|
const usati = /* @__PURE__ */ new Set();
|
|
228
227
|
for (const campo of ["cover", "card", "icon"]) {
|
|
@@ -277,6 +276,11 @@ function validaManifest(valore) {
|
|
|
277
276
|
}
|
|
278
277
|
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
279
278
|
const language = languages2[0] ?? legacyLanguage;
|
|
279
|
+
if (typeof description === "object") {
|
|
280
|
+
for (const tag of Object.keys(description)) {
|
|
281
|
+
if (!languages2.includes(tag)) errori.push(`description.${tag}: language must be declared in languages.`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
280
284
|
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
281
285
|
errori.push("language: must match the first entry in languages when both are present.");
|
|
282
286
|
}
|
|
@@ -801,6 +805,11 @@ async function probeDevice(globals, timeoutMs = 1500) {
|
|
|
801
805
|
return { ...report, tier: deviceTier(report) };
|
|
802
806
|
}
|
|
803
807
|
|
|
808
|
+
// ../contracts/src/versioni.ts
|
|
809
|
+
function numeroVersione(value) {
|
|
810
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
811
|
+
}
|
|
812
|
+
|
|
804
813
|
// ../contracts/src/overlay.ts
|
|
805
814
|
function overlayConfiguration(manifest, coverUrl = null, invite = null, iconUrl = null) {
|
|
806
815
|
const validated = validaManifest(manifest);
|
|
@@ -913,6 +922,8 @@ function readMatchResult(value, playerIds) {
|
|
|
913
922
|
// src/overlay/i18n.ts
|
|
914
923
|
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
915
924
|
var words = {
|
|
925
|
+
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"],
|
|
926
|
+
reloadGame: ["Reload game", "Ricarica il gioco", "Recargar el juego", "Recharger le jeu", "Spiel neu laden", "Recarregar o jogo"],
|
|
916
927
|
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
917
928
|
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
918
929
|
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."],
|
|
@@ -1067,8 +1078,8 @@ function createTextLoader(fetcher, language, pathname = "/") {
|
|
|
1067
1078
|
}
|
|
1068
1079
|
|
|
1069
1080
|
// src/errors.ts
|
|
1070
|
-
function creaErrore(code, message) {
|
|
1071
|
-
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
1081
|
+
function creaErrore(code, message, version = {}) {
|
|
1082
|
+
return Object.assign(new Error(message), { name: "CaisualError", code, ...version });
|
|
1072
1083
|
}
|
|
1073
1084
|
function erroreOffline() {
|
|
1074
1085
|
return creaErrore("offline", "Caisual services are unavailable.");
|
|
@@ -1313,8 +1324,15 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1313
1324
|
}
|
|
1314
1325
|
}
|
|
1315
1326
|
const direct = base.room;
|
|
1327
|
+
const stopVersionErrors = direct.onError((error) => {
|
|
1328
|
+
if (!standard || disposed) return;
|
|
1329
|
+
if (error.code === "version_mismatch") direct.reload();
|
|
1330
|
+
else if (error.code === "version_outdated") notify(errorListeners, { sessionId: current.kind === "idle" ? null : current.id, error });
|
|
1331
|
+
});
|
|
1316
1332
|
const rooms = !standard ? direct : {
|
|
1317
1333
|
invited: direct.invited,
|
|
1334
|
+
reload: () => direct.reload(),
|
|
1335
|
+
onError: (listener) => direct.onError(listener),
|
|
1318
1336
|
create(options) {
|
|
1319
1337
|
if (manifest && modalitaLocale(manifest, options.mode)) return Promise.reject(creaErrore("invalid_request", "Local modes cannot create rooms."));
|
|
1320
1338
|
return run("attaching", options.mode, () => direct.create(options));
|
|
@@ -1527,6 +1545,7 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1527
1545
|
}
|
|
1528
1546
|
},
|
|
1529
1547
|
dispose() {
|
|
1548
|
+
stopVersionErrors();
|
|
1530
1549
|
cancel();
|
|
1531
1550
|
detach(true);
|
|
1532
1551
|
disposed = true;
|
|
@@ -1635,7 +1654,8 @@ async function leggiErrore(response) {
|
|
|
1635
1654
|
}
|
|
1636
1655
|
return creaErrore(
|
|
1637
1656
|
typeof corpo.error?.code === "string" ? corpo.error.code : response.status === 401 ? "invalid_ticket" : "internal_error",
|
|
1638
|
-
typeof corpo.error?.message === "string" ? corpo.error.message : `The request failed with status ${response.status}
|
|
1657
|
+
typeof corpo.error?.message === "string" ? corpo.error.message : `The request failed with status ${response.status}.`,
|
|
1658
|
+
{ currentVersion: corpo.error?.currentVersion, roomVersion: corpo.error?.roomVersion }
|
|
1639
1659
|
);
|
|
1640
1660
|
}
|
|
1641
1661
|
function creaRichiedente(origin, prefix, fetcher, biglietto) {
|
|
@@ -1840,7 +1860,7 @@ function attendiHandshake(finestra, appOrigin, timeoutMs = 3e3) {
|
|
|
1840
1860
|
if (!eTipo(evento.data, "caisual:hello")) return;
|
|
1841
1861
|
const dati = record2(evento.data);
|
|
1842
1862
|
const porta = evento.ports[0];
|
|
1843
|
-
if (typeof dati?.ticket !== "string" || porta === void 0) return;
|
|
1863
|
+
if (typeof dati?.ticket !== "string" || !numeroVersione(dati.n) || porta === void 0) return;
|
|
1844
1864
|
porta.start();
|
|
1845
1865
|
const overlay = normalizeOverlayHello(dati.overlay);
|
|
1846
1866
|
const tags = (value) => Array.isArray(value) ? value.map(normalizeLanguage).filter((tag) => tag !== null) : void 0;
|
|
@@ -1851,6 +1871,7 @@ function attendiHandshake(finestra, appOrigin, timeoutMs = 3e3) {
|
|
|
1851
1871
|
languagePreferences: tags(dati.languagePreferences),
|
|
1852
1872
|
gameLanguages: tags(dati.gameLanguages),
|
|
1853
1873
|
ticket: dati.ticket,
|
|
1874
|
+
n: dati.n,
|
|
1854
1875
|
live: leggiOrigine(dati.live),
|
|
1855
1876
|
invite: typeof dati.invite === "string" ? dati.invite : null,
|
|
1856
1877
|
porta
|
|
@@ -2882,7 +2903,20 @@ function applicaPatch(state, value) {
|
|
|
2882
2903
|
return { ok: true, state: risultato };
|
|
2883
2904
|
}
|
|
2884
2905
|
function creaApiLive(input) {
|
|
2885
|
-
const
|
|
2906
|
+
const richiedi = creaRichiedente(input.liveOrigin, "", input.fetcher, input.biglietto);
|
|
2907
|
+
const richiesta = async (path, method, body, renew) => {
|
|
2908
|
+
try {
|
|
2909
|
+
return await richiedi(path, method, { ...record3(body), n: input.n }, renew);
|
|
2910
|
+
} catch (error) {
|
|
2911
|
+
if (error instanceof Error && "code" in error && ["version_outdated", "version_mismatch"].includes(String(error.code))) {
|
|
2912
|
+
const value = record3(body);
|
|
2913
|
+
const code = typeof value?.code === "string" ? value.code.toUpperCase().replace(/[\s-]/g, "") : void 0;
|
|
2914
|
+
const roomId = typeof value?.roomId === "string" ? value.roomId : void 0;
|
|
2915
|
+
input.onVersionError?.(error, error.code === "version_mismatch" ? { code, roomId, watch: path === "/rooms/watch" } : void 0);
|
|
2916
|
+
}
|
|
2917
|
+
throw error;
|
|
2918
|
+
}
|
|
2919
|
+
};
|
|
2886
2920
|
async function ingresso(path, body, rinnova = false) {
|
|
2887
2921
|
const value = await richiesta(path, "POST", body, rinnova);
|
|
2888
2922
|
if (!ingressoValido(value)) {
|
|
@@ -3532,8 +3566,11 @@ var StanzaClient = class {
|
|
|
3532
3566
|
this.segnalaStanza({ code: this.codice });
|
|
3533
3567
|
}
|
|
3534
3568
|
this.apri(ingresso.url);
|
|
3535
|
-
} catch {
|
|
3536
|
-
|
|
3569
|
+
} catch (error) {
|
|
3570
|
+
if (error instanceof Error && "code" in error && ["version_mismatch", "version_outdated", "room_not_found"].includes(String(error.code))) {
|
|
3571
|
+
this.notifica(this.errorListeners, { code: String(error.code), message: error.message });
|
|
3572
|
+
this.termina(4004, String(error.code));
|
|
3573
|
+
} else this.programmaRiconnessione();
|
|
3537
3574
|
}
|
|
3538
3575
|
}
|
|
3539
3576
|
fermaRiconnessione() {
|
|
@@ -3606,6 +3643,13 @@ var StanzaClient = class {
|
|
|
3606
3643
|
function creaStanzeOffline(invited = null) {
|
|
3607
3644
|
return {
|
|
3608
3645
|
invited,
|
|
3646
|
+
reload() {
|
|
3647
|
+
if (typeof window !== "undefined") window.location.reload();
|
|
3648
|
+
},
|
|
3649
|
+
onError() {
|
|
3650
|
+
return () => {
|
|
3651
|
+
};
|
|
3652
|
+
},
|
|
3609
3653
|
async create() {
|
|
3610
3654
|
throw erroreOffline();
|
|
3611
3655
|
},
|
|
@@ -3621,7 +3665,17 @@ function creaStanzeOffline(invited = null) {
|
|
|
3621
3665
|
};
|
|
3622
3666
|
}
|
|
3623
3667
|
function creaGestoreStanze(input, invited) {
|
|
3624
|
-
|
|
3668
|
+
let reloadTarget;
|
|
3669
|
+
const errors = /* @__PURE__ */ new Set();
|
|
3670
|
+
const api = creaApiLive({ ...input, onVersionError(error, target) {
|
|
3671
|
+
reloadTarget = target;
|
|
3672
|
+
for (const listener of errors) {
|
|
3673
|
+
try {
|
|
3674
|
+
listener(error);
|
|
3675
|
+
} catch {
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
} });
|
|
3625
3679
|
let haSegnalato = false;
|
|
3626
3680
|
let ultimoCodice = null;
|
|
3627
3681
|
const segnalaStanza = (room) => {
|
|
@@ -3812,6 +3866,15 @@ function creaGestoreStanze(input, invited) {
|
|
|
3812
3866
|
});
|
|
3813
3867
|
return {
|
|
3814
3868
|
invited,
|
|
3869
|
+
reload() {
|
|
3870
|
+
input.reload?.(reloadTarget);
|
|
3871
|
+
},
|
|
3872
|
+
onError(listener) {
|
|
3873
|
+
errors.add(listener);
|
|
3874
|
+
return () => {
|
|
3875
|
+
errors.delete(listener);
|
|
3876
|
+
};
|
|
3877
|
+
},
|
|
3815
3878
|
async create(options) {
|
|
3816
3879
|
return collega(await api.create(options.mode));
|
|
3817
3880
|
},
|
|
@@ -3994,6 +4057,8 @@ async function connetti(input) {
|
|
|
3994
4057
|
const scartoOrario = me.serverTime - (prima + dopo) / 2;
|
|
3995
4058
|
const room = handshake.live === null ? creaStanzeOffline(handshake.invite) : creaGestoreStanze({
|
|
3996
4059
|
appOrigin,
|
|
4060
|
+
n: handshake.n,
|
|
4061
|
+
reload: (target) => handshake.porta.postMessage({ type: "caisual:reload", target }),
|
|
3997
4062
|
liveOrigin: handshake.live,
|
|
3998
4063
|
fetcher: input.fetcher,
|
|
3999
4064
|
biglietto: creaGestoreBiglietto(
|
package/dist/overlay.js
CHANGED
|
@@ -180,7 +180,7 @@ function testoFacoltativo(value, key, max, path, errors) {
|
|
|
180
180
|
}
|
|
181
181
|
return text2.trim();
|
|
182
182
|
};
|
|
183
|
-
const text = value[key], field = `${path}.${key}
|
|
183
|
+
const text = value[key], field = path ? `${path}.${key}` : key;
|
|
184
184
|
if (typeof text === "string") return check(text, field);
|
|
185
185
|
const translations = oggetto(text);
|
|
186
186
|
if (!translations || Object.keys(translations).length === 0) {
|
|
@@ -221,8 +221,7 @@ function validaManifest(valore) {
|
|
|
221
221
|
else if (typeof dati.name === "string" && (name.trim() === "" || name.length > 60)) {
|
|
222
222
|
errori.push("name: must contain 1-60 characters.");
|
|
223
223
|
}
|
|
224
|
-
const description =
|
|
225
|
-
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
224
|
+
const description = dati.description === "" ? "" : testoFacoltativo(dati, "description", 500, "", errori) ?? "";
|
|
226
225
|
const immagini = { cover: "", card: "", icon: "" };
|
|
227
226
|
const usati = /* @__PURE__ */ new Set();
|
|
228
227
|
for (const campo of ["cover", "card", "icon"]) {
|
|
@@ -277,6 +276,11 @@ function validaManifest(valore) {
|
|
|
277
276
|
}
|
|
278
277
|
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
279
278
|
const language = languages2[0] ?? legacyLanguage;
|
|
279
|
+
if (typeof description === "object") {
|
|
280
|
+
for (const tag of Object.keys(description)) {
|
|
281
|
+
if (!languages2.includes(tag)) errori.push(`description.${tag}: language must be declared in languages.`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
280
284
|
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
281
285
|
errori.push("language: must match the first entry in languages when both are present.");
|
|
282
286
|
}
|
|
@@ -803,8 +807,8 @@ function readMatchResult(value, playerIds) {
|
|
|
803
807
|
}
|
|
804
808
|
|
|
805
809
|
// src/errors.ts
|
|
806
|
-
function creaErrore(code, message) {
|
|
807
|
-
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
810
|
+
function creaErrore(code, message, version = {}) {
|
|
811
|
+
return Object.assign(new Error(message), { name: "CaisualError", code, ...version });
|
|
808
812
|
}
|
|
809
813
|
|
|
810
814
|
// src/overlay/host-bridge.ts
|
|
@@ -896,6 +900,13 @@ function creaPonteOspite(input) {
|
|
|
896
900
|
});
|
|
897
901
|
return;
|
|
898
902
|
}
|
|
903
|
+
if (data2?.type === "caisual:reload") {
|
|
904
|
+
const target = record(data2.target);
|
|
905
|
+
const code = typeof target?.code === "string" && /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(target.code) ? target.code : void 0;
|
|
906
|
+
const roomId = typeof target?.roomId === "string" && /^g[1-9][0-9]*-[1-9][0-9]*\.[a-z0-9]{16}$/.test(target.roomId) ? target.roomId : void 0;
|
|
907
|
+
input.reload?.(code || roomId ? { code, roomId, watch: target?.watch === true } : void 0);
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
899
910
|
const room = stanzaDaMessaggio(data2);
|
|
900
911
|
if (room !== void 0) {
|
|
901
912
|
input.onRoom(room);
|
|
@@ -934,6 +945,7 @@ function creaPonteOspite(input) {
|
|
|
934
945
|
currentPort.start();
|
|
935
946
|
input.frame.contentWindow?.postMessage({
|
|
936
947
|
type: "caisual:hello",
|
|
948
|
+
n: input.n,
|
|
937
949
|
ticket: input.ticket,
|
|
938
950
|
live: input.origineLive,
|
|
939
951
|
invite: input.invite,
|
|
@@ -948,6 +960,12 @@ function creaPonteOspite(input) {
|
|
|
948
960
|
input.frame.addEventListener?.("load", loaded);
|
|
949
961
|
poll();
|
|
950
962
|
return {
|
|
963
|
+
get watch() {
|
|
964
|
+
return input.watch === true;
|
|
965
|
+
},
|
|
966
|
+
reload() {
|
|
967
|
+
input.reload?.();
|
|
968
|
+
},
|
|
951
969
|
get epoch() {
|
|
952
970
|
return epoch;
|
|
953
971
|
},
|
|
@@ -1159,6 +1177,8 @@ function createBoardController(input) {
|
|
|
1159
1177
|
// src/overlay/i18n.ts
|
|
1160
1178
|
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
1161
1179
|
var words = {
|
|
1180
|
+
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"],
|
|
1181
|
+
reloadGame: ["Reload game", "Ricarica il gioco", "Recargar el juego", "Recharger le jeu", "Spiel neu laden", "Recarregar o jogo"],
|
|
1162
1182
|
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
1163
1183
|
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
1164
1184
|
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."],
|
|
@@ -1298,6 +1318,7 @@ function translator(language) {
|
|
|
1298
1318
|
return (key, values = {}) => dictionary[key].replace(/\{(\w+)\}/g, (_all, name) => String(values[name] ?? ""));
|
|
1299
1319
|
}
|
|
1300
1320
|
function errorText(code) {
|
|
1321
|
+
if (code === "version_outdated") return "gameUpdated";
|
|
1301
1322
|
if (code === "permission_denied") return "voiceDenied";
|
|
1302
1323
|
if (code === "unsupported") return "voiceUnsupported";
|
|
1303
1324
|
if (code === "voice_disabled") return "voiceUnavailable";
|
|
@@ -1712,10 +1733,11 @@ function mountOverlay(input) {
|
|
|
1712
1733
|
}
|
|
1713
1734
|
function home() {
|
|
1714
1735
|
const selected = selectedMode(), action = primaryAction(manifest, model.mode), session = model.session;
|
|
1736
|
+
const description = resolveText(manifest.description, input.language, manifestLanguages(manifest)[0]);
|
|
1715
1737
|
const hasRooms = manifest.modes.some((mode) => mode.execution === "room" && risolviModalita(manifest, mode.id).players.max > 1);
|
|
1716
|
-
return `${input.configuration.iconUrl ? `<img class="game-icon game-icon-title" src="${escape(input.configuration.iconUrl)}" alt="" />` : ""}<h1>${escape(manifest.name)}</h1
|
|
1738
|
+
return `${input.configuration.iconUrl ? `<img class="game-icon game-icon-title" src="${escape(input.configuration.iconUrl)}" alt="" />` : ""}<h1>${escape(manifest.name)}</h1>${description ? `<p class="muted" data-game-description>${escape(description)}</p>` : ""}<p class="muted" data-game-languages>${t("gameLanguages")}: ${escape(manifestLanguages(manifest).join(" \xB7 "))}</p><label>${t("mode")}<select data-control="mode"${disabled()}>${manifest.modes.map((mode) => `<option value="${escape(mode.id)}"${mode.id === model.mode ? " selected" : ""}>${escape(risolviPresentazione(manifest, mode.id, input.language).label)}</option>`).join("")}</select></label>
|
|
1717
1739
|
${selected?.instructions ? `<p class="muted">${escape(resolveText(selected.instructions, input.language, manifestLanguages(manifest)[0]))}</p>` : ""}
|
|
1718
|
-
${input.configuration.invite && phase(session) === "home" ? button("join-invite", "joinInvite", ' class="primary"', !session?.ready) : ""}
|
|
1740
|
+
${input.configuration.invite && phase(session) === "home" ? button("join-invite", input.bridge.watch ? "watch" : "joinInvite", ' class="primary"', !session?.ready) : ""}
|
|
1719
1741
|
${action ? button("play", action.friends ? "friendsPlay" : "play", ' class="primary"', !session?.ready) : ""}
|
|
1720
1742
|
${selected?.matchmaking ? button("match", "find", "", !selected.matchmaking.defaults || !session?.ready) : ""}
|
|
1721
1743
|
${session?.resume ? button("resume", "resume", "", !session.ready) + `<small>${escape(solo() || soloMode(session.resume.mode) ? "" : session.resume.code)}</small>` : ""}
|
|
@@ -1860,7 +1882,7 @@ function mountOverlay(input) {
|
|
|
1860
1882
|
const label = current === "watching" ? t("watching") : room2?.connection === "reconnecting" ? t("reconnecting") : solo() ? "Caisual" : room2?.code ?? "Caisual";
|
|
1861
1883
|
surface.innerHTML = current === "boot" ? "" : `<div class="pill" data-reserve><button type="button" data-action="menu" aria-label="${t("menu")}" aria-expanded="${!!panel}">C<span aria-hidden="true"><small>${escape(label)}</small></span></button>${voiceEligible(manifest, model.session) && model.session?.kind === "room" ? `<button type="button" class="voice-toggle" data-voice-toggle data-action="panel:voice"></button>` : ""}${invitations ? `<button type="button" data-action="panel:friends" aria-label="${t("friends")} (${invitations})">${invitations}</button>` : ""}</div>
|
|
1862
1884
|
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}">${resultBar()}${boards?.state.saving ? `<small role="status" data-saving>${t(boards.state.saving)}</small>` : ""}${canPlayAgain(model.session) ? button("again", "again", ' class="primary"') : model.session?.kind === "room" && room2?.status !== "finished" && !solo() ? `<small>${t("waitHost")}</small>` : ""}${rematchBar()}${Object.keys(manifest.boards).length ? button("panel:boards", "boards") : ""}${button("panel:home", "homeMenu")}</div>` : ""}
|
|
1863
|
-
${panel ? `<div class="backdrop${panel === "home" ? " home" : ""}"><section class="dialog${panel === "boards" || panel === "friends" ? " wide" : ""}" role="dialog" aria-modal="true" aria-labelledby="panel-title" tabindex="-1"><div class="top"><h2 id="panel-title">${title(panel)}</h2><button type="button" data-action="close" aria-label="${t("close")}">\xD7</button></div><div class="stack">${content(panel)}${model.error ? `<p class="error" role="alert" data-error>${t(errorText(model.error))}</p
|
|
1885
|
+
${panel ? `<div class="backdrop${panel === "home" ? " home" : ""}"><section class="dialog${panel === "boards" || panel === "friends" ? " wide" : ""}" role="dialog" aria-modal="true" aria-labelledby="panel-title" tabindex="-1"><div class="top"><h2 id="panel-title">${title(panel)}</h2><button type="button" data-action="close" aria-label="${t("close")}">\xD7</button></div><div class="stack">${content(panel)}${model.error ? `<p class="error" role="alert" data-error>${t(errorText(model.error))}</p>${model.error === "version_outdated" ? button("reload-game", "reloadGame", ' class="primary"') : ""}` : ""}${model.session?.resumeError ? `<p class="error" role="alert">${t("saveFailed")}</p>` : ""}${model.notice ? `<p class="notice" role="status">${escape(model.notice)}</p>` : ""}</div></section></div>` : ""}`;
|
|
1864
1886
|
for (const element of surface.querySelectorAll(".pill,.backdrop,.ended")) element.style.pointerEvents = "auto";
|
|
1865
1887
|
const backdrop = root.querySelector(".backdrop.home");
|
|
1866
1888
|
if (backdrop && input.configuration.coverUrl) backdrop.style.backgroundImage = `linear-gradient(#0b151c99,#0b151cee),url(${JSON.stringify(input.configuration.coverUrl)})`;
|
|
@@ -1916,7 +1938,7 @@ function mountOverlay(input) {
|
|
|
1916
1938
|
void perform("room.match", { mode: model.mode });
|
|
1917
1939
|
break;
|
|
1918
1940
|
case "join-invite":
|
|
1919
|
-
if (input.configuration.invite) void perform("room.join", { code: input.configuration.invite });
|
|
1941
|
+
if (input.configuration.invite) void perform(input.bridge.watch ? "room.watch" : "room.join", { code: input.configuration.invite });
|
|
1920
1942
|
break;
|
|
1921
1943
|
case "resume":
|
|
1922
1944
|
void perform("session.resume", {});
|
|
@@ -1969,6 +1991,9 @@ function mountOverlay(input) {
|
|
|
1969
1991
|
case "exit-now":
|
|
1970
1992
|
input.exit();
|
|
1971
1993
|
break;
|
|
1994
|
+
case "reload-game":
|
|
1995
|
+
input.bridge.reload();
|
|
1996
|
+
break;
|
|
1972
1997
|
case "reload":
|
|
1973
1998
|
boot?.focus({ preventScroll: true });
|
|
1974
1999
|
resetBootWait();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type VersioneGioco } from './versioni.js';
|
|
1
2
|
export type DestinatarioBiglietto = 'portal' | 'live';
|
|
2
|
-
export interface Biglietto {
|
|
3
|
+
export interface Biglietto extends VersioneGioco {
|
|
3
4
|
sub: string;
|
|
4
5
|
game: string;
|
|
5
6
|
name: string;
|
|
@@ -8,7 +9,7 @@ export interface Biglietto {
|
|
|
8
9
|
iat: number;
|
|
9
10
|
exp: number;
|
|
10
11
|
}
|
|
11
|
-
export interface DatiBiglietto {
|
|
12
|
+
export interface DatiBiglietto extends VersioneGioco {
|
|
12
13
|
sub: string;
|
|
13
14
|
game: string;
|
|
14
15
|
name: string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Il numero identifica gli artefatti del gioco, non il formato dei dati salvati. */
|
|
2
|
+
export interface VersioneGioco {
|
|
3
|
+
n: number;
|
|
4
|
+
}
|
|
5
|
+
export interface ErroreVersione {
|
|
6
|
+
currentVersion?: number;
|
|
7
|
+
roomVersion?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface RicaricaGioco {
|
|
10
|
+
code?: string;
|
|
11
|
+
roomId?: string;
|
|
12
|
+
watch?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function numeroVersione(value: unknown): value is number;
|
|
15
|
+
export declare function analizzaRoomId(roomId: string): {
|
|
16
|
+
gameId: number;
|
|
17
|
+
n: number;
|
|
18
|
+
} | null;
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ErroreCaisual = Error & {
|
|
2
2
|
code: string;
|
|
3
|
-
};
|
|
4
|
-
export declare function creaErrore(code: string, message: string): ErroreCaisual;
|
|
3
|
+
} & import('./contracts/index.js').ErroreVersione;
|
|
4
|
+
export declare function creaErrore(code: string, message: string, version?: import('./contracts/index.js').ErroreVersione): ErroreCaisual;
|
|
5
5
|
export declare function erroreOffline(): ErroreCaisual;
|
|
6
6
|
export declare function codiceErrore(valore: unknown): unknown;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type OverlayHello } from './contracts/index.js';
|
|
2
|
+
import type { VersioneGioco } from './contracts/index.js';
|
|
2
3
|
export interface GenitoreHandshake {
|
|
3
4
|
postMessage(message: unknown, targetOrigin: string): void;
|
|
4
5
|
}
|
|
@@ -9,7 +10,7 @@ export interface FinestraHandshakeKit extends GenitoreHandshake {
|
|
|
9
10
|
setTimeout(handler: () => void, timeout: number): number;
|
|
10
11
|
clearTimeout(id: number): void;
|
|
11
12
|
}
|
|
12
|
-
export interface EsitoHandshake {
|
|
13
|
+
export interface EsitoHandshake extends VersioneGioco {
|
|
13
14
|
language?: string;
|
|
14
15
|
uiLanguage?: string;
|
|
15
16
|
languagePreferences?: string[];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -184,6 +184,8 @@ export interface MatchOptions {
|
|
|
184
184
|
}): void;
|
|
185
185
|
}
|
|
186
186
|
export interface Rooms {
|
|
187
|
+
reload(): void;
|
|
188
|
+
onError(listener: (error: import('./errors.js').ErroreCaisual) => void): () => void;
|
|
187
189
|
readonly invited: string | null;
|
|
188
190
|
create(options: {
|
|
189
191
|
mode: string | null;
|
|
@@ -20,6 +20,9 @@ export interface HostBridgeInput {
|
|
|
20
20
|
frame: FrameHandshake;
|
|
21
21
|
origineGioco: string;
|
|
22
22
|
origineLive: string;
|
|
23
|
+
n: number;
|
|
24
|
+
watch?: boolean;
|
|
25
|
+
reload?(target?: import('../contracts/index.js').RicaricaGioco): void;
|
|
23
26
|
language?: string;
|
|
24
27
|
languagePreferences?: readonly string[];
|
|
25
28
|
invite: string | null;
|
|
@@ -39,6 +42,8 @@ export declare function stanzaDaMessaggio(value: unknown): {
|
|
|
39
42
|
code: string;
|
|
40
43
|
} | null | undefined;
|
|
41
44
|
export declare function creaPonteOspite(input: HostBridgeInput): {
|
|
45
|
+
readonly watch: boolean;
|
|
46
|
+
reload(): void;
|
|
42
47
|
readonly epoch: string | null;
|
|
43
48
|
serverTime(): number | null;
|
|
44
49
|
readonly state: OverlaySessionState | null;
|
|
@@ -46,7 +51,7 @@ export declare function creaPonteOspite(input: HostBridgeInput): {
|
|
|
46
51
|
onShortcut(listener: () => void): () => void;
|
|
47
52
|
onOpen(listener: (value: OverlayPanel) => void): () => void;
|
|
48
53
|
onError(listener: (value: {
|
|
49
|
-
sessionId: string;
|
|
54
|
+
sessionId: string | null;
|
|
50
55
|
error: {
|
|
51
56
|
code: string;
|
|
52
57
|
message: string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const languages: readonly ['en', 'it', 'es', 'fr', 'de', 'pt'];
|
|
2
2
|
export type OverlayLanguage = typeof languages[number];
|
|
3
3
|
declare const words: {
|
|
4
|
+
readonly gameUpdated: readonly ["This game was updated", "Questo gioco è stato aggiornato", "Este juego se ha actualizado", "Ce jeu a été mis à jour", "Dieses Spiel wurde aktualisiert", "Este jogo foi atualizado"];
|
|
5
|
+
readonly reloadGame: readonly ["Reload game", "Ricarica il gioco", "Recargar el juego", "Recharger le jeu", "Spiel neu laden", "Recarregar o jogo"];
|
|
4
6
|
readonly gameLanguages: readonly ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"];
|
|
5
7
|
readonly loading: readonly ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."];
|
|
6
8
|
readonly loadingSlow: readonly ["This game is taking longer than expected. You can wait a little longer or try again.", "Il gioco ci sta mettendo più del previsto. Puoi aspettare ancora un po’ o riprovare.", "El juego está tardando más de lo esperado. Puedes esperar un poco más o volver a intentarlo.", "Le jeu met plus de temps que prévu. Vous pouvez patienter encore un peu ou réessayer.", "Das Spiel braucht länger als erwartet. Du kannst noch etwas warten oder es erneut versuchen.", "O jogo está demorando mais do que o esperado. Você pode esperar mais um pouco ou tentar novamente."];
|
|
@@ -36,7 +36,7 @@ export declare function createSession(base: BaseConnection, configuration?: Over
|
|
|
36
36
|
onState(listener: (value: OverlaySessionState) => void): () => void;
|
|
37
37
|
onOpen(listener: (value: OverlayPanel) => void): () => void;
|
|
38
38
|
onError(listener: (value: {
|
|
39
|
-
sessionId: string;
|
|
39
|
+
sessionId: string | null;
|
|
40
40
|
error: {
|
|
41
41
|
code: string;
|
|
42
42
|
message: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Rooms } from '../index.js';
|
|
2
|
+
import { type ErroreCaisual } from '../errors.js';
|
|
2
3
|
import type { GestoreBiglietto } from '../handshake.js';
|
|
3
4
|
import { type DipendenzeVoce } from '../voce/index.js';
|
|
4
5
|
interface TimerStanza {
|
|
@@ -8,6 +9,9 @@ interface TimerStanza {
|
|
|
8
9
|
clearInterval(id: number): void;
|
|
9
10
|
}
|
|
10
11
|
export interface DipendenzeStanze extends TimerStanza {
|
|
12
|
+
n: number;
|
|
13
|
+
reload?(target?: import('../contracts/index.js').RicaricaGioco): void;
|
|
14
|
+
onVersionError?(error: ErroreCaisual, target?: import('../contracts/index.js').RicaricaGioco): void;
|
|
11
15
|
appOrigin: string;
|
|
12
16
|
liveOrigin: string;
|
|
13
17
|
fetcher: typeof fetch;
|