@signalwire/js 4.0.0-beta.4 → 4.0.0-beta.6

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/browser.mjs CHANGED
@@ -10471,6 +10471,15 @@ const RPCConnect = (params) => {
10471
10471
  });
10472
10472
  };
10473
10473
 
10474
+ //#endregion
10475
+ //#region src/core/RPCMessages/RPCReauthenticate.ts
10476
+ const RPCReauthenticate = (authentication) => {
10477
+ return buildRPCRequest({
10478
+ method: "signalwire.reauthenticate",
10479
+ params: { authentication }
10480
+ });
10481
+ };
10482
+
10474
10483
  //#endregion
10475
10484
  //#region src/core/RPCMessages/RPCPing.ts
10476
10485
  const RPCPingResponse = (id, timestamp$1) => {
@@ -15335,13 +15344,13 @@ var ClientSessionManager = class extends Destroyable {
15335
15344
  this.callCreateTimeout = 6e3;
15336
15345
  this.agent = `signalwire-typescript-sdk/1.0.0`;
15337
15346
  this.eventAcks = true;
15338
- this.authorization$ = this.createSubject();
15339
15347
  this.authorizationState$ = this.createReplaySubject(1);
15340
15348
  this.connectVersion = {
15341
15349
  major: 4,
15342
15350
  minor: 0,
15343
15351
  revision: 0
15344
15352
  };
15353
+ this._authorization$ = this.createBehaviorSubject(void 0);
15345
15354
  this._errors$ = this.createSubject();
15346
15355
  this._authenticated$ = this.createBehaviorSubject(false);
15347
15356
  this._subscriberInfo$ = this.createBehaviorSubject(null);
@@ -15372,6 +15381,12 @@ var ClientSessionManager = class extends Destroyable {
15372
15381
  get iceServers() {
15373
15382
  return this._iceServers$.value;
15374
15383
  }
15384
+ get authorization$() {
15385
+ return this._authorization$.asObservable();
15386
+ }
15387
+ get authorization() {
15388
+ return this._authorization$.value;
15389
+ }
15375
15390
  get errors$() {
15376
15391
  return this._errors$.asObservable();
15377
15392
  }
@@ -15523,6 +15538,24 @@ var ClientSessionManager = class extends Destroyable {
15523
15538
  this._errors$.next(new AuthStateHandlerError(error));
15524
15539
  }
15525
15540
  }
15541
+ async reauthenticate(token) {
15542
+ logger$6.debug("[Session] Re-authenticating session");
15543
+ try {
15544
+ const request = RPCReauthenticate({
15545
+ project: this._authorization$.value?.project_id ?? "",
15546
+ jwt_token: token
15547
+ });
15548
+ await (0, import_cjs$5.lastValueFrom)((0, import_cjs$5.from)(this.transport.execute(request)).pipe(throwOnRPCError(), (0, import_cjs$5.take)(1), (0, import_cjs$5.catchError)((err) => {
15549
+ logger$6.error("[Session] Re-authentication RPC failed:", err);
15550
+ throw err;
15551
+ })));
15552
+ logger$6.debug("[Session] Re-authentication successful, updating stored auth state");
15553
+ } catch (error) {
15554
+ logger$6.error("[Session] Re-authentication failed:", error);
15555
+ this._errors$.next(new AuthStateHandlerError(error));
15556
+ throw error;
15557
+ }
15558
+ }
15526
15559
  async authenticate() {
15527
15560
  logger$6.debug("[Session] Starting authentication process");
15528
15561
  const params = {
@@ -15558,7 +15591,7 @@ var ClientSessionManager = class extends Destroyable {
15558
15591
  hasIceServers: !!response.ice_servers
15559
15592
  });
15560
15593
  if (response.protocol) await this.transport.setProtocol(response.protocol);
15561
- this.authorization$.next(response.authorization);
15594
+ this._authorization$.next(response.authorization);
15562
15595
  this._iceServers$.next(response.ice_servers ?? []);
15563
15596
  this._authenticated$.next(true);
15564
15597
  logger$6.debug("[Session] Authentication completed successfully");
@@ -16277,7 +16310,10 @@ var SignalWire = class extends Destroyable {
16277
16310
  throw new InvalidCredentialsError("Provided credentials have expired.");
16278
16311
  }
16279
16312
  if (_credentials.expiry_at && credentialProvider.refresh) {
16280
- const refreshFn = credentialProvider.refresh;
16313
+ const refreshFn = async () => {
16314
+ if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
16315
+ return credentialProvider.refresh();
16316
+ };
16281
16317
  const refreshInterval = Math.max(_credentials.expiry_at - Date.now() - 5e3, 1e3);
16282
16318
  this._refreshTimerId = setTimeout(async () => {
16283
16319
  try {
@@ -16295,6 +16331,13 @@ var SignalWire = class extends Destroyable {
16295
16331
  }, refreshInterval);
16296
16332
  }
16297
16333
  this._deps.credential = _credentials;
16334
+ if (this.isConnected && this._clientSession.authenticated && _credentials.token) try {
16335
+ await this._clientSession.reauthenticate(_credentials.token);
16336
+ logger$1.info("[SignalWire] Session refreshed with new credentials.");
16337
+ } catch (error) {
16338
+ logger$1.error("[SignalWire] Failed to refresh session with new credentials:", error);
16339
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
16340
+ }
16298
16341
  }
16299
16342
  async init() {
16300
16343
  this._subscriber$.next(new Subscriber(this._deps.http));