castle-web-sdk 0.4.36 → 0.4.38

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/castle.d.ts CHANGED
@@ -14,9 +14,9 @@ export type { LeaderboardData, LeaderboardEntry, LeaderboardOptions, Leaderboard
14
14
  export { Lifecycle } from "./lifecycle";
15
15
  export type { CastleLifecycleApi } from "./lifecycle";
16
16
  export { Multiplayer } from "./multiplayer";
17
- export type { CastleMultiplayerApi, MultiplayerConnection, MultiplayerConnectionState, MultiplayerJoinOptions, MultiplayerRoster, MultiplayerStateMetadata, } from "./multiplayer";
18
- export type { MultiplayerVoice, VoiceJoinStatus, VoiceMixEntry, VoiceState, } from "./multiplayerVoice";
19
- export type { MultiplayerSoloReason } from "./commands";
17
+ export type { CastleMultiplayerApi, MultiplayerConnection, MultiplayerConnectionState, MultiplayerDestinationJoinResult, MultiplayerDestinationOptions, MultiplayerJoinOptions, MultiplayerRoster, MultiplayerStateMetadata, } from "./multiplayer";
18
+ export type { MultiplayerVoice, VoiceJoinStatus, VoiceListener, VoiceMixEntry, VoiceSpatialOptions, VoiceState, VoiceVector, } from "./multiplayerVoice";
19
+ export type { MultiplayerDestinationAudience, MultiplayerSoloReason } from "./commands";
20
20
  export { MAX_CLIENT_FRAME_BYTES, MAX_PLAYERS_CAP } from "./multiplayerProtocol";
21
21
  export type { ClientByeFrame, ClientHelloFrame, ClientMessageFrame, ClientPingFrame, ClientPongFrame, ClientReplacedFrame, ClientRosterFrame, ClientToPlatformFrame, ClientToPlatformMessageFrame, MultiplayerPlayer, PlayerIdentity, PlatformToClientFrame, SessionPlayer, SessionType, } from "./multiplayerProtocol";
22
22
  export { registerParams } from "./paramsRegistry";
@@ -103,14 +103,51 @@ 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 interface MultiplayerJoinDestinationParams {
107
+ routeId: string;
108
+ slot: string;
109
+ }
110
+ export type MultiplayerDestinationAudience = "player" | "party" | "public";
111
+ export type MultiplayerJoinDestinationStatus = "ok" | "cancelled" | "full" | "unavailable" | "not_found" | "forbidden" | "party_required";
112
+ export interface MultiplayerJoinDestinationResult {
113
+ status: MultiplayerJoinDestinationStatus;
114
+ url: string | null;
115
+ nonce: string | null;
116
+ sessionId: string | null;
117
+ audience: MultiplayerDestinationAudience | null;
118
+ }
106
119
  export type VoiceState = "unavailable" | "off" | "joining" | "live";
107
120
  export type VoiceJoinStatus = "joined" | "declined" | "unavailable";
108
121
  export interface VoiceMixEntry {
109
122
  /** 0 (silent) to 1 (full). */
110
123
  gain?: number;
111
- /** -1 (left) to 1 (right). */
124
+ /** -1 (left) to 1 (right). Ignored for a player with a 3D position. */
112
125
  pan?: number;
113
126
  }
127
+ export type VoiceVector = [number, number, number];
128
+ export interface VoiceListener {
129
+ position: VoiceVector;
130
+ /** The direction the listener faces; need not be normalized. */
131
+ forward: VoiceVector;
132
+ /** Defaults to [0, 1, 0]. */
133
+ up?: VoiceVector;
134
+ }
135
+ export interface VoiceSpatialOptions {
136
+ /** How volume falls off with distance; default "inverse". */
137
+ distanceModel?: "linear" | "inverse" | "exponential";
138
+ /** Distance at which a voice is at full volume; default 1. */
139
+ refDistance?: number;
140
+ /** Beyond this, a voice gets no quieter ("linear": silent); default 100. */
141
+ maxDistance?: number;
142
+ /** How fast volume falls off; default 1. */
143
+ rolloff?: number;
144
+ }
145
+ export interface VoiceSpatialUpdate {
146
+ listener?: VoiceListener;
147
+ /** Keyed by userId. `null` returns a player to plain gain and pan. */
148
+ positions?: Record<string, VoiceVector | null>;
149
+ options?: VoiceSpatialOptions;
150
+ }
114
151
  export interface CharacterSummary {
115
152
  id: string;
116
153
  version: string;
@@ -303,6 +340,7 @@ export interface CommandParams {
303
340
  style: HapticStyle;
304
341
  };
305
342
  "multiplayer.getSession": MultiplayerGetSessionParams;
343
+ "multiplayer.joinDestination": MultiplayerJoinDestinationParams;
306
344
  "voice.getState": {
307
345
  sessionId: string;
308
346
  };
@@ -316,6 +354,9 @@ export interface CommandParams {
316
354
  sessionId: string;
317
355
  mix: Record<string, VoiceMixEntry>;
318
356
  };
357
+ "voice.setSpatial": {
358
+ sessionId: string;
359
+ } & VoiceSpatialUpdate;
319
360
  "characters.open": {
320
361
  characterId: string;
321
362
  };
@@ -438,6 +479,7 @@ export interface CommandResult {
438
479
  "portal.info": PortalInfoResult;
439
480
  "haptics.play": HapticsResult;
440
481
  "multiplayer.getSession": MultiplayerGetSessionResult;
482
+ "multiplayer.joinDestination": MultiplayerJoinDestinationResult;
441
483
  "voice.getState": {
442
484
  state: VoiceState;
443
485
  };
@@ -450,6 +492,9 @@ export interface CommandResult {
450
492
  "voice.setMix": {
451
493
  ok: true;
452
494
  };
495
+ "voice.setSpatial": {
496
+ ok: true;
497
+ };
453
498
  "characters.open": CharacterAdmission;
454
499
  "characters.send": CharacterOperation;
455
500
  "characters.status": CharacterOperation;
@@ -1,6 +1,7 @@
1
- import type { MultiplayerSoloReason } from "./commands";
1
+ import type { MultiplayerDestinationAudience, MultiplayerSoloReason } from "./commands";
2
2
  import { CastleError } from "./errors";
3
- import { type MultiplayerPlayer } from "./multiplayerProtocol";
3
+ import type { Json } from "./types";
4
+ import { type MultiplayerPlayer, type MultiplayerCharacterDisclosure, type MultiplayerCharacterTurnStatus } from "./multiplayerProtocol";
4
5
  import { type MultiplayerVoice } from "./multiplayerVoice";
5
6
  export type MultiplayerJoinOptions = {
6
7
  mode: "named";
@@ -10,6 +11,17 @@ export type MultiplayerJoinOptions = {
10
11
  } | {
11
12
  mode: "public";
12
13
  };
14
+ export interface MultiplayerDestinationOptions {
15
+ routeId: string;
16
+ slot: string;
17
+ }
18
+ export type MultiplayerDestinationJoinResult = {
19
+ status: "joined";
20
+ connection: MultiplayerConnection;
21
+ audience: MultiplayerDestinationAudience;
22
+ } | {
23
+ status: "cancelled" | "full" | "unavailable" | "not_found" | "forbidden" | "party_required";
24
+ };
13
25
  export type MultiplayerConnectionState = "acquiring" | "connecting" | "connected" | "reconnecting" | "closed";
14
26
  export type MultiplayerStateMetadata = {
15
27
  type: "connectionLost";
@@ -28,6 +40,63 @@ export interface MultiplayerRoster {
28
40
  players: MultiplayerPlayer[];
29
41
  you: MultiplayerPlayer | null;
30
42
  }
43
+ export interface MultiplayerCharacterAudience {
44
+ disclosure?: MultiplayerCharacterDisclosure;
45
+ playerIds?: string[];
46
+ characterIds?: string[];
47
+ }
48
+ export interface MultiplayerCharacterTurnRequest {
49
+ requestId: string;
50
+ operationId: string;
51
+ characterId: string;
52
+ input: string;
53
+ audience?: MultiplayerCharacterAudience;
54
+ }
55
+ export interface MultiplayerCharacterTurnAdmission {
56
+ operationId: string;
57
+ status: "queued" | "completed" | "interrupted";
58
+ replayed: boolean;
59
+ }
60
+ export interface MultiplayerCharacterTurnStatusResult {
61
+ operationId: string;
62
+ status: MultiplayerCharacterTurnStatus;
63
+ jobStatus: MultiplayerCharacterTurnStatus;
64
+ turnStatus: "admitted" | "reply_committed" | "completed" | "interrupted";
65
+ response?: string;
66
+ progress?: {
67
+ response: string;
68
+ };
69
+ replayed: boolean;
70
+ }
71
+ export type MultiplayerWorldCharacterCommand = {
72
+ type: "perform_action";
73
+ characterId: string;
74
+ actionId: string;
75
+ parameters?: Json;
76
+ consentQuote?: string;
77
+ } | {
78
+ type: "record_event";
79
+ eventTypeId: string;
80
+ data?: Json;
81
+ };
82
+ export type MultiplayerWorldCharacterQuery = {
83
+ type: "inspect";
84
+ } | {
85
+ type: "status";
86
+ operationId: string;
87
+ } | {
88
+ type: "history";
89
+ characterId?: string;
90
+ limit?: number;
91
+ cursor?: string;
92
+ };
93
+ export interface MultiplayerWorldCharacterCommandResult {
94
+ operationId: string;
95
+ status: "applied" | "ineligible";
96
+ replayed: boolean;
97
+ result: unknown;
98
+ worldRevision: string;
99
+ }
31
100
  export interface MultiplayerConnection {
32
101
  readonly state: MultiplayerConnectionState;
33
102
  readonly playerId: string;
@@ -40,6 +109,19 @@ export interface MultiplayerConnection {
40
109
  readonly soloReason: MultiplayerSoloReason | null;
41
110
  /** Sends byte payloads as binary frames and all other payloads as JSON. */
42
111
  send(data: unknown): void;
112
+ /** Requests one billed character turn through this authenticated world socket. */
113
+ requestCharacterTurn(request: MultiplayerCharacterTurnRequest): Promise<MultiplayerCharacterTurnAdmission>;
114
+ /** Recovers the durable status of a prior operation after reconnecting. */
115
+ getCharacterTurnStatus(operationId: string): Promise<MultiplayerCharacterTurnStatusResult>;
116
+ requestCharacterCommand(request: {
117
+ requestId: string;
118
+ operationId: string;
119
+ command: MultiplayerWorldCharacterCommand;
120
+ }): Promise<MultiplayerWorldCharacterCommandResult>;
121
+ readCharacters<T = unknown>(request: {
122
+ requestId: string;
123
+ query: MultiplayerWorldCharacterQuery;
124
+ }): Promise<T>;
43
125
  /** Receives binary payloads as Uint8Array values and JSON payloads otherwise. */
44
126
  onMessage(callback: (data: unknown) => void): () => void;
45
127
  onRoster(callback: (roster: MultiplayerRoster) => void): () => void;
@@ -50,5 +132,6 @@ export interface MultiplayerConnection {
50
132
  }
51
133
  export interface CastleMultiplayerApi {
52
134
  join(options: MultiplayerJoinOptions): Promise<MultiplayerConnection>;
135
+ joinDestination(options: MultiplayerDestinationOptions): Promise<MultiplayerDestinationJoinResult>;
53
136
  }
54
137
  export declare const Multiplayer: CastleMultiplayerApi;