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

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.
@@ -10475,6 +10475,15 @@ const RPCConnect = (params) => {
10475
10475
  });
10476
10476
  };
10477
10477
 
10478
+ //#endregion
10479
+ //#region src/core/RPCMessages/RPCReauthenticate.ts
10480
+ const RPCReauthenticate = (authentication) => {
10481
+ return buildRPCRequest({
10482
+ method: "signalwire.reauthenticate",
10483
+ params: { authentication }
10484
+ });
10485
+ };
10486
+
10478
10487
  //#endregion
10479
10488
  //#region src/core/RPCMessages/RPCPing.ts
10480
10489
  const RPCPingResponse = (id, timestamp$1) => {
@@ -15339,13 +15348,13 @@ var ClientSessionManager = class extends Destroyable {
15339
15348
  this.callCreateTimeout = 6e3;
15340
15349
  this.agent = `signalwire-typescript-sdk/1.0.0`;
15341
15350
  this.eventAcks = true;
15342
- this.authorization$ = this.createSubject();
15343
15351
  this.authorizationState$ = this.createReplaySubject(1);
15344
15352
  this.connectVersion = {
15345
15353
  major: 4,
15346
15354
  minor: 0,
15347
15355
  revision: 0
15348
15356
  };
15357
+ this._authorization$ = this.createBehaviorSubject(void 0);
15349
15358
  this._errors$ = this.createSubject();
15350
15359
  this._authenticated$ = this.createBehaviorSubject(false);
15351
15360
  this._subscriberInfo$ = this.createBehaviorSubject(null);
@@ -15376,6 +15385,12 @@ var ClientSessionManager = class extends Destroyable {
15376
15385
  get iceServers() {
15377
15386
  return this._iceServers$.value;
15378
15387
  }
15388
+ get authorization$() {
15389
+ return this._authorization$.asObservable();
15390
+ }
15391
+ get authorization() {
15392
+ return this._authorization$.value;
15393
+ }
15379
15394
  get errors$() {
15380
15395
  return this._errors$.asObservable();
15381
15396
  }
@@ -15527,6 +15542,24 @@ var ClientSessionManager = class extends Destroyable {
15527
15542
  this._errors$.next(new AuthStateHandlerError(error));
15528
15543
  }
15529
15544
  }
15545
+ async reauthenticate(token) {
15546
+ logger$6.debug("[Session] Re-authenticating session");
15547
+ try {
15548
+ const request = RPCReauthenticate({
15549
+ project: this._authorization$.value?.project_id ?? "",
15550
+ jwt_token: token
15551
+ });
15552
+ 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) => {
15553
+ logger$6.error("[Session] Re-authentication RPC failed:", err);
15554
+ throw err;
15555
+ })));
15556
+ logger$6.debug("[Session] Re-authentication successful, updating stored auth state");
15557
+ } catch (error) {
15558
+ logger$6.error("[Session] Re-authentication failed:", error);
15559
+ this._errors$.next(new AuthStateHandlerError(error));
15560
+ throw error;
15561
+ }
15562
+ }
15530
15563
  async authenticate() {
15531
15564
  logger$6.debug("[Session] Starting authentication process");
15532
15565
  const params = {
@@ -15562,7 +15595,7 @@ var ClientSessionManager = class extends Destroyable {
15562
15595
  hasIceServers: !!response.ice_servers
15563
15596
  });
15564
15597
  if (response.protocol) await this.transport.setProtocol(response.protocol);
15565
- this.authorization$.next(response.authorization);
15598
+ this._authorization$.next(response.authorization);
15566
15599
  this._iceServers$.next(response.ice_servers ?? []);
15567
15600
  this._authenticated$.next(true);
15568
15601
  logger$6.debug("[Session] Authentication completed successfully");
@@ -16299,6 +16332,13 @@ var SignalWire = class extends Destroyable {
16299
16332
  }, refreshInterval);
16300
16333
  }
16301
16334
  this._deps.credential = _credentials;
16335
+ if (this.isConnected && this._clientSession.authenticated && _credentials.token) try {
16336
+ await this._clientSession.reauthenticate(_credentials.token);
16337
+ logger$1.info("[SignalWire] Session refreshed with new credentials.");
16338
+ } catch (error) {
16339
+ logger$1.error("[SignalWire] Failed to refresh session with new credentials:", error);
16340
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
16341
+ }
16302
16342
  }
16303
16343
  async init() {
16304
16344
  this._subscriber$.next(new Subscriber(this._deps.http));