@caisual/kit 0.4.0 → 0.8.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 -157
- package/dist/kit.js +1539 -59
- package/dist/node.d.ts +1 -77
- package/dist/node.js +341 -42
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.js +1846 -0
- package/dist/runtime.d.ts +1 -108
- package/dist/runtime.js +191 -41
- package/dist/server.d.ts +1 -71
- package/dist/server.js +1 -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/index.d.ts +10 -0
- package/dist/types/contracts/keys.d.ts +59 -0
- package/dist/types/contracts/manifest.d.ts +118 -0
- package/dist/types/contracts/overlay-boards.d.ts +3 -0
- package/dist/types/contracts/overlay.d.ts +215 -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 +26 -0
- package/dist/types/http.d.ts +3 -0
- package/dist/types/index.d.ts +217 -0
- package/dist/types/kit.d.ts +26 -0
- package/dist/types/node/index.d.ts +96 -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 +58 -0
- package/dist/types/overlay/i18n.d.ts +122 -0
- package/dist/types/overlay/index.d.ts +9 -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 +257 -0
- package/dist/types/runtime/index.d.ts +127 -0
- package/dist/types/server/index.d.ts +72 -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 +97 -0
- package/dist/types/stanza/tipi.d.ts +134 -0
- package/dist/types/stanza-client/index.d.ts +24 -0
- package/dist/types/voce/index.d.ts +124 -0
- package/package.json +10 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Manifest, type OverlayPanel, type OverlaySessionState } from '../contracts/index.js';
|
|
2
|
+
export type Phase = 'boot' | 'home' | 'attaching' | 'matching' | 'lobby' | 'countdown' | 'playing' | 'ended' | 'watching' | 'error';
|
|
3
|
+
export type Panel = OverlayPanel | 'join' | 'watch' | 'exit';
|
|
4
|
+
export interface UiModel {
|
|
5
|
+
session: OverlaySessionState | null;
|
|
6
|
+
panel: Panel | 'auto' | null;
|
|
7
|
+
mode: string;
|
|
8
|
+
busy: boolean;
|
|
9
|
+
error: string | null;
|
|
10
|
+
notice: string | null;
|
|
11
|
+
shortcutEnabled: boolean;
|
|
12
|
+
}
|
|
13
|
+
export type UiAction = {
|
|
14
|
+
type: 'session';
|
|
15
|
+
session: OverlaySessionState | null;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'panel';
|
|
18
|
+
panel: Panel | null;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'mode';
|
|
21
|
+
mode: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'busy';
|
|
24
|
+
busy: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'error';
|
|
27
|
+
code: string | null;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'notice';
|
|
30
|
+
notice: string | null;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'shortcut';
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare function phase(session: OverlaySessionState | null): Phase;
|
|
36
|
+
export declare function initialUi(manifest: Manifest): UiModel;
|
|
37
|
+
export declare function reduceUi(model: UiModel, action: UiAction): UiModel;
|
|
38
|
+
export declare function visiblePanel(model: UiModel): Panel | 'boot' | 'attaching' | 'matching' | 'countdown' | 'error' | null;
|
|
39
|
+
export declare function primaryAction(manifest: Manifest, mode: string): {
|
|
40
|
+
op: "local.start" | "room.create";
|
|
41
|
+
friends: boolean;
|
|
42
|
+
} | null;
|
|
43
|
+
export declare function startReason(manifest: Manifest, session: OverlaySessionState | null): string | null;
|
|
44
|
+
export declare function canPlayAgain(session: OverlaySessionState | null): boolean;
|
|
45
|
+
export declare function normalizeInvite(code: string): string | null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type OverlayConfiguration } from '../contracts/index.js';
|
|
2
|
+
import type { HostBridge } from './host-bridge.js';
|
|
3
|
+
import { type BoardReader } from './boards.js';
|
|
4
|
+
export interface CrewPerson {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
online: boolean;
|
|
8
|
+
game: {
|
|
9
|
+
slug: string;
|
|
10
|
+
name: string;
|
|
11
|
+
} | null;
|
|
12
|
+
room: {
|
|
13
|
+
code: string;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CrewSnapshot {
|
|
17
|
+
connected: boolean;
|
|
18
|
+
you: {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
} | null;
|
|
22
|
+
friends: CrewPerson[];
|
|
23
|
+
party: {
|
|
24
|
+
id: string;
|
|
25
|
+
leader: string;
|
|
26
|
+
members: CrewPerson[];
|
|
27
|
+
} | null;
|
|
28
|
+
invites: {
|
|
29
|
+
party: string;
|
|
30
|
+
from: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
};
|
|
34
|
+
at: number;
|
|
35
|
+
}[];
|
|
36
|
+
follow: {
|
|
37
|
+
from: {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
game: {
|
|
42
|
+
slug: string;
|
|
43
|
+
name: string;
|
|
44
|
+
};
|
|
45
|
+
code: string;
|
|
46
|
+
} | null;
|
|
47
|
+
}
|
|
48
|
+
export interface OverlayCrew {
|
|
49
|
+
unavailable?: 'local' | 'login';
|
|
50
|
+
getSnapshot(): CrewSnapshot;
|
|
51
|
+
subscribe(listener: () => void): () => void;
|
|
52
|
+
party: {
|
|
53
|
+
create(): void;
|
|
54
|
+
invite(player: string): void;
|
|
55
|
+
accept(party: string): void;
|
|
56
|
+
decline(party: string): void;
|
|
57
|
+
leave(): void;
|
|
58
|
+
};
|
|
59
|
+
follow(game: string, code: string): void;
|
|
60
|
+
}
|
|
61
|
+
export interface MountOverlayInput {
|
|
62
|
+
container: HTMLElement;
|
|
63
|
+
frame: HTMLIFrameElement;
|
|
64
|
+
bridge: HostBridge;
|
|
65
|
+
configuration: OverlayConfiguration;
|
|
66
|
+
language: string;
|
|
67
|
+
player: {
|
|
68
|
+
id: string;
|
|
69
|
+
guest: boolean;
|
|
70
|
+
};
|
|
71
|
+
exit(): void;
|
|
72
|
+
inviteUrl(code: string): string;
|
|
73
|
+
boards?: BoardReader;
|
|
74
|
+
crew?: OverlayCrew;
|
|
75
|
+
}
|
|
76
|
+
export declare function mountOverlay(input: MountOverlayInput): {
|
|
77
|
+
element: HTMLDivElement;
|
|
78
|
+
root: ShadowRoot;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
} | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Manifest, OverlaySessionState, OverlayVoice } from '../contracts/index.js';
|
|
2
|
+
import { type translator } from './i18n.js';
|
|
3
|
+
type Translate = ReturnType<typeof translator>;
|
|
4
|
+
export declare function voiceEligible(manifest: Manifest, session: OverlaySessionState | null): boolean;
|
|
5
|
+
export declare function voiceStatus(voice: OverlayVoice, t: Translate): string;
|
|
6
|
+
export declare function updateVoicePanel(container: HTMLElement, input: {
|
|
7
|
+
manifest: Manifest;
|
|
8
|
+
session: OverlaySessionState | null;
|
|
9
|
+
t: Translate;
|
|
10
|
+
error: string | null;
|
|
11
|
+
pending: string | null;
|
|
12
|
+
}): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import type { QueuedScore } from './contracts/index.js';
|
|
2
|
+
import type { JsonValue, RoomStatus } from './server/index.js';
|
|
3
|
+
export type PercorsoDiff = Array<string | number>;
|
|
4
|
+
export type OperazioneDiff = {
|
|
5
|
+
op: 'set';
|
|
6
|
+
path: PercorsoDiff;
|
|
7
|
+
value: JsonValue;
|
|
8
|
+
} | {
|
|
9
|
+
op: 'del';
|
|
10
|
+
path: PercorsoDiff;
|
|
11
|
+
};
|
|
12
|
+
export interface GiocatoreProtocollo {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
guest: boolean;
|
|
16
|
+
role: string | null;
|
|
17
|
+
team: number | null;
|
|
18
|
+
ready: boolean;
|
|
19
|
+
connected: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
|
|
22
|
+
/** Un giocatore che sta pubblicando la voce: `session` e' la sessione SFU (o `mesh` in locale). */
|
|
23
|
+
export interface VocePeerProtocollo {
|
|
24
|
+
id: string;
|
|
25
|
+
session: string;
|
|
26
|
+
track: string;
|
|
27
|
+
muted: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface IceServerProtocollo {
|
|
30
|
+
urls: string | string[];
|
|
31
|
+
username?: string;
|
|
32
|
+
credential?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface RoomConfiguration {
|
|
35
|
+
players: {
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
};
|
|
39
|
+
lobby: boolean;
|
|
40
|
+
persistent: boolean;
|
|
41
|
+
requestRole: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface StanzaProtocollo {
|
|
44
|
+
countdownAt?: number | null;
|
|
45
|
+
configuration?: RoomConfiguration;
|
|
46
|
+
id: string;
|
|
47
|
+
seed: number;
|
|
48
|
+
status: RoomStatus;
|
|
49
|
+
mode: string | null;
|
|
50
|
+
tick: number;
|
|
51
|
+
tickRate: number;
|
|
52
|
+
serverTime: number;
|
|
53
|
+
host: string | null;
|
|
54
|
+
}
|
|
55
|
+
export interface FotografiaStanza {
|
|
56
|
+
room: StanzaProtocollo;
|
|
57
|
+
players: GiocatoreProtocollo[];
|
|
58
|
+
state: JsonValue;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Operazioni voce del client. Ogni richiesta porta `r`, un intero crescente per
|
|
62
|
+
* connessione: la risposta del server ripete lo stesso `r`. Gli op `session`,
|
|
63
|
+
* `subscribe`, `answer` e `close` esistono solo con trasporto `sfu`; `publish` e
|
|
64
|
+
* `signal` solo con trasporto `mesh` (sviluppo locale).
|
|
65
|
+
*/
|
|
66
|
+
export type MessaggioClientVoce = {
|
|
67
|
+
t: 'voice';
|
|
68
|
+
op: 'ice';
|
|
69
|
+
r: number;
|
|
70
|
+
} | {
|
|
71
|
+
t: 'voice';
|
|
72
|
+
op: 'session';
|
|
73
|
+
r: number;
|
|
74
|
+
sdp?: string;
|
|
75
|
+
mid?: string;
|
|
76
|
+
} | {
|
|
77
|
+
t: 'voice';
|
|
78
|
+
op: 'subscribe';
|
|
79
|
+
r: number;
|
|
80
|
+
session: string;
|
|
81
|
+
tracks: Array<{
|
|
82
|
+
session: string;
|
|
83
|
+
track: string;
|
|
84
|
+
}>;
|
|
85
|
+
} | {
|
|
86
|
+
t: 'voice';
|
|
87
|
+
op: 'answer';
|
|
88
|
+
r: number;
|
|
89
|
+
session: string;
|
|
90
|
+
sdp: string;
|
|
91
|
+
} | {
|
|
92
|
+
t: 'voice';
|
|
93
|
+
op: 'close';
|
|
94
|
+
r: number;
|
|
95
|
+
session: string;
|
|
96
|
+
mids: string[];
|
|
97
|
+
} | {
|
|
98
|
+
t: 'voice';
|
|
99
|
+
op: 'publish';
|
|
100
|
+
r: number;
|
|
101
|
+
mic?: boolean;
|
|
102
|
+
} | {
|
|
103
|
+
t: 'voice';
|
|
104
|
+
op: 'signal';
|
|
105
|
+
r: number;
|
|
106
|
+
to: string;
|
|
107
|
+
data: JsonValue;
|
|
108
|
+
} | {
|
|
109
|
+
t: 'voice';
|
|
110
|
+
op: 'mute';
|
|
111
|
+
r: number;
|
|
112
|
+
muted: boolean;
|
|
113
|
+
} | {
|
|
114
|
+
t: 'voice';
|
|
115
|
+
op: 'stop';
|
|
116
|
+
r: number;
|
|
117
|
+
};
|
|
118
|
+
export type OpVoce = MessaggioClientVoce['op'];
|
|
119
|
+
export type MessaggioServerVoce = {
|
|
120
|
+
t: 'voice';
|
|
121
|
+
op: 'ice';
|
|
122
|
+
r: number;
|
|
123
|
+
transport: 'sfu' | 'mesh';
|
|
124
|
+
mode: VoiceMode;
|
|
125
|
+
iceServers: IceServerProtocollo[];
|
|
126
|
+
} | {
|
|
127
|
+
t: 'voice';
|
|
128
|
+
op: 'session';
|
|
129
|
+
r: number;
|
|
130
|
+
session: string;
|
|
131
|
+
sdp: string | null;
|
|
132
|
+
} | {
|
|
133
|
+
t: 'voice';
|
|
134
|
+
op: 'subscribe';
|
|
135
|
+
r: number;
|
|
136
|
+
sdp: string;
|
|
137
|
+
tracks: Array<{
|
|
138
|
+
mid: string | null;
|
|
139
|
+
session: string;
|
|
140
|
+
track: string;
|
|
141
|
+
error: string | null;
|
|
142
|
+
}>;
|
|
143
|
+
} | {
|
|
144
|
+
t: 'voice';
|
|
145
|
+
op: 'answer' | 'close' | 'publish' | 'signal' | 'mute' | 'stop';
|
|
146
|
+
r: number;
|
|
147
|
+
} | {
|
|
148
|
+
t: 'voice';
|
|
149
|
+
op: 'closed';
|
|
150
|
+
mids: string[];
|
|
151
|
+
} | {
|
|
152
|
+
t: 'voice';
|
|
153
|
+
op: OpVoce;
|
|
154
|
+
r: number;
|
|
155
|
+
error: {
|
|
156
|
+
code: string;
|
|
157
|
+
message: string;
|
|
158
|
+
};
|
|
159
|
+
} | {
|
|
160
|
+
t: 'voice';
|
|
161
|
+
op: 'roster';
|
|
162
|
+
mode: VoiceMode;
|
|
163
|
+
peers: VocePeerProtocollo[];
|
|
164
|
+
listeners: string[];
|
|
165
|
+
} | {
|
|
166
|
+
t: 'voice';
|
|
167
|
+
op: 'gain';
|
|
168
|
+
gains: Record<string, number>;
|
|
169
|
+
} | {
|
|
170
|
+
t: 'voice';
|
|
171
|
+
op: 'signal';
|
|
172
|
+
from: string;
|
|
173
|
+
data: JsonValue;
|
|
174
|
+
};
|
|
175
|
+
export type MessaggioClientStanza = MessaggioClientVoce | {
|
|
176
|
+
t: 'ready';
|
|
177
|
+
ready: boolean;
|
|
178
|
+
} | {
|
|
179
|
+
t: 'role';
|
|
180
|
+
role: string;
|
|
181
|
+
} | {
|
|
182
|
+
t: 'request-role';
|
|
183
|
+
role: string;
|
|
184
|
+
r: number;
|
|
185
|
+
} | {
|
|
186
|
+
t: 'team';
|
|
187
|
+
team: number;
|
|
188
|
+
} | {
|
|
189
|
+
t: 'start';
|
|
190
|
+
} | {
|
|
191
|
+
t: 'msg';
|
|
192
|
+
seq: number;
|
|
193
|
+
m: JsonValue;
|
|
194
|
+
} | {
|
|
195
|
+
t: 'ping';
|
|
196
|
+
c: number;
|
|
197
|
+
} | {
|
|
198
|
+
t: 'resync';
|
|
199
|
+
} | {
|
|
200
|
+
t: 'leave';
|
|
201
|
+
};
|
|
202
|
+
export type MessaggioServerStanza = {
|
|
203
|
+
t: 'welcome';
|
|
204
|
+
you: string;
|
|
205
|
+
room: StanzaProtocollo;
|
|
206
|
+
players: GiocatoreProtocollo[];
|
|
207
|
+
state: JsonValue;
|
|
208
|
+
} | {
|
|
209
|
+
t: 'players';
|
|
210
|
+
players: GiocatoreProtocollo[];
|
|
211
|
+
host?: string | null;
|
|
212
|
+
} | {
|
|
213
|
+
t: 'role-result';
|
|
214
|
+
r: number;
|
|
215
|
+
ok: boolean;
|
|
216
|
+
code: string | null;
|
|
217
|
+
} | {
|
|
218
|
+
t: 'score-queued';
|
|
219
|
+
score: QueuedScore;
|
|
220
|
+
} | {
|
|
221
|
+
t: 'status';
|
|
222
|
+
status: RoomStatus;
|
|
223
|
+
at: number;
|
|
224
|
+
result: JsonValue;
|
|
225
|
+
countdownAt?: number | null;
|
|
226
|
+
host?: string | null;
|
|
227
|
+
} | {
|
|
228
|
+
t: 'state';
|
|
229
|
+
tick: number;
|
|
230
|
+
serverTime: number;
|
|
231
|
+
base: number;
|
|
232
|
+
patch: OperazioneDiff[];
|
|
233
|
+
} | {
|
|
234
|
+
t: 'snapshot';
|
|
235
|
+
tick: number;
|
|
236
|
+
serverTime: number;
|
|
237
|
+
state: JsonValue;
|
|
238
|
+
} | {
|
|
239
|
+
t: 'msg';
|
|
240
|
+
m: JsonValue;
|
|
241
|
+
} | {
|
|
242
|
+
t: 'error';
|
|
243
|
+
code: string;
|
|
244
|
+
message: string;
|
|
245
|
+
} | {
|
|
246
|
+
t: 'pong';
|
|
247
|
+
c: number;
|
|
248
|
+
s: number;
|
|
249
|
+
} | {
|
|
250
|
+
t: 'flush';
|
|
251
|
+
} | MessaggioServerVoce;
|
|
252
|
+
export type MessaggioServerSpettatore = ({
|
|
253
|
+
t: 'watching';
|
|
254
|
+
delayMs: number;
|
|
255
|
+
} & FotografiaStanza) | Extract<MessaggioServerStanza, {
|
|
256
|
+
t: 'players' | 'status' | 'state' | 'snapshot' | 'msg' | 'error' | 'pong';
|
|
257
|
+
}>;
|
|
@@ -0,0 +1,127 @@
|
|
|
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): Promise<Esito>;
|
|
100
|
+
disconnetti(connessione: string): Promise<Esito>;
|
|
101
|
+
tick(): Promise<Esito>;
|
|
102
|
+
sveglia(): Promise<Esito>;
|
|
103
|
+
flush(): Promise<EsitoFlush>;
|
|
104
|
+
}
|
|
105
|
+
export interface StorageFacet {
|
|
106
|
+
get<T>(chiave: string): Promise<T | undefined>;
|
|
107
|
+
put(chiave: string, valore: unknown): Promise<void>;
|
|
108
|
+
delete(chiave: string): Promise<boolean>;
|
|
109
|
+
list<T>(opzioni?: {
|
|
110
|
+
prefix?: string;
|
|
111
|
+
}): Promise<Map<string, T>>;
|
|
112
|
+
}
|
|
113
|
+
export interface StatoFacet {
|
|
114
|
+
readonly id: string | {
|
|
115
|
+
readonly name?: string;
|
|
116
|
+
toString(): string;
|
|
117
|
+
};
|
|
118
|
+
readonly storage: StorageFacet;
|
|
119
|
+
blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
|
|
120
|
+
}
|
|
121
|
+
export interface ClasseBaseFacet {
|
|
122
|
+
new (stato: StatoFacet, ambiente: unknown): object;
|
|
123
|
+
}
|
|
124
|
+
export interface ClasseFacetStanza {
|
|
125
|
+
new (stato: StatoFacet, ambiente: unknown): FacetStanza;
|
|
126
|
+
}
|
|
127
|
+
export declare function creaFacetStanza(DurableObject: ClasseBaseFacet, definizione: GameDefinition, manifest: RoomManifest): ClasseFacetStanza;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type RoomStatus = 'lobby' | 'countdown' | 'playing' | '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): void;
|
|
39
|
+
save(key: string, value: JsonValue): Promise<void>;
|
|
40
|
+
load(key: string): Promise<JsonValue | null>;
|
|
41
|
+
readonly shared: SharedGameStore;
|
|
42
|
+
schedule(milliseconds: number, handler: string, payload: JsonValue): void;
|
|
43
|
+
readonly board: {
|
|
44
|
+
submit(player: Player | string, board: string, score: number, options?: {
|
|
45
|
+
daily?: boolean;
|
|
46
|
+
}): void;
|
|
47
|
+
};
|
|
48
|
+
readonly daily: {
|
|
49
|
+
readonly day: string;
|
|
50
|
+
readonly seed: number;
|
|
51
|
+
};
|
|
52
|
+
readonly time: {
|
|
53
|
+
now(): number;
|
|
54
|
+
};
|
|
55
|
+
readonly voice: {
|
|
56
|
+
readonly mode: VoiceMode;
|
|
57
|
+
setGain(listener: Player | string, speaker: Player | string, gain: number): void;
|
|
58
|
+
setProximity(a: Player | string, b: Player | string, gain: number): void;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface GameDefinition<State extends JsonValue = JsonValue> {
|
|
62
|
+
tickRate: number;
|
|
63
|
+
onCreate?(room: Room<State>): void | Promise<void>;
|
|
64
|
+
onStart?(room: Room<State>): void | Promise<void>;
|
|
65
|
+
onJoin?(room: Room<State>, player: Player): void | Promise<void>;
|
|
66
|
+
onLeave?(room: Room<State>, player: Player, reason: LeaveReason): void | Promise<void>;
|
|
67
|
+
onRoleRequest?(room: Room<State>, player: Player, role: string): void | Promise<void>;
|
|
68
|
+
onMessage?(room: Room<State>, player: Player, message: JsonValue): void | Promise<void>;
|
|
69
|
+
onTick?(room: Room<State>, deltaSeconds: number): void | Promise<void>;
|
|
70
|
+
onEnd?(room: Room<State>): void | Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
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;
|