@signalwire/js 4.0.0-dev-20260804221355 → 4.0.0-dev-20260908172838

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
@@ -2685,9 +2685,27 @@ declare class AttachManager {
2685
2685
  private readonly deviceController;
2686
2686
  private readonly reconnectCallsTimeout;
2687
2687
  private attachKey;
2688
+ /**
2689
+ * Whether a credential recovery has been verified on this client — the
2690
+ * session reauthenticated with a fresh token AND the operation that
2691
+ * reauthentication was meant to unblock then succeeded. Gates attach-record
2692
+ * discard together with the failure kind: a record is dropped only when
2693
+ * this is true AND the reattach refusal was NOT a credential refusal
2694
+ * (-32003). See {@link reattachCalls}.
2695
+ */
2696
+ private readonly credentialRecovered;
2688
2697
  private session;
2689
2698
  private writeQueue;
2690
- constructor(storage: StorageManager, deviceController: DeviceController, reconnectCallsTimeout: number, attachKey: string);
2699
+ constructor(storage: StorageManager, deviceController: DeviceController, reconnectCallsTimeout: number, attachKey: string,
2700
+ /**
2701
+ * Whether a credential recovery has been verified on this client — the
2702
+ * session reauthenticated with a fresh token AND the operation that
2703
+ * reauthentication was meant to unblock then succeeded. Gates attach-record
2704
+ * discard together with the failure kind: a record is dropped only when
2705
+ * this is true AND the reattach refusal was NOT a credential refusal
2706
+ * (-32003). See {@link reattachCalls}.
2707
+ */
2708
+ credentialRecovered: () => boolean);
2691
2709
  detachAll(): Promise<void>;
2692
2710
  setSession(session: OutboundCallProvider): void;
2693
2711
  private readAttached;
@@ -2714,8 +2732,14 @@ declare class AttachManager {
2714
2732
  * rejecting. Once that fix is deployed, this will work for both
2715
2733
  * page reloads and WebSocket reconnects.
2716
2734
  *
2717
- * Failed reattach attempts are handled gracefully — the stale call
2718
- * reference is cleaned up from storage.
2735
+ * A failed reattach does NOT generally cost the stored reference. It is
2736
+ * discarded only when the server denied the reattach on a session whose
2737
+ * credential it had already accepted — a verified reauthentication followed
2738
+ * by a refusal is the server saying the call is gone, and that is the one
2739
+ * refusal worth acting on. Until then the credential may be what is being
2740
+ * refused, and the record is the only way a later reload can try again;
2741
+ * keeping it costs nothing, since `detachExpired` reaps it once it is older
2742
+ * than `reconnectCallsTimeout`.
2719
2743
  */
2720
2744
  reattachCalls(): Promise<void>;
2721
2745
  /**
@@ -2951,6 +2975,15 @@ interface ClientSession {
2951
2975
  * indicates a re-authentication after the initial connect).
2952
2976
  */
2953
2977
  readonly authenticated$: Observable<boolean>;
2978
+ /**
2979
+ * Control transport for every call in this session: `'routed'` (default) sends
2980
+ * call.* verbs on the client's session channel; `'in-dialog'` carries them on
2981
+ * each call's own signaling channel via `verto.info`. Set once as a client
2982
+ * config ({@link SignalWireOptions.callControl}) — it is session-wide, so a
2983
+ * reattached call reads it here rather than restoring it from persisted state.
2984
+ * Read by {@link Call.executeMethod}.
2985
+ */
2986
+ readonly callControl: 'routed' | 'in-dialog';
2954
2987
  }
2955
2988
  //#endregion
2956
2989
  //#region src/interfaces/SessionState.d.ts
@@ -3022,6 +3055,12 @@ declare class ClientSessionManager extends Destroyable implements SessionState {
3022
3055
  * @internal
3023
3056
  */
3024
3057
  onBeforeReconnect?: () => Promise<void>;
3058
+ /**
3059
+ * Session-wide call control transport (see {@link ClientSession.callControl}).
3060
+ * Set from {@link SignalWireOptions.callControl} by SignalWire after construction;
3061
+ * defaults to `'routed'`. Read by every Call, so it needs no per-call persistence.
3062
+ */
3063
+ callControl: 'routed' | 'in-dialog';
3025
3064
  private _authorization$;
3026
3065
  private _errors$;
3027
3066
  private _directory?;
@@ -3225,7 +3264,10 @@ declare class ClientSessionManager extends Destroyable implements SessionState {
3225
3264
  connect(): Promise<void>;
3226
3265
  private handleAuthenticationError;
3227
3266
  /**
3228
- * Clear the resume state (authorization_state + protocol) only.
3267
+ * Clear the resume state (authorization_state + protocol) and ask the
3268
+ * transport to reconnect. The `connected` event re-triggers
3269
+ * `authenticate()`, which now has no stored state and so performs a fresh
3270
+ * connect.
3229
3271
  *
3230
3272
  * This is the stale-auth-state recovery helper used by handleAuthError:
3231
3273
  * the server rejected a reconnect, so the resume state is discarded and a
@@ -3233,9 +3275,16 @@ declare class ClientSessionManager extends Destroyable implements SessionState {
3233
3275
  * session lives on through the reconnect and reattachCalls() needs the
3234
3276
  * stored call references afterwards. Do NOT add detachAll() here.
3235
3277
  *
3278
+ * Connect-time recovery only. A *request* refused on an already
3279
+ * authenticated session is never healed here: dropping the resume state
3280
+ * destroys the association between the socket and the previous session,
3281
+ * which is what reattach depends on. That path mints a fresh credential and
3282
+ * reauthenticates instead (see `SignalWire.recoverAndRetry`).
3283
+ *
3236
3284
  * For public teardown (disconnect/destroy), use {@link teardownSessionState}
3237
3285
  * instead, which clears the attach records as well.
3238
3286
  */
3287
+ private discardResumeStateAndReconnect;
3239
3288
  cleanupStoredConnectionParams(): Promise<void>;
3240
3289
  /**
3241
3290
  * Public-teardown helper for disconnect()/destroy(). Clears the resume
@@ -3435,6 +3484,7 @@ declare class ClientSessionWrapper implements SessionState {
3435
3484
  is_author: boolean;
3436
3485
  })>;
3437
3486
  get iceServers(): RTCIceServer[] | undefined;
3487
+ get callControl(): 'routed' | 'in-dialog';
3438
3488
  execute<T extends JSONRPCResponse = JSONRPCResponse>(request: JSONRPCRequest, options?: PendingRPCOptions): Promise<T>;
3439
3489
  get incomingCalls$(): Observable<Call[]>;
3440
3490
  get incomingCalls(): Call[];
@@ -3600,6 +3650,24 @@ interface SignalWireOptions {
3600
3650
  logLevel?: LogLevel;
3601
3651
  /** Debug options for verbose SDK diagnostics (e.g., `{ logWsTraffic: true }`). */
3602
3652
  debug?: DebugOptions;
3653
+ /**
3654
+ * Control transport for `call.*` verbs across ALL calls in this session:
3655
+ * - `'routed'` (default) sends them on the client's session channel.
3656
+ * - `'in-dialog'` carries them on each call's own signaling channel via `verto.info`,
3657
+ * so control works without the client needing to know how the conference is hosted.
3658
+ *
3659
+ * `'in-dialog'` is opt-in because it does not reach everywhere `'routed'` does: use it
3660
+ * only for calls that join a conference over SWML (e.g. an SWML `join_conference`).
3661
+ *
3662
+ * It is a client-wide setting rather than per-`dial()` because the SDK issues some
3663
+ * control RPCs itself (fetching the layout list on join, for example), and those must
3664
+ * travel the same way as the app's own, or reads and writes land on different transports.
3665
+ *
3666
+ * @experimental A rollout switch, not a long-term part of the API. Expected to
3667
+ * disappear once `'in-dialog'` becomes the only transport, so it carries no semver
3668
+ * promise and application code should not depend on it.
3669
+ */
3670
+ callControl?: 'routed' | 'in-dialog';
3603
3671
  }
3604
3672
  /** Options for {@link SignalWire.dial}. Extends {@link MediaOptions} with dial-specific settings. */
3605
3673
  interface DialOptions extends MediaOptions {
@@ -3640,6 +3708,13 @@ declare class SignalWire extends Destroyable implements DeviceController {
3640
3708
  private _publicSession;
3641
3709
  private _deviceController;
3642
3710
  private _attachManager?;
3711
+ /**
3712
+ * Set once a credential recovery has been *verified* — reauthenticated and
3713
+ * then proven by the operation it was meant to unblock. Read by the attach
3714
+ * path, which may only discard an attach record when a reattach is refused
3715
+ * on a credential the server has already accepted.
3716
+ */
3717
+ private _credentialRecovered;
3643
3718
  private _isConnected$;
3644
3719
  private _isRegistered$;
3645
3720
  private _errors$;
@@ -3647,6 +3722,10 @@ declare class SignalWire extends Destroyable implements DeviceController {
3647
3722
  private _options;
3648
3723
  private _dpopManager?;
3649
3724
  private _refreshCoordinator?;
3725
+ /** The refresh path's own HTTP controller — see resolveCredentials. */
3726
+ private _refreshHttp?;
3727
+ /** Host `_refreshHttp` was built against, so it can be rebuilt when the token's `ch` changes. */
3728
+ private _refreshHttpHost?;
3650
3729
  private _credentialProvider?;
3651
3730
  private _deps;
3652
3731
  private _networkMonitor?;
@@ -3660,6 +3739,14 @@ declare class SignalWire extends Destroyable implements DeviceController {
3660
3739
  * @param options - Configuration options (connection, device monitoring, preferences).
3661
3740
  */
3662
3741
  constructor(credentialProvider: CredentialProvider | undefined, options?: SignalWireOptions);
3742
+ /**
3743
+ * Build the refresh path's own HTTP controller, against whatever host is current.
3744
+ *
3745
+ * Called on first use rather than up front, so `apiHost` already reflects the
3746
+ * token's `ch` claim. Same credential source as the container's controller — only
3747
+ * the instance, and therefore its observable streams, is separate.
3748
+ */
3749
+ private createRefreshHttpController;
3663
3750
  /**
3664
3751
  * Initializes DPoP if not already set up. Returns the fingerprint on success.
3665
3752
  */
@@ -3684,25 +3771,40 @@ declare class SignalWire extends Destroyable implements DeviceController {
3684
3771
  */
3685
3772
  private reauthenticateLiveSession;
3686
3773
  /**
3687
- * One-shot recovery for a live session that failed with a recoverable auth
3688
- * error (`-32002`/`-32003`) because its token went stale — e.g. a refresh
3689
- * timer that was throttled while the tab was backgrounded.
3774
+ * Recover a session the server is refusing: mint a fresh credential,
3775
+ * reauthenticate the live session with it, and retry the operation.
3776
+ *
3777
+ * The connection is deliberately kept. A reload authenticates the new socket
3778
+ * against the persisted `authorization_state`, and that handshake is what
3779
+ * associates the socket with the previous session — the association reattach
3780
+ * depends on. `signalwire.reauthenticate` swaps the credential *on that same
3781
+ * session*, so recovery never touches the resume state. Discarding it would
3782
+ * heal the credential by destroying the very thing the caller is trying to
3783
+ * get back to.
3784
+ *
3785
+ * The operation is still the verdict, never the RPC. Reauthenticating with
3786
+ * the in-memory token is accepted by a resume even while requests stay
3787
+ * refused, because the persisted `authorization_state` short-circuits token
3788
+ * validation — and `signalwire.reauthenticate` with a *freshly minted* token
3789
+ * has also been observed accepted while `subscriber.online` keeps being
3790
+ * refused (staging run 33826974634). Both look like success and are not.
3791
+ *
3792
+ * @returns the operation's value, or the reason recovery could not deliver
3793
+ * one. `error` is undefined when there was no way to mint at all.
3794
+ */
3795
+ private recoverAndRetry;
3796
+ /**
3797
+ * Re-mint a credential and adopt it only if the live session accepts it.
3690
3798
  *
3691
- * Two steps, first that succeeds wins:
3692
- * 1. Reauthenticate with the in-memory token (a fresh DPoP proof is
3693
- * generated automatically). Heals a session whose token was already
3694
- * refreshed by the coordinator but never applied to the open socket,
3695
- * and a client-bound session whose server-side auth merely drifted.
3696
- * 2. Re-mint via the developer provider's `refresh()` and reauthenticate.
3697
- * Skipped for client-bound sessions (the DeviceTokenManager owns their
3698
- * refresh; re-minting a base SAT here would drop the DPoP binding).
3799
+ * The mechanism follows the binding: a client-bound session re-mints a bound
3800
+ * base SAT through `authenticate()` with the DPoP fingerprint, because the
3801
+ * developer refresh handler would hand back an unbound token and silently
3802
+ * degrade the session. An unbound session uses the refresh handler. Rotation
3803
+ * cost is not a reason to skip this — the only reason is having no mechanism.
3699
3804
  *
3700
- * @param allowRemint - Whether step 2 (provider re-mint) may run. Callers
3701
- * pass `false` for non-auth failures so a transient network error never
3702
- * escalates to a token re-mint; step 1 (in-memory reauth) always runs.
3703
- * @returns `true` if the session was reauthenticated, `false` otherwise.
3805
+ * @returns whether the session is now running on a freshly accepted credential.
3704
3806
  */
3705
- private recoverStaleCredential;
3807
+ private remintAndReauthenticate;
3706
3808
  /**
3707
3809
  * Re-mint a credential via `provider.refresh()`, routed through the
3708
3810
  * coordinator's shared in-flight guard so concurrent re-mint paths (a
@@ -3729,8 +3831,32 @@ declare class SignalWire extends Destroyable implements DeviceController {
3729
3831
  private refreshCredentialForReconnect;
3730
3832
  /** Persist credential to localStorage when persistSession is enabled. */
3731
3833
  private persistCredential;
3834
+ /**
3835
+ * Persist whether the session is client-bound, mirroring the credential's
3836
+ * storage scopes so it survives a reload. The preflight recovery reads it
3837
+ * before any session exists to decide whether to re-bind via `authenticate()`
3838
+ * or refresh an unbound token; the marker tracks the latest binding, so an
3839
+ * unbound reconnect clears a stale marker from an earlier client-bound login.
3840
+ */
3841
+ private persistClientBoundMarker;
3842
+ /** Read the persisted client-bound marker (see {@link persistClientBoundMarker}). */
3843
+ private wasClientBound;
3732
3844
  private init;
3733
3845
  private handleAttachments;
3846
+ /**
3847
+ * Fetch the authenticated user profile, recovering a stale credential.
3848
+ *
3849
+ * On a reload the persisted credential can be expired. Unlike the WS resume —
3850
+ * which the server accepts against the persisted `authorization_state` even
3851
+ * with an expired token — this REST preflight has no such short-circuit and is
3852
+ * refused (401). There is no session yet to reauthenticate, so recovery
3853
+ * re-mints the credential through the provider ({@link refreshCredentialForReconnect})
3854
+ * and retries with a FRESH {@link User}: Fetchable memoizes its result
3855
+ * (shareReplay), so reusing the instance would replay the 401 instead of
3856
+ * re-fetching with the new token. Without the user id the transport/session —
3857
+ * and the reattach a reload is trying to preserve — cannot even be addressed.
3858
+ */
3859
+ private fetchUserOrRecover;
3734
3860
  /**
3735
3861
  * Establishes the WebSocket connection and authenticates the session.
3736
3862
  *
@@ -4464,6 +4590,15 @@ interface WebRTCVerto extends VertoManager {
4464
4590
  readonly mainPeerConnection: RTCPeerConnectionController;
4465
4591
  bye(cause?: string): Promise<void>;
4466
4592
  sendDigits(dtmf: string): Promise<void>;
4593
+ /**
4594
+ * Send a member-control op in-dialog via verto.info (no self/target member
4595
+ * tuple). The payload rides in the verto.info `params.command` body — a
4596
+ * sibling of `dialogParams`, same level as `dtmf` — matched to this call's
4597
+ * channel by `dialogParams.callID`, so control lands on the call's own channel
4598
+ * without relying on the {node_id,call_id,member_id} addressing the routed
4599
+ * transport uses.
4600
+ */
4601
+ sendCallControl(method: string, params: Record<string, unknown>): Promise<unknown>;
4467
4602
  hold(): Promise<void>;
4468
4603
  unhold(): Promise<void>;
4469
4604
  destroy(): void;
@@ -4705,6 +4840,61 @@ declare class WebRTCCall extends Destroyable implements CallManager {
4705
4840
  * @throws {JSONRPCError} If the RPC call returns an error.
4706
4841
  */
4707
4842
  executeMethod<T extends JSONRPCResponse = JSONRPCResponse>(target: string | MemberTarget, method: string, args: Record<string, unknown>): Promise<T>;
4843
+ /**
4844
+ * `executeMethod` for a call opened with `callControl: 'in-dialog'`.
4845
+ *
4846
+ * Translates the routed transport's calling convention into the in-dialog one. No
4847
+ * `self` tuple is sent, but a `target` is — the same {call_id, member_id} the routed
4848
+ * transport puts in `target` (minus node_id), for self-ops and cross-member ops alike.
4849
+ *
4850
+ * Target shapes are per-verb and irregular, so they are centralised here rather
4851
+ * than left to callers: most verbs take a singular `target`, `call.member.remove`
4852
+ * takes a plural `targets` array, and `call.member.position.set` takes a flat
4853
+ * `targets` of `{call_id, position}` — the one verb keyed on call_id rather than
4854
+ * member_id, so the member triple `Participant.setPosition` built is unwrapped.
4855
+ */
4856
+ private executeMethodInDialog;
4857
+ /**
4858
+ * Sends a `call.*` control verb **in-dialog** via `verto.info`, as an alternative
4859
+ * to the routed {@link executeMethod} transport.
4860
+ *
4861
+ * Why both exist: `executeMethod` addresses the member with an explicit
4862
+ * `{node_id, call_id, member_id}` tuple, which does not resolve for every conference,
4863
+ * so the op can fail. An in-dialog frame carries the verb on the member's own
4864
+ * signaling channel instead, so control works without the client needing to know how
4865
+ * the conference is hosted.
4866
+ *
4867
+ * The trade-off is reach: the in-dialog transport is only accepted for calls that
4868
+ * join a conference over SWML (e.g. an SWML `join_conference`); use the routed
4869
+ * default otherwise.
4870
+ *
4871
+ * `params` are sent verbatim — nothing is built for you, which includes the target.
4872
+ * **A self-directed op still needs one**, or it is refused; name yourself explicitly:
4873
+ *
4874
+ * ```ts
4875
+ * const { call_id, member_id } = call.self.target;
4876
+ * await call.sendCommand('call.mute', { channels: ['audio'], target: { call_id, member_id } });
4877
+ * ```
4878
+ *
4879
+ * Never include `node_id` — only the two ids. The shapes are per-verb: most take a
4880
+ * singular `target`, `call.member.remove` takes a plural `targets` array, and
4881
+ * `call.member.position.set` takes a flat `targets: [{call_id, position}]` (the one
4882
+ * verb keyed on `call_id` rather than `member_id`). Verbs that act on the call as a
4883
+ * whole, or that the SDK does not wrap at all, take no target.
4884
+ *
4885
+ * For the typed alternative that handles all of this, create the client with
4886
+ * `callControl: 'in-dialog'` and use the ordinary `Call`/`Participant` methods.
4887
+ *
4888
+ * @internal Not part of the supported surface while the in-dialog transport is still
4889
+ * rolling out. `WebRTCCall` is exported from the package entry, so without this tag
4890
+ * TypeDoc publishes the method — and the example above — as public API.
4891
+ *
4892
+ * @param method - A `call.*` method name (e.g. `'call.mute'`).
4893
+ * @param params - Method parameters, sent verbatim.
4894
+ * @returns The method's own reply, unwrapped from the `verto.info` envelope.
4895
+ * @throws {JSONRPCError} If the control op fails.
4896
+ */
4897
+ sendCommand<T extends JSONRPCResponse = JSONRPCResponse>(method: string, params?: Record<string, unknown>): Promise<T>;
4708
4898
  /**
4709
4899
  * The local leg's member triple — sent as `self` in every member RPC
4710
4900
  * envelope, and as the `target` of call-scoped self-operations (e.g. lock,