@caisual/kit 0.5.0 → 0.10.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.d.ts +2 -175
- package/dist/kit.js +1808 -76
- package/dist/node.d.ts +1 -88
- package/dist/node.js +354 -96
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.js +2074 -0
- package/dist/runtime.d.ts +1 -111
- package/dist/runtime.js +335 -67
- package/dist/server.d.ts +1 -71
- package/dist/server.js +3 -0
- package/dist/types/api.d.ts +25 -0
- package/dist/types/contracts/biglietto.d.ts +24 -0
- package/dist/types/contracts/device.d.ts +66 -0
- package/dist/types/contracts/firma.d.ts +21 -0
- package/dist/types/contracts/i18n.d.ts +12 -0
- package/dist/types/contracts/index.d.ts +13 -0
- package/dist/types/contracts/keys.d.ts +59 -0
- package/dist/types/contracts/manifest.d.ts +123 -0
- package/dist/types/contracts/overlay-boards.d.ts +3 -0
- package/dist/types/contracts/overlay.d.ts +223 -0
- package/dist/types/contracts/player.d.ts +1 -0
- package/dist/types/contracts/room-limits.d.ts +13 -0
- package/dist/types/contracts/runtime.d.ts +70 -0
- package/dist/types/contracts/server-js.d.ts +11 -0
- package/dist/types/contracts/slug.d.ts +5 -0
- package/dist/types/contracts/token-crew.d.ts +21 -0
- package/dist/types/daily.d.ts +3 -0
- package/dist/types/errors.d.ts +6 -0
- package/dist/types/handshake.d.ts +30 -0
- package/dist/types/http.d.ts +3 -0
- package/dist/types/index.d.ts +231 -0
- package/dist/types/kit.d.ts +28 -0
- package/dist/types/node/index.d.ts +97 -0
- package/dist/types/node/websocket.d.ts +29 -0
- package/dist/types/overlay/boards.d.ts +48 -0
- package/dist/types/overlay/bridge.d.ts +3 -0
- package/dist/types/overlay/host-bridge.d.ts +74 -0
- package/dist/types/overlay/i18n.d.ts +128 -0
- package/dist/types/overlay/index.d.ts +10 -0
- package/dist/types/overlay/shortcut.d.ts +4 -0
- package/dist/types/overlay/styles.d.ts +1 -0
- package/dist/types/overlay/ui-model.d.ts +45 -0
- package/dist/types/overlay/ui.d.ts +80 -0
- package/dist/types/overlay/voice-panel.d.ts +13 -0
- package/dist/types/protocollo.d.ts +262 -0
- package/dist/types/runtime/index.d.ts +128 -0
- package/dist/types/server/index.d.ts +76 -0
- package/dist/types/session/index.d.ts +49 -0
- package/dist/types/session/resume.d.ts +13 -0
- package/dist/types/standalone.d.ts +14 -0
- package/dist/types/stanza/index.d.ts +3 -0
- package/dist/types/stanza/json.d.ts +18 -0
- package/dist/types/stanza/nucleo.d.ts +100 -0
- package/dist/types/stanza/tipi.d.ts +136 -0
- package/dist/types/stanza-client/index.d.ts +24 -0
- package/dist/types/text.d.ts +2 -0
- package/dist/types/voce/index.d.ts +124 -0
- package/package.json +10 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contratto sulla forma degli URL di gioco, condiviso fra i due Worker.
|
|
3
|
+
*
|
|
4
|
+
* `portal` costruisce l'URL da mettere nell'iframe, `play` lo interpreta. Sono due
|
|
5
|
+
* Worker distinti su due domini distinti: se la forma dell'URL vivesse in
|
|
6
|
+
* entrambi, prima o poi divergerebbero e il sintomo sarebbe un 404 su tutti i
|
|
7
|
+
* giochi. Vive qui, una volta sola.
|
|
8
|
+
*
|
|
9
|
+
* ## Cos'e' la versione di runtime
|
|
10
|
+
*
|
|
11
|
+
* Prima di servirlo, `play` inietta nell'HTML del gioco il viewport, lo stile
|
|
12
|
+
* touch e lo script anti pinch-zoom: cose che nel sistema vecchio metteva la
|
|
13
|
+
* pagina padre entrando nel DOM dell'iframe, e che ora non puo' piu' fare
|
|
14
|
+
* perche' il gioco sta su un'altra origine.
|
|
15
|
+
*
|
|
16
|
+
* Il risultato di quell'iniezione finisce in cache. Se un domani cambiamo cosa
|
|
17
|
+
* iniettiamo senza cambiare niente altro, le cache continuerebbero a servire la
|
|
18
|
+
* versione vecchia della trasformazione su un artefatto che non e' cambiato, e
|
|
19
|
+
* non ci sarebbe modo di invalidarle se non a mano.
|
|
20
|
+
*
|
|
21
|
+
* Mettendo la versione nell'URL il problema sparisce: una trasformazione nuova
|
|
22
|
+
* e' `rt/v2`, cioe' un URL nuovo, e le due non si incontrano mai. L'artefatto su
|
|
23
|
+
* R2 resta intatto in entrambi i casi.
|
|
24
|
+
*/
|
|
25
|
+
/** Versioni di runtime che sappiamo servire. Non se ne toglie mai una. */
|
|
26
|
+
declare const RUNTIME_VERSIONS: readonly ['v1'];
|
|
27
|
+
export type RuntimeVersion = (typeof RUNTIME_VERSIONS)[number];
|
|
28
|
+
export declare function isRuntimeVersion(value: string): value is RuntimeVersion;
|
|
29
|
+
/**
|
|
30
|
+
* Path di un file di gioco sull'origine di `play`.
|
|
31
|
+
* Forma: `/rt/{runtime}/{n}/{path}`.
|
|
32
|
+
*
|
|
33
|
+
* Lo slug NON sta nel path: sta nell'hostname. Vedi `playOrigin`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function playPath(n: number, path?: string, runtime?: RuntimeVersion): string;
|
|
36
|
+
/**
|
|
37
|
+
* Origine su cui gira un gioco: `https://<slug>.<dominio>`.
|
|
38
|
+
*
|
|
39
|
+
* Un'origine per slug, non per versione. La differenza conta: con
|
|
40
|
+
* un'origine per versione ogni improve creerebbe una partizione di storage
|
|
41
|
+
* nuova, e il giocatore perderebbe i progressi ogni volta che l'autore migliora
|
|
42
|
+
* il gioco. Con l'origine per slug le versioni condividono lo storage (che
|
|
43
|
+
* e' quello che ci si aspetta dallo stesso gioco) e giochi diversi no.
|
|
44
|
+
*
|
|
45
|
+
* Anche gli UUID v4 dei giochi storici sono slug validi, percio' conservano
|
|
46
|
+
* origine, storage e link esistenti.
|
|
47
|
+
*/
|
|
48
|
+
export declare function playOrigin(slug: string, domain: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Le origini di play tutte insieme, per la CSP: `https://*.<dominio>`.
|
|
51
|
+
*
|
|
52
|
+
* Sta accanto a `playOrigin` apposta. Una pagina che mostra venti copertine
|
|
53
|
+
* punta a venti origini diverse, una per gioco, quindi nella CSP non si puo'
|
|
54
|
+
* elencarle: serve il carattere jolly. Tenendo le due funzioni vicine, se
|
|
55
|
+
* cambia la forma dell'origine si vede subito che va cambiata anche qui.
|
|
56
|
+
*
|
|
57
|
+
* L'alternativa sarebbe stata servire le copertine dall'app, ma sono oggetti
|
|
58
|
+
* immutabili gia' su R2 con la loro cache: farle passare da qui vorrebbe dire
|
|
59
|
+
* pagare una richiesta al Worker per ogni scheda di ogni griglia.
|
|
60
|
+
*/
|
|
61
|
+
export declare function playOriginPattern(domain: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Estrae lo slug dall'hostname, o `null` se l'host non ha la forma attesa.
|
|
64
|
+
*
|
|
65
|
+
* `play` deve usare QUESTO slug per risolvere il gioco, mai uno preso dal path:
|
|
66
|
+
* e' l'unico modo perche' una versione di un altro gioco non possa
|
|
67
|
+
* essere servita nell'origine sbagliata.
|
|
68
|
+
*/
|
|
69
|
+
export declare function slugFromHostname(hostname: string, domain: string): string | null;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const MASSIMO_BYTE_SERVER_JS = 1000000;
|
|
2
|
+
/** Il modulo pubblico va risolto nel kit incluso insieme al sorgente del creatore. */
|
|
3
|
+
export declare function riscriviImportServerJs(sorgente: string): string;
|
|
4
|
+
export type EsitoServerJs = {
|
|
5
|
+
ok: true;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
errori: string[];
|
|
9
|
+
};
|
|
10
|
+
/** Valida le regole che rendono server.js componibile come modulo singolo. */
|
|
11
|
+
export declare function validaServerJs(sorgente: string): EsitoServerJs;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Nomi che non possono diventare l'origine di un gioco. */
|
|
2
|
+
export declare const NOMI_RISERVATI: readonly ['www', 'api', 'app', 'play', 'live', 'multi', 'cdn', 'assets', 'static', 'mail', 'mx', 'ns1', 'ns2', 'autodiscover', '_dmarc', 'admin', 'login', 'account', 'auth', 'pay', 'secure', 'support', 'help', 'blog', 'status', 'dev', 'staging', 'test', 'caisual', 'shipz'];
|
|
3
|
+
/** Controlla solo la forma; i nomi riservati hanno un controllo separato. */
|
|
4
|
+
export declare function isValidSlug(value: string): boolean;
|
|
5
|
+
export declare function isReservedSlug(value: string): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gettone della crew: apre il socket di presenza sul servizio live dal portale.
|
|
3
|
+
*
|
|
4
|
+
* Non porta un gioco perche' la crew attraversa tutti i giochi; il destinatario
|
|
5
|
+
* e' fisso, quindi un biglietto di gioco non puo' essere riusato qui e viceversa.
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenCrew {
|
|
8
|
+
sub: string;
|
|
9
|
+
name: string;
|
|
10
|
+
aud: 'crew';
|
|
11
|
+
iat: number;
|
|
12
|
+
exp: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function firmaTokenCrew(input: {
|
|
15
|
+
sub: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}, secret: string, now?: Date): Promise<string>;
|
|
18
|
+
/** Restituisce null senza distinguere quale controllo ha rifiutato il gettone. */
|
|
19
|
+
export declare function verificaTokenCrew(token: string, secret: string, atteso?: {
|
|
20
|
+
now?: Date;
|
|
21
|
+
}): Promise<TokenCrew | null>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type OverlayHello } from './contracts/index.js';
|
|
2
|
+
export interface GenitoreHandshake {
|
|
3
|
+
postMessage(message: unknown, targetOrigin: string): void;
|
|
4
|
+
}
|
|
5
|
+
export interface FinestraHandshakeKit extends GenitoreHandshake {
|
|
6
|
+
readonly parent: GenitoreHandshake;
|
|
7
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
8
|
+
removeEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
9
|
+
setTimeout(handler: () => void, timeout: number): number;
|
|
10
|
+
clearTimeout(id: number): void;
|
|
11
|
+
}
|
|
12
|
+
export interface EsitoHandshake {
|
|
13
|
+
language?: string;
|
|
14
|
+
uiLanguage?: string;
|
|
15
|
+
languagePreferences?: string[];
|
|
16
|
+
gameLanguages?: string[];
|
|
17
|
+
overlay?: OverlayHello;
|
|
18
|
+
ticket: string;
|
|
19
|
+
live: string | null;
|
|
20
|
+
invite: string | null;
|
|
21
|
+
porta: MessagePort;
|
|
22
|
+
}
|
|
23
|
+
export type DestinatarioBiglietto = 'portal' | 'live';
|
|
24
|
+
/** Il limite evita che un gioco copiato aspetti un contenitore che non esiste. */
|
|
25
|
+
export declare function attendiHandshake(finestra: FinestraHandshakeKit, appOrigin: string, timeoutMs?: number): Promise<EsitoHandshake | null>;
|
|
26
|
+
export interface GestoreBiglietto {
|
|
27
|
+
ottieni(): Promise<string>;
|
|
28
|
+
rinnova(): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
export declare function creaGestoreBiglietto(ticketIniziale: string | null, porta: MessagePort, finestra: Pick<FinestraHandshakeKit, 'setTimeout' | 'clearTimeout'>, ora: () => number, timeoutMs?: number, aud?: DestinatarioBiglietto): GestoreBiglietto;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GestoreBiglietto } from './handshake.js';
|
|
2
|
+
export type MetodoHttp = 'GET' | 'PUT' | 'POST' | 'DELETE';
|
|
3
|
+
export declare function creaRichiedente(origin: string, prefix: string, fetcher: typeof fetch, biglietto: GestoreBiglietto): <T>(path: string, metodo: MetodoHttp, corpo?: unknown, forzaRinnovo?: boolean) => Promise<T>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { Text } from './text.js';
|
|
2
|
+
export type { Text } from './text.js';
|
|
3
|
+
import type { ConnectionState, QueuedScore } from './contracts/index.js';
|
|
4
|
+
import type { Session, Overlay } from './session/index.js';
|
|
5
|
+
import type { RoomConfiguration } from './protocollo.js';
|
|
6
|
+
export type { Session, GameSession, Overlay } from './session/index.js';
|
|
7
|
+
export type { ConnectionState, QueuedScore, OverlayView, OverlayPanel } from './contracts/index.js';
|
|
8
|
+
import type { DeviceReport } from './contracts/index.js';
|
|
9
|
+
export type { DeviceReport } from './contracts/index.js';
|
|
10
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
11
|
+
[key: string]: JsonValue;
|
|
12
|
+
};
|
|
13
|
+
export interface Player {
|
|
14
|
+
language: string;
|
|
15
|
+
uiLanguage: string;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
guest: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SaveInfo {
|
|
21
|
+
key: string;
|
|
22
|
+
bytes: number;
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
}
|
|
25
|
+
export interface BoardEntry {
|
|
26
|
+
rank: number;
|
|
27
|
+
name: string;
|
|
28
|
+
score: number;
|
|
29
|
+
guest: boolean;
|
|
30
|
+
me: boolean;
|
|
31
|
+
verified: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface BoardTop {
|
|
34
|
+
day: string | null;
|
|
35
|
+
entries: BoardEntry[];
|
|
36
|
+
me: {
|
|
37
|
+
rank: number;
|
|
38
|
+
score: number;
|
|
39
|
+
verified: boolean;
|
|
40
|
+
} | null;
|
|
41
|
+
}
|
|
42
|
+
export type BoardResult = {
|
|
43
|
+
accepted: true;
|
|
44
|
+
best: number;
|
|
45
|
+
rank: number;
|
|
46
|
+
day: string | null;
|
|
47
|
+
verified: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type BoardOffline = {
|
|
50
|
+
accepted: false;
|
|
51
|
+
reason: 'offline';
|
|
52
|
+
verified: false;
|
|
53
|
+
};
|
|
54
|
+
export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
|
|
55
|
+
export interface RoomPlayer {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
guest: boolean;
|
|
59
|
+
role: string | null;
|
|
60
|
+
team: number | null;
|
|
61
|
+
ready: boolean;
|
|
62
|
+
connected: boolean;
|
|
63
|
+
}
|
|
64
|
+
export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
|
|
65
|
+
export type VoiceState = 'off' | 'joining' | 'on' | 'reconnecting';
|
|
66
|
+
export interface VoicePeer {
|
|
67
|
+
id: string;
|
|
68
|
+
mic: boolean;
|
|
69
|
+
muted: boolean;
|
|
70
|
+
speaking: boolean;
|
|
71
|
+
volume: number;
|
|
72
|
+
gain: number;
|
|
73
|
+
}
|
|
74
|
+
export interface Voice {
|
|
75
|
+
readonly mode: VoiceMode;
|
|
76
|
+
readonly state: VoiceState;
|
|
77
|
+
readonly mic: boolean;
|
|
78
|
+
readonly muted: boolean;
|
|
79
|
+
readonly speaking: boolean;
|
|
80
|
+
readonly peers: readonly VoicePeer[];
|
|
81
|
+
join(options?: {
|
|
82
|
+
mic?: boolean;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
leave(): void;
|
|
85
|
+
mute(muted?: boolean): void;
|
|
86
|
+
setVolume(playerId: string, volume: number): void;
|
|
87
|
+
onPeers(listener: (peers: readonly VoicePeer[]) => void): () => void;
|
|
88
|
+
onState(listener: (state: VoiceState) => void): () => void;
|
|
89
|
+
}
|
|
90
|
+
export interface RoomInvite {
|
|
91
|
+
code: string;
|
|
92
|
+
url: string;
|
|
93
|
+
}
|
|
94
|
+
export interface RoomMetadata {
|
|
95
|
+
host: string | null;
|
|
96
|
+
mode: string | null;
|
|
97
|
+
countdownAt: number | null;
|
|
98
|
+
configuration: RoomConfiguration | null;
|
|
99
|
+
connection: ConnectionState;
|
|
100
|
+
closedCode: number | null;
|
|
101
|
+
}
|
|
102
|
+
export interface Room {
|
|
103
|
+
readonly mode: string | null;
|
|
104
|
+
readonly countdownAt: number | null;
|
|
105
|
+
readonly connection: ConnectionState;
|
|
106
|
+
readonly metadata: RoomMetadata;
|
|
107
|
+
onMetadata(listener: (metadata: RoomMetadata) => void): () => void;
|
|
108
|
+
onConnection(listener: (state: ConnectionState) => void): () => void;
|
|
109
|
+
disconnect(): void;
|
|
110
|
+
readonly state: JsonValue;
|
|
111
|
+
readonly tick: number;
|
|
112
|
+
readonly tickRate: number;
|
|
113
|
+
readonly latency: number | null;
|
|
114
|
+
readonly seed: number;
|
|
115
|
+
readonly status: RoomStatus;
|
|
116
|
+
readonly players: readonly RoomPlayer[];
|
|
117
|
+
readonly you: string;
|
|
118
|
+
readonly host: string | null;
|
|
119
|
+
readonly code: string;
|
|
120
|
+
readonly result: JsonValue;
|
|
121
|
+
readonly voice: Voice;
|
|
122
|
+
readonly queuedScores: readonly QueuedScore[];
|
|
123
|
+
onError(listener: (error: {
|
|
124
|
+
code: string;
|
|
125
|
+
message: string;
|
|
126
|
+
}) => void): () => void;
|
|
127
|
+
onScoreQueued(listener: (score: QueuedScore) => void): () => void;
|
|
128
|
+
requestRole(role: string): Promise<void>;
|
|
129
|
+
invite(): RoomInvite;
|
|
130
|
+
onState(listener: (state: JsonValue, tick: number, serverTime: number) => void): () => void;
|
|
131
|
+
onPlayers(listener: (players: readonly RoomPlayer[]) => void): () => void;
|
|
132
|
+
onStatus(listener: (status: RoomStatus, result: JsonValue, at: number) => void): () => void;
|
|
133
|
+
onMessage(listener: (message: JsonValue) => void): () => void;
|
|
134
|
+
send(message: JsonValue): void;
|
|
135
|
+
input(value: JsonValue): void;
|
|
136
|
+
ready(ready: boolean): void;
|
|
137
|
+
setRole(role: string): void;
|
|
138
|
+
setTeam(team: number): void;
|
|
139
|
+
start(): void;
|
|
140
|
+
restart(): void;
|
|
141
|
+
leave(): void;
|
|
142
|
+
serverTime(): number;
|
|
143
|
+
}
|
|
144
|
+
export interface Spectate {
|
|
145
|
+
readonly mode: string | null;
|
|
146
|
+
readonly countdownAt: number | null;
|
|
147
|
+
readonly connection: ConnectionState;
|
|
148
|
+
readonly metadata: RoomMetadata;
|
|
149
|
+
onMetadata(listener: (metadata: RoomMetadata) => void): () => void;
|
|
150
|
+
onConnection(listener: (state: ConnectionState) => void): () => void;
|
|
151
|
+
disconnect(): void;
|
|
152
|
+
readonly state: JsonValue;
|
|
153
|
+
readonly tick: number;
|
|
154
|
+
readonly tickRate: number;
|
|
155
|
+
readonly latency: number | null;
|
|
156
|
+
readonly seed: number;
|
|
157
|
+
readonly status: RoomStatus;
|
|
158
|
+
readonly players: readonly RoomPlayer[];
|
|
159
|
+
readonly host: string | null;
|
|
160
|
+
readonly code: string;
|
|
161
|
+
readonly result: JsonValue;
|
|
162
|
+
readonly delayMs: number;
|
|
163
|
+
onState(listener: (state: JsonValue, tick: number, serverTime: number) => void): () => void;
|
|
164
|
+
onPlayers(listener: (players: readonly RoomPlayer[]) => void): () => void;
|
|
165
|
+
onStatus(listener: (status: RoomStatus, result: JsonValue, at: number) => void): () => void;
|
|
166
|
+
onMessage(listener: (message: JsonValue) => void): () => void;
|
|
167
|
+
leave(): void;
|
|
168
|
+
serverTime(): number;
|
|
169
|
+
}
|
|
170
|
+
export interface MatchOptions {
|
|
171
|
+
mode: string;
|
|
172
|
+
key: Record<string, string | number>;
|
|
173
|
+
signal?: AbortSignal;
|
|
174
|
+
onWaiting?(waiting: {
|
|
175
|
+
players: number;
|
|
176
|
+
min: number;
|
|
177
|
+
max: number;
|
|
178
|
+
}): void;
|
|
179
|
+
}
|
|
180
|
+
export interface Rooms {
|
|
181
|
+
readonly invited: string | null;
|
|
182
|
+
create(options: {
|
|
183
|
+
mode: string | null;
|
|
184
|
+
}): Promise<Room>;
|
|
185
|
+
join(code?: string): Promise<Room>;
|
|
186
|
+
watch(code: string): Promise<Spectate>;
|
|
187
|
+
match(options: MatchOptions): Promise<Room>;
|
|
188
|
+
}
|
|
189
|
+
export interface CaisualConnection {
|
|
190
|
+
text(): Promise<Text>;
|
|
191
|
+
session: Session;
|
|
192
|
+
overlay: Overlay;
|
|
193
|
+
connected: boolean;
|
|
194
|
+
device: DeviceReport;
|
|
195
|
+
player: Player;
|
|
196
|
+
daily: {
|
|
197
|
+
day: string;
|
|
198
|
+
seed: number;
|
|
199
|
+
random(): number;
|
|
200
|
+
rng(): () => number;
|
|
201
|
+
};
|
|
202
|
+
time: {
|
|
203
|
+
now(): number;
|
|
204
|
+
};
|
|
205
|
+
save: {
|
|
206
|
+
set(key: string, value: JsonValue): Promise<SaveInfo>;
|
|
207
|
+
get(key: string): Promise<JsonValue | null>;
|
|
208
|
+
remove(key: string): Promise<void>;
|
|
209
|
+
list(): Promise<SaveInfo[]>;
|
|
210
|
+
};
|
|
211
|
+
board: {
|
|
212
|
+
submit(board: string, score: number, options?: {
|
|
213
|
+
daily?: boolean;
|
|
214
|
+
}): Promise<BoardResult | BoardOffline>;
|
|
215
|
+
top(board: string, options?: {
|
|
216
|
+
daily?: boolean;
|
|
217
|
+
day?: string;
|
|
218
|
+
limit?: number;
|
|
219
|
+
guests?: boolean;
|
|
220
|
+
}): Promise<BoardTop>;
|
|
221
|
+
};
|
|
222
|
+
room: Rooms;
|
|
223
|
+
}
|
|
224
|
+
export type BaseConnection = Omit<CaisualConnection, 'device' | 'session' | 'overlay' | 'text' | 'player'> & {
|
|
225
|
+
player: Omit<Player, 'language' | 'uiLanguage'>;
|
|
226
|
+
};
|
|
227
|
+
export interface Caisual {
|
|
228
|
+
connect(): Promise<CaisualConnection>;
|
|
229
|
+
}
|
|
230
|
+
export declare const caisual: Caisual;
|
|
231
|
+
export default caisual;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type DeviceReport } from './contracts/index.js';
|
|
2
|
+
import type { Caisual } from './index.js';
|
|
3
|
+
import { type FinestraHandshakeKit } from './handshake.js';
|
|
4
|
+
import { type ArchivioLocale } from './standalone.js';
|
|
5
|
+
import type { DipendenzeVoce } from './voce/index.js';
|
|
6
|
+
interface DocumentoMeta {
|
|
7
|
+
querySelector(selector: string): {
|
|
8
|
+
getAttribute(name: string): string | null;
|
|
9
|
+
} | null;
|
|
10
|
+
}
|
|
11
|
+
export interface DipendenzeKit {
|
|
12
|
+
language?: string;
|
|
13
|
+
pathname?: string;
|
|
14
|
+
finestra: FinestraHandshakeKit | null;
|
|
15
|
+
documento: DocumentoMeta | null;
|
|
16
|
+
fetcher: typeof fetch;
|
|
17
|
+
archivio: ArchivioLocale | null;
|
|
18
|
+
hostname: string;
|
|
19
|
+
subtle: SubtleCrypto;
|
|
20
|
+
ora: () => number;
|
|
21
|
+
sonda: () => Promise<DeviceReport>;
|
|
22
|
+
apriSocket?: (url: string) => WebSocket;
|
|
23
|
+
voce?: DipendenzeVoce;
|
|
24
|
+
timeoutHandshake?: number;
|
|
25
|
+
timeoutRinnovo?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function creaKit(input?: DipendenzeKit): Caisual;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type { Duplex } from 'node:stream';
|
|
3
|
+
import type { GameDefinition, JsonValue, RoomStatus, SharedGameStore } from '../server/index.js';
|
|
4
|
+
export interface NodeWebSocket {
|
|
5
|
+
on(event: 'message', listener: (message: string) => void): this;
|
|
6
|
+
on(event: 'close', listener: () => void): this;
|
|
7
|
+
send(message: string): void;
|
|
8
|
+
close(code?: number, reason?: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): NodeWebSocket;
|
|
11
|
+
export interface NodePlayerIdentity {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
guest: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface NodeRoomManifest {
|
|
17
|
+
id: string;
|
|
18
|
+
players: {
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
};
|
|
22
|
+
lobby: boolean;
|
|
23
|
+
persistent?: boolean;
|
|
24
|
+
spectators?: {
|
|
25
|
+
delayMs: number;
|
|
26
|
+
} | null;
|
|
27
|
+
roles: Array<{
|
|
28
|
+
id: string;
|
|
29
|
+
min: number;
|
|
30
|
+
max?: number;
|
|
31
|
+
}>;
|
|
32
|
+
teams: {
|
|
33
|
+
min: number;
|
|
34
|
+
max: number;
|
|
35
|
+
} | null;
|
|
36
|
+
modes: Array<{
|
|
37
|
+
id: string;
|
|
38
|
+
execution?: 'local' | 'room';
|
|
39
|
+
players?: {
|
|
40
|
+
min: number;
|
|
41
|
+
max: number;
|
|
42
|
+
};
|
|
43
|
+
lobby?: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
voice?: 'none' | 'room' | 'team' | 'proximity';
|
|
46
|
+
}
|
|
47
|
+
export type NodeRoomJoinResult = {
|
|
48
|
+
ok: true;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
code: 'room_not_found' | 'room_full' | 'room_ended' | 'room_playing';
|
|
52
|
+
};
|
|
53
|
+
export type NodeRoomWatchResult = {
|
|
54
|
+
ok: true;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
code: 'room_not_found' | 'room_ended' | 'spectators_disabled' | 'spectators_full';
|
|
58
|
+
};
|
|
59
|
+
export interface NodeRoomInfo {
|
|
60
|
+
roomId: string;
|
|
61
|
+
status: RoomStatus;
|
|
62
|
+
players: number;
|
|
63
|
+
max: number;
|
|
64
|
+
mode: string | null;
|
|
65
|
+
}
|
|
66
|
+
export interface NodeRoomFlush {
|
|
67
|
+
scores: Array<{
|
|
68
|
+
playerId: string;
|
|
69
|
+
board: string;
|
|
70
|
+
score: number;
|
|
71
|
+
daily: boolean;
|
|
72
|
+
day?: string | null;
|
|
73
|
+
submittedAt?: number;
|
|
74
|
+
}>;
|
|
75
|
+
ended: {
|
|
76
|
+
result: JsonValue;
|
|
77
|
+
at: number;
|
|
78
|
+
} | null;
|
|
79
|
+
}
|
|
80
|
+
export interface NodeRoomOptions {
|
|
81
|
+
storageFile?: string;
|
|
82
|
+
dailyDay?: string;
|
|
83
|
+
deposito?: SharedGameStore | null;
|
|
84
|
+
}
|
|
85
|
+
export interface NodeRoom {
|
|
86
|
+
create(roomId: string, mode: string | null, creator: NodePlayerIdentity): Promise<boolean>;
|
|
87
|
+
info(): Promise<NodeRoomInfo | null>;
|
|
88
|
+
canJoin(identity: NodePlayerIdentity): Promise<NodeRoomJoinResult>;
|
|
89
|
+
canWatch(): Promise<NodeRoomWatchResult>;
|
|
90
|
+
connect(socket: NodeWebSocket, identity: NodePlayerIdentity): Promise<NodeRoomJoinResult>;
|
|
91
|
+
watch(socket: NodeWebSocket, identity: NodePlayerIdentity): Promise<NodeRoomWatchResult>;
|
|
92
|
+
flush(): Promise<NodeRoomFlush>;
|
|
93
|
+
wake(): Promise<void>;
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/** Crea una stanza Node usando memoria o un singolo file JSON persistente. */
|
|
97
|
+
export declare function createNodeRoom(definition: GameDefinition, manifest: NodeRoomManifest, options?: NodeRoomOptions): Promise<NodeRoom>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import type { Duplex } from 'node:stream';
|
|
4
|
+
export declare interface NodeWebSocket {
|
|
5
|
+
on(event: 'message', listener: (message: string) => void): this;
|
|
6
|
+
on(event: 'close', listener: () => void): this;
|
|
7
|
+
}
|
|
8
|
+
/** WebSocket testuale minimo per server Node, senza estensioni negoziate. */
|
|
9
|
+
export declare class NodeWebSocket extends EventEmitter {
|
|
10
|
+
private readonly socket;
|
|
11
|
+
private readonly massimoMessaggio;
|
|
12
|
+
private buffer;
|
|
13
|
+
private frammenti;
|
|
14
|
+
private byteFrammenti;
|
|
15
|
+
private frammentando;
|
|
16
|
+
private chiusuraInviata;
|
|
17
|
+
private terminato;
|
|
18
|
+
constructor(socket: Duplex, head: Buffer, massimoMessaggio?: number);
|
|
19
|
+
send(message: string): void;
|
|
20
|
+
close(code?: number, reason?: string): void;
|
|
21
|
+
private termina;
|
|
22
|
+
private erroreProtocollo;
|
|
23
|
+
private aggiungi;
|
|
24
|
+
private leggiFrame;
|
|
25
|
+
private gestisciControllo;
|
|
26
|
+
private gestisciDati;
|
|
27
|
+
}
|
|
28
|
+
/** Completa un upgrade HTTP gia autorizzato e restituisce il canale testuale. */
|
|
29
|
+
export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): NodeWebSocket;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Manifest, type QueuedScore } from '../contracts/index.js';
|
|
2
|
+
export interface BoardQuery {
|
|
3
|
+
board: string;
|
|
4
|
+
period: 'daily' | 'all-time';
|
|
5
|
+
guests: boolean;
|
|
6
|
+
day?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BoardData {
|
|
9
|
+
day: string | null;
|
|
10
|
+
entries: {
|
|
11
|
+
rank: number;
|
|
12
|
+
name: string;
|
|
13
|
+
guest: boolean;
|
|
14
|
+
me: boolean;
|
|
15
|
+
score: number;
|
|
16
|
+
verified: boolean;
|
|
17
|
+
}[];
|
|
18
|
+
me: {
|
|
19
|
+
rank: number;
|
|
20
|
+
score: number;
|
|
21
|
+
verified: boolean;
|
|
22
|
+
} | null;
|
|
23
|
+
ownGuest: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type BoardReader = (query: BoardQuery) => Promise<BoardData>;
|
|
26
|
+
export type Saving = 'saving' | 'saved' | 'bestAlready' | 'refreshHint';
|
|
27
|
+
export declare function createBoardController(input: {
|
|
28
|
+
manifest: Manifest;
|
|
29
|
+
player: string;
|
|
30
|
+
guests?: boolean;
|
|
31
|
+
read: BoardReader;
|
|
32
|
+
changed(): void;
|
|
33
|
+
later?: (callback: () => void, ms: number) => ReturnType<typeof setTimeout>;
|
|
34
|
+
clear?: (timer: ReturnType<typeof setTimeout>) => void;
|
|
35
|
+
}): {
|
|
36
|
+
readonly state: {
|
|
37
|
+
query: BoardQuery | null;
|
|
38
|
+
data: BoardData | null;
|
|
39
|
+
loading: boolean;
|
|
40
|
+
error: boolean;
|
|
41
|
+
saving: Saving | null;
|
|
42
|
+
};
|
|
43
|
+
select(next: BoardQuery): void;
|
|
44
|
+
queued(score: QueuedScore): void;
|
|
45
|
+
refresh: () => Promise<void>;
|
|
46
|
+
reset(): void;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type OverlayConfiguration, type OverlayOperations, type OverlaySessionState, type QueuedScore, type OverlayPanel } from '../contracts/index.js';
|
|
2
|
+
export interface FinestraHandshake {
|
|
3
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
4
|
+
removeEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
5
|
+
setInterval(handler: () => void, timeout: number): number;
|
|
6
|
+
clearInterval(id: number): void;
|
|
7
|
+
setTimeout(handler: () => void, timeout: number): number;
|
|
8
|
+
clearTimeout(id: number): void;
|
|
9
|
+
}
|
|
10
|
+
export interface FrameHandshake {
|
|
11
|
+
readonly src?: string;
|
|
12
|
+
contentWindow: {
|
|
13
|
+
postMessage(message: unknown, targetOrigin: string, transfer?: Transferable[]): void;
|
|
14
|
+
} | null;
|
|
15
|
+
addEventListener?(type: 'load', listener: () => void): void;
|
|
16
|
+
removeEventListener?(type: 'load', listener: () => void): void;
|
|
17
|
+
}
|
|
18
|
+
export interface HostBridgeInput {
|
|
19
|
+
finestra: FinestraHandshake;
|
|
20
|
+
frame: FrameHandshake;
|
|
21
|
+
origineGioco: string;
|
|
22
|
+
origineLive: string;
|
|
23
|
+
language?: string;
|
|
24
|
+
languagePreferences?: readonly string[];
|
|
25
|
+
invite: string | null;
|
|
26
|
+
ticket: string;
|
|
27
|
+
configuration?: OverlayConfiguration;
|
|
28
|
+
rinnova(aud: 'portal' | 'live'): Promise<string>;
|
|
29
|
+
onRoom(room: {
|
|
30
|
+
code: string;
|
|
31
|
+
} | null): void;
|
|
32
|
+
creaCanale?(): MessageChannel;
|
|
33
|
+
epoch?(): string;
|
|
34
|
+
requestTimeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function eMessaggioReady(value: unknown): boolean;
|
|
37
|
+
export declare function eRichiestaBiglietto(value: unknown): boolean;
|
|
38
|
+
export declare function stanzaDaMessaggio(value: unknown): {
|
|
39
|
+
code: string;
|
|
40
|
+
} | null | undefined;
|
|
41
|
+
export declare function creaPonteOspite(input: HostBridgeInput): {
|
|
42
|
+
readonly epoch: string | null;
|
|
43
|
+
serverTime(): number | null;
|
|
44
|
+
readonly state: OverlaySessionState | null;
|
|
45
|
+
subscribe(listener: (value: OverlaySessionState | null) => void): () => void;
|
|
46
|
+
onShortcut(listener: () => void): () => void;
|
|
47
|
+
onOpen(listener: (value: OverlayPanel) => void): () => void;
|
|
48
|
+
onError(listener: (value: {
|
|
49
|
+
sessionId: string;
|
|
50
|
+
error: {
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
};
|
|
54
|
+
}) => void): () => void;
|
|
55
|
+
onScore(listener: (value: QueuedScore) => void): () => void;
|
|
56
|
+
request<K extends keyof OverlayOperations>(op: K, args: OverlayOperations[K]): Promise<void>;
|
|
57
|
+
dispose(): void;
|
|
58
|
+
};
|
|
59
|
+
export type HostBridge = ReturnType<typeof creaPonteOspite>;
|
|
60
|
+
export declare function avviaHandshake(input: HostBridgeInput): () => void;
|
|
61
|
+
export declare function gameViewport(frame: HTMLIFrameElement): {
|
|
62
|
+
left: number;
|
|
63
|
+
top: number;
|
|
64
|
+
right: number;
|
|
65
|
+
bottom: number;
|
|
66
|
+
scaleX: number;
|
|
67
|
+
scaleY: number;
|
|
68
|
+
};
|
|
69
|
+
export declare function measureSafeArea(frame: HTMLIFrameElement, probe: HTMLElement): {
|
|
70
|
+
top: number;
|
|
71
|
+
right: number;
|
|
72
|
+
bottom: number;
|
|
73
|
+
left: number;
|
|
74
|
+
};
|