@signalwire/js 4.0.0-dev-20260714201720 → 4.0.0-dev-20260721161304

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/index.d.cts CHANGED
@@ -1173,6 +1173,14 @@ declare class CallCreateError extends Error {
1173
1173
  direction: 'inbound' | 'outbound';
1174
1174
  constructor(message: string, error?: unknown, direction?: 'inbound' | 'outbound', options?: ErrorOptions);
1175
1175
  }
1176
+ declare class CallNotReadyError extends Error {
1177
+ callId: string;
1178
+ constructor(callId: string, options?: ErrorOptions);
1179
+ }
1180
+ declare class ParticipantNotReadyError extends Error {
1181
+ memberId: string;
1182
+ constructor(memberId: string, options?: ErrorOptions);
1183
+ }
1176
1184
  declare class VertoPongError extends Error {
1177
1185
  originalError: unknown;
1178
1186
  constructor(originalError: unknown);
@@ -1789,12 +1797,12 @@ type ParticipantState = Member & {
1789
1797
  * the local participant with additional device control.
1790
1798
  */
1791
1799
  declare class Participant extends Destroyable implements CallParticipant {
1792
- protected executeMethod: ExecuteMethod;
1800
+ private callExecuteMethod;
1793
1801
  protected deviceController: DeviceController;
1794
1802
  /** Unique member ID of this participant. */
1795
1803
  readonly id: string;
1796
1804
  private _state$;
1797
- constructor(id: string, executeMethod: ExecuteMethod, deviceController: DeviceController);
1805
+ constructor(id: string, callExecuteMethod: ExecuteMethod, deviceController: DeviceController);
1798
1806
  /** @internal */
1799
1807
  upnext(data: Partial<ParticipantState>): void;
1800
1808
  /** Observable of the participant's display name. */
@@ -1917,6 +1925,30 @@ declare class Participant extends Destroyable implements CallParticipant {
1917
1925
  get callId(): string | undefined;
1918
1926
  /** @internal */
1919
1927
  get value(): Partial<Member>;
1928
+ /**
1929
+ * Target triple for member RPCs, built from the participant's own state.
1930
+ * The backend locates the member's session by the target `call_id`/`node_id`,
1931
+ * so this must always be the participant's own call context — never the
1932
+ * local call's id (issue #19400).
1933
+ *
1934
+ * Reading it doubles as a readiness probe: it throws until the first full
1935
+ * member event (`member.joined`/`member.updated` or the `call.joined`
1936
+ * roster) arrives, and never regresses afterwards.
1937
+ *
1938
+ * @throws {ParticipantNotReadyError} If the member state has not been
1939
+ * received yet (e.g. a participant first seen via `member.talking`) — an
1940
+ * empty call context can never address the member, so fail fast instead of
1941
+ * sending a doomed RPC.
1942
+ */
1943
+ get target(): MemberTarget;
1944
+ /**
1945
+ * Executes a member RPC against this participant, injecting its own
1946
+ * {@link target} as the target.
1947
+ *
1948
+ * @throws {ParticipantNotReadyError} Via {@link target}, when the
1949
+ * member state has not been received yet.
1950
+ */
1951
+ protected executeMethod(method: string, args: Record<string, unknown>): Promise<JSONRPCResponse>;
1920
1952
  /** Toggles the deafened state (mutes/unmutes incoming audio). */
1921
1953
  toggleDeaf(): Promise<void>;
1922
1954
  /** Toggles the hand-raised state. */
@@ -1981,12 +2013,10 @@ declare class Participant extends Destroyable implements CallParticipant {
1981
2013
  /**
1982
2014
  * Sets the participant's position in the video layout.
1983
2015
  *
1984
- * Requires the `member.position` capability. The gateway keys positions by the
1985
- * **target member's own** `call_id`/`node_id` (see issue #19400 and the legacy
1986
- * `setPositions` implementation), so this sends the participant's own call
1987
- * context — matching {@link Participant.remove}. A resolved promise does not
1988
- * guarantee a visible change: the backend silently returns `200` (no-op) for
1989
- * non-conference targets.
2016
+ * Requires the `member.position` capability. The gateway requires a
2017
+ * `targets` array of `{ target, position }` entries (issue #19400). A
2018
+ * resolved promise does not guarantee a visible change: the backend silently
2019
+ * returns `200` (no-op) for non-conference targets.
1990
2020
  *
1991
2021
  * @param value - The {@link VideoPosition} to assign (e.g. `'auto'`, `'reserved-0'`).
1992
2022
  */
@@ -2030,7 +2060,7 @@ declare class SelfParticipant extends Participant implements CallSelfParticipant
2030
2060
  */
2031
2061
  private _studioAudio$;
2032
2062
  /** @internal */
2033
- constructor(id: string, executeMethod: ExecuteMethod, vertoManager: VertoManager, deviceController: DeviceController);
2063
+ constructor(id: string, callExecuteMethod: ExecuteMethod, vertoManager: VertoManager, deviceController: DeviceController);
2034
2064
  destroy(): void;
2035
2065
  /** Observable indicating whether studio audio (raw/unprocessed audio) mode is enabled. */
2036
2066
  get studioAudio$(): Observable<boolean>;
@@ -2177,6 +2207,9 @@ interface CallParticipant {
2177
2207
  readonly addressId: string | undefined;
2178
2208
  readonly nodeId: string | undefined;
2179
2209
  readonly callId: string | undefined;
2210
+ /** The member's own RPC target triple. Throws `ParticipantNotReadyError`
2211
+ * until the member's call context has been received. */
2212
+ readonly target: MemberTarget;
2180
2213
  readonly isTalking: boolean;
2181
2214
  readonly position: LayoutLayer | undefined;
2182
2215
  readonly isAudience: boolean;
@@ -3635,6 +3668,59 @@ declare class SignalWire extends Destroyable implements DeviceController {
3635
3668
  */
3636
3669
  private resolveCredentials;
3637
3670
  private validateCredentials;
3671
+ /**
3672
+ * Reauthenticate the currently-open session with a freshly obtained
3673
+ * credential so the new token takes effect on the live socket immediately —
3674
+ * not just on the next reconnect. No-op when the session is not
3675
+ * connected/authenticated or the credential carries no token (e.g. an
3676
+ * authorization-state-only refresh). Non-fatal: reauth failures surface on
3677
+ * `errors$` without aborting the refresh that triggered this.
3678
+ */
3679
+ private reauthenticateLiveSession;
3680
+ /**
3681
+ * One-shot recovery for a live session that failed with a recoverable auth
3682
+ * error (`-32002`/`-32003`) because its token went stale — e.g. a refresh
3683
+ * timer that was throttled while the tab was backgrounded.
3684
+ *
3685
+ * Two steps, first that succeeds wins:
3686
+ * 1. Reauthenticate with the in-memory token (a fresh DPoP proof is
3687
+ * generated automatically). Heals a session whose token was already
3688
+ * refreshed by the coordinator but never applied to the open socket,
3689
+ * and a client-bound session whose server-side auth merely drifted.
3690
+ * 2. Re-mint via the developer provider's `refresh()` and reauthenticate.
3691
+ * Skipped for client-bound sessions (the DeviceTokenManager owns their
3692
+ * refresh; re-minting a base SAT here would drop the DPoP binding).
3693
+ *
3694
+ * @param allowRemint - Whether step 2 (provider re-mint) may run. Callers
3695
+ * pass `false` for non-auth failures so a transient network error never
3696
+ * escalates to a token re-mint; step 1 (in-memory reauth) always runs.
3697
+ * @returns `true` if the session was reauthenticated, `false` otherwise.
3698
+ */
3699
+ private recoverStaleCredential;
3700
+ /**
3701
+ * Re-mint a credential via `provider.refresh()`, routed through the
3702
+ * coordinator's shared in-flight guard so concurrent re-mint paths (a
3703
+ * scheduled/resume refresh, -32003 recovery, and reconnect) never fire a
3704
+ * second `provider.refresh()` in parallel — which rotating one-time-use
3705
+ * refresh tokens reject. Falls back to a direct call only if the coordinator
3706
+ * has not been constructed yet.
3707
+ */
3708
+ private remintCredential;
3709
+ /**
3710
+ * Re-mint credentials before a fresh (re)connect (`onBeforeReconnect` hook).
3711
+ * The session invokes this only when it is client-bound OR the in-memory
3712
+ * token is expired. The re-mint mechanism depends on the binding:
3713
+ * - Client-bound: `authenticate()` with the DPoP fingerprint to obtain a
3714
+ * fresh base SAT the upcoming reconnect can re-bind (the
3715
+ * DeviceTokenManager re-activates afterwards).
3716
+ * - Unbound: the developer's non-interactive `refresh()` handler.
3717
+ * `authenticate()` is deliberately NOT used here — it may be interactive
3718
+ * (a login prompt) and must not fire on a background reconnect.
3719
+ *
3720
+ * Rejects on failure so the session aborts the reconnect rather than
3721
+ * replaying a stale token.
3722
+ */
3723
+ private refreshCredentialForReconnect;
3638
3724
  /** Persist credential to localStorage when persistSession is enabled. */
3639
3725
  private persistCredential;
3640
3726
  private init;
@@ -4602,14 +4688,27 @@ declare class WebRTCCall extends Destroyable implements CallManager {
4602
4688
  *
4603
4689
  * Constructs call context (node_id, call_id, member_id) and sends the RPC request.
4604
4690
  *
4605
- * @param target - Target member ID string, or a {@link MemberTarget} object.
4691
+ * @param target - Target {@link MemberTarget} triple, or the local member's
4692
+ * ID string for self-operations (any other string is rejected — a bare
4693
+ * member id cannot carry the remote member's own call context).
4606
4694
  * @param method - Verto method name (e.g. `'call.mute'`, `'call.member.remove'`).
4607
4695
  * @param args - Parameters for the RPC method.
4608
4696
  * @returns The RPC response.
4697
+ * @throws {CallNotReadyError} If the call has no self member context yet.
4698
+ * @throws {InvalidParams} If a string target is not the local member's ID.
4609
4699
  * @throws {JSONRPCError} If the RPC call returns an error.
4610
4700
  */
4611
4701
  executeMethod<T extends JSONRPCResponse = JSONRPCResponse>(target: string | MemberTarget, method: string, args: Record<string, unknown>): Promise<T>;
4612
- private buildMethodParams;
4702
+ /**
4703
+ * The local leg's member triple — sent as `self` in every member RPC
4704
+ * envelope, and as the `target` of call-scoped self-operations (e.g. lock,
4705
+ * layout).
4706
+ *
4707
+ * @throws {CallNotReadyError} Before `call.joined` delivers the self member
4708
+ * context (`selfId`/`nodeId`) — an RPC without it cannot be routed, so fail
4709
+ * fast instead of sending a doomed request.
4710
+ */
4711
+ private get callSelf();
4613
4712
  /** Observable of the current call status (e.g. `'ringing'`, `'connected'`). */
4614
4713
  get status$(): Observable<CallStatus>;
4615
4714
  /** Observable of the participants list, emits on join/leave/update. */
@@ -4853,12 +4952,17 @@ declare class WebRTCCall extends Destroyable implements CallManager {
4853
4952
  *
4854
4953
  * **These operations are NOT atomic.** The layout is applied first, then each
4855
4954
  * member position sequentially, so members may briefly flash into their
4856
- * default slots before being moved to the requested positions.
4955
+ * default slots before being moved to the requested positions. Targeted
4956
+ * members are validated upfront, though: when any of them has no
4957
+ * {@link Participant.target | member call context} yet, the whole call
4958
+ * rejects before any request is sent and the layout is left unchanged.
4857
4959
  *
4858
4960
  * @param layout - Layout name (must be one of {@link layouts}).
4859
4961
  * @param positions - Optional map of member IDs to {@link VideoPosition} values.
4860
4962
  * When omitted or empty, only the layout is changed.
4861
4963
  * @throws {InvalidParams} If the layout is not in the available {@link layouts}.
4964
+ * @throws {ParticipantNotReadyError} If a targeted member's call context has
4965
+ * not been received yet — thrown before any request is sent.
4862
4966
  *
4863
4967
  * @example
4864
4968
  * ```ts
@@ -4971,5 +5075,5 @@ declare const version: string;
4971
5075
  */
4972
5076
  declare const ready: boolean;
4973
5077
  //#endregion
4974
- export { Address, type AddressHistory, type AudioConstraintsEvent, type AuthenticateContext, type Call, type CallAddress, type CallCapabilitiesState, CallCreateError, type CallDiagnosticSummary, type CallDirection, type CallError, type CallErrorKind, type NetworkIssue as CallNetworkIssue, type NetworkIssue, type NetworkMetrics as CallNetworkMetrics, type NetworkMetrics, type CallOptions, type CallParticipant, type CallSelfParticipant, type CallState, type CallStatus, type Capability, ClientPreferences, CollectionFetchError, type ConstraintFallbackEvent, type CredentialNoRefreshHandlerWarning, type CredentialProvider, type CredentialRefreshFallbackReason, type CredentialRefreshFallbackWarning, DPoPInitError, type DebugOptions, type DeviceController, type DeviceRecoveryEvent, DeviceTokenError, type DiagnosticEvent, type DialOptions, type Directory, EmbedTokenCredentialProvider, type ExecuteMethod, InvalidCredentialsError, type JSONRPCErrorResponse, type JSONRPCRequest, type JSONRPCResponse, type JSONRPCSuccessResponse, type LayoutLayer, type LogLevel, MediaAccessError, type MediaDirection, type MediaDirections, type MediaOptions, type MediaParamsEvent, MediaTrackError, type MemberCapabilities, MessageParseError, type NodeSocketAdapter, type OnOffCapability, OverconstrainedFallbackError, Participant, type PendingRPCOptions, type PermissionResult, type PlatformCapabilities, PreflightError, type PreflightOptions, type PreflightResult, type QualityLevel, RecoveryError, type RecoveryEvent, type RecoveryState, type ResilienceCallStatus, type SATClaims, type SDKCredential, type SDKLogger, type SDKWarning, type ScreenShareStatus, type SelectDeviceOptions, SelfCapabilities, SelfParticipant, type SessionDiagnostics, type SessionState, SignalWire, type SignalWireOptions, StaticCredentialProvider, type Storage, type StoredDevicePreference, type TextMessage, TokenRefreshError, type TransferOptions, UnexpectedError, User, type UserPresence, VertoPongError, type VideoPosition, type WebRTCApiProvider, WebRTCCall, type WebRTCMediaDevices, type WebSocketAdapter, embeddableCall, getLogger, isSelfParticipant, ready, setDebugOptions, setLogLevel, setLogger, version };
5078
+ export { Address, type AddressHistory, type AudioConstraintsEvent, type AuthenticateContext, type Call, type CallAddress, type CallCapabilitiesState, CallCreateError, type CallDiagnosticSummary, type CallDirection, type CallError, type CallErrorKind, type NetworkIssue as CallNetworkIssue, type NetworkIssue, type NetworkMetrics as CallNetworkMetrics, type NetworkMetrics, CallNotReadyError, type CallOptions, type CallParticipant, type CallSelfParticipant, type CallState, type CallStatus, type Capability, ClientPreferences, CollectionFetchError, type ConstraintFallbackEvent, type CredentialNoRefreshHandlerWarning, type CredentialProvider, type CredentialRefreshFallbackReason, type CredentialRefreshFallbackWarning, DPoPInitError, type DebugOptions, type DeviceController, type DeviceRecoveryEvent, DeviceTokenError, type DiagnosticEvent, type DialOptions, type Directory, EmbedTokenCredentialProvider, type ExecuteMethod, InvalidCredentialsError, type JSONRPCErrorResponse, type JSONRPCRequest, type JSONRPCResponse, type JSONRPCSuccessResponse, type LayoutLayer, type LogLevel, MediaAccessError, type MediaDirection, type MediaDirections, type MediaOptions, type MediaParamsEvent, MediaTrackError, type MemberCapabilities, MessageParseError, type NodeSocketAdapter, type OnOffCapability, OverconstrainedFallbackError, Participant, ParticipantNotReadyError, type PendingRPCOptions, type PermissionResult, type PlatformCapabilities, PreflightError, type PreflightOptions, type PreflightResult, type QualityLevel, RecoveryError, type RecoveryEvent, type RecoveryState, type ResilienceCallStatus, type SATClaims, type SDKCredential, type SDKLogger, type SDKWarning, type ScreenShareStatus, type SelectDeviceOptions, SelfCapabilities, SelfParticipant, type SessionDiagnostics, type SessionState, SignalWire, type SignalWireOptions, StaticCredentialProvider, type Storage, type StoredDevicePreference, type TextMessage, TokenRefreshError, type TransferOptions, UnexpectedError, User, type UserPresence, VertoPongError, type VideoPosition, type WebRTCApiProvider, WebRTCCall, type WebRTCMediaDevices, type WebSocketAdapter, embeddableCall, getLogger, isSelfParticipant, ready, setDebugOptions, setLogLevel, setLogger, version };
4975
5079
  //# sourceMappingURL=index.d.cts.map