@signalwire/js 4.0.0-dev-20261001133709 → 4.0.0-dev-20261125185248

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
@@ -9108,6 +9108,10 @@ const MEDIA_ACCESS_DENIAL_NAMES = [
9108
9108
  ];
9109
9109
  /** Error names browsers use when the capture hardware is already held exclusively. */
9110
9110
  const MEDIA_DEVICE_IN_USE_NAMES = ["NotReadableError", "TrackStartError"];
9111
+ const INACTIVE_MEDIA_DIRECTIONS = Object.freeze({
9112
+ audio: "inactive",
9113
+ video: "inactive"
9114
+ });
9111
9115
  /** Default polling interval for RTCPeerConnection.getStats() in milliseconds. */
9112
9116
  const DEFAULT_STATS_POLLING_INTERVAL_MS = 1e3;
9113
9117
  /** Number of initial samples used to build a baseline for spike detection. */
@@ -17080,10 +17084,7 @@ var RTCPeerConnectionController = class extends Destroyable {
17080
17084
  });
17081
17085
  }
17082
17086
  get mediaDirections() {
17083
- return this.transceiverController?.getMediaDirections() ?? this._remoteOfferMediaDirections ?? {
17084
- audio: "inactive",
17085
- video: "inactive"
17086
- };
17087
+ return this.transceiverController?.getMediaDirections() ?? this._remoteOfferMediaDirections ?? INACTIVE_MEDIA_DIRECTIONS;
17087
17088
  }
17088
17089
  async _setRemoteDescription(params) {
17089
17090
  if (!this.peerConnection) throw new DependencyError("RTCPeerConnection is not initialized");
@@ -17260,7 +17261,7 @@ var WebRTCVertoManager = class extends VertoManager {
17260
17261
  }
17261
17262
  }
17262
17263
  get mediaDirections() {
17263
- return this.mainPeerConnection.mediaDirections;
17264
+ return this._rtcPeerConnectionsMap.get(this.webRtcCallSession.id)?.mediaDirections ?? INACTIVE_MEDIA_DIRECTIONS;
17264
17265
  }
17265
17266
  get rtcPeerConnections$() {
17266
17267
  return this._rtcPeerConnections$.asObservable();
@@ -17718,7 +17719,7 @@ var WebRTCVertoManager = class extends VertoManager {
17718
17719
  if (rtcPeerConnController.isMainDevice) {
17719
17720
  this._selfId$.next(memberId);
17720
17721
  this._nodeId$.next(nodeId);
17721
- this.attachManager.attach(this.buildAttachableCall(callId, nodeId ?? void 0));
17722
+ if (this._rtcPeerConnectionsMap.has(this.webRtcCallSession.id)) this.attachManager.attach(this.buildAttachableCall(callId, nodeId ?? void 0));
17722
17723
  }
17723
17724
  if (callId) this.webRtcCallSession.addCallId(callId);
17724
17725
  logger$16.info("[WebRTCManager] Verto invite successful");
@@ -17894,7 +17895,7 @@ var WebRTCVertoManager = class extends VertoManager {
17894
17895
  this.emitMainSignalingStatus(rtcPeerConnectionController.id, "connecting");
17895
17896
  await this.sendLocalDescription(vertoMessageRequest, rtcPeerConnectionController);
17896
17897
  await rtcPeerConnectionController.updateAnswerStatus({ status: "sent" });
17897
- await this.attachManager.attach(this.buildAttachableCall());
17898
+ if (this._rtcPeerConnectionsMap.has(this.webRtcCallSession.id)) await this.attachManager.attach(this.buildAttachableCall());
17898
17899
  } catch (error) {
17899
17900
  logger$16.error("[WebRTCManager] Error sending Verto answer:", error);
17900
17901
  this.reportLegError(toError(error), rtcPeerConnectionController);
@@ -19665,7 +19666,7 @@ var WebRTCCall = class extends Destroyable {
19665
19666
  get mediaDirections$() {
19666
19667
  return this.deferEmission(this.vertoManager.mediaDirections$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
19667
19668
  }
19668
- /** Current audio/video send/receive directions. */
19669
+ /** Current audio/video send/receive directions. Both are `'inactive'` once the call is destroyed. */
19669
19670
  get mediaDirections() {
19670
19671
  return this.vertoManager.mediaDirections;
19671
19672
  }
@@ -20689,6 +20690,8 @@ var ClientSessionManager = class extends Destroyable {
20689
20690
  this._errors$ = this.createReplaySubject(1);
20690
20691
  this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
20691
20692
  this._wasClientBound = false;
20693
+ this._lastFreshConnectReminted = false;
20694
+ this._remintBeforeNextFreshConnect = false;
20692
20695
  this._userInfo$ = this.createBehaviorSubject(null);
20693
20696
  this._calls$ = this.createBehaviorSubject({});
20694
20697
  this._iceServers$ = this.createBehaviorSubject([]);
@@ -20894,7 +20897,17 @@ var ClientSessionManager = class extends Destroyable {
20894
20897
  if (isRecoverableAuthError$1 && hasStoredState) {
20895
20898
  logger$9.debug("[Session] Recoverable auth error — cleaning up stored state and reconnecting fresh");
20896
20899
  await this.discardResumeStateAndReconnect();
20897
- } else this._errors$.next(error);
20900
+ } else if (isRecoverableAuthError$1 && this.onBeforeReconnect && !this._lastFreshConnectReminted) {
20901
+ logger$9.debug("[Session] Fresh connect refused — re-minting the credential and retrying once");
20902
+ this._remintBeforeNextFreshConnect = true;
20903
+ this.transport.reconnect();
20904
+ } else {
20905
+ this._errors$.next(error);
20906
+ if (isRecoverableAuthError$1) {
20907
+ this.transport.disconnect();
20908
+ this.onAuthenticationRejected?.();
20909
+ }
20910
+ }
20898
20911
  }
20899
20912
  /**
20900
20913
  * Clear the resume state (authorization_state + protocol) and ask the
@@ -20986,6 +20999,7 @@ var ClientSessionManager = class extends Destroyable {
20986
20999
  }
20987
21000
  async authenticate() {
20988
21001
  logger$9.debug("[Session] Starting authentication process");
21002
+ this._lastFreshConnectReminted = false;
20989
21003
  const persistedParams = await (0, import_cjs$7.firstValueFrom)((0, import_cjs$7.combineLatest)({
20990
21004
  protocol: this.transport.protocol$,
20991
21005
  authorization_state: this.authorizationState$
@@ -21002,8 +21016,11 @@ var ClientSessionManager = class extends Destroyable {
21002
21016
  else {
21003
21017
  const credential = this.getCredential();
21004
21018
  const credentialExpired = credential.expiry_at !== void 0 && credential.expiry_at <= Date.now() + CREDENTIAL_EXPIRY_SKEW_MS;
21005
- if (this.onBeforeReconnect && (this.clientBound || credentialExpired)) {
21019
+ const remint = this.clientBound || credentialExpired || this._remintBeforeNextFreshConnect;
21020
+ this._remintBeforeNextFreshConnect = false;
21021
+ if (this.onBeforeReconnect && remint) {
21006
21022
  logger$9.debug("[Session] Refreshing credentials before fresh connect");
21023
+ this._lastFreshConnectReminted = true;
21007
21024
  await this.onBeforeReconnect();
21008
21025
  }
21009
21026
  }
@@ -23063,6 +23080,7 @@ var SignalWire = class extends Destroyable {
23063
23080
  this.persistClientBoundMarker(Boolean(authorization?.cnf?.jkt));
23064
23081
  });
23065
23082
  await this._clientSession.connect();
23083
+ this._clientSession.onAuthenticationRejected = () => void this.disconnect();
23066
23084
  await this._refreshCoordinator?.activate(this._deps.user, this._clientSession);
23067
23085
  this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(1), (0, import_cjs$1.filter)(Boolean)), async () => {
23068
23086
  try {
@@ -23242,7 +23260,7 @@ var SignalWire = class extends Destroyable {
23242
23260
  logger$1.warn("[SignalWire] Failed to initialize VisibilityController:", error);
23243
23261
  }
23244
23262
  try {
23245
- this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-dev-20261001133709" });
23263
+ this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-dev-20261125185248" });
23246
23264
  } catch (error) {
23247
23265
  logger$1.warn("[SignalWire] Failed to initialize DiagnosticsCollector:", error);
23248
23266
  }
@@ -23797,7 +23815,7 @@ var StaticCredentialProvider = class {
23797
23815
  /**
23798
23816
  * Library version from package.json, injected at build time.
23799
23817
  */
23800
- const version = "4.0.0-dev-20261001133709";
23818
+ const version = "4.0.0-dev-20261125185248";
23801
23819
  /**
23802
23820
  * Flag indicating the library has been loaded and is ready to use.
23803
23821
  * For UMD builds: `window.SignalWire.ready`
@@ -23819,7 +23837,7 @@ const ready = true;
23819
23837
  */
23820
23838
  const emitReadyEvent = () => {
23821
23839
  if (typeof window !== "undefined") {
23822
- const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-dev-20261001133709" } });
23840
+ const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-dev-20261125185248" } });
23823
23841
  window.dispatchEvent(event);
23824
23842
  }
23825
23843
  };