@signalwire/js 4.0.0-dev-20260410155733 → 4.0.0-dev-20260410161919

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
@@ -10755,7 +10755,7 @@ var NavigatorDeviceController = class extends Destroyable {
10755
10755
  enableAudioInput() {
10756
10756
  if (this._audioInputDisabled$.value) {
10757
10757
  this._audioInputDisabled$.next(false);
10758
- const restored = this._lastAudioInputBeforeDisable ?? this.audioInputDevices[0] ?? null;
10758
+ const restored = this._lastAudioInputBeforeDisable ?? this.audioInputDevices[0];
10759
10759
  this._selectedDevicesState$.next({
10760
10760
  ...this._selectedDevicesState$.value,
10761
10761
  audioinput: restored
@@ -10776,7 +10776,7 @@ var NavigatorDeviceController = class extends Destroyable {
10776
10776
  enableVideoInput() {
10777
10777
  if (this._videoInputDisabled$.value) {
10778
10778
  this._videoInputDisabled$.next(false);
10779
- const restored = this._lastVideoInputBeforeDisable ?? this.videoInputDevices[0] ?? null;
10779
+ const restored = this._lastVideoInputBeforeDisable ?? this.videoInputDevices[0];
10780
10780
  this._selectedDevicesState$.next({
10781
10781
  ...this._selectedDevicesState$.value,
10782
10782
  videoinput: restored
@@ -11134,10 +11134,10 @@ var StorageManager = class {
11134
11134
  //#region src/containers/DependencyContainer.ts
11135
11135
  var DependencyContainer = class {
11136
11136
  constructor() {
11137
+ this.persistSession = false;
11137
11138
  this._webSocketConstructor = typeof WebSocket !== "undefined" ? WebSocket : void 0;
11138
11139
  this._baseURL = this.apiHost;
11139
11140
  this._credential = {};
11140
- this.persistSession = false;
11141
11141
  }
11142
11142
  get subscriberId() {
11143
11143
  return this.subscriber.id;
@@ -11275,7 +11275,7 @@ const computeJwkThumbprint = async (jwk) => {
11275
11275
  });
11276
11276
  return base64url(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)));
11277
11277
  };
11278
- function openDpopDB() {
11278
+ async function openDpopDB() {
11279
11279
  return new Promise((resolve, reject) => {
11280
11280
  const request = indexedDB.open(DPOP_DB_NAME, DPOP_DB_VERSION);
11281
11281
  request.onupgradeneeded = () => {
@@ -11283,7 +11283,7 @@ function openDpopDB() {
11283
11283
  if (!db.objectStoreNames.contains(DPOP_STORE_NAME)) db.createObjectStore(DPOP_STORE_NAME);
11284
11284
  };
11285
11285
  request.onsuccess = () => resolve(request.result);
11286
- request.onerror = () => reject(request.error);
11286
+ request.onerror = () => reject(request.error ?? /* @__PURE__ */ new Error("Failed to open IndexedDB"));
11287
11287
  });
11288
11288
  }
11289
11289
  async function loadKeyPairFromDB() {
@@ -11293,7 +11293,7 @@ async function loadKeyPairFromDB() {
11293
11293
  const tx = db.transaction(DPOP_STORE_NAME, "readonly");
11294
11294
  const req = tx.objectStore(DPOP_STORE_NAME).get(DPOP_KEY_ID);
11295
11295
  req.onsuccess = () => resolve(req.result ?? null);
11296
- req.onerror = () => reject(req.error);
11296
+ req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("Failed to load key pair from IndexedDB"));
11297
11297
  tx.oncomplete = () => db.close();
11298
11298
  });
11299
11299
  } catch (error) {
@@ -11313,7 +11313,7 @@ async function saveKeyPairToDB(keyPair) {
11313
11313
  };
11314
11314
  tx.onerror = () => {
11315
11315
  db.close();
11316
- reject(tx.error);
11316
+ reject(tx.error ?? /* @__PURE__ */ new Error("Failed to save key pair to IndexedDB"));
11317
11317
  };
11318
11318
  });
11319
11319
  } catch (error) {
@@ -11332,7 +11332,7 @@ async function deleteKeyPairFromDB() {
11332
11332
  };
11333
11333
  tx.onerror = () => {
11334
11334
  db.close();
11335
- reject(tx.error);
11335
+ reject(tx.error ?? /* @__PURE__ */ new Error("Failed to delete key pair from IndexedDB"));
11336
11336
  };
11337
11337
  });
11338
11338
  } catch (error) {
@@ -11713,7 +11713,7 @@ function detectScreenShareAudio() {
11713
11713
  * Safely retrieves navigator.mediaDevices, returning null if unavailable.
11714
11714
  */
11715
11715
  function getNavigatorMediaDevices() {
11716
- if (typeof navigator !== "undefined" && navigator.mediaDevices) return navigator.mediaDevices;
11716
+ if (typeof navigator !== "undefined") return navigator.mediaDevices;
11717
11717
  return null;
11718
11718
  }
11719
11719
 
@@ -15774,7 +15774,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15774
15774
  const preferredAudioCodecs = this.options.preferredAudioCodecs ?? PreferencesContainer.instance.preferredAudioCodecs;
15775
15775
  const preferredVideoCodecs = this.options.preferredVideoCodecs ?? PreferencesContainer.instance.preferredVideoCodecs;
15776
15776
  const stereo = this.options.stereo ?? PreferencesContainer.instance.stereoAudio;
15777
- if (preferredAudioCodecs && preferredAudioCodecs.length > 0 || preferredVideoCodecs && preferredVideoCodecs.length > 0) {
15777
+ if (preferredAudioCodecs.length > 0 || preferredVideoCodecs.length > 0) {
15778
15778
  result = setCodecPreferences(result, preferredAudioCodecs, preferredVideoCodecs);
15779
15779
  logger$14.debug("[RTCPeerConnectionController] Applied codec preferences to SDP", {
15780
15780
  preferredAudioCodecs,
@@ -16016,11 +16016,9 @@ var RTCPeerConnectionController = class extends Destroyable {
16016
16016
  oldTrack.stop();
16017
16017
  this.localStreamController.removeTrack(trackId);
16018
16018
  const newTrack = (await this.getUserMedia({ audio: mergedConstraints })).getAudioTracks()[0];
16019
- if (newTrack) {
16020
- await sender.replaceTrack(newTrack);
16021
- this.localStreamController.addTrack(newTrack);
16022
- logger$14.debug(`[RTCPeerConnectionController] Audio track replaced for server-pushed params. New track: ${newTrack.id}`);
16023
- }
16019
+ await sender.replaceTrack(newTrack);
16020
+ this.localStreamController.addTrack(newTrack);
16021
+ logger$14.debug(`[RTCPeerConnectionController] Audio track replaced for server-pushed params. New track: ${newTrack.id}`);
16024
16022
  }
16025
16023
  }
16026
16024
  /**
@@ -16315,7 +16313,7 @@ var WebRTCVertoManager = class extends VertoManager {
16315
16313
  logger$13.warn("[WebRTCManager] No peer connection for keyframe request");
16316
16314
  return;
16317
16315
  }
16318
- const videoReceiver = pc.getReceivers().find((r) => r.track?.kind === "video");
16316
+ const videoReceiver = pc.getReceivers().find((r) => r.track.kind === "video");
16319
16317
  if (!videoReceiver) {
16320
16318
  logger$13.warn("[WebRTCManager] No video receiver for keyframe request");
16321
16319
  return;
@@ -16391,7 +16389,7 @@ var WebRTCVertoManager = class extends VertoManager {
16391
16389
  try {
16392
16390
  const pc = controller.peerConnection;
16393
16391
  if (!pc) continue;
16394
- const videoReceiver = pc.getReceivers().find((r) => r.track?.kind === "video");
16392
+ const videoReceiver = pc.getReceivers().find((r) => r.track.kind === "video");
16395
16393
  if (!videoReceiver) continue;
16396
16394
  if (typeof videoReceiver.requestKeyFrame === "function") {
16397
16395
  videoReceiver.requestKeyFrame();
@@ -18052,10 +18050,10 @@ var WebRTCCall = class extends Destroyable {
18052
18050
  logger$10.debug("[Call] Recovery manager failed to enable video");
18053
18051
  });
18054
18052
  },
18055
- isNegotiating: () => this.vertoManager.mainPeerConnection?.isNegotiating ?? false,
18053
+ isNegotiating: () => this.vertoManager.mainPeerConnection.isNegotiating,
18056
18054
  isWebSocketConnected: () => this._lastMergedStatus !== "disconnected",
18057
18055
  isCallConnected: () => this._lastMergedStatus === "connected",
18058
- getPeerConnectionState: () => pc.connectionState ?? null
18056
+ getPeerConnectionState: () => pc.connectionState
18059
18057
  }, {
18060
18058
  debounceTimeMs: prefs.recoveryDebounceTime,
18061
18059
  cooldownMs: prefs.recoveryCooldown,
@@ -19270,7 +19268,7 @@ var ClientSessionManager = class extends Destroyable {
19270
19268
  */
19271
19269
  async handleVertoAttach(attach) {
19272
19270
  const { callID } = attach;
19273
- if (this._calls$.value[callID]) {
19271
+ if (callID in this._calls$.value) {
19274
19272
  logger$7.debug(`[Session] Verto attach for existing call ${callID}, deferring to per-call handler`);
19275
19273
  return;
19276
19274
  }
@@ -19972,12 +19970,12 @@ var TransportManager = class extends Destroyable {
19972
19970
  this.discardStaleEvents = () => {
19973
19971
  return (0, import_cjs$1.filter)((message) => {
19974
19972
  if (!isSignalwireRequest(message)) return true;
19975
- const eventChannel = message.params?.event_channel;
19973
+ const eventChannel = message.params.event_channel;
19976
19974
  if (!eventChannel) return true;
19977
19975
  const currentProtocol = this._currentProtocol;
19978
19976
  if (!currentProtocol) return true;
19979
19977
  if (!eventChannel.includes(currentProtocol)) {
19980
- const eventType = message.params.event_type ?? "unknown";
19978
+ const eventType = message.params.event_type;
19981
19979
  logger$2.warn(`[Transport] Discarding stale event: ${eventType} (event_channel does not match current protocol)`);
19982
19980
  return false;
19983
19981
  }
@@ -20228,7 +20226,7 @@ var SignalWire = class extends Destroyable {
20228
20226
  const cached = await this._deps.storage.getItem("sw:cached_credential", scope);
20229
20227
  if (cached?.token) {
20230
20228
  logger$1.debug(`[SignalWire] Using cached credential from ${scope}Storage`);
20231
- return this.validateCredentials(void 0, cached);
20229
+ return await this.validateCredentials(void 0, cached);
20232
20230
  }
20233
20231
  } catch {}
20234
20232
  throw new InvalidCredentialsError("No credential provider and no cached session. Provide a CredentialProvider or enable persistSession with a prior login.");
@@ -20254,7 +20252,7 @@ var SignalWire = class extends Destroyable {
20254
20252
  }
20255
20253
  if (_credentials.expiry_at && credentialProvider?.refresh) {
20256
20254
  const refreshFn = async () => {
20257
- if (!credentialProvider?.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20255
+ if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20258
20256
  return credentialProvider.refresh();
20259
20257
  };
20260
20258
  const refreshInterval = Math.max(_credentials.expiry_at - Date.now() - 5e3, 1e3);
@@ -20662,7 +20660,7 @@ var SignalWire = class extends Destroyable {
20662
20660
  * ```
20663
20661
  */
20664
20662
  async preflight(destination, options) {
20665
- const iceServers = this._clientSession?.iceServers ?? PreferencesContainer.instance.iceServers ?? [];
20663
+ const iceServers = this._clientSession.iceServers ?? PreferencesContainer.instance.iceServers ?? [];
20666
20664
  const isConnected = this._isConnected$.value;
20667
20665
  return new PreflightRunner(this._deviceController, iceServers, isConnected, 0, async (dest, opts) => this.dial(dest, opts), options).run(destination);
20668
20666
  }
@@ -20879,8 +20877,8 @@ var SignalWire = class extends Destroyable {
20879
20877
  this._deviceTokenManager?.destroy();
20880
20878
  this._dpopManager?.destroy();
20881
20879
  if (this._attachManager) this._attachManager.detachAll();
20882
- this._transport?.destroy();
20883
- this._clientSession?.destroy();
20880
+ this._transport.destroy();
20881
+ this._clientSession.destroy();
20884
20882
  try {
20885
20883
  this._networkMonitor?.destroy();
20886
20884
  } catch {}