castle-web-cli 0.4.208 → 0.4.209
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/api.d.ts +5 -0
- package/dist/castle-host/host.js +151 -0
- package/dist/castleJson.d.ts +4 -0
- package/dist/castleJson.js +3 -1
- package/dist/devSessionServer.js +1 -0
- package/dist/editorConfig.d.ts +12 -0
- package/dist/editorConfig.js +72 -6
- package/dist/init.js +1 -1
- package/dist/native/loop.js +1 -1
- package/dist/native/playtest-executor.js +36 -4
- package/dist/native/playtest-remote.d.ts +1 -0
- package/dist/native/playtest-remote.js +61 -5
- package/dist/native/playtest.d.ts +35 -2
- package/dist/native/playtest.js +162 -18
- package/dist/platformDoc.d.ts +1 -0
- package/dist/platformDoc.js +24 -3
- package/dist/playUrl.d.ts +3 -0
- package/dist/playUrl.js +12 -0
- package/dist/save-deck.js +1 -0
- package/dist/shell/assets/{index-b_bebkRb.css → index-BCrgYh76.css} +1 -1
- package/dist/shell/assets/{index-C6SXXPwm.js → index-DzLbNBc7.js} +68 -68
- package/dist/shell/index.html +2 -2
- package/kits/base/CLAUDE.md +1 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +70 -7
- package/kits/base/sdk/castle.d.ts +1 -0
- package/kits/base/sdk/commands.d.ts +48 -0
- package/kits/base/sdk/commands.js +25 -0
- package/kits/base/sdk/multiplayer.d.ts +3 -0
- package/kits/base/sdk/multiplayer.js +13 -0
- package/kits/base/sdk/multiplayerVoice.d.ts +67 -0
- package/kits/base/sdk/multiplayerVoice.js +309 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +15 -1
- package/kits/multiplayer-2d/castle.json +2 -2
- package/kits/multiplayer-2d/code/systems/multiplayer.js +7 -1
- package/kits/multiplayer-3d/castle.json +2 -2
- package/kits/multiplayer-3d/code/systems/multiplayer.js +8 -4
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/SceneEditor.jsx +18 -4
- package/kits/physics-2d/systems/media.js +3 -5
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/pxmodel.js +7 -0
- package/kits/real-time/CLAUDE.md +3 -0
- package/kits/real-time/castle.json +1 -1
- package/kits/real-time/code/client/connection.js +17 -2
- package/kits/real-time/code/client/gameHooks.js +5 -0
- package/kits/real-time/code/client/joinOverlay.js +23 -5
- package/kits/real-time/code/client/messages.js +4 -0
- package/kits/real-time/code/server/persist.js +19 -10
- package/kits/real-time/code/server/session.js +19 -0
- package/package.json +2 -2
package/dist/shell/index.html
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
<link rel="icon" type="image/png" sizes="32x32" href="/__castle/ide/favicon-32x32.png" />
|
|
11
11
|
<link rel="icon" type="image/png" sizes="16x16" href="/__castle/ide/favicon-16x16.png" />
|
|
12
12
|
<link rel="icon" href="/__castle/ide/favicon.ico" sizes="any" />
|
|
13
|
-
<script type="module" crossorigin src="/__castle/ide/assets/index-
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/__castle/ide/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/__castle/ide/assets/index-DzLbNBc7.js"></script>
|
|
14
|
+
<link rel="stylesheet" crossorigin href="/__castle/ide/assets/index-BCrgYh76.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
17
17
|
<div id="root"></div>
|
package/kits/base/CLAUDE.md
CHANGED
|
@@ -17,6 +17,7 @@ that framework provides. This one is true either way.
|
|
|
17
17
|
- `import { setup, initCard } from 'castle-web-sdk'`. Call `setup()` first, once; `initCard()` returns the element to render into (a React tree mounted at `#root` needs no `initCard`). Castle services — `Store`, `Leaderboard`, `Time`, `User`, `Haptics`, `Pass`, `Snapshot`, `Portal`, `Multiplayer`, `Lifecycle` — come from the same package. `Store` is how a deck saves anything; the older `Storage`/`SharedStorage` still work but should not be used in new decks; the full reference is `imports/castle.base/sdk/README.md`.
|
|
18
18
|
- `Agent.chat({ messages, tools?, toolChoice?, model?, maxTokens?, reasoning?, onDelta?, signal? })` gets one chat completion from a language model (OpenAI message and tool format, default model `meta/muse-spark-1.3`) through Castle's oracle on the player's account. `onDelta` streams text and reasoning pieces and each finished tool call; `signal` cancels; `reasoning: { effort: 'minimal' | 'low' | 'medium' | 'high' }` sets how hard the model thinks, and minimal answers soonest. It resolves with the whole `message`: the deck runs any `tool_calls` itself, appends the message and the `tool` results, and calls again. Admin only: other players get `refused`.
|
|
19
19
|
- `Decks.mine({ limit? })` and `Decks.saved({ limit? })` list decks a portal can lead to (the player's published decks; their bookmarks and playlists) as `{ deckId, title, creator, coverUrl }`, with `coverUrl` a `data:` url. Use them to offer a portal destination picker. Admin only: other players get a `PERMISSION_DENIED` error.
|
|
20
|
+
- What each service cannot do is in that README beside the service: `Store` / `Storage` size caps (no media in storage), the Castle app build a command needs (older builds reject it with `UNKNOWN_COMMAND`), no clipboard command, no call that sets the deck's cover. Read it before telling someone a service can or cannot do something.
|
|
20
21
|
- The SDK is a file of this import, not an npm package: `castle-web-sdk` resolves here. Nothing needs installing, and nothing in a deck's `package.json` names it.
|
|
21
22
|
- Vite serves and bundles the deck: ES modules, JSX, JSON, CSS and npm packages all work with no build step of your own — don't add one.
|
|
22
23
|
- Details: `## Files`, `## Editors` and `## The SDK` in this file (`imports/castle.base/CLAUDE.md`). The rules every deck plays by -- the card, touch, assets and formats, imports, reloading -- are the platform's: `.castle/docs/platform.md`, written by the serve.
|
package/kits/base/castle.json
CHANGED
package/kits/base/sdk/README.md
CHANGED
|
@@ -25,6 +25,7 @@ import { setup, initCard, Store, Leaderboard } from "castle-web-sdk";
|
|
|
25
25
|
- [Snapshot](#snapshot)
|
|
26
26
|
- [Portal](#portal)
|
|
27
27
|
- [Decks](#decks)
|
|
28
|
+
- [Clipboard](#clipboard)
|
|
28
29
|
- [Haptics](#haptics)
|
|
29
30
|
- [Agent](#agent)
|
|
30
31
|
- [Lifecycle](#lifecycle)
|
|
@@ -251,11 +252,30 @@ guide.
|
|
|
251
252
|
|
|
252
253
|
### Limits
|
|
253
254
|
|
|
254
|
-
The platform caps key length, value size, how many keys one
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
The platform caps key length, value size, how many keys one read may
|
|
256
|
+
name, and how much a deck may store in total, and it limits how fast a
|
|
257
|
+
player may read and write. Going over one of these rejects with a
|
|
258
|
+
`CastleError` whose `code` says which, so a deck can tell a player it is
|
|
259
|
+
saving too fast apart from a deck that is out of space:
|
|
260
|
+
|
|
261
|
+
| limit | value |
|
|
262
|
+
|---|---|
|
|
263
|
+
| key | 128 bytes |
|
|
264
|
+
| value | 256 KB |
|
|
265
|
+
| keys in one `get` | 32 |
|
|
266
|
+
| whole deck | 50 MB, 500,000 keys |
|
|
267
|
+
| one player's calls | 20 a second, 512 KB a second |
|
|
268
|
+
| every player of a deck together | 500 calls a second, 8 MB a second |
|
|
269
|
+
|
|
270
|
+
These do not reject. `set` and `remove` with more than 32 keys are split
|
|
271
|
+
into several calls by the SDK (each still counts against the rate above).
|
|
272
|
+
A `list` page holds at most 1,000 entries (a larger `limit` is lowered to
|
|
273
|
+
it) and ends early once it reaches 1 MB; take the next page with its
|
|
274
|
+
`cursor`.
|
|
275
|
+
|
|
276
|
+
A value is JSON, so binary data such as a picture or a video clip costs
|
|
277
|
+
about a third more once encoded, and a clip of more than a few seconds
|
|
278
|
+
does not fit in one. Ship media with the deck instead.
|
|
259
279
|
|
|
260
280
|
## Storage
|
|
261
281
|
|
|
@@ -267,6 +287,10 @@ player it is saving too fast apart from a deck that is out of space.
|
|
|
267
287
|
|
|
268
288
|
`Storage` saves data for the current player. Nobody else can read it.
|
|
269
289
|
|
|
290
|
+
A player's whole `Storage` document is at most 2 MB. A write that takes
|
|
291
|
+
it past that never saves, and nothing tells the deck: `set` has already
|
|
292
|
+
returned.
|
|
293
|
+
|
|
270
294
|
- **`Storage.get<T>(key): Promise<T | null>`** — the value at `key`, or
|
|
271
295
|
`null` if it is not set.
|
|
272
296
|
- **`Storage.set(key, value)`** — sets `key`. `value` must be something
|
|
@@ -295,7 +319,9 @@ await Store.private.set({ level: 7 });
|
|
|
295
319
|
> and adds counters, listing, and leaderboards.
|
|
296
320
|
|
|
297
321
|
`SharedStorage` saves data that other players can read. Values must be
|
|
298
|
-
something that converts to JSON, same as `Storage`.
|
|
322
|
+
something that converts to JSON, same as `Storage`. Each bucket holds at
|
|
323
|
+
most 2 MB, and a write past that is dropped without an error, as with
|
|
324
|
+
`Storage`.
|
|
299
325
|
|
|
300
326
|
Scopes: `'deck'` is one bucket for the whole deck, readable and writable
|
|
301
327
|
by any player. `'user'` is a per-player bucket that anyone can read and
|
|
@@ -522,6 +548,9 @@ when the player collects or closes it. `options`:
|
|
|
522
548
|
|
|
523
549
|
Collecting works only in the Castle mobile app; the website shows "collect in
|
|
524
550
|
the app" and the dev server a short notice, and both resolve `unavailable`.
|
|
551
|
+
`offer` was added to the app on 2026-09-22; an app build from before then
|
|
552
|
+
rejects it with `UNKNOWN_COMMAND` (see [CastleError](#castleerror)), so catch
|
|
553
|
+
it where a deck has to keep going without the card.
|
|
525
554
|
`SnapshotOfferResult` has a `status`:
|
|
526
555
|
|
|
527
556
|
- `'collected'` — the player collected it.
|
|
@@ -536,6 +565,11 @@ const { status } = await Snapshot.offer({
|
|
|
536
565
|
});
|
|
537
566
|
```
|
|
538
567
|
|
|
568
|
+
A snapshot is not the deck's cover, and no SDK call sets the cover. A cover
|
|
569
|
+
the creator chose by hand is kept; otherwise `save-deck` photographs the deck
|
|
570
|
+
as it opens, falling back to a `preview.png` the deck folder holds when that
|
|
571
|
+
capture does not produce one.
|
|
572
|
+
|
|
539
573
|
### `Snapshot.onTaken(handler): () => void`
|
|
540
574
|
|
|
541
575
|
Registers a function called just before an offer's capture, the twin of the
|
|
@@ -606,7 +640,9 @@ label as the fallback. `PortalInfoResult` has a `status`:
|
|
|
606
640
|
`null`), and `coverUrl`, a `data:` url of the deck's cover or `null`.
|
|
607
641
|
- `'broken'` — the portal wouldn't work for this player: the deck doesn't
|
|
608
642
|
exist, has portals turned off, or isn't visible to them.
|
|
609
|
-
- `'unavailable'` — the host couldn't look it up.
|
|
643
|
+
- `'unavailable'` — the host couldn't look it up. This includes a Castle
|
|
644
|
+
app built before `portal.info` was added (2026-09-22): `info` never
|
|
645
|
+
throws `UNKNOWN_COMMAND`.
|
|
610
646
|
|
|
611
647
|
```js
|
|
612
648
|
const info = await Portal.info(doorway.deckId);
|
|
@@ -650,6 +686,13 @@ for (const deck of decks) {
|
|
|
650
686
|
}
|
|
651
687
|
```
|
|
652
688
|
|
|
689
|
+
## Clipboard
|
|
690
|
+
|
|
691
|
+
The SDK has no clipboard command, and neither Castle host adds one: the
|
|
692
|
+
Castle app has no clipboard bridge, and castle.xyz's player does not grant
|
|
693
|
+
its frame `clipboard-write`. `navigator.clipboard` is best-effort — catch
|
|
694
|
+
its failure and show the text so the player can copy it by hand.
|
|
695
|
+
|
|
653
696
|
## Haptics
|
|
654
697
|
|
|
655
698
|
`Haptics` plays a short device vibration ("buzz") for tactile feedback —
|
|
@@ -1030,5 +1073,25 @@ Common codes:
|
|
|
1030
1073
|
- `CASTLE_HOST_UNAVAILABLE` — the Castle host (the app or website running
|
|
1031
1074
|
the deck) didn't handle the request — e.g. it timed out or wasn't
|
|
1032
1075
|
reachable. Usually transient; retry or surface a gentle error.
|
|
1076
|
+
- `UNKNOWN_COMMAND` ("Unknown Castle command.") — the Castle app running
|
|
1077
|
+
the deck is a build older than the command. Each app build knows only the
|
|
1078
|
+
commands it shipped with, and only an app update adds one, so keep the
|
|
1079
|
+
deck working without it. The app's last version bump, iOS v1.149, came
|
|
1080
|
+
before every command below, so v1.149 and earlier builds lack all of
|
|
1081
|
+
them. Each date is the commit that added the command to the app's code,
|
|
1082
|
+
not when a build carrying it reached the stores; an app built from code
|
|
1083
|
+
before that commit answers `UNKNOWN_COMMAND`:
|
|
1084
|
+
- `Multiplayer.join` — 2026-08-29
|
|
1085
|
+
- `Store` (every method) — 2026-09-03
|
|
1086
|
+
- `Lifecycle.restoreState` — 2026-09-08 (resolves `null` instead of
|
|
1087
|
+
throwing)
|
|
1088
|
+
- `User.get` — 2026-09-10
|
|
1089
|
+
- `Characters` — 2026-09-20
|
|
1090
|
+
- `Snapshot.offer` — 2026-09-22
|
|
1091
|
+
- `Portal.info` — 2026-09-22 (resolves `unavailable` instead of throwing)
|
|
1092
|
+
- `Agent.chat`, `Decks.mine`, `Decks.saved` — 2026-09-23
|
|
1093
|
+
|
|
1094
|
+
`Leaderboard.show` resolves `unavailable` rather than throwing on an app
|
|
1095
|
+
that lacks it.
|
|
1033
1096
|
- `CAULDRON_STORAGE_STALE_GENERATION` — the handle belongs to an older reset
|
|
1034
1097
|
generation; reopen explicitly rather than replaying work into the new one.
|
|
@@ -15,6 +15,7 @@ export { Lifecycle } from "./lifecycle";
|
|
|
15
15
|
export type { CastleLifecycleApi } from "./lifecycle";
|
|
16
16
|
export { Multiplayer } from "./multiplayer";
|
|
17
17
|
export type { CastleMultiplayerApi, MultiplayerConnection, MultiplayerConnectionState, MultiplayerJoinOptions, MultiplayerRoster, MultiplayerStateMetadata, } from "./multiplayer";
|
|
18
|
+
export type { MultiplayerVoice, VoiceJoinStatus, VoiceMixEntry, VoiceState, } from "./multiplayerVoice";
|
|
18
19
|
export type { MultiplayerSoloReason } from "./commands";
|
|
19
20
|
export { MAX_CLIENT_FRAME_BYTES, MAX_PLAYERS_CAP } from "./multiplayerProtocol";
|
|
20
21
|
export type { ClientByeFrame, ClientHelloFrame, ClientMessageFrame, ClientPingFrame, ClientPongFrame, ClientReplacedFrame, ClientRosterFrame, ClientToPlatformFrame, ClientToPlatformMessageFrame, MultiplayerPlayer, PlayerIdentity, PlatformToClientFrame, SessionPlayer, SessionType, } from "./multiplayerProtocol";
|
|
@@ -103,6 +103,14 @@ export interface MultiplayerGetSessionResult {
|
|
|
103
103
|
/** Internal local-serve scope for restoring this Play panel after a reload. */
|
|
104
104
|
devReconnectScope?: string;
|
|
105
105
|
}
|
|
106
|
+
export type VoiceState = "unavailable" | "off" | "joining" | "live";
|
|
107
|
+
export type VoiceJoinStatus = "joined" | "declined" | "unavailable";
|
|
108
|
+
export interface VoiceMixEntry {
|
|
109
|
+
/** 0 (silent) to 1 (full). */
|
|
110
|
+
gain?: number;
|
|
111
|
+
/** -1 (left) to 1 (right). */
|
|
112
|
+
pan?: number;
|
|
113
|
+
}
|
|
106
114
|
export interface CharacterSummary {
|
|
107
115
|
id: string;
|
|
108
116
|
version: string;
|
|
@@ -295,6 +303,19 @@ export interface CommandParams {
|
|
|
295
303
|
style: HapticStyle;
|
|
296
304
|
};
|
|
297
305
|
"multiplayer.getSession": MultiplayerGetSessionParams;
|
|
306
|
+
"voice.getState": {
|
|
307
|
+
sessionId: string;
|
|
308
|
+
};
|
|
309
|
+
"voice.requestJoin": {
|
|
310
|
+
sessionId: string;
|
|
311
|
+
};
|
|
312
|
+
"voice.leave": {
|
|
313
|
+
sessionId: string;
|
|
314
|
+
};
|
|
315
|
+
"voice.setMix": {
|
|
316
|
+
sessionId: string;
|
|
317
|
+
mix: Record<string, VoiceMixEntry>;
|
|
318
|
+
};
|
|
298
319
|
"characters.open": {
|
|
299
320
|
characterId: string;
|
|
300
321
|
};
|
|
@@ -417,6 +438,18 @@ export interface CommandResult {
|
|
|
417
438
|
"portal.info": PortalInfoResult;
|
|
418
439
|
"haptics.play": HapticsResult;
|
|
419
440
|
"multiplayer.getSession": MultiplayerGetSessionResult;
|
|
441
|
+
"voice.getState": {
|
|
442
|
+
state: VoiceState;
|
|
443
|
+
};
|
|
444
|
+
"voice.requestJoin": {
|
|
445
|
+
status: VoiceJoinStatus;
|
|
446
|
+
};
|
|
447
|
+
"voice.leave": {
|
|
448
|
+
ok: true;
|
|
449
|
+
};
|
|
450
|
+
"voice.setMix": {
|
|
451
|
+
ok: true;
|
|
452
|
+
};
|
|
420
453
|
"characters.open": CharacterAdmission;
|
|
421
454
|
"characters.send": CharacterOperation;
|
|
422
455
|
"characters.status": CharacterOperation;
|
|
@@ -510,3 +543,18 @@ export interface UnloadDoneEnvelope {
|
|
|
510
543
|
state?: string;
|
|
511
544
|
};
|
|
512
545
|
}
|
|
546
|
+
export type VoiceEvent = {
|
|
547
|
+
type: "state";
|
|
548
|
+
sessionId: string;
|
|
549
|
+
state: VoiceState;
|
|
550
|
+
} | {
|
|
551
|
+
type: "speaking";
|
|
552
|
+
sessionId: string;
|
|
553
|
+
userIds: string[];
|
|
554
|
+
};
|
|
555
|
+
export interface VoiceEventEnvelope {
|
|
556
|
+
castleSdk: typeof CASTLE_SDK_PROTOCOL;
|
|
557
|
+
voice: VoiceEvent;
|
|
558
|
+
}
|
|
559
|
+
export declare function isVoiceState(value: unknown): value is VoiceState;
|
|
560
|
+
export declare function voiceEventFrom(value: unknown): VoiceEvent | null;
|
|
@@ -44,3 +44,28 @@ export function unloadRequestId(value) {
|
|
|
44
44
|
const unload = record.unload;
|
|
45
45
|
return typeof unload?.unloadId === "string" ? unload.unloadId : null;
|
|
46
46
|
}
|
|
47
|
+
const VOICE_STATES = ["unavailable", "off", "joining", "live"];
|
|
48
|
+
export function isVoiceState(value) {
|
|
49
|
+
return typeof value === "string" && VOICE_STATES.includes(value);
|
|
50
|
+
}
|
|
51
|
+
export function voiceEventFrom(value) {
|
|
52
|
+
if (typeof value !== "object" || value === null)
|
|
53
|
+
return null;
|
|
54
|
+
const record = value;
|
|
55
|
+
if (record.castleSdk !== CASTLE_SDK_PROTOCOL)
|
|
56
|
+
return null;
|
|
57
|
+
const event = record.voice;
|
|
58
|
+
if (typeof event !== "object" || event === null)
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof event.sessionId !== "string")
|
|
61
|
+
return null;
|
|
62
|
+
if (event.type === "state" && isVoiceState(event.state)) {
|
|
63
|
+
return { type: "state", sessionId: event.sessionId, state: event.state };
|
|
64
|
+
}
|
|
65
|
+
if (event.type === "speaking" &&
|
|
66
|
+
Array.isArray(event.userIds) &&
|
|
67
|
+
event.userIds.every((userId) => typeof userId === "string")) {
|
|
68
|
+
return { type: "speaking", sessionId: event.sessionId, userIds: event.userIds.slice() };
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MultiplayerSoloReason } from "./commands";
|
|
2
2
|
import { CastleError } from "./errors";
|
|
3
3
|
import { type MultiplayerPlayer } from "./multiplayerProtocol";
|
|
4
|
+
import { type MultiplayerVoice } from "./multiplayerVoice";
|
|
4
5
|
export type MultiplayerJoinOptions = {
|
|
5
6
|
mode: "named";
|
|
6
7
|
key: string;
|
|
@@ -43,6 +44,8 @@ export interface MultiplayerConnection {
|
|
|
43
44
|
onMessage(callback: (data: unknown) => void): () => void;
|
|
44
45
|
onRoster(callback: (roster: MultiplayerRoster) => void): () => void;
|
|
45
46
|
onStateChange(callback: (state: MultiplayerConnectionState, metadata?: MultiplayerStateMetadata) => void): () => void;
|
|
47
|
+
/** Voice chat for this session, run by the host. See MultiplayerVoice. */
|
|
48
|
+
readonly voice: MultiplayerVoice;
|
|
46
49
|
leave(): void;
|
|
47
50
|
}
|
|
48
51
|
export interface CastleMultiplayerApi {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CastleError } from "./errors";
|
|
2
2
|
import { BINARY_MESSAGE_TAG, isBinaryPayload, MAX_CLIENT_FRAME_BYTES, toUint8Array, } from "./multiplayerProtocol";
|
|
3
3
|
import { hostRequest } from "./transport";
|
|
4
|
+
import { MultiplayerVoiceImpl } from "./multiplayerVoice";
|
|
4
5
|
const KEEPALIVE_INTERVAL_MS = 25_000;
|
|
5
6
|
const HELLO_TIMEOUT_MS = 10_000;
|
|
6
7
|
const RECONNECT_BUDGET_MS = 30_000;
|
|
@@ -39,6 +40,11 @@ class MultiplayerConnectionImpl {
|
|
|
39
40
|
messages = new Set();
|
|
40
41
|
rosters = new Set();
|
|
41
42
|
states = new Set();
|
|
43
|
+
voiceImpl = new MultiplayerVoiceImpl({
|
|
44
|
+
sessionId: () => this.currentSessionId,
|
|
45
|
+
players: () => this.roster?.players ?? [],
|
|
46
|
+
isSolo: () => this.solo,
|
|
47
|
+
});
|
|
42
48
|
constructor(params, onClosed) {
|
|
43
49
|
this.params = params;
|
|
44
50
|
this.onClosed = onClosed;
|
|
@@ -58,6 +64,9 @@ class MultiplayerConnectionImpl {
|
|
|
58
64
|
get soloReason() {
|
|
59
65
|
return this.currentSoloReason;
|
|
60
66
|
}
|
|
67
|
+
get voice() {
|
|
68
|
+
return this.voiceImpl;
|
|
69
|
+
}
|
|
61
70
|
async start() {
|
|
62
71
|
try {
|
|
63
72
|
await this.acquire();
|
|
@@ -171,6 +180,7 @@ class MultiplayerConnectionImpl {
|
|
|
171
180
|
};
|
|
172
181
|
this.setRoster({ players: [you], you });
|
|
173
182
|
this.transition("connected");
|
|
183
|
+
void this.voiceImpl.attach();
|
|
174
184
|
}
|
|
175
185
|
openSocket(credential, value) {
|
|
176
186
|
const attempt = ++this.socketAttempt;
|
|
@@ -253,6 +263,7 @@ class MultiplayerConnectionImpl {
|
|
|
253
263
|
this.reAcquisitionUsed = false;
|
|
254
264
|
this.transition("connected");
|
|
255
265
|
this.startKeepalive();
|
|
266
|
+
void this.voiceImpl.attach();
|
|
256
267
|
}
|
|
257
268
|
handleFrame(frame) {
|
|
258
269
|
switch (frame.t) {
|
|
@@ -293,6 +304,7 @@ class MultiplayerConnectionImpl {
|
|
|
293
304
|
}
|
|
294
305
|
setRoster(roster) {
|
|
295
306
|
this.roster = roster;
|
|
307
|
+
this.voiceImpl.rosterChanged();
|
|
296
308
|
for (const callback of this.rosters)
|
|
297
309
|
callListener(callback, roster);
|
|
298
310
|
}
|
|
@@ -391,6 +403,7 @@ class MultiplayerConnectionImpl {
|
|
|
391
403
|
this.socketAttempt += 1;
|
|
392
404
|
closeSocket(socket, 1000, "session closed");
|
|
393
405
|
this.currentState = "closed";
|
|
406
|
+
this.voiceImpl.dispose();
|
|
394
407
|
for (const callback of this.states)
|
|
395
408
|
callStateListener(callback, "closed", metadata);
|
|
396
409
|
this.onClosed();
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { VoiceEvent, VoiceJoinStatus, VoiceMixEntry, VoiceState } from "./commands";
|
|
2
|
+
import type { MultiplayerPlayer } from "./multiplayerProtocol";
|
|
3
|
+
export declare const VOICE_MIX_INTERVAL_MS = 100;
|
|
4
|
+
export type { VoiceJoinStatus, VoiceMixEntry, VoiceState };
|
|
5
|
+
export interface MultiplayerVoice {
|
|
6
|
+
/** "unavailable" when this host, deck, session or player can't have voice. */
|
|
7
|
+
readonly state: VoiceState;
|
|
8
|
+
/**
|
|
9
|
+
* Asks the player to join voice. The host shows its own prompt; nothing happens
|
|
10
|
+
* without the player's say-so. Resolves once they have chosen.
|
|
11
|
+
*/
|
|
12
|
+
requestJoin(): Promise<VoiceJoinStatus>;
|
|
13
|
+
/** Leaves voice, or withdraws a pending request. The game connection is unaffected. */
|
|
14
|
+
leave(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Suggested volume (0-1) and stereo position (-1 left to 1 right) per player,
|
|
17
|
+
* keyed by playerId. Players and fields not named keep their last value (initially
|
|
18
|
+
* full volume, centered). Sent at most ten times a second; the latest values win.
|
|
19
|
+
*/
|
|
20
|
+
setMix(mix: Record<string, VoiceMixEntry>): void;
|
|
21
|
+
onState(callback: (state: VoiceState) => void): () => void;
|
|
22
|
+
/** The playerIds speaking right now; called whenever that set changes. */
|
|
23
|
+
onSpeaking(callback: (playerIds: string[]) => void): () => void;
|
|
24
|
+
}
|
|
25
|
+
export interface VoiceSessionAccess {
|
|
26
|
+
sessionId(): string;
|
|
27
|
+
players(): MultiplayerPlayer[];
|
|
28
|
+
isSolo(): boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class MultiplayerVoiceImpl implements MultiplayerVoice {
|
|
31
|
+
private readonly access;
|
|
32
|
+
private currentState;
|
|
33
|
+
private voiceSessionId;
|
|
34
|
+
private attaching;
|
|
35
|
+
private hostStateVersion;
|
|
36
|
+
private pendingJoin;
|
|
37
|
+
private joinRequest;
|
|
38
|
+
private speakingUserIds;
|
|
39
|
+
private speaking;
|
|
40
|
+
private pendingMix;
|
|
41
|
+
private sentMix;
|
|
42
|
+
private mixTimer;
|
|
43
|
+
private lastMixSentAt;
|
|
44
|
+
private disposed;
|
|
45
|
+
private readonly states;
|
|
46
|
+
private readonly speakers;
|
|
47
|
+
constructor(access: VoiceSessionAccess);
|
|
48
|
+
get state(): VoiceState;
|
|
49
|
+
attach(): Promise<void>;
|
|
50
|
+
requestJoin(): Promise<VoiceJoinStatus>;
|
|
51
|
+
private askToJoin;
|
|
52
|
+
leave(): void;
|
|
53
|
+
setMix(mix: Record<string, VoiceMixEntry>): void;
|
|
54
|
+
onState(callback: (state: VoiceState) => void): () => void;
|
|
55
|
+
onSpeaking(callback: (playerIds: string[]) => void): () => void;
|
|
56
|
+
receive(event: VoiceEvent): void;
|
|
57
|
+
rosterChanged(): void;
|
|
58
|
+
dispose(): void;
|
|
59
|
+
private isCurrent;
|
|
60
|
+
private withdraw;
|
|
61
|
+
private endSession;
|
|
62
|
+
private sendLeave;
|
|
63
|
+
private setState;
|
|
64
|
+
private emitSpeaking;
|
|
65
|
+
private scheduleMix;
|
|
66
|
+
private flushMix;
|
|
67
|
+
}
|