@signalwire/js 4.0.0-rc.4 → 4.0.0-rc.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.
package/dist/browser.mjs CHANGED
@@ -20689,6 +20689,8 @@ var ClientSessionManager = class extends Destroyable {
20689
20689
  this._errors$ = this.createReplaySubject(1);
20690
20690
  this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
20691
20691
  this._wasClientBound = false;
20692
+ this._lastFreshConnectReminted = false;
20693
+ this._remintBeforeNextFreshConnect = false;
20692
20694
  this._userInfo$ = this.createBehaviorSubject(null);
20693
20695
  this._calls$ = this.createBehaviorSubject({});
20694
20696
  this._iceServers$ = this.createBehaviorSubject([]);
@@ -20894,7 +20896,17 @@ var ClientSessionManager = class extends Destroyable {
20894
20896
  if (isRecoverableAuthError$1 && hasStoredState) {
20895
20897
  logger$9.debug("[Session] Recoverable auth error — cleaning up stored state and reconnecting fresh");
20896
20898
  await this.discardResumeStateAndReconnect();
20897
- } else this._errors$.next(error);
20899
+ } else if (isRecoverableAuthError$1 && this.onBeforeReconnect && !this._lastFreshConnectReminted) {
20900
+ logger$9.debug("[Session] Fresh connect refused — re-minting the credential and retrying once");
20901
+ this._remintBeforeNextFreshConnect = true;
20902
+ this.transport.reconnect();
20903
+ } else {
20904
+ this._errors$.next(error);
20905
+ if (isRecoverableAuthError$1) {
20906
+ this.transport.disconnect();
20907
+ this.onAuthenticationRejected?.();
20908
+ }
20909
+ }
20898
20910
  }
20899
20911
  /**
20900
20912
  * Clear the resume state (authorization_state + protocol) and ask the
@@ -20986,6 +20998,7 @@ var ClientSessionManager = class extends Destroyable {
20986
20998
  }
20987
20999
  async authenticate() {
20988
21000
  logger$9.debug("[Session] Starting authentication process");
21001
+ this._lastFreshConnectReminted = false;
20989
21002
  const persistedParams = await (0, import_cjs$7.firstValueFrom)((0, import_cjs$7.combineLatest)({
20990
21003
  protocol: this.transport.protocol$,
20991
21004
  authorization_state: this.authorizationState$
@@ -21002,8 +21015,11 @@ var ClientSessionManager = class extends Destroyable {
21002
21015
  else {
21003
21016
  const credential = this.getCredential();
21004
21017
  const credentialExpired = credential.expiry_at !== void 0 && credential.expiry_at <= Date.now() + CREDENTIAL_EXPIRY_SKEW_MS;
21005
- if (this.onBeforeReconnect && (this.clientBound || credentialExpired)) {
21018
+ const remint = this.clientBound || credentialExpired || this._remintBeforeNextFreshConnect;
21019
+ this._remintBeforeNextFreshConnect = false;
21020
+ if (this.onBeforeReconnect && remint) {
21006
21021
  logger$9.debug("[Session] Refreshing credentials before fresh connect");
21022
+ this._lastFreshConnectReminted = true;
21007
21023
  await this.onBeforeReconnect();
21008
21024
  }
21009
21025
  }
@@ -23063,6 +23079,7 @@ var SignalWire = class extends Destroyable {
23063
23079
  this.persistClientBoundMarker(Boolean(authorization?.cnf?.jkt));
23064
23080
  });
23065
23081
  await this._clientSession.connect();
23082
+ this._clientSession.onAuthenticationRejected = () => void this.disconnect();
23066
23083
  await this._refreshCoordinator?.activate(this._deps.user, this._clientSession);
23067
23084
  this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(1), (0, import_cjs$1.filter)(Boolean)), async () => {
23068
23085
  try {
@@ -23242,7 +23259,7 @@ var SignalWire = class extends Destroyable {
23242
23259
  logger$1.warn("[SignalWire] Failed to initialize VisibilityController:", error);
23243
23260
  }
23244
23261
  try {
23245
- this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-rc.4" });
23262
+ this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-rc.5" });
23246
23263
  } catch (error) {
23247
23264
  logger$1.warn("[SignalWire] Failed to initialize DiagnosticsCollector:", error);
23248
23265
  }
@@ -23797,7 +23814,7 @@ var StaticCredentialProvider = class {
23797
23814
  /**
23798
23815
  * Library version from package.json, injected at build time.
23799
23816
  */
23800
- const version = "4.0.0-rc.4";
23817
+ const version = "4.0.0-rc.5";
23801
23818
  /**
23802
23819
  * Flag indicating the library has been loaded and is ready to use.
23803
23820
  * For UMD builds: `window.SignalWire.ready`
@@ -23819,7 +23836,7 @@ const ready = true;
23819
23836
  */
23820
23837
  const emitReadyEvent = () => {
23821
23838
  if (typeof window !== "undefined") {
23822
- const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-rc.4" } });
23839
+ const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-rc.5" } });
23823
23840
  window.dispatchEvent(event);
23824
23841
  }
23825
23842
  };