@signalwire/js 4.0.0-dev-20260911135809 → 4.0.0-dev-20260911173516

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_operators = require('./operators-B3G5z2B1.cjs');
1
+ const require_operators = require('./operators-Cgz7QUVJ.cjs');
2
2
  let jwt_decode = require("jwt-decode");
3
3
  let rxjs = require("rxjs");
4
4
  let uuid = require("uuid");
@@ -3632,11 +3632,15 @@ var SelfParticipant = class extends Participant {
3632
3632
  /**
3633
3633
  * Starts sharing the local screen.
3634
3634
  *
3635
- * The call is unaffected when acquisition fails.
3635
+ * A call carries at most one screen share. Read `screenShareStatus` before
3636
+ * calling and treat `'starting'`/`'stopping'` as busy.
3636
3637
  *
3637
- * Known issue: stopping the share before its leg connects can leave this
3638
- * promise pending until the call ends, so do not gate UI on it.
3638
+ * The call is unaffected when acquisition fails.
3639
3639
  *
3640
+ * @throws {ScreenShareAlreadyActiveError} When this call is already
3641
+ * sharing a screen. Call {@link stopScreenShare} before starting another.
3642
+ * @throws {AuxiliaryLegCancelledError} When {@link stopScreenShare} removes
3643
+ * the share before its leg finishes connecting.
3640
3644
  * @throws The raw `getDisplayMedia` error. A dismissed picker or a
3641
3645
  * permission denial rejects with a `NotAllowedError` `DOMException` —
3642
3646
  * inspect `error.name` to tell benign cancels apart from real failures.
@@ -3645,7 +3649,8 @@ var SelfParticipant = class extends Participant {
3645
3649
  try {
3646
3650
  await this.vertoManager.addScreenMedia();
3647
3651
  } catch (error) {
3648
- logger$24.error("[Participant.startScreenShare] Screen share error:", error);
3652
+ if (error instanceof require_operators.AuxiliaryLegCancelledError) logger$24.debug("[Participant.startScreenShare] Screen share cancelled before connecting.");
3653
+ else logger$24.error("[Participant.startScreenShare] Screen share error:", error);
3649
3654
  throw error;
3650
3655
  }
3651
3656
  }
@@ -3666,9 +3671,8 @@ var SelfParticipant = class extends Participant {
3666
3671
  *
3667
3672
  * The call is unaffected when acquisition fails.
3668
3673
  *
3669
- * Known issue: removing the device before its leg connects can leave this
3670
- * promise pending until the call ends, so do not gate UI on it.
3671
- *
3674
+ * @throws {AuxiliaryLegCancelledError} When {@link removeAdditionalDevice}
3675
+ * removes the device before its leg finishes connecting.
3672
3676
  * @throws The raw `getUserMedia` error (e.g. `NotAllowedError` on
3673
3677
  * permission denial) — inspect `error.name` to decide how to react — or
3674
3678
  * `AuxiliaryLegTimeoutError` if the leg does not connect in time.
@@ -3677,7 +3681,8 @@ var SelfParticipant = class extends Participant {
3677
3681
  try {
3678
3682
  await this.vertoManager.addInputDevice(options);
3679
3683
  } catch (error) {
3680
- logger$24.error("[Participant.addAdditionalDevice] Additional device error:", error);
3684
+ if (error instanceof require_operators.AuxiliaryLegCancelledError) logger$24.debug("[Participant.addAdditionalDevice] Device removed before connecting.");
3685
+ else logger$24.error("[Participant.addAdditionalDevice] Additional device error:", error);
3681
3686
  throw error;
3682
3687
  }
3683
3688
  }
@@ -5470,6 +5475,9 @@ var RTCPeerConnectionController = class extends Destroyable {
5470
5475
  get propose() {
5471
5476
  return this.options.propose ?? "main";
5472
5477
  }
5478
+ get connectionState() {
5479
+ return this.peerConnection?.connectionState;
5480
+ }
5473
5481
  get isAdditionalDevice() {
5474
5482
  return this.propose === "additional-device";
5475
5483
  }
@@ -7090,6 +7098,7 @@ var WebRTCVertoManager = class extends VertoManager {
7090
7098
  }
7091
7099
  async initAdditionalPeerConnection(propose, options) {
7092
7100
  const isScreenShare = propose === "screenshare";
7101
+ if (isScreenShare && this._screenShareId && this._rtcPeerConnectionsMap.has(this._screenShareId)) throw new require_operators.ScreenShareAlreadyActiveError(this._screenShareId);
7093
7102
  let firstPeerConnectionError;
7094
7103
  let rtcPeerConnController = null;
7095
7104
  try {
@@ -7109,20 +7118,26 @@ var WebRTCVertoManager = class extends VertoManager {
7109
7118
  this.reportLegError(error, rtcPeerConnController);
7110
7119
  });
7111
7120
  const pc = rtcPeerConnController;
7112
- await (0, rxjs.firstValueFrom)((0, rxjs.merge)(pc.localMediaSettled$.pipe((0, rxjs.take)(1), (0, rxjs.switchMap)(() => pc.connectionState$.pipe((0, rxjs.filter)((state) => state === "connected"), (0, rxjs.take)(1), (0, rxjs.timeout)(require_operators.DEFAULT_AUX_LEG_CONNECT_TIMEOUT_MS)))), this.legError$(pc.id)).pipe((0, rxjs.takeUntil)(this.destroyed$)));
7121
+ await (0, rxjs.firstValueFrom)((0, rxjs.merge)(pc.localMediaSettled$.pipe((0, rxjs.take)(1), (0, rxjs.switchMap)(() => pc.connectionState$.pipe((0, rxjs.filter)((state) => state === "connected"), (0, rxjs.take)(1), (0, rxjs.timeout)(require_operators.DEFAULT_AUX_LEG_CONNECT_TIMEOUT_MS)))), this.legError$(pc.id)).pipe((0, rxjs.takeUntil)((0, rxjs.merge)(this.destroyed$, pc.destroyed$))));
7113
7122
  if (isScreenShare) this._screenShareStatus$.next("started");
7114
7123
  logger$16.info(`[WebRTCManager] Additional peer connection connected (${propose}).`);
7115
7124
  return rtcPeerConnController.id;
7116
7125
  } catch (error) {
7117
- logger$16.warn("[WebRTCManager] Error initializing additional peer connection:", error);
7118
- if (rtcPeerConnController) {
7126
+ const cancelled = error instanceof require_operators.AuxiliaryLegCancelledError;
7127
+ const aborted = error instanceof rxjs.EmptyError && !firstPeerConnectionError;
7128
+ if (!cancelled && !aborted) logger$16.warn("[WebRTCManager] Error initializing additional peer connection:", error);
7129
+ if (rtcPeerConnController && this._rtcPeerConnectionsMap.has(rtcPeerConnController.id)) {
7119
7130
  rtcPeerConnController.destroy();
7120
7131
  this._rtcPeerConnectionsMap.delete(rtcPeerConnController.id);
7121
7132
  this._rtcPeerConnections$.next(Array.from(this._rtcPeerConnectionsMap.values()));
7122
7133
  }
7123
7134
  if (isScreenShare) {
7124
- this._screenShareStatus$.next("none");
7125
7135
  this._screenShareId = void 0;
7136
+ this._screenShareStatus$.next("none");
7137
+ }
7138
+ if (cancelled) {
7139
+ logger$16.debug("[WebRTCManager] Additional peer connection removed before connecting.");
7140
+ throw error;
7126
7141
  }
7127
7142
  if (firstPeerConnectionError) throw firstPeerConnectionError instanceof require_operators.MediaAccessError && firstPeerConnectionError.originalError instanceof Error ? firstPeerConnectionError.originalError : firstPeerConnectionError;
7128
7143
  if (error instanceof rxjs.EmptyError) {
@@ -7146,7 +7161,10 @@ var WebRTCVertoManager = class extends VertoManager {
7146
7161
  if (removeTrack) return this.mainPeerConnection.stopTrackSender(removeTrack, { updateTransceiverDirection: true });
7147
7162
  }
7148
7163
  async removeScreenMedia() {
7149
- if (!["starting", "started"].includes(this._screenShareStatus$.value)) logger$16.warn("[WebRTCManager] No active screen share to stop.");
7164
+ if (!["starting", "started"].includes(this._screenShareStatus$.value)) {
7165
+ logger$16.warn("[WebRTCManager] No active screen share to stop.");
7166
+ return;
7167
+ }
7150
7168
  if (!this._screenShareId) {
7151
7169
  logger$16.debug("[WebRTCManager] No screen share peer connection found.");
7152
7170
  return;
@@ -7161,6 +7179,10 @@ var WebRTCVertoManager = class extends VertoManager {
7161
7179
  try {
7162
7180
  if (rtcPeerConnController) await this.executeVertoBye(rtcPeerConnController);
7163
7181
  } finally {
7182
+ if (rtcPeerConnController && rtcPeerConnController.connectionState !== "connected") this._legErrors$.next({
7183
+ legId: id,
7184
+ error: new require_operators.AuxiliaryLegCancelledError(rtcPeerConnController.propose)
7185
+ });
7164
7186
  rtcPeerConnController?.destroy();
7165
7187
  this._rtcPeerConnectionsMap.delete(id);
7166
7188
  this._rtcPeerConnections$.next(Array.from(this._rtcPeerConnectionsMap.values()));
@@ -12821,6 +12843,7 @@ emitReadyEvent();
12821
12843
 
12822
12844
  //#endregion
12823
12845
  exports.Address = Address;
12846
+ exports.AuxiliaryLegCancelledError = require_operators.AuxiliaryLegCancelledError;
12824
12847
  exports.AuxiliaryLegTimeoutError = require_operators.AuxiliaryLegTimeoutError;
12825
12848
  exports.CallCreateError = require_operators.CallCreateError;
12826
12849
  exports.CallNotReadyError = require_operators.CallNotReadyError;
@@ -12838,6 +12861,7 @@ exports.Participant = Participant;
12838
12861
  exports.ParticipantNotReadyError = require_operators.ParticipantNotReadyError;
12839
12862
  exports.PreflightError = require_operators.PreflightError;
12840
12863
  exports.RecoveryError = require_operators.RecoveryError;
12864
+ exports.ScreenShareAlreadyActiveError = require_operators.ScreenShareAlreadyActiveError;
12841
12865
  exports.SelfCapabilities = SelfCapabilities;
12842
12866
  exports.SelfParticipant = SelfParticipant;
12843
12867
  exports.SignalWire = SignalWire;