@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,128 @@
|
|
|
1
|
+
import type { FotografiaStanza } from '../protocollo.js';
|
|
2
|
+
import type { GameDefinition, JsonValue, RoomStatus } from '../server/index.js';
|
|
3
|
+
export interface RoomManifest {
|
|
4
|
+
id: string;
|
|
5
|
+
players: {
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
};
|
|
9
|
+
lobby: boolean;
|
|
10
|
+
persistent?: boolean;
|
|
11
|
+
roles: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
min: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}>;
|
|
16
|
+
teams: {
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
} | null;
|
|
20
|
+
modes: Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
execution?: 'local' | 'room';
|
|
23
|
+
players?: {
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
};
|
|
27
|
+
lobby?: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
voice?: 'none' | 'room' | 'team' | 'proximity';
|
|
30
|
+
}
|
|
31
|
+
export interface IdentitaGiocatore {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
guest: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface Esito {
|
|
37
|
+
frames: Array<{
|
|
38
|
+
connessione: string;
|
|
39
|
+
testo: string;
|
|
40
|
+
}>;
|
|
41
|
+
pubblici: string[];
|
|
42
|
+
chiusure: Array<{
|
|
43
|
+
connessione: string;
|
|
44
|
+
codice: number;
|
|
45
|
+
motivo: string;
|
|
46
|
+
}>;
|
|
47
|
+
sveglia: number | null;
|
|
48
|
+
tick: boolean;
|
|
49
|
+
tickRate: number;
|
|
50
|
+
status: RoomStatus | null;
|
|
51
|
+
voceRivedi: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface InfoStanza {
|
|
54
|
+
roomId: string;
|
|
55
|
+
status: RoomStatus;
|
|
56
|
+
players: number;
|
|
57
|
+
max: number;
|
|
58
|
+
mode: string | null;
|
|
59
|
+
member: boolean;
|
|
60
|
+
}
|
|
61
|
+
export type EsitoIngresso = {
|
|
62
|
+
ok: true;
|
|
63
|
+
} | {
|
|
64
|
+
ok: false;
|
|
65
|
+
code: 'room_not_found' | 'room_full' | 'room_ended' | 'room_playing';
|
|
66
|
+
};
|
|
67
|
+
export type EsitoAscolto = {
|
|
68
|
+
ok: true;
|
|
69
|
+
} | {
|
|
70
|
+
ok: false;
|
|
71
|
+
reason: 'mode' | 'unknown' | 'team' | 'gain';
|
|
72
|
+
};
|
|
73
|
+
export interface EsitoFlush {
|
|
74
|
+
scores: Array<{
|
|
75
|
+
playerId: string;
|
|
76
|
+
board: string;
|
|
77
|
+
score: number;
|
|
78
|
+
daily: boolean;
|
|
79
|
+
day?: string | null;
|
|
80
|
+
submittedAt?: number;
|
|
81
|
+
}>;
|
|
82
|
+
ended: {
|
|
83
|
+
result: JsonValue;
|
|
84
|
+
at: number;
|
|
85
|
+
} | null;
|
|
86
|
+
}
|
|
87
|
+
export interface FacetStanza {
|
|
88
|
+
crea(input: {
|
|
89
|
+
mode: string | null;
|
|
90
|
+
creator: IdentitaGiocatore;
|
|
91
|
+
}): Promise<Esito & {
|
|
92
|
+
ok: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
info(playerId?: string): Promise<InfoStanza | null>;
|
|
95
|
+
fotografia(): Promise<FotografiaStanza | null>;
|
|
96
|
+
puoEntrare(identita: IdentitaGiocatore): Promise<EsitoIngresso>;
|
|
97
|
+
puoAscoltare(listener: string, speakers: string[]): Promise<EsitoAscolto[]>;
|
|
98
|
+
entra(identita: IdentitaGiocatore, connessione: string): Promise<Esito>;
|
|
99
|
+
ricevi(connessione: string, testo: string, limiteVerificato?: boolean): Promise<Esito>;
|
|
100
|
+
disconnetti(connessione: string): Promise<Esito>;
|
|
101
|
+
riconciliaConnessioni(connessioni: string[]): Promise<Esito>;
|
|
102
|
+
tick(): Promise<Esito>;
|
|
103
|
+
sveglia(): Promise<Esito>;
|
|
104
|
+
flush(): Promise<EsitoFlush>;
|
|
105
|
+
}
|
|
106
|
+
export interface StorageFacet {
|
|
107
|
+
get<T>(chiave: string): Promise<T | undefined>;
|
|
108
|
+
put(chiave: string, valore: unknown): Promise<void>;
|
|
109
|
+
delete(chiave: string): Promise<boolean>;
|
|
110
|
+
list<T>(opzioni?: {
|
|
111
|
+
prefix?: string;
|
|
112
|
+
}): Promise<Map<string, T>>;
|
|
113
|
+
}
|
|
114
|
+
export interface StatoFacet {
|
|
115
|
+
readonly id: string | {
|
|
116
|
+
readonly name?: string;
|
|
117
|
+
toString(): string;
|
|
118
|
+
};
|
|
119
|
+
readonly storage: StorageFacet;
|
|
120
|
+
blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
|
|
121
|
+
}
|
|
122
|
+
export interface ClasseBaseFacet {
|
|
123
|
+
new (stato: StatoFacet, ambiente: unknown): object;
|
|
124
|
+
}
|
|
125
|
+
export interface ClasseFacetStanza {
|
|
126
|
+
new (stato: StatoFacet, ambiente: unknown): FacetStanza;
|
|
127
|
+
}
|
|
128
|
+
export declare function creaFacetStanza(DurableObject: ClasseBaseFacet, definizione: GameDefinition, manifest: RoomManifest): ClasseFacetStanza;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
|
|
5
|
+
export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
|
|
6
|
+
export type LeaveReason = 'left' | 'timeout' | 'kicked';
|
|
7
|
+
export interface SharedGameStore {
|
|
8
|
+
get(key: string): Promise<JsonValue | null>;
|
|
9
|
+
set(key: string, value: JsonValue): Promise<void>;
|
|
10
|
+
delete(key: string): Promise<void>;
|
|
11
|
+
list(prefix?: string): Promise<string[]>;
|
|
12
|
+
increment(key: string, amount?: number): Promise<number>;
|
|
13
|
+
}
|
|
14
|
+
export interface Player {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly guest: boolean;
|
|
18
|
+
readonly role: string | null;
|
|
19
|
+
readonly team: number | null;
|
|
20
|
+
readonly connected: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface Room<State extends JsonValue = JsonValue> {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly seed: number;
|
|
25
|
+
readonly mode: string | null;
|
|
26
|
+
readonly status: RoomStatus;
|
|
27
|
+
readonly tick: number;
|
|
28
|
+
readonly tickRate: number;
|
|
29
|
+
readonly result: JsonValue | null;
|
|
30
|
+
state: State;
|
|
31
|
+
readonly players: readonly Player[];
|
|
32
|
+
readonly host: Player | null;
|
|
33
|
+
broadcast(message: JsonValue): void;
|
|
34
|
+
send(player: Player | string, message: JsonValue): void;
|
|
35
|
+
kick(player: Player | string): void;
|
|
36
|
+
setRole(player: Player | string, role: string): void;
|
|
37
|
+
setTeam(player: Player | string, team: number): void;
|
|
38
|
+
end(result: JsonValue, options?: {
|
|
39
|
+
rematch?: boolean;
|
|
40
|
+
}): void;
|
|
41
|
+
save(key: string, value: JsonValue): Promise<void>;
|
|
42
|
+
load(key: string): Promise<JsonValue | null>;
|
|
43
|
+
readonly shared: SharedGameStore;
|
|
44
|
+
schedule(milliseconds: number, handler: string, payload: JsonValue): void;
|
|
45
|
+
readonly board: {
|
|
46
|
+
submit(player: Player | string, board: string, score: number, options?: {
|
|
47
|
+
daily?: boolean;
|
|
48
|
+
}): void;
|
|
49
|
+
};
|
|
50
|
+
readonly daily: {
|
|
51
|
+
readonly day: string;
|
|
52
|
+
readonly seed: number;
|
|
53
|
+
};
|
|
54
|
+
readonly time: {
|
|
55
|
+
now(): number;
|
|
56
|
+
};
|
|
57
|
+
readonly voice: {
|
|
58
|
+
readonly mode: VoiceMode;
|
|
59
|
+
setGain(listener: Player | string, speaker: Player | string, gain: number): void;
|
|
60
|
+
setProximity(a: Player | string, b: Player | string, gain: number): void;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface GameDefinition<State extends JsonValue = JsonValue> {
|
|
64
|
+
tickRate: number;
|
|
65
|
+
onCreate?(room: Room<State>): void | Promise<void>;
|
|
66
|
+
onRestart?(room: Room<State>): void | Promise<void>;
|
|
67
|
+
onStart?(room: Room<State>): void | Promise<void>;
|
|
68
|
+
onJoin?(room: Room<State>, player: Player): void | Promise<void>;
|
|
69
|
+
onConnection?(room: Room<State>, player: Player, connected: boolean): void | Promise<void>;
|
|
70
|
+
onLeave?(room: Room<State>, player: Player, reason: LeaveReason): void | Promise<void>;
|
|
71
|
+
onRoleRequest?(room: Room<State>, player: Player, role: string): void | Promise<void>;
|
|
72
|
+
onMessage?(room: Room<State>, player: Player, message: JsonValue): void | Promise<void>;
|
|
73
|
+
onTick?(room: Room<State>, deltaSeconds: number): void | Promise<void>;
|
|
74
|
+
onEnd?(room: Room<State>): void | Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
export declare function defineGame<State extends JsonValue = JsonValue, const Definition extends GameDefinition<State> = GameDefinition<State>>(definition: Definition): Definition;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type OverlayCapabilities, type OverlayConfiguration, type OverlayPanel, type OverlayRequest, type OverlaySessionState, type OverlayView, type QueuedScore } from '../contracts/index.js';
|
|
2
|
+
import type { BaseConnection, Room, Rooms, Spectate } from '../index.js';
|
|
3
|
+
export type GameSession = {
|
|
4
|
+
kind: 'idle';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'local';
|
|
7
|
+
id: string;
|
|
8
|
+
mode: string | null;
|
|
9
|
+
status: 'playing' | 'ended';
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'room';
|
|
12
|
+
id: string;
|
|
13
|
+
room: Room;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'watch';
|
|
16
|
+
id: string;
|
|
17
|
+
room: Spectate;
|
|
18
|
+
};
|
|
19
|
+
export interface Session {
|
|
20
|
+
readonly current: GameSession;
|
|
21
|
+
readonly capabilities: OverlayCapabilities;
|
|
22
|
+
onChange(listener: (session: GameSession) => void): () => void;
|
|
23
|
+
ready(): void;
|
|
24
|
+
finish(): void;
|
|
25
|
+
}
|
|
26
|
+
export interface Overlay {
|
|
27
|
+
open(panel: OverlayPanel): void;
|
|
28
|
+
onChange(listener: (view: OverlayView) => void): () => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createSession(base: BaseConnection, configuration?: OverlayConfiguration | null, roomsAvailable?: boolean): {
|
|
31
|
+
session: Session;
|
|
32
|
+
overlay: Overlay;
|
|
33
|
+
rooms: Rooms;
|
|
34
|
+
snapshot: () => OverlaySessionState;
|
|
35
|
+
serverTime: () => number;
|
|
36
|
+
onState(listener: (value: OverlaySessionState) => void): () => void;
|
|
37
|
+
onOpen(listener: (value: OverlayPanel) => void): () => void;
|
|
38
|
+
onError(listener: (value: {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
error: {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
}) => void): () => void;
|
|
45
|
+
onScore(listener: (value: QueuedScore) => void): () => void;
|
|
46
|
+
execute(request: OverlayRequest): Promise<void>;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
};
|
|
49
|
+
export type SessionCoordinator = ReturnType<typeof createSession>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type SessionResume } from '../contracts/index.js';
|
|
2
|
+
import type { BaseConnection } from '../index.js';
|
|
3
|
+
export declare function createResume(save: BaseConnection['save'], changed: () => void): {
|
|
4
|
+
loaded: Promise<void>;
|
|
5
|
+
readonly value: {
|
|
6
|
+
version: 1;
|
|
7
|
+
code: string;
|
|
8
|
+
mode: string | null;
|
|
9
|
+
updatedAt: number;
|
|
10
|
+
} | null;
|
|
11
|
+
readonly error: boolean;
|
|
12
|
+
set(value: SessionResume | null): Promise<void>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseConnection } from './index.js';
|
|
2
|
+
export interface ArchivioLocale {
|
|
3
|
+
readonly length: number;
|
|
4
|
+
key(index: number): string | null;
|
|
5
|
+
getItem(key: string): string | null;
|
|
6
|
+
setItem(key: string, value: string): void;
|
|
7
|
+
removeItem(key: string): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function creaStandalone(input: {
|
|
10
|
+
hostname: string;
|
|
11
|
+
archivio: ArchivioLocale | null;
|
|
12
|
+
subtle: SubtleCrypto;
|
|
13
|
+
ora: () => number;
|
|
14
|
+
}, invited?: string | null): Promise<BaseConnection>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { NucleoStanza } from './nucleo.js';
|
|
2
|
+
export type { AdattatoreStanza, ArchivioStanza, EsitoFlush, EsitoIngresso, IdentitaGiocatore, InfoStanza, ManifestStanza, } from './tipi.js';
|
|
3
|
+
export { analizzaJson, creaDiff, giornoUtc, hashSeed, seedGiornata, seedStanza } from './json.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonValue } from '../server/index.js';
|
|
2
|
+
import type { OperazioneDiff } from '../protocollo.js';
|
|
3
|
+
export type { OperazioneDiff, PercorsoDiff } from '../protocollo.js';
|
|
4
|
+
export type EsitoJson = {
|
|
5
|
+
ok: true;
|
|
6
|
+
testo: string;
|
|
7
|
+
valore: JsonValue;
|
|
8
|
+
bytes: number;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
code: 'state_invalid';
|
|
12
|
+
};
|
|
13
|
+
export declare function analizzaJson(value: unknown): EsitoJson;
|
|
14
|
+
export declare function creaDiff(prima: JsonValue, dopo: JsonValue): OperazioneDiff[];
|
|
15
|
+
export declare function giornoUtc(ora: number): string;
|
|
16
|
+
export declare function hashSeed(testo: string): number;
|
|
17
|
+
export declare function seedGiornata(slug: string, day: string): number;
|
|
18
|
+
export declare function seedStanza(roomId: string): number;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Player } from '../server/index.js';
|
|
2
|
+
import type { FotografiaStanza } from '../protocollo.js';
|
|
3
|
+
import type { AdattatoreStanza, EsitoAscolto, EsitoFlush, EsitoIngresso, IdentitaGiocatore, InfoStanza, ManifestStanza } from './tipi.js';
|
|
4
|
+
export declare class NucleoStanza {
|
|
5
|
+
private readonly definizione;
|
|
6
|
+
private readonly manifest;
|
|
7
|
+
private readonly adattatore;
|
|
8
|
+
private dati;
|
|
9
|
+
private readonly room;
|
|
10
|
+
private readonly frequenza;
|
|
11
|
+
private frequenzaDeposito;
|
|
12
|
+
private readonly kickRichiesti;
|
|
13
|
+
private readonly voceGuadagniCambiati;
|
|
14
|
+
private fineRichiesta;
|
|
15
|
+
private applicandoAzioni;
|
|
16
|
+
private ultimoStatoOsservato;
|
|
17
|
+
private tickRateSincronizzato;
|
|
18
|
+
private voceDaPersistire;
|
|
19
|
+
private constructor();
|
|
20
|
+
static apri(definizione: unknown, manifest: ManifestStanza, adattatore: AdattatoreStanza): Promise<NucleoStanza>;
|
|
21
|
+
private static verificaManifest;
|
|
22
|
+
private richiediDati;
|
|
23
|
+
private stanzaTerminata;
|
|
24
|
+
get esiste(): boolean;
|
|
25
|
+
crea(id: string, mode: string | null, _creator: IdentitaGiocatore): Promise<boolean>;
|
|
26
|
+
private get configurazione();
|
|
27
|
+
info(playerId?: string): InfoStanza | null;
|
|
28
|
+
fotografia(): FotografiaStanza | null;
|
|
29
|
+
giocatoreConnesso(connessione: string): Player | null;
|
|
30
|
+
puoAscoltare(listener: string, speakers: string[]): EsitoAscolto[];
|
|
31
|
+
puoEntrare(identity: IdentitaGiocatore): EsitoIngresso;
|
|
32
|
+
entra(identity: IdentitaGiocatore, connessione: string): Promise<EsitoIngresso>;
|
|
33
|
+
disconnetti(connessione: string): Promise<void>;
|
|
34
|
+
ricevi(connessione: string, frame: string, limiteVerificato?: boolean): Promise<void>;
|
|
35
|
+
eseguiTick(): Promise<void>;
|
|
36
|
+
sveglia(): Promise<void>;
|
|
37
|
+
flush(): Promise<EsitoFlush>;
|
|
38
|
+
riconciliaConnessioni(): Promise<void>;
|
|
39
|
+
private ruoloAutomatico;
|
|
40
|
+
private squadraAutomatica;
|
|
41
|
+
private inLobby;
|
|
42
|
+
private cambiaRuolo;
|
|
43
|
+
private cambiaSquadra;
|
|
44
|
+
private impostaRuoloDalServer;
|
|
45
|
+
private impostaSquadraDalServer;
|
|
46
|
+
private giocatorePerModificaDalServer;
|
|
47
|
+
private erroreMinimi;
|
|
48
|
+
private rivincita;
|
|
49
|
+
private avviaCountdown;
|
|
50
|
+
private verificaCountdown;
|
|
51
|
+
private messaggioErrato;
|
|
52
|
+
private chiudiConnessione;
|
|
53
|
+
private rimuoviGiocatore;
|
|
54
|
+
private assegnaHost;
|
|
55
|
+
private eseguiTimer;
|
|
56
|
+
private pianifica;
|
|
57
|
+
private giornata;
|
|
58
|
+
private accodaPunteggio;
|
|
59
|
+
private richiediFine;
|
|
60
|
+
private salva;
|
|
61
|
+
private caricaSave;
|
|
62
|
+
private verificaChiaveDeposito;
|
|
63
|
+
private verificaPrefissoDeposito;
|
|
64
|
+
private contaOperazioneDeposito;
|
|
65
|
+
private usaDeposito;
|
|
66
|
+
private leggiDeposito;
|
|
67
|
+
private scriviDeposito;
|
|
68
|
+
private eliminaDeposito;
|
|
69
|
+
private elencaDeposito;
|
|
70
|
+
private incrementaDeposito;
|
|
71
|
+
private broadcastCreatore;
|
|
72
|
+
private inviaCreatore;
|
|
73
|
+
private broadcast;
|
|
74
|
+
private inviaErrore;
|
|
75
|
+
private giocatoriProtocollo;
|
|
76
|
+
private inviaWelcome;
|
|
77
|
+
private stanzaProtocollo;
|
|
78
|
+
private inviaGiocatori;
|
|
79
|
+
private inviaStatus;
|
|
80
|
+
private inviaDiff;
|
|
81
|
+
private inviaSnapshotTutti;
|
|
82
|
+
private chiama;
|
|
83
|
+
private applicaAzioni;
|
|
84
|
+
private concludiEvento;
|
|
85
|
+
private verificaStato;
|
|
86
|
+
private impostaGuadagno;
|
|
87
|
+
private salvaGuadagno;
|
|
88
|
+
private creaCambiVoce;
|
|
89
|
+
private rivediVoce;
|
|
90
|
+
private inviaGuadagniCambiati;
|
|
91
|
+
private pulisciGuadagni;
|
|
92
|
+
private terminaPerStato;
|
|
93
|
+
private terminaInterna;
|
|
94
|
+
private registraCpu;
|
|
95
|
+
private persisti;
|
|
96
|
+
private persistiEProgramma;
|
|
97
|
+
private serveTick;
|
|
98
|
+
private terminaSeInattiva;
|
|
99
|
+
private aggiornaProgrammazione;
|
|
100
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { JsonValue, RoomStatus, SharedGameStore } from '../server/index.js';
|
|
2
|
+
import type { MessaggioServerStanza } from '../protocollo.js';
|
|
3
|
+
export interface ManifestStanza {
|
|
4
|
+
id: string;
|
|
5
|
+
players: {
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
};
|
|
9
|
+
lobby: boolean;
|
|
10
|
+
persistent?: boolean;
|
|
11
|
+
roles: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
min: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}>;
|
|
16
|
+
teams: {
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
} | null;
|
|
20
|
+
modes: Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
execution?: 'local' | 'room';
|
|
23
|
+
players?: {
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
};
|
|
27
|
+
lobby?: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
voice?: 'none' | 'room' | 'team' | 'proximity';
|
|
30
|
+
}
|
|
31
|
+
export interface ArchivioStanza {
|
|
32
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
33
|
+
put(key: string, value: unknown): Promise<void>;
|
|
34
|
+
delete(key: string): Promise<void>;
|
|
35
|
+
list(prefix?: string): Promise<Map<string, unknown>>;
|
|
36
|
+
}
|
|
37
|
+
export type DepositoCondiviso = SharedGameStore;
|
|
38
|
+
export interface AdattatoreStanza {
|
|
39
|
+
readonly storage: ArchivioStanza;
|
|
40
|
+
readonly deposito: DepositoCondiviso | null;
|
|
41
|
+
invia(connessione: string, messaggio: MessaggioServerStanza): void;
|
|
42
|
+
pubblica(messaggio: MessaggioServerStanza): void;
|
|
43
|
+
chiudi(connessione: string, codice: number, motivo: string): void;
|
|
44
|
+
connessioniAttive(): readonly string[];
|
|
45
|
+
ora(): number;
|
|
46
|
+
giorno?(ora: number): string;
|
|
47
|
+
misuraCpu(): number;
|
|
48
|
+
rivediVoce(): void;
|
|
49
|
+
programmaTick(intervalloMs: number | null): void;
|
|
50
|
+
programmaSveglia(ora: number | null): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
export interface IdentitaGiocatore {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
guest: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface GiocatorePersistito extends IdentitaGiocatore {
|
|
58
|
+
role: string | null;
|
|
59
|
+
team: number | null;
|
|
60
|
+
ready: boolean;
|
|
61
|
+
connected: boolean;
|
|
62
|
+
entratoAt: number;
|
|
63
|
+
graziaFinoA: number | null;
|
|
64
|
+
connessione: string | null;
|
|
65
|
+
seq: number;
|
|
66
|
+
}
|
|
67
|
+
export interface TimerPersistito {
|
|
68
|
+
id: number;
|
|
69
|
+
at: number;
|
|
70
|
+
handler: string;
|
|
71
|
+
payload: JsonValue;
|
|
72
|
+
}
|
|
73
|
+
export interface PunteggioPersistito {
|
|
74
|
+
playerId: string;
|
|
75
|
+
board: string;
|
|
76
|
+
score: number;
|
|
77
|
+
daily: boolean;
|
|
78
|
+
day?: string | null;
|
|
79
|
+
submittedAt?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface FinePersistita {
|
|
82
|
+
result: JsonValue;
|
|
83
|
+
at: number;
|
|
84
|
+
}
|
|
85
|
+
export interface StatoPersistito {
|
|
86
|
+
versione: 1;
|
|
87
|
+
id: string;
|
|
88
|
+
mode: string | null;
|
|
89
|
+
status: RoomStatus;
|
|
90
|
+
tick: number;
|
|
91
|
+
tickRate: number;
|
|
92
|
+
ultimoInputAt: number;
|
|
93
|
+
ultimoCambioStatoAt: number;
|
|
94
|
+
state: JsonValue;
|
|
95
|
+
giocatori: GiocatorePersistito[];
|
|
96
|
+
hostId: string | null;
|
|
97
|
+
result: JsonValue | null;
|
|
98
|
+
resultAt: number | null;
|
|
99
|
+
rivincitaFinoA?: number | null;
|
|
100
|
+
countdownAt: number | null;
|
|
101
|
+
timer: TimerPersistito[];
|
|
102
|
+
prossimoTimerId: number;
|
|
103
|
+
punteggi: PunteggioPersistito[];
|
|
104
|
+
fineInCoda: FinePersistita | null;
|
|
105
|
+
vuotaDa: number | null;
|
|
106
|
+
cancellaDopoFlush: boolean;
|
|
107
|
+
tickSincronizzato: number;
|
|
108
|
+
statoSincronizzato: JsonValue;
|
|
109
|
+
durateCpu: number[];
|
|
110
|
+
cpuOltreCento: number;
|
|
111
|
+
voceGuadagni?: Record<string, Record<string, number>>;
|
|
112
|
+
}
|
|
113
|
+
export type EsitoIngresso = {
|
|
114
|
+
ok: true;
|
|
115
|
+
} | {
|
|
116
|
+
ok: false;
|
|
117
|
+
code: 'room_not_found' | 'room_full' | 'room_ended' | 'room_playing';
|
|
118
|
+
};
|
|
119
|
+
export type EsitoAscolto = {
|
|
120
|
+
ok: true;
|
|
121
|
+
} | {
|
|
122
|
+
ok: false;
|
|
123
|
+
reason: 'mode' | 'unknown' | 'team' | 'gain';
|
|
124
|
+
};
|
|
125
|
+
export interface InfoStanza {
|
|
126
|
+
roomId: string;
|
|
127
|
+
status: RoomStatus;
|
|
128
|
+
players: number;
|
|
129
|
+
max: number;
|
|
130
|
+
mode: string | null;
|
|
131
|
+
member: boolean;
|
|
132
|
+
}
|
|
133
|
+
export interface EsitoFlush {
|
|
134
|
+
scores: PunteggioPersistito[];
|
|
135
|
+
ended: FinePersistita | null;
|
|
136
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Rooms } from '../index.js';
|
|
2
|
+
import type { GestoreBiglietto } from '../handshake.js';
|
|
3
|
+
import { type DipendenzeVoce } from '../voce/index.js';
|
|
4
|
+
interface TimerStanza {
|
|
5
|
+
setTimeout(handler: () => void, timeout: number): number;
|
|
6
|
+
clearTimeout(id: number): void;
|
|
7
|
+
setInterval(handler: () => void, timeout: number): number;
|
|
8
|
+
clearInterval(id: number): void;
|
|
9
|
+
}
|
|
10
|
+
export interface DipendenzeStanze extends TimerStanza {
|
|
11
|
+
appOrigin: string;
|
|
12
|
+
liveOrigin: string;
|
|
13
|
+
fetcher: typeof fetch;
|
|
14
|
+
biglietto: GestoreBiglietto;
|
|
15
|
+
apriSocket(url: string): WebSocket;
|
|
16
|
+
ora(): number;
|
|
17
|
+
voce?: DipendenzeVoce;
|
|
18
|
+
segnalaStanza?(room: {
|
|
19
|
+
code: string;
|
|
20
|
+
} | null): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function creaStanzeOffline(invited?: string | null): Rooms;
|
|
23
|
+
export declare function creaGestoreStanze(input: DipendenzeStanze, invited: string | null): Rooms;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { RoomPlayer, Voice, VoiceMode, VoicePeer, VoiceState } from '../index.js';
|
|
2
|
+
import type { MessaggioClientVoce, MessaggioServerVoce } from '../protocollo.js';
|
|
3
|
+
export interface DipendenzeVoce {
|
|
4
|
+
creaPeerConnection(configuration?: RTCConfiguration): RTCPeerConnection;
|
|
5
|
+
getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
|
|
6
|
+
creaAudioContext(): AudioContext;
|
|
7
|
+
creaAudioElement(): HTMLAudioElement;
|
|
8
|
+
creaMediaStream(tracks: MediaStreamTrack[]): MediaStream;
|
|
9
|
+
ora(): number;
|
|
10
|
+
setTimeout(handler: () => void, timeout: number): number;
|
|
11
|
+
clearTimeout(id: number): void;
|
|
12
|
+
setInterval(handler: () => void, timeout: number): number;
|
|
13
|
+
clearInterval(id: number): void;
|
|
14
|
+
}
|
|
15
|
+
export interface ContestoVoce {
|
|
16
|
+
invia(message: MessaggioClientVoce): void;
|
|
17
|
+
connessa(): boolean;
|
|
18
|
+
you(): string;
|
|
19
|
+
giocatori(): readonly RoomPlayer[];
|
|
20
|
+
rosterPronto(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class VoceClient implements Voice {
|
|
23
|
+
private readonly contesto;
|
|
24
|
+
private modeCorrente;
|
|
25
|
+
private stateCorrente;
|
|
26
|
+
private mutedCorrente;
|
|
27
|
+
private speakingCorrente;
|
|
28
|
+
private roster;
|
|
29
|
+
private readonly gains;
|
|
30
|
+
private readonly volumi;
|
|
31
|
+
private readonly speakingPeers;
|
|
32
|
+
private readonly ultimoAudio;
|
|
33
|
+
private readonly zeroDa;
|
|
34
|
+
private readonly timerZero;
|
|
35
|
+
private readonly ascoltatoriPeers;
|
|
36
|
+
private readonly ascoltatoriState;
|
|
37
|
+
private readonly richieste;
|
|
38
|
+
private readonly riproduzioni;
|
|
39
|
+
private readonly sfuAttive;
|
|
40
|
+
private readonly midGiocatori;
|
|
41
|
+
private readonly negati;
|
|
42
|
+
private readonly mesh;
|
|
43
|
+
private dipendenze;
|
|
44
|
+
private stream;
|
|
45
|
+
private tracciaMic;
|
|
46
|
+
private audioContext;
|
|
47
|
+
private analyser;
|
|
48
|
+
private peerSfu;
|
|
49
|
+
private sessioneSfu;
|
|
50
|
+
private connessioneSfuAttesa;
|
|
51
|
+
private trasporto;
|
|
52
|
+
private intervalloAudio;
|
|
53
|
+
private timerConnessione;
|
|
54
|
+
private cancellaAttesaConnessione;
|
|
55
|
+
private timerRiconnessione;
|
|
56
|
+
private ultimoAudioMic;
|
|
57
|
+
private sequenzaRichieste;
|
|
58
|
+
private generazione;
|
|
59
|
+
private tentativoRiconnessione;
|
|
60
|
+
private desiderata;
|
|
61
|
+
private micDesiderato;
|
|
62
|
+
private promessaIngresso;
|
|
63
|
+
private negoziazione;
|
|
64
|
+
constructor(contesto: ContestoVoce, timer: Pick<DipendenzeVoce, 'ora' | 'setTimeout' | 'clearTimeout' | 'setInterval' | 'clearInterval'>, dipendenze?: DipendenzeVoce);
|
|
65
|
+
get mode(): VoiceMode;
|
|
66
|
+
get state(): VoiceState;
|
|
67
|
+
get mic(): boolean;
|
|
68
|
+
get muted(): boolean;
|
|
69
|
+
get speaking(): boolean;
|
|
70
|
+
get peers(): readonly VoicePeer[];
|
|
71
|
+
join(options?: {
|
|
72
|
+
mic?: boolean;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
private completaIngresso;
|
|
75
|
+
leave(): void;
|
|
76
|
+
mute(muted?: boolean): void;
|
|
77
|
+
setVolume(playerId: string, volume: number): void;
|
|
78
|
+
onPeers(listener: (peers: readonly VoicePeer[]) => void): () => void;
|
|
79
|
+
onState(listener: (state: VoiceState) => void): () => void;
|
|
80
|
+
ricevi(message: MessaggioServerVoce): void;
|
|
81
|
+
giocatoriCambiati(): void;
|
|
82
|
+
socketDisconnesso(): void;
|
|
83
|
+
socketRiconnesso(): void;
|
|
84
|
+
termina(): void;
|
|
85
|
+
private scegliMic;
|
|
86
|
+
private verificaIngresso;
|
|
87
|
+
private entra;
|
|
88
|
+
private entraSfu;
|
|
89
|
+
private attendiConnessione;
|
|
90
|
+
private accodaRiconciliazione;
|
|
91
|
+
private riconciliaSfu;
|
|
92
|
+
private riconciliaMesh;
|
|
93
|
+
private creaMesh;
|
|
94
|
+
private offriMesh;
|
|
95
|
+
private riceviSegnale;
|
|
96
|
+
private inviaSegnale;
|
|
97
|
+
private peerDesiderati;
|
|
98
|
+
private publisherDesiderati;
|
|
99
|
+
private aggiornaZero;
|
|
100
|
+
private collegaTraccia;
|
|
101
|
+
private scollegaTraccia;
|
|
102
|
+
private aggiornaGuadagno;
|
|
103
|
+
private preparaAnalizzatore;
|
|
104
|
+
private avviaMisuraAudio;
|
|
105
|
+
private misuraAudio;
|
|
106
|
+
private livelloAnalizzatore;
|
|
107
|
+
private copiaPeers;
|
|
108
|
+
private pulisciPeerAssenti;
|
|
109
|
+
private osservaCaduta;
|
|
110
|
+
private avviaRiconnessione;
|
|
111
|
+
private programmaRiconnessione;
|
|
112
|
+
private fermaRiconnessione;
|
|
113
|
+
private chiudiRisorse;
|
|
114
|
+
private richiedi;
|
|
115
|
+
private rifiutaRichieste;
|
|
116
|
+
private aggiornaState;
|
|
117
|
+
private notificaPeers;
|
|
118
|
+
private controllaGenerazione;
|
|
119
|
+
private richiediDipendenze;
|
|
120
|
+
private richiediMic;
|
|
121
|
+
private richiediAudioContext;
|
|
122
|
+
private permessoNegato;
|
|
123
|
+
private mappaErrore;
|
|
124
|
+
}
|