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

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.
@@ -9026,6 +9026,15 @@ var Destroyable = class {
9026
9026
  const INVITE_VERSION = 1e3;
9027
9027
  const DEFAULT_ICE_CANDIDATE_TIMEOUT_MS = 600;
9028
9028
  const DEFAULT_ICE_GATHERING_TIMEOUT_MS = 6e3;
9029
+ /**
9030
+ * How long a first gather may find no candidate at all before it is given up.
9031
+ * Longer than the gathering timeout so a TURN allocation whose first Allocates
9032
+ * were lost can still answer (Chromium resends one at ~7.9 s), and shorter than
9033
+ * the dial's create timeout, so a dial still fails with the gathering error.
9034
+ */
9035
+ const DEFAULT_ICE_GATHERING_FAILURE_TIMEOUT_MS = 1e4;
9036
+ /** Prefix of an SDP line that carries an ICE candidate. */
9037
+ const SDP_CANDIDATE_LINE_PREFIX = "a=candidate:";
9029
9038
  const DEFAULT_RECONNECT_CALLS_TIMEOUT_MS = 300 * 1e3;
9030
9039
  const DEFAULT_CONNECTION_TIMEOUT_MS = 1e4;
9031
9040
  /**
@@ -9443,6 +9452,20 @@ var AuxiliaryLegCancelledError = class extends Error {
9443
9452
  this.name = "AuxiliaryLegCancelledError";
9444
9453
  }
9445
9454
  };
9455
+ /**
9456
+ * ICE gathering for a call's first offer or answer ended without a single
9457
+ * candidate, as when the device has no usable network, so there is nothing the
9458
+ * far end could connect to. Fatal for the main leg: the SDP is never sent, and
9459
+ * waiting would stall the call forever.
9460
+ */
9461
+ var IceGatheringError = class extends Error {
9462
+ constructor(sdpType, gatheringState) {
9463
+ super(`ICE gathering ended (${gatheringState}) with no candidates; the ${sdpType} cannot be sent`);
9464
+ this.sdpType = sdpType;
9465
+ this.gatheringState = gatheringState;
9466
+ this.name = "IceGatheringError";
9467
+ }
9468
+ };
9446
9469
  var MediaTrackError = class extends Error {
9447
9470
  constructor(operation, kind, originalError) {
9448
9471
  super(`Media track ${operation} failed for ${kind}`, { cause: originalError instanceof Error ? originalError : void 0 });
@@ -12640,6 +12663,7 @@ var AttachManager = class {
12640
12663
  const options = this.buildCallOptions(attachment);
12641
12664
  let succeeded = false;
12642
12665
  let refusedOnCredentials = false;
12666
+ let gatheredNothing = false;
12643
12667
  for (let attempt = 1; attempt <= 3; attempt++) try {
12644
12668
  await this.session.createOutboundCall(destination, {
12645
12669
  callId,
@@ -12650,6 +12674,7 @@ var AttachManager = class {
12650
12674
  break;
12651
12675
  } catch (error) {
12652
12676
  logger$26.warn(`[AttachManager] Reattach attempt ${attempt}/3 failed for call ${callId}:`, error);
12677
+ gatheredNothing = error instanceof Error && error.cause instanceof IceGatheringError;
12653
12678
  if (isRequesterValidationError(error)) {
12654
12679
  refusedOnCredentials = true;
12655
12680
  logger$26.warn(`[AttachManager] Reattach of ${callId} was refused on credentials; not retrying.`);
@@ -12657,7 +12682,7 @@ var AttachManager = class {
12657
12682
  }
12658
12683
  if (attempt < 3) await new Promise((r) => setTimeout(r, (attempt + 1) * 1e3));
12659
12684
  }
12660
- if (!succeeded) if (this.credentialRecovered() && !refusedOnCredentials) {
12685
+ if (!succeeded) if (this.credentialRecovered() && !refusedOnCredentials && !gatheredNothing) {
12661
12686
  logger$26.warn(`[AttachManager] Reattach of ${callId} was denied after a verified reauthentication, removing reference`);
12662
12687
  await this.detach({
12663
12688
  id: callId,
@@ -15125,6 +15150,17 @@ function extractMediaDirectionsFromSDP(sdp) {
15125
15150
  return result;
15126
15151
  }
15127
15152
  /**
15153
+ * Whether an SDP string carries at least one ICE candidate of any type.
15154
+ *
15155
+ * The end-of-candidates indication (`a=end-of-candidates`) is not a candidate.
15156
+ *
15157
+ * @param sdp - The SDP string to check
15158
+ * @returns true if any line is an `a=candidate:` line
15159
+ */
15160
+ function hasCandidates(sdp) {
15161
+ return sdp.split(/\r?\n/).some((line) => line.startsWith(SDP_CANDIDATE_LINE_PREFIX));
15162
+ }
15163
+ /**
15128
15164
  * Validates that an SDP string has at least one non-host ICE candidate
15129
15165
  * for each media section (m= line).
15130
15166
  *
@@ -15155,7 +15191,7 @@ function isValidLocalDescription(sdp) {
15155
15191
  for (const line of lines) if (line.startsWith("m=")) {
15156
15192
  currentSection += 1;
15157
15193
  mediaSectionsValidCandidates[currentSection] = 0;
15158
- } else if (line.startsWith("a=candidate:")) {
15194
+ } else if (line.startsWith(SDP_CANDIDATE_LINE_PREFIX)) {
15159
15195
  const typeMatch = /\styp\s+(host|srflx|prflx|relay)/.exec(line);
15160
15196
  if (typeMatch && typeMatch[1] !== "host") mediaSectionsValidCandidates[currentSection] += 1;
15161
15197
  }
@@ -15343,19 +15379,31 @@ var ICEGatheringController = class extends Destroyable {
15343
15379
  this.iceCandidateTimeout = options.iceCandidateTimeout ?? DEFAULT_ICE_CANDIDATE_TIMEOUT_MS;
15344
15380
  this.iceGatheringTimeout = options.iceGatheringTimeout ?? DEFAULT_ICE_GATHERING_TIMEOUT_MS;
15345
15381
  this.relayOnly = options.relayOnly ?? false;
15382
+ this.endGatheringWithoutCandidates = options.endGatheringWithoutCandidates ?? (() => false);
15346
15383
  this.setupEventListeners();
15347
15384
  this.subscribeTo(this.peerConnectionControllerNegotiating$.pipe((0, import_cjs$19.filter)((isNegotiating) => isNegotiating)), (isNegotiating) => {
15348
15385
  if (isNegotiating) {
15349
15386
  this.setupEventListeners();
15350
- this.iceGatheringTimer = setTimeout(() => {
15351
- if (this.peerConnection.iceGatheringState !== "complete") {
15352
- logger$21.warn("[ICEGatheringController] ICE gathering timeout, using current SDP");
15353
- this.handleICEGatheringTimeout();
15354
- }
15355
- }, this.iceGatheringTimeout);
15387
+ this.restartGatheringTimer();
15356
15388
  }
15357
15389
  });
15358
15390
  }
15391
+ /**
15392
+ * (Re)starts the gathering timeout and the give-up deadline from now. An
15393
+ * inbound call starts negotiating while it rings, so its answer calls this
15394
+ * to count both from when the answer's gathering actually starts.
15395
+ */
15396
+ restartGatheringTimer() {
15397
+ this.removeTimer("iceGatheringTimer");
15398
+ this.removeTimer("iceGatheringFailureTimer");
15399
+ this.iceGatheringTimer = setTimeout(() => {
15400
+ if (this.peerConnection.iceGatheringState !== "complete") {
15401
+ logger$21.warn("[ICEGatheringController] ICE gathering timeout, using current SDP");
15402
+ this.handleICEGatheringTimeout();
15403
+ }
15404
+ }, this.iceGatheringTimeout);
15405
+ this.iceGatheringFailureTimer = setTimeout(() => this.handleICEGatheringFailureTimeout(), Math.max(this.iceGatheringTimeout, DEFAULT_ICE_GATHERING_FAILURE_TIMEOUT_MS));
15406
+ }
15359
15407
  setupEventListeners() {
15360
15408
  this.peerConnection.removeEventListener("icecandidate", this.onicecandidateHandler);
15361
15409
  this.peerConnection.addEventListener("icecandidate", this.onicecandidateHandler);
@@ -15369,6 +15417,11 @@ var ICEGatheringController = class extends Destroyable {
15369
15417
  const sdp = this.peerConnection.localDescription?.sdp;
15370
15418
  return isValidLocalDescription(sdp ?? "");
15371
15419
  }
15420
+ /** A local description is set and carries no candidate of any type. */
15421
+ get hasNoCandidates() {
15422
+ const sdp = this.peerConnection.localDescription?.sdp;
15423
+ return sdp !== void 0 && !hasCandidates(sdp);
15424
+ }
15372
15425
  get isRelayOnly() {
15373
15426
  return this.relayOnly;
15374
15427
  }
@@ -15402,6 +15455,22 @@ var ICEGatheringController = class extends Destroyable {
15402
15455
  this.stopGathering();
15403
15456
  } else logger$21.debug("### ICE gathering timeout\n", this.peerConnection.localDescription?.sdp);
15404
15457
  }
15458
+ /**
15459
+ * Nothing at all was gathered by the give-up deadline. Without a candidate
15460
+ * the SDP is never sent, so end gathering when allowed rather than wait for
15461
+ * the browser. Any candidate, even a host one, keeps it gathering as before.
15462
+ * A gather that already ended has cleared this timer in stopGathering().
15463
+ */
15464
+ handleICEGatheringFailureTimeout() {
15465
+ this.removeTimer("iceGatheringFailureTimer");
15466
+ if (!this.hasNoCandidates || !this.endGatheringWithoutCandidates()) return;
15467
+ logger$21.warn("[ICEGatheringController] ICE gathering found no candidates, giving up");
15468
+ this._iceCandidatesState.next({
15469
+ state: "timeout",
15470
+ validSDP: false
15471
+ });
15472
+ this.stopGathering();
15473
+ }
15405
15474
  handleICECandidateTimeout() {
15406
15475
  if (this.iceCandidateTimer) this.removeTimer("iceCandidateTimer");
15407
15476
  logger$21.warn("[ICEGatheringController] ICE candidate timeout");
@@ -15434,6 +15503,7 @@ var ICEGatheringController = class extends Destroyable {
15434
15503
  clearAllTimers() {
15435
15504
  logger$21.debug("[ICEGatheringController] Clearing all timers");
15436
15505
  this.removeTimer("iceGatheringTimer");
15506
+ this.removeTimer("iceGatheringFailureTimer");
15437
15507
  this.removeTimer("iceCandidateTimer");
15438
15508
  }
15439
15509
  removeEventListeners() {
@@ -16085,8 +16155,9 @@ var RTCPeerConnectionController = class extends Destroyable {
16085
16155
  this.options = options;
16086
16156
  this.firstSDPExchangeCompleted = false;
16087
16157
  this.negotiationNeeded$ = this.createSubject();
16088
- this.localDescription$ = (0, import_cjs$16.defer)(() => (0, import_cjs$16.from)(this.init())).pipe((0, import_cjs$16.switchMap)(() => this.iceGatheringController.iceCandidatesState$.pipe((0, import_cjs$16.filter)((iceCandidateState) => !["new", "gathering"].includes(iceCandidateState)), (0, import_cjs$16.tap)(() => {
16158
+ this.localDescription$ = (0, import_cjs$16.defer)(() => (0, import_cjs$16.from)(this.init())).pipe((0, import_cjs$16.switchMap)(() => this.iceGatheringController.iceCandidatesState$.pipe((0, import_cjs$16.filter)((iceCandidateState) => iceCandidateState === "complete" || iceCandidateState === "timeout"), (0, import_cjs$16.tap)((iceCandidateState) => {
16089
16159
  this.negotiationEnded();
16160
+ this.failFirstExchangeWithoutCandidates(iceCandidateState);
16090
16161
  }), (0, import_cjs$16.filter)(() => this.shouldEmitLocalDescription), (0, import_cjs$16.map)(() => this.peerConnection?.localDescription), filterNull(), (0, import_cjs$16.tap)((desc) => {
16091
16162
  if (desc.type === "answer") this._type = "offer";
16092
16163
  }))), (0, import_cjs$16.shareReplay)(1), (0, import_cjs$16.takeUntil)(this.destroyed$));
@@ -16196,6 +16267,20 @@ var RTCPeerConnectionController = class extends Destroyable {
16196
16267
  if (!this._iceGatheringController) throw new DependencyError("ICEGatheringController is not initialized");
16197
16268
  return this._iceGatheringController;
16198
16269
  }
16270
+ /**
16271
+ * Gathering for the first offer or answer ended without a single candidate.
16272
+ * That SDP is never sent (see {@link shouldEmitLocalDescription}), and
16273
+ * nothing else would end the call, so report it. A later renegotiation is
16274
+ * left to call recovery.
16275
+ */
16276
+ failFirstExchangeWithoutCandidates(iceCandidateState) {
16277
+ const localDescription = this.peerConnection?.localDescription;
16278
+ if (this.firstSDPExchangeCompleted || !localDescription || hasCandidates(localDescription.sdp)) return;
16279
+ const error = new IceGatheringError(localDescription.type, iceCandidateState);
16280
+ logger$17.error(`[RTCPeerConnectionController] ICE gathering for the ${error.sdpType} ended (${error.gatheringState}) with no candidates`);
16281
+ logger$17.debug("[RTCPeerConnectionController] SDP without candidates:", localDescription.sdp);
16282
+ this._errors$.next(error);
16283
+ }
16199
16284
  get shouldEmitLocalDescription() {
16200
16285
  if (!this.peerConnection) return false;
16201
16286
  const { localDescription, signalingState } = this.peerConnection;
@@ -16440,7 +16525,8 @@ var RTCPeerConnectionController = class extends Destroyable {
16440
16525
  this._iceGatheringController = new ICEGatheringController(this.peerConnection, this.isNegotiating$, {
16441
16526
  iceCandidateTimeout: this.options.iceCandidateTimeout,
16442
16527
  iceGatheringTimeout: this.options.iceGatheringTimeout,
16443
- relayOnly: this.options.relayOnly
16528
+ relayOnly: this.options.relayOnly,
16529
+ endGatheringWithoutCandidates: () => !this.firstSDPExchangeCompleted
16444
16530
  });
16445
16531
  this.transceiverController = new TransceiverController({
16446
16532
  peerConnection: this.peerConnection,
@@ -16555,6 +16641,7 @@ var RTCPeerConnectionController = class extends Destroyable {
16555
16641
  }
16556
16642
  const { answerOptions } = this;
16557
16643
  logger$17.debug("[RTCPeerConnectionController] Creating inbound answer with options:", answerOptions);
16644
+ this.iceGatheringController.restartGatheringTimer();
16558
16645
  await this.createAnswer(answerOptions);
16559
16646
  }
16560
16647
  async handleOfferReceived() {
@@ -17771,7 +17858,8 @@ var WebRTCVertoManager = class extends VertoManager {
17771
17858
  this._rtcPeerConnectionsMap.set(rtcPeerConnController.id, rtcPeerConnController);
17772
17859
  this._rtcPeerConnections$.next(Array.from(this._rtcPeerConnectionsMap.values()));
17773
17860
  this.subscribeTo(rtcPeerConnController.errors$, (error) => {
17774
- this.reportLegError(error, rtcPeerConnController);
17861
+ const fatal = error instanceof IceGatheringError && this.isReattaching(rtcPeerConnController) ? false : void 0;
17862
+ this.reportLegError(error, rtcPeerConnController, { fatal });
17775
17863
  });
17776
17864
  if (options.initOffer) this.handleInboundAnswer(rtcPeerConnController);
17777
17865
  }
@@ -17909,6 +17997,10 @@ var WebRTCVertoManager = class extends VertoManager {
17909
17997
  }
17910
17998
  }
17911
17999
  }
18000
+ /** The leg's first exchange is a reattach of a call that already exists on the server. */
18001
+ isReattaching(rtcPeerConnectionController) {
18002
+ return rtcPeerConnectionController.propose === "main" && !rtcPeerConnectionController.firstSDPExchangeCompleted && this.webRtcCallSession.options.reattach === true;
18003
+ }
17912
18004
  dialogParams(rtcPeerConnectionController) {
17913
18005
  const memberId = rtcPeerConnectionController.memberId ?? this._selfId$.value ?? void 0;
17914
18006
  const attach = rtcPeerConnectionController.propose === "main" && !rtcPeerConnectionController.firstSDPExchangeCompleted && this.webRtcCallSession.options.reattach;
@@ -20115,6 +20207,7 @@ function inferCallErrorKind(error) {
20115
20207
  if (error instanceof JSONRPCError) return "signaling";
20116
20208
  if (error instanceof MediaTrackError) return "media";
20117
20209
  if (error instanceof MediaAccessError) return "media";
20210
+ if (error instanceof IceGatheringError) return "media";
20118
20211
  if (error instanceof WebSocketConnectionError || error instanceof TransportConnectionError) return "network";
20119
20212
  return "internal";
20120
20213
  }
@@ -21124,6 +21217,10 @@ var ClientSessionManager = class extends Destroyable {
21124
21217
  [`${callSession.id}`]: callSession,
21125
21218
  ...this._calls$.value
21126
21219
  });
21220
+ this.subscribeTo(callSession.errors$.pipe((0, import_cjs$7.filter)(({ error, leg }) => (leg ?? "main") === "main" && error instanceof IceGatheringError), (0, import_cjs$7.take)(1)), () => {
21221
+ logger$9.warn(`[Session] Reattach of ${callSession.id} gathered no candidates; dropping the local call`);
21222
+ callSession.destroy();
21223
+ });
21127
21224
  }
21128
21225
  async createOutboundCall(destination, options = {}) {
21129
21226
  const destinationURI = destination instanceof Address ? destination.defaultChannel : destination;
@@ -23266,7 +23363,7 @@ var SignalWire = class extends Destroyable {
23266
23363
  logger$1.warn("[SignalWire] Failed to initialize VisibilityController:", error);
23267
23364
  }
23268
23365
  try {
23269
- this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-dev-20261125185248" });
23366
+ this._diagnosticsCollector = new DiagnosticsCollector({ sdkVersion: "4.0.0-dev-20261126184919" });
23270
23367
  } catch (error) {
23271
23368
  logger$1.warn("[SignalWire] Failed to initialize DiagnosticsCollector:", error);
23272
23369
  }
@@ -23821,7 +23918,7 @@ var StaticCredentialProvider = class {
23821
23918
  /**
23822
23919
  * Library version from package.json, injected at build time.
23823
23920
  */
23824
- const version = "4.0.0-dev-20261125185248";
23921
+ const version = "4.0.0-dev-20261126184919";
23825
23922
  /**
23826
23923
  * Flag indicating the library has been loaded and is ready to use.
23827
23924
  * For UMD builds: `window.SignalWire.ready`
@@ -23843,7 +23940,7 @@ const ready = true;
23843
23940
  */
23844
23941
  const emitReadyEvent = () => {
23845
23942
  if (typeof window !== "undefined") {
23846
- const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-dev-20261125185248" } });
23943
+ const event = new CustomEvent("signalwire:js:ready", { detail: { version: "4.0.0-dev-20261126184919" } });
23847
23944
  window.dispatchEvent(event);
23848
23945
  }
23849
23946
  };
@@ -23877,6 +23974,7 @@ exports.CollectionFetchError = CollectionFetchError;
23877
23974
  exports.DPoPInitError = DPoPInitError;
23878
23975
  exports.DeviceTokenError = DeviceTokenError;
23879
23976
  exports.EmbedTokenCredentialProvider = EmbedTokenCredentialProvider;
23977
+ exports.IceGatheringError = IceGatheringError;
23880
23978
  exports.InvalidCredentialsError = InvalidCredentialsError;
23881
23979
  exports.MediaAccessError = MediaAccessError;
23882
23980
  exports.MediaTrackError = MediaTrackError;