@signalwire/js 4.0.0-dev-20260413184938 → 4.0.0-dev-20260416174405

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
@@ -1125,9 +1125,9 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1125
1125
  var ObjectUnsubscribedError_1$1 = require_ObjectUnsubscribedError();
1126
1126
  var arrRemove_1$6 = require_arrRemove();
1127
1127
  var errorContext_1 = require_errorContext();
1128
- var Subject$3 = function(_super) {
1129
- __extends$13(Subject$4, _super);
1130
- function Subject$4() {
1128
+ var Subject$2 = function(_super) {
1129
+ __extends$13(Subject$3, _super);
1130
+ function Subject$3() {
1131
1131
  var _this = _super.call(this) || this;
1132
1132
  _this.closed = false;
1133
1133
  _this.currentObservers = null;
@@ -1137,15 +1137,15 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1137
1137
  _this.thrownError = null;
1138
1138
  return _this;
1139
1139
  }
1140
- Subject$4.prototype.lift = function(operator) {
1140
+ Subject$3.prototype.lift = function(operator) {
1141
1141
  var subject = new AnonymousSubject(this, this);
1142
1142
  subject.operator = operator;
1143
1143
  return subject;
1144
1144
  };
1145
- Subject$4.prototype._throwIfClosed = function() {
1145
+ Subject$3.prototype._throwIfClosed = function() {
1146
1146
  if (this.closed) throw new ObjectUnsubscribedError_1$1.ObjectUnsubscribedError();
1147
1147
  };
1148
- Subject$4.prototype.next = function(value) {
1148
+ Subject$3.prototype.next = function(value) {
1149
1149
  var _this = this;
1150
1150
  errorContext_1.errorContext(function() {
1151
1151
  var e_1, _a;
@@ -1166,7 +1166,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1166
1166
  }
1167
1167
  });
1168
1168
  };
1169
- Subject$4.prototype.error = function(err) {
1169
+ Subject$3.prototype.error = function(err) {
1170
1170
  var _this = this;
1171
1171
  errorContext_1.errorContext(function() {
1172
1172
  _this._throwIfClosed();
@@ -1178,7 +1178,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1178
1178
  }
1179
1179
  });
1180
1180
  };
1181
- Subject$4.prototype.complete = function() {
1181
+ Subject$3.prototype.complete = function() {
1182
1182
  var _this = this;
1183
1183
  errorContext_1.errorContext(function() {
1184
1184
  _this._throwIfClosed();
@@ -1189,11 +1189,11 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1189
1189
  }
1190
1190
  });
1191
1191
  };
1192
- Subject$4.prototype.unsubscribe = function() {
1192
+ Subject$3.prototype.unsubscribe = function() {
1193
1193
  this.isStopped = this.closed = true;
1194
1194
  this.observers = this.currentObservers = null;
1195
1195
  };
1196
- Object.defineProperty(Subject$4.prototype, "observed", {
1196
+ Object.defineProperty(Subject$3.prototype, "observed", {
1197
1197
  get: function() {
1198
1198
  var _a;
1199
1199
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
@@ -1201,16 +1201,16 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1201
1201
  enumerable: false,
1202
1202
  configurable: true
1203
1203
  });
1204
- Subject$4.prototype._trySubscribe = function(subscriber) {
1204
+ Subject$3.prototype._trySubscribe = function(subscriber) {
1205
1205
  this._throwIfClosed();
1206
1206
  return _super.prototype._trySubscribe.call(this, subscriber);
1207
1207
  };
1208
- Subject$4.prototype._subscribe = function(subscriber) {
1208
+ Subject$3.prototype._subscribe = function(subscriber) {
1209
1209
  this._throwIfClosed();
1210
1210
  this._checkFinalizedStatuses(subscriber);
1211
1211
  return this._innerSubscribe(subscriber);
1212
1212
  };
1213
- Subject$4.prototype._innerSubscribe = function(subscriber) {
1213
+ Subject$3.prototype._innerSubscribe = function(subscriber) {
1214
1214
  var _this = this;
1215
1215
  var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1216
1216
  if (hasError || isStopped) return Subscription_1$6.EMPTY_SUBSCRIPTION;
@@ -1221,22 +1221,22 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1221
1221
  arrRemove_1$6.arrRemove(observers, subscriber);
1222
1222
  });
1223
1223
  };
1224
- Subject$4.prototype._checkFinalizedStatuses = function(subscriber) {
1224
+ Subject$3.prototype._checkFinalizedStatuses = function(subscriber) {
1225
1225
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1226
1226
  if (hasError) subscriber.error(thrownError);
1227
1227
  else if (isStopped) subscriber.complete();
1228
1228
  };
1229
- Subject$4.prototype.asObservable = function() {
1229
+ Subject$3.prototype.asObservable = function() {
1230
1230
  var observable = new Observable_1$24.Observable();
1231
1231
  observable.source = this;
1232
1232
  return observable;
1233
1233
  };
1234
- Subject$4.create = function(destination, source) {
1234
+ Subject$3.create = function(destination, source) {
1235
1235
  return new AnonymousSubject(destination, source);
1236
1236
  };
1237
- return Subject$4;
1237
+ return Subject$3;
1238
1238
  }(Observable_1$24.Observable);
1239
- exports.Subject = Subject$3;
1239
+ exports.Subject = Subject$2;
1240
1240
  var AnonymousSubject = function(_super) {
1241
1241
  __extends$13(AnonymousSubject$1, _super);
1242
1242
  function AnonymousSubject$1(destination, source) {
@@ -1262,7 +1262,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1262
1262
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1$6.EMPTY_SUBSCRIPTION;
1263
1263
  };
1264
1264
  return AnonymousSubject$1;
1265
- }(Subject$3);
1265
+ }(Subject$2);
1266
1266
  exports.AnonymousSubject = AnonymousSubject;
1267
1267
  }));
1268
1268
 
@@ -3344,8 +3344,8 @@ var require_timeout = /* @__PURE__ */ __commonJSMin(((exports) => {
3344
3344
  };
3345
3345
  });
3346
3346
  function timeout$4(config, schedulerArg) {
3347
- var _a = isDate_1$2.isValidDate(config) ? { first: config } : typeof config === "number" ? { each: config } : config, first$1 = _a.first, each = _a.each, _b = _a.with, _with = _b === void 0 ? timeoutErrorFactory : _b, _c = _a.scheduler, scheduler = _c === void 0 ? schedulerArg !== null && schedulerArg !== void 0 ? schedulerArg : async_1$12.asyncScheduler : _c, _d = _a.meta, meta = _d === void 0 ? null : _d;
3348
- if (first$1 == null && each == null) throw new TypeError("No timeout provided.");
3347
+ var _a = isDate_1$2.isValidDate(config) ? { first: config } : typeof config === "number" ? { each: config } : config, first$2 = _a.first, each = _a.each, _b = _a.with, _with = _b === void 0 ? timeoutErrorFactory : _b, _c = _a.scheduler, scheduler = _c === void 0 ? schedulerArg !== null && schedulerArg !== void 0 ? schedulerArg : async_1$12.asyncScheduler : _c, _d = _a.meta, meta = _d === void 0 ? null : _d;
3348
+ if (first$2 == null && each == null) throw new TypeError("No timeout provided.");
3349
3349
  return lift_1$65.operate(function(source, subscriber) {
3350
3350
  var originalSourceSubscription;
3351
3351
  var timerSubscription;
@@ -3374,7 +3374,7 @@ var require_timeout = /* @__PURE__ */ __commonJSMin(((exports) => {
3374
3374
  if (!(timerSubscription === null || timerSubscription === void 0 ? void 0 : timerSubscription.closed)) timerSubscription === null || timerSubscription === void 0 || timerSubscription.unsubscribe();
3375
3375
  lastValue = null;
3376
3376
  }));
3377
- !seen && startTimer(first$1 != null ? typeof first$1 === "number" ? first$1 : +first$1 - scheduler.now() : each);
3377
+ !seen && startTimer(first$2 != null ? typeof first$2 === "number" ? first$2 : +first$2 - scheduler.now() : each);
3378
3378
  });
3379
3379
  }
3380
3380
  exports.timeout = timeout$4;
@@ -3390,7 +3390,7 @@ var require_map = /* @__PURE__ */ __commonJSMin(((exports) => {
3390
3390
  exports.map = void 0;
3391
3391
  var lift_1$64 = require_lift();
3392
3392
  var OperatorSubscriber_1$54 = require_OperatorSubscriber();
3393
- function map$19(project, thisArg) {
3393
+ function map$18(project, thisArg) {
3394
3394
  return lift_1$64.operate(function(source, subscriber) {
3395
3395
  var index = 0;
3396
3396
  source.subscribe(OperatorSubscriber_1$54.createOperatorSubscriber(subscriber, function(value) {
@@ -3398,7 +3398,7 @@ var require_map = /* @__PURE__ */ __commonJSMin(((exports) => {
3398
3398
  }));
3399
3399
  });
3400
3400
  }
3401
- exports.map = map$19;
3401
+ exports.map = map$18;
3402
3402
  }));
3403
3403
 
3404
3404
  //#endregion
@@ -5470,23 +5470,23 @@ var require_distinctUntilChanged = /* @__PURE__ */ __commonJSMin(((exports) => {
5470
5470
  var identity_1$10 = require_identity();
5471
5471
  var lift_1$42 = require_lift();
5472
5472
  var OperatorSubscriber_1$31 = require_OperatorSubscriber();
5473
- function distinctUntilChanged$7(comparator, keySelector) {
5473
+ function distinctUntilChanged$8(comparator, keySelector) {
5474
5474
  if (keySelector === void 0) keySelector = identity_1$10.identity;
5475
5475
  comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
5476
5476
  return lift_1$42.operate(function(source, subscriber) {
5477
5477
  var previousKey;
5478
- var first$1 = true;
5478
+ var first$2 = true;
5479
5479
  source.subscribe(OperatorSubscriber_1$31.createOperatorSubscriber(subscriber, function(value) {
5480
5480
  var currentKey = keySelector(value);
5481
- if (first$1 || !comparator(previousKey, currentKey)) {
5482
- first$1 = false;
5481
+ if (first$2 || !comparator(previousKey, currentKey)) {
5482
+ first$2 = false;
5483
5483
  previousKey = currentKey;
5484
5484
  subscriber.next(value);
5485
5485
  }
5486
5486
  }));
5487
5487
  });
5488
5488
  }
5489
- exports.distinctUntilChanged = distinctUntilChanged$7;
5489
+ exports.distinctUntilChanged = distinctUntilChanged$8;
5490
5490
  function defaultCompare(a, b) {
5491
5491
  return a === b;
5492
5492
  }
@@ -5767,7 +5767,7 @@ var require_first = /* @__PURE__ */ __commonJSMin(((exports) => {
5767
5767
  var defaultIfEmpty_1$3 = require_defaultIfEmpty();
5768
5768
  var throwIfEmpty_1$3 = require_throwIfEmpty();
5769
5769
  var identity_1$8 = require_identity();
5770
- function first(predicate, defaultValue) {
5770
+ function first$1(predicate, defaultValue) {
5771
5771
  var hasDefaultValue = arguments.length >= 2;
5772
5772
  return function(source) {
5773
5773
  return source.pipe(predicate ? filter_1$5.filter(function(v, i) {
@@ -5777,7 +5777,7 @@ var require_first = /* @__PURE__ */ __commonJSMin(((exports) => {
5777
5777
  }));
5778
5778
  };
5779
5779
  }
5780
- exports.first = first;
5780
+ exports.first = first$1;
5781
5781
  }));
5782
5782
 
5783
5783
  //#endregion
@@ -6825,12 +6825,12 @@ var require_skip = /* @__PURE__ */ __commonJSMin(((exports) => {
6825
6825
  Object.defineProperty(exports, "__esModule", { value: true });
6826
6826
  exports.skip = void 0;
6827
6827
  var filter_1$3 = require_filter();
6828
- function skip$4(count$1) {
6828
+ function skip$3(count$1) {
6829
6829
  return filter_1$3.filter(function(_, index) {
6830
6830
  return count$1 <= index;
6831
6831
  });
6832
6832
  }
6833
- exports.skip = skip$4;
6833
+ exports.skip = skip$3;
6834
6834
  }));
6835
6835
 
6836
6836
  //#endregion
@@ -7208,19 +7208,19 @@ var require_timeoutWith = /* @__PURE__ */ __commonJSMin(((exports) => {
7208
7208
  var isDate_1 = require_isDate();
7209
7209
  var timeout_1$2 = require_timeout();
7210
7210
  function timeoutWith(due, withObservable, scheduler) {
7211
- var first$1;
7211
+ var first$2;
7212
7212
  var each;
7213
7213
  var _with;
7214
7214
  scheduler = scheduler !== null && scheduler !== void 0 ? scheduler : async_1$2.async;
7215
- if (isDate_1.isValidDate(due)) first$1 = due;
7215
+ if (isDate_1.isValidDate(due)) first$2 = due;
7216
7216
  else if (typeof due === "number") each = due;
7217
7217
  if (withObservable) _with = function() {
7218
7218
  return withObservable;
7219
7219
  };
7220
7220
  else throw new TypeError("No observable provided to switch to");
7221
- if (first$1 == null && each == null) throw new TypeError("No timeout provided.");
7221
+ if (first$2 == null && each == null) throw new TypeError("No timeout provided.");
7222
7222
  return timeout_1$2.timeout({
7223
- first: first$1,
7223
+ first: first$2,
7224
7224
  each,
7225
7225
  scheduler,
7226
7226
  with: _with
@@ -8933,19 +8933,17 @@ var require_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
8933
8933
 
8934
8934
  //#endregion
8935
8935
  //#region src/behaviors/Destroyable.ts
8936
- var import_cjs$28 = require_cjs();
8936
+ var import_cjs$29 = require_cjs();
8937
8937
  var Destroyable = class {
8938
8938
  constructor() {
8939
8939
  this.subscriptions = [];
8940
8940
  this.subjects = [];
8941
- this._destroyed$ = new import_cjs$28.Subject();
8942
- this._change$ = new import_cjs$28.Subject();
8941
+ this._destroyed$ = new import_cjs$29.Subject();
8943
8942
  }
8944
8943
  destroy() {
8945
8944
  this._observableCache?.clear();
8946
8945
  this.subscriptions.forEach((sub) => sub.unsubscribe());
8947
8946
  this.subjects.forEach((subject) => subject.complete());
8948
- this._change$.complete();
8949
8947
  this._destroyed$.next();
8950
8948
  this._destroyed$.complete();
8951
8949
  }
@@ -8976,7 +8974,7 @@ var Destroyable = class {
8976
8974
  this._observableCache ??= /* @__PURE__ */ new Map();
8977
8975
  let cached = this._observableCache.get(publicKey);
8978
8976
  if (!cached) {
8979
- cached = factory().pipe((0, import_cjs$28.observeOn)(import_cjs$28.asapScheduler));
8977
+ cached = factory().pipe((0, import_cjs$29.observeOn)(import_cjs$29.asapScheduler));
8980
8978
  this._observableCache.set(publicKey, cached);
8981
8979
  }
8982
8980
  return cached;
@@ -8990,33 +8988,27 @@ var Destroyable = class {
8990
8988
  * Do NOT use for observables consumed internally by the SDK.
8991
8989
  */
8992
8990
  deferEmission(observable) {
8993
- return observable.pipe((0, import_cjs$28.observeOn)(import_cjs$28.asapScheduler));
8991
+ return observable.pipe((0, import_cjs$29.observeOn)(import_cjs$29.asapScheduler));
8994
8992
  }
8995
8993
  subscribeTo(observable, observerOrNext) {
8996
8994
  const subscription = observable.subscribe(observerOrNext);
8997
8995
  this.subscriptions.push(subscription);
8998
8996
  }
8999
8997
  createSubject() {
9000
- const subject = new import_cjs$28.Subject();
8998
+ const subject = new import_cjs$29.Subject();
9001
8999
  this.subjects.push(subject);
9002
- this.subscriptions.push(subject.pipe((0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9003
9000
  return subject;
9004
9001
  }
9005
9002
  createReplaySubject(bufferSize, windowTime$1) {
9006
- const subject = new import_cjs$28.ReplaySubject(bufferSize, windowTime$1);
9003
+ const subject = new import_cjs$29.ReplaySubject(bufferSize, windowTime$1);
9007
9004
  this.subjects.push(subject);
9008
- this.subscriptions.push(subject.pipe((0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9009
9005
  return subject;
9010
9006
  }
9011
9007
  createBehaviorSubject(initialValue) {
9012
- const subject = new import_cjs$28.BehaviorSubject(initialValue);
9008
+ const subject = new import_cjs$29.BehaviorSubject(initialValue);
9013
9009
  this.subjects.push(subject);
9014
- this.subscriptions.push(subject.pipe((0, import_cjs$28.skip)(1), (0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9015
9010
  return subject;
9016
9011
  }
9017
- get $() {
9018
- return this._change$.pipe((0, import_cjs$28.map)(() => this));
9019
- }
9020
9012
  /**
9021
9013
  * Observable that emits when the instance is destroyed
9022
9014
  */
@@ -9500,33 +9492,70 @@ const originalFactory = defaultLogger.methodFactory;
9500
9492
  defaultLogger.methodFactory = (methodName, logLevel, loggerName) => {
9501
9493
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
9502
9494
  return function(...args) {
9503
- args.unshift(datetime(), "-");
9504
- rawMethod.apply(void 0, args);
9495
+ const prefixed = [
9496
+ datetime(),
9497
+ "-",
9498
+ ...args
9499
+ ];
9500
+ rawMethod.apply(void 0, prefixed);
9505
9501
  };
9506
9502
  };
9507
- const defaultLoggerLevel = defaultLogger.levels.DEBUG;
9503
+ const defaultLoggerLevel = defaultLogger.levels.WARN;
9508
9504
  defaultLogger.setLevel(defaultLoggerLevel);
9509
- let userLogger;
9505
+ let userLogger = null;
9506
+ /** Replace the built-in logger with a custom implementation. Pass `null` to restore defaults. */
9507
+ const setLogger = (logger$30) => {
9508
+ userLogger = logger$30;
9509
+ };
9510
9510
  let debugOptions = {};
9511
+ /** Configure debug options (e.g., `{ logWsTraffic: true }`). */
9512
+ const setDebugOptions = (options) => {
9513
+ if (options == null) {
9514
+ debugOptions = {};
9515
+ return;
9516
+ }
9517
+ debugOptions = {
9518
+ ...debugOptions,
9519
+ ...options
9520
+ };
9521
+ };
9522
+ /**
9523
+ * Set the log level for the built-in logger.
9524
+ * Has no effect when a custom logger is set via `setLogger()`.
9525
+ */
9526
+ const setLogLevel = (level) => {
9527
+ defaultLogger.setLevel(level);
9528
+ };
9511
9529
  const getLoggerInstance = () => {
9512
9530
  return userLogger ?? defaultLogger;
9513
9531
  };
9514
9532
  const shouldStringify = (payload) => {
9515
- if ("method" in payload && payload.method === "signalwire.ping") return false;
9533
+ if (payload != null && typeof payload === "object" && "method" in payload) return payload.method !== "signalwire.ping";
9516
9534
  return true;
9517
9535
  };
9518
- const wsTraffic = ({ type, payload }) => {
9519
- const logger$30 = getLoggerInstance();
9520
- const { logWsTraffic } = debugOptions ?? {};
9536
+ const wsTraffic = (options) => {
9537
+ const { logWsTraffic } = debugOptions;
9521
9538
  if (!logWsTraffic) return;
9539
+ const loggerInstance = getLoggerInstance();
9540
+ let payload;
9541
+ if ("raw" in options) try {
9542
+ payload = JSON.parse(options.raw);
9543
+ } catch {
9544
+ loggerInstance.debug(`[WebSocket] ${options.type.toUpperCase()}: non-JSON message`);
9545
+ return;
9546
+ }
9547
+ else payload = options.payload;
9522
9548
  const msg = shouldStringify(payload) ? JSON.stringify(payload, null, 2) : payload;
9523
- return logger$30.debug(`${type.toUpperCase()}: \n`, msg, "\n");
9549
+ loggerInstance.debug(`${options.type.toUpperCase()}: \n`, msg, "\n");
9524
9550
  };
9525
9551
  const getLogger = () => {
9526
9552
  const logger$30 = getLoggerInstance();
9527
- return new Proxy(logger$30, { get(target, prop, receiver) {
9553
+ return new Proxy(logger$30, { get(_target, prop, _receiver) {
9528
9554
  if (prop === "wsTraffic") return wsTraffic;
9529
- return Reflect.get(target, prop, receiver);
9555
+ const instance = getLoggerInstance();
9556
+ const value = Reflect.get(instance, prop);
9557
+ if (typeof value === "function") return value.bind(instance);
9558
+ return value;
9530
9559
  } });
9531
9560
  };
9532
9561
 
@@ -9573,7 +9602,7 @@ const asyncRetry = async ({ asyncCallable, maxRetries: retries = DEFAULT_MAX_RET
9573
9602
 
9574
9603
  //#endregion
9575
9604
  //#region src/controllers/HTTPRequestController.ts
9576
- var import_cjs$27 = require_cjs();
9605
+ var import_cjs$28 = require_cjs();
9577
9606
  const logger$29 = getLogger();
9578
9607
  const GET_PARAMS = {
9579
9608
  method: "GET",
@@ -9609,9 +9638,9 @@ var HTTPRequestController = class HTTPRequestController {
9609
9638
  constructor(baseURL, getCredential, options = {}) {
9610
9639
  this.baseURL = baseURL;
9611
9640
  this.getCredential = getCredential;
9612
- this._responses$ = new import_cjs$27.Subject();
9613
- this._errors$ = new import_cjs$27.Subject();
9614
- this._status$ = new import_cjs$27.BehaviorSubject("idle");
9641
+ this._responses$ = new import_cjs$28.Subject();
9642
+ this._errors$ = new import_cjs$28.Subject();
9643
+ this._status$ = new import_cjs$28.BehaviorSubject("idle");
9615
9644
  this.maxRetries = options.maxRetries ?? HTTPRequestController.defaultMaxRetries;
9616
9645
  this.retryDelayMin = options.retryDelayMin ?? HTTPRequestController.defaultRetryDelayMinMs;
9617
9646
  this.retryDelayMax = options.retryDelayMax ?? HTTPRequestController.defaultRetryDelayMaxMs;
@@ -9871,6 +9900,14 @@ const DEVICE_TOKEN_REFRESH_BUFFER_MS = 3e4;
9871
9900
  const DEVICE_TOKEN_REFRESH_MAX_RETRIES = 3;
9872
9901
  /** Base delay in milliseconds for exponential backoff on refresh retry. */
9873
9902
  const DEVICE_TOKEN_REFRESH_RETRY_BASE_MS = 1e3;
9903
+ /** Maximum retry attempts for developer credential refresh on transient failure. */
9904
+ const CREDENTIAL_REFRESH_MAX_RETRIES = 5;
9905
+ /** Base delay in milliseconds for exponential backoff on credential refresh retry. */
9906
+ const CREDENTIAL_REFRESH_RETRY_BASE_MS = 1e3;
9907
+ /** Maximum delay in milliseconds for credential refresh backoff. */
9908
+ const CREDENTIAL_REFRESH_MAX_DELAY_MS = 3e4;
9909
+ /** Buffer in milliseconds before token expiry to trigger refresh. */
9910
+ const CREDENTIAL_REFRESH_BUFFER_MS = 5e3;
9874
9911
  /** JSON-RPC error code for requester validation failure (corrupted auth state). */
9875
9912
  const RPC_ERROR_REQUESTER_VALIDATION_FAILED = -32003;
9876
9913
  /** JSON-RPC error code for invalid params (e.g., missing authentication block). */
@@ -10637,9 +10674,23 @@ var ClientPreferences = class {
10637
10674
  }
10638
10675
  };
10639
10676
 
10677
+ //#endregion
10678
+ //#region src/utils/toError.ts
10679
+ /**
10680
+ * Normalizes an unknown caught value into a proper Error instance.
10681
+ *
10682
+ * In catch blocks, the caught value is `unknown` — it could be an Error,
10683
+ * string, number, or any other value. This utility ensures a consistent
10684
+ * Error object is produced.
10685
+ */
10686
+ function toError(value) {
10687
+ if (value instanceof Error) return value;
10688
+ return new Error(String(value));
10689
+ }
10690
+
10640
10691
  //#endregion
10641
10692
  //#region src/controllers/NavigatorDeviceController.ts
10642
- var import_cjs$26 = require_cjs();
10693
+ var import_cjs$27 = require_cjs();
10643
10694
  const logger$27 = getLogger();
10644
10695
  /** Maps a device kind to its storage key. */
10645
10696
  const DEVICE_STORAGE_KEYS = {
@@ -10699,17 +10750,17 @@ var NavigatorDeviceController = class extends Destroyable {
10699
10750
  return {};
10700
10751
  }
10701
10752
  get errors$() {
10702
- return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$26.takeUntil)(this.destroyed$)));
10753
+ return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$27.takeUntil)(this.destroyed$)));
10703
10754
  }
10704
10755
  /** Observable that emits when the SDK auto-switches a device. */
10705
10756
  get deviceRecovered$() {
10706
- return this._deviceRecovered$.asObservable().pipe((0, import_cjs$26.takeUntil)(this.destroyed$));
10757
+ return this._deviceRecovered$.asObservable().pipe((0, import_cjs$27.takeUntil)(this.destroyed$));
10707
10758
  }
10708
10759
  get videoInputDisabled$() {
10709
- return this.cachedObservable("videoInputDisabled$", () => this._videoInputDisabled$.asObservable().pipe((0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10760
+ return this.cachedObservable("videoInputDisabled$", () => this._videoInputDisabled$.asObservable().pipe((0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10710
10761
  }
10711
10762
  get audioInputDisabled$() {
10712
- return this.cachedObservable("audioInputDisabled$", () => this._audioInputDisabled$.asObservable().pipe((0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10763
+ return this.cachedObservable("audioInputDisabled$", () => this._audioInputDisabled$.asObservable().pipe((0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10713
10764
  }
10714
10765
  get videoInputDisabled() {
10715
10766
  return this._videoInputDisabled$.value;
@@ -10718,22 +10769,22 @@ var NavigatorDeviceController = class extends Destroyable {
10718
10769
  return this._audioInputDisabled$.value;
10719
10770
  }
10720
10771
  get audioInputDevices$() {
10721
- return this.cachedObservable("audioInputDevices$", () => this._devicesState$.pipe((0, import_cjs$26.map)((state) => state.audioinput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10772
+ return this.cachedObservable("audioInputDevices$", () => this._devicesState$.pipe((0, import_cjs$27.map)((state) => state.audioinput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10722
10773
  }
10723
10774
  get audioOutputDevices$() {
10724
- return this.cachedObservable("audioOutputDevices$", () => this._devicesState$.pipe((0, import_cjs$26.map)((state) => state.audiooutput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10775
+ return this.cachedObservable("audioOutputDevices$", () => this._devicesState$.pipe((0, import_cjs$27.map)((state) => state.audiooutput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10725
10776
  }
10726
10777
  get videoInputDevices$() {
10727
- return this.cachedObservable("videoInputDevices$", () => this._devicesState$.pipe((0, import_cjs$26.map)((state) => state.videoinput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10778
+ return this.cachedObservable("videoInputDevices$", () => this._devicesState$.pipe((0, import_cjs$27.map)((state) => state.videoinput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10728
10779
  }
10729
10780
  get selectedAudioInputDevice$() {
10730
- return this.cachedObservable("selectedAudioInputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$26.map)((state) => state.audioinput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$), (0, import_cjs$26.tap)((info) => logger$27.debug("[DeviceController] Selected audio input device changed:", info))));
10781
+ return this.cachedObservable("selectedAudioInputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$27.map)((state) => state.audioinput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$), (0, import_cjs$27.tap)((info) => logger$27.debug("[DeviceController] Selected audio input device changed:", info))));
10731
10782
  }
10732
10783
  get selectedAudioOutputDevice$() {
10733
- return this.cachedObservable("selectedAudioOutputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$26.map)((state) => state.audiooutput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$), (0, import_cjs$26.tap)((info) => logger$27.debug("[DeviceController] Selected audio output device changed:", info))));
10784
+ return this.cachedObservable("selectedAudioOutputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$27.map)((state) => state.audiooutput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$), (0, import_cjs$27.tap)((info) => logger$27.debug("[DeviceController] Selected audio output device changed:", info))));
10734
10785
  }
10735
10786
  get selectedVideoInputDevice$() {
10736
- return this.cachedObservable("selectedVideoInputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$26.map)((state) => state.videoinput), (0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$), (0, import_cjs$26.tap)((info) => logger$27.debug("[DeviceController] Selected video input device changed:", info))));
10787
+ return this.cachedObservable("selectedVideoInputDevice$", () => this._selectedDevicesState$.asObservable().pipe((0, import_cjs$27.map)((state) => state.videoinput), (0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$), (0, import_cjs$27.tap)((info) => logger$27.debug("[DeviceController] Selected video input device changed:", info))));
10737
10788
  }
10738
10789
  get selectedAudioInputDevice() {
10739
10790
  if (this._audioInputDisabled$.value) return null;
@@ -10829,7 +10880,7 @@ var NavigatorDeviceController = class extends Destroyable {
10829
10880
  }
10830
10881
  init() {
10831
10882
  this.loadPersistedDevices();
10832
- this.subscribeTo(this._devicesState$.pipe((0, import_cjs$26.debounceTime)(PreferencesContainer.instance.deviceDebounceTime)), (devicesState) => {
10883
+ this.subscribeTo(this._devicesState$.pipe((0, import_cjs$27.debounceTime)(PreferencesContainer.instance.deviceDebounceTime)), (devicesState) => {
10833
10884
  const currentSelected = this._selectedDevicesState$.value;
10834
10885
  const newAudioInput = this._audioInputDisabled$.value ? null : this.resolveDevice("audioinput", devicesState.audioinput, currentSelected.audioinput, PreferencesContainer.instance.preferredAudioInput);
10835
10886
  const newAudioOutput = this.resolveDevice("audiooutput", devicesState.audiooutput, currentSelected.audiooutput, PreferencesContainer.instance.preferredAudioOutput);
@@ -10951,7 +11002,7 @@ var NavigatorDeviceController = class extends Destroyable {
10951
11002
  enableDeviceMonitoring() {
10952
11003
  this.disableDeviceMonitoring();
10953
11004
  this.webRTCApiProvider.mediaDevices.addEventListener("devicechange", this.deviceChangeHandler);
10954
- if (PreferencesContainer.instance.devicePollingInterval > 0) this._devicesPoolingSubscription = (0, import_cjs$26.interval)(PreferencesContainer.instance.devicePollingInterval).subscribe(() => {
11005
+ if (PreferencesContainer.instance.devicePollingInterval > 0) this._devicesPoolingSubscription = (0, import_cjs$27.interval)(PreferencesContainer.instance.devicePollingInterval).subscribe(() => {
10955
11006
  logger$27.debug("[DeviceController] Polling devices due to interval");
10956
11007
  this.enumerateDevices();
10957
11008
  });
@@ -10985,7 +11036,7 @@ var NavigatorDeviceController = class extends Destroyable {
10985
11036
  });
10986
11037
  } catch (error) {
10987
11038
  logger$27.error("[DeviceController] Failed to enumerate devices:", error);
10988
- this._errors$.next(error);
11039
+ this._errors$.next(toError(error));
10989
11040
  }
10990
11041
  }
10991
11042
  async getDeviceCapabilities(deviceInfo) {
@@ -11001,7 +11052,7 @@ var NavigatorDeviceController = class extends Destroyable {
11001
11052
  return capabilities;
11002
11053
  } catch (error) {
11003
11054
  logger$27.error("[DeviceController] Failed to get device capabilities:", error);
11004
- this._errors$.next(error);
11055
+ this._errors$.next(toError(error));
11005
11056
  throw error;
11006
11057
  }
11007
11058
  }
@@ -11519,7 +11570,7 @@ var CryptoController = class {
11519
11570
 
11520
11571
  //#endregion
11521
11572
  //#region src/controllers/NetworkMonitor.ts
11522
- var import_cjs$25 = require_cjs();
11573
+ var import_cjs$26 = require_cjs();
11523
11574
  const logger$25 = getLogger();
11524
11575
  /**
11525
11576
  * Safely check whether we are running in a browser environment
@@ -11563,13 +11614,13 @@ var NetworkMonitor = class extends Destroyable {
11563
11614
  this.attachListeners();
11564
11615
  }
11565
11616
  get isOnline$() {
11566
- return this._isOnline$.asObservable().pipe((0, import_cjs$25.takeUntil)(this._destroyed$));
11617
+ return this._isOnline$.asObservable().pipe((0, import_cjs$26.takeUntil)(this._destroyed$));
11567
11618
  }
11568
11619
  get isOnline() {
11569
11620
  return this._isOnline$.value;
11570
11621
  }
11571
11622
  get networkChange$() {
11572
- return this._networkChange$.asObservable().pipe((0, import_cjs$25.takeUntil)(this._destroyed$));
11623
+ return this._networkChange$.asObservable().pipe((0, import_cjs$26.takeUntil)(this._destroyed$));
11573
11624
  }
11574
11625
  destroy() {
11575
11626
  this.removeListeners();
@@ -11732,7 +11783,7 @@ function getNavigatorMediaDevices() {
11732
11783
 
11733
11784
  //#endregion
11734
11785
  //#region src/controllers/PreflightRunner.ts
11735
- var import_cjs$24 = require_cjs();
11786
+ var import_cjs$25 = require_cjs();
11736
11787
  const logger$24 = getLogger();
11737
11788
  const DEFAULT_MEDIA_TEST_DURATION_S = 10;
11738
11789
  const ICE_GATHERING_TIMEOUT_MS = 1e4;
@@ -11901,7 +11952,7 @@ var PreflightRunner = class extends Destroyable {
11901
11952
  audio: true,
11902
11953
  video: false
11903
11954
  });
11904
- await (0, import_cjs$24.firstValueFrom)(call.status$.pipe((0, import_cjs$24.filter)((s) => s === "connected"), (0, import_cjs$24.take)(1), (0, import_cjs$24.timeout)(SIGNALING_RTT_TIMEOUT_MS)));
11955
+ await (0, import_cjs$25.firstValueFrom)(call.status$.pipe((0, import_cjs$25.filter)((s) => s === "connected"), (0, import_cjs$25.take)(1), (0, import_cjs$25.timeout)(SIGNALING_RTT_TIMEOUT_MS)));
11905
11956
  const durationMs = this._options.duration * 1e3;
11906
11957
  await new Promise((resolve) => setTimeout(resolve, durationMs));
11907
11958
  const metrics = call.networkMetrics;
@@ -11930,7 +11981,7 @@ var PreflightRunner = class extends Destroyable {
11930
11981
 
11931
11982
  //#endregion
11932
11983
  //#region src/controllers/VisibilityController.ts
11933
- var import_cjs$23 = require_cjs();
11984
+ var import_cjs$24 = require_cjs();
11934
11985
  const logger$23 = getLogger();
11935
11986
  /**
11936
11987
  * Checks whether the document visibility API is available.
@@ -11976,7 +12027,7 @@ var VisibilityController = class extends Destroyable {
11976
12027
  * Emits 'visible' or 'hidden'. Always starts with the current state.
11977
12028
  */
11978
12029
  get visibility$() {
11979
- return this._visibility$.pipe((0, import_cjs$23.takeUntil)(this._destroyed$));
12030
+ return this._visibility$.pipe((0, import_cjs$24.takeUntil)(this._destroyed$));
11980
12031
  }
11981
12032
  /**
11982
12033
  * The current visibility state value.
@@ -11989,7 +12040,7 @@ var VisibilityController = class extends Destroyable {
11989
12040
  * Each event includes the previous state, new state, and timestamp.
11990
12041
  */
11991
12042
  get visibilityChange$() {
11992
- return this._visibilityChange$.pipe((0, import_cjs$23.takeUntil)(this._destroyed$));
12043
+ return this._visibilityChange$.pipe((0, import_cjs$24.takeUntil)(this._destroyed$));
11993
12044
  }
11994
12045
  destroy() {
11995
12046
  if (this._hasVisibilityApi) {
@@ -12021,13 +12072,13 @@ var VisibilityController = class extends Destroyable {
12021
12072
 
12022
12073
  //#endregion
12023
12074
  //#region src/behaviors/Fetchable.ts
12024
- var import_cjs$22 = require_cjs();
12075
+ var import_cjs$23 = require_cjs();
12025
12076
  var Fetchable = class extends Destroyable {
12026
12077
  constructor(fromPath, http) {
12027
12078
  super();
12028
12079
  this.fromPath = fromPath;
12029
12080
  this.http = http;
12030
- this.fetched$ = (0, import_cjs$22.defer)(() => (0, import_cjs$22.from)(this.fetch())).pipe((0, import_cjs$22.shareReplay)(1), (0, import_cjs$22.takeUntil)(this.destroyed$));
12081
+ this.fetched$ = (0, import_cjs$23.defer)(() => (0, import_cjs$23.from)(this.fetch())).pipe((0, import_cjs$23.shareReplay)(1), (0, import_cjs$23.takeUntil)(this.destroyed$));
12031
12082
  }
12032
12083
  async fetch() {
12033
12084
  const response = await this.http.request({
@@ -13260,24 +13311,6 @@ var require_operators = /* @__PURE__ */ __commonJSMin(((exports) => {
13260
13311
  });
13261
13312
  }));
13262
13313
 
13263
- //#endregion
13264
- //#region src/operators/filterNull.ts
13265
- var import_operators$1 = require_operators();
13266
- var import_cjs$21 = require_cjs();
13267
- /**
13268
- * RxJS operator that filters out `null` and `undefined` values with type narrowing.
13269
- *
13270
- * @example
13271
- * ```ts
13272
- * source$.pipe(filterNull()).subscribe(value => {
13273
- * // value is guaranteed non-null
13274
- * });
13275
- * ```
13276
- */
13277
- function filterNull() {
13278
- return (0, import_cjs$21.filter)((value) => value != null);
13279
- }
13280
-
13281
13314
  //#endregion
13282
13315
  //#region src/core/capabilities/types.ts
13283
13316
  /**
@@ -13403,7 +13436,7 @@ function computeCapabilities(capabilities) {
13403
13436
 
13404
13437
  //#endregion
13405
13438
  //#region src/core/capabilities/SelfCapabilities.ts
13406
- var import_cjs$20 = require_cjs();
13439
+ var import_cjs$22 = require_cjs();
13407
13440
  /**
13408
13441
  * SelfCapabilities manages the capability state for the self participant.
13409
13442
  *
@@ -13439,7 +13472,7 @@ var SelfCapabilities = class extends Destroyable {
13439
13472
  }
13440
13473
  /** Observable for self member capabilities */
13441
13474
  get self$() {
13442
- return this.cachedObservable("self$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.self), (0, import_cjs$20.distinctUntilChanged)()));
13475
+ return this.cachedObservable("self$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.self), (0, import_cjs$22.distinctUntilChanged)()));
13443
13476
  }
13444
13477
  /** Current self member capabilities */
13445
13478
  get self() {
@@ -13447,7 +13480,7 @@ var SelfCapabilities = class extends Destroyable {
13447
13480
  }
13448
13481
  /** Observable for other member capabilities */
13449
13482
  get member$() {
13450
- return this.cachedObservable("member$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.member), (0, import_cjs$20.distinctUntilChanged)()));
13483
+ return this.cachedObservable("member$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.member), (0, import_cjs$22.distinctUntilChanged)()));
13451
13484
  }
13452
13485
  /** Current other member capabilities */
13453
13486
  get member() {
@@ -13455,7 +13488,7 @@ var SelfCapabilities = class extends Destroyable {
13455
13488
  }
13456
13489
  /** Observable for end call capability */
13457
13490
  get end$() {
13458
- return this.cachedObservable("end$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.end), (0, import_cjs$20.distinctUntilChanged)()));
13491
+ return this.cachedObservable("end$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.end), (0, import_cjs$22.distinctUntilChanged)()));
13459
13492
  }
13460
13493
  /** Current end call capability */
13461
13494
  get end() {
@@ -13463,7 +13496,7 @@ var SelfCapabilities = class extends Destroyable {
13463
13496
  }
13464
13497
  /** Observable for set layout capability */
13465
13498
  get setLayout$() {
13466
- return this.cachedObservable("setLayout$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.setLayout), (0, import_cjs$20.distinctUntilChanged)()));
13499
+ return this.cachedObservable("setLayout$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.setLayout), (0, import_cjs$22.distinctUntilChanged)()));
13467
13500
  }
13468
13501
  /** Current set layout capability */
13469
13502
  get setLayout() {
@@ -13471,7 +13504,7 @@ var SelfCapabilities = class extends Destroyable {
13471
13504
  }
13472
13505
  /** Observable for send digit capability */
13473
13506
  get sendDigit$() {
13474
- return this.cachedObservable("sendDigit$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.sendDigit), (0, import_cjs$20.distinctUntilChanged)()));
13507
+ return this.cachedObservable("sendDigit$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.sendDigit), (0, import_cjs$22.distinctUntilChanged)()));
13475
13508
  }
13476
13509
  /** Current send digit capability */
13477
13510
  get sendDigit() {
@@ -13479,7 +13512,7 @@ var SelfCapabilities = class extends Destroyable {
13479
13512
  }
13480
13513
  /** Observable for vmuted hide capability */
13481
13514
  get vmutedHide$() {
13482
- return this.cachedObservable("vmutedHide$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.vmutedHide), (0, import_cjs$20.distinctUntilChanged)()));
13515
+ return this.cachedObservable("vmutedHide$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.vmutedHide), (0, import_cjs$22.distinctUntilChanged)()));
13483
13516
  }
13484
13517
  /** Current vmuted hide capability */
13485
13518
  get vmutedHide() {
@@ -13487,7 +13520,7 @@ var SelfCapabilities = class extends Destroyable {
13487
13520
  }
13488
13521
  /** Observable for lock capability */
13489
13522
  get lock$() {
13490
- return this.cachedObservable("lock$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.lock), (0, import_cjs$20.distinctUntilChanged)()));
13523
+ return this.cachedObservable("lock$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.lock), (0, import_cjs$22.distinctUntilChanged)()));
13491
13524
  }
13492
13525
  /** Current lock capability */
13493
13526
  get lock() {
@@ -13495,7 +13528,7 @@ var SelfCapabilities = class extends Destroyable {
13495
13528
  }
13496
13529
  /** Observable for device capability */
13497
13530
  get device$() {
13498
- return this.cachedObservable("device$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.device), (0, import_cjs$20.distinctUntilChanged)()));
13531
+ return this.cachedObservable("device$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.device), (0, import_cjs$22.distinctUntilChanged)()));
13499
13532
  }
13500
13533
  /** Current device capability */
13501
13534
  get device() {
@@ -13503,7 +13536,7 @@ var SelfCapabilities = class extends Destroyable {
13503
13536
  }
13504
13537
  /** Observable for screenshare capability */
13505
13538
  get screenshare$() {
13506
- return this.cachedObservable("screenshare$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.screenshare), (0, import_cjs$20.distinctUntilChanged)()));
13539
+ return this.cachedObservable("screenshare$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.screenshare), (0, import_cjs$22.distinctUntilChanged)()));
13507
13540
  }
13508
13541
  /** Current screenshare capability */
13509
13542
  get screenshare() {
@@ -13521,6 +13554,7 @@ var SelfCapabilities = class extends Destroyable {
13521
13554
 
13522
13555
  //#endregion
13523
13556
  //#region src/core/RPCMessages/utils.ts
13557
+ var import_operators$1 = require_operators();
13524
13558
  function toggleDeafMethod(is) {
13525
13559
  return is ? "call.undeaf" : "call.deaf";
13526
13560
  }
@@ -13556,83 +13590,83 @@ var Participant = class extends Destroyable {
13556
13590
  }
13557
13591
  /** Observable of the participant's display name. */
13558
13592
  get name$() {
13559
- return this.cachedObservable("name$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.name), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13593
+ return this.cachedObservable("name$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.name), (0, import_operators$1.distinctUntilChanged)()));
13560
13594
  }
13561
13595
  /** Observable of the participant type (e.g. `'member'`, `'screen'`). */
13562
13596
  get type$() {
13563
- return this.cachedObservable("type$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.type), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13597
+ return this.cachedObservable("type$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.type), (0, import_operators$1.distinctUntilChanged)()));
13564
13598
  }
13565
13599
  /** Observable indicating whether the participant has raised their hand. */
13566
13600
  get handraised$() {
13567
- return this.cachedObservable("handraised$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.handraised), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13601
+ return this.cachedObservable("handraised$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.handraised), (0, import_operators$1.distinctUntilChanged)()));
13568
13602
  }
13569
13603
  /** Observable indicating whether the participant is visible in the layout. */
13570
13604
  get visible$() {
13571
- return this.cachedObservable("visible$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.visible), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13605
+ return this.cachedObservable("visible$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.visible), (0, import_operators$1.distinctUntilChanged)()));
13572
13606
  }
13573
13607
  /** Observable indicating whether the participant's audio is muted. */
13574
13608
  get audioMuted$() {
13575
- return this.cachedObservable("audioMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.audio_muted), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13609
+ return this.cachedObservable("audioMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.audio_muted), (0, import_operators$1.distinctUntilChanged)()));
13576
13610
  }
13577
13611
  /** Observable indicating whether the participant's video is muted. */
13578
13612
  get videoMuted$() {
13579
- return this.cachedObservable("videoMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.video_muted), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13613
+ return this.cachedObservable("videoMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.video_muted), (0, import_operators$1.distinctUntilChanged)()));
13580
13614
  }
13581
13615
  /** Observable indicating whether the participant is deafened. */
13582
13616
  get deaf$() {
13583
- return this.cachedObservable("deaf$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.deaf), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13617
+ return this.cachedObservable("deaf$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.deaf), (0, import_operators$1.distinctUntilChanged)()));
13584
13618
  }
13585
13619
  /** Observable of the participant's microphone input volume. */
13586
13620
  get inputVolume$() {
13587
- return this.cachedObservable("inputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_volume), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13621
+ return this.cachedObservable("inputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_volume), (0, import_operators$1.distinctUntilChanged)()));
13588
13622
  }
13589
13623
  /** Observable of the participant's speaker output volume. */
13590
13624
  get outputVolume$() {
13591
- return this.cachedObservable("outputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.output_volume), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13625
+ return this.cachedObservable("outputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.output_volume), (0, import_operators$1.distinctUntilChanged)()));
13592
13626
  }
13593
13627
  /** Observable of the microphone input sensitivity level. */
13594
13628
  get inputSensitivity$() {
13595
- return this.cachedObservable("inputSensitivity$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_sensitivity), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13629
+ return this.cachedObservable("inputSensitivity$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_sensitivity), (0, import_operators$1.distinctUntilChanged)()));
13596
13630
  }
13597
13631
  /** Observable indicating whether echo cancellation is enabled. */
13598
13632
  get echoCancellation$() {
13599
- return this.cachedObservable("echoCancellation$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.echo_cancellation), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13633
+ return this.cachedObservable("echoCancellation$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.echo_cancellation), (0, import_operators$1.distinctUntilChanged)()));
13600
13634
  }
13601
13635
  /** Observable indicating whether auto-gain control is enabled. */
13602
13636
  get autoGain$() {
13603
- return this.cachedObservable("autoGain$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.auto_gain), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13637
+ return this.cachedObservable("autoGain$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.auto_gain), (0, import_operators$1.distinctUntilChanged)()));
13604
13638
  }
13605
13639
  /** Observable indicating whether noise suppression is enabled. */
13606
13640
  get noiseSuppression$() {
13607
- return this.cachedObservable("noiseSuppression$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.noise_suppression), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13641
+ return this.cachedObservable("noiseSuppression$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.noise_suppression), (0, import_operators$1.distinctUntilChanged)()));
13608
13642
  }
13609
13643
  /** Observable indicating whether low-bitrate mode is active. */
13610
13644
  get lowbitrate$() {
13611
- return this.cachedObservable("lowbitrate$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.lowbitrate), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13645
+ return this.cachedObservable("lowbitrate$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.lowbitrate), (0, import_operators$1.distinctUntilChanged)()));
13612
13646
  }
13613
13647
  /** Observable indicating whether noise reduction is active. */
13614
13648
  get denoise$() {
13615
- return this.cachedObservable("denoise$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.denoise), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13649
+ return this.cachedObservable("denoise$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.denoise), (0, import_operators$1.distinctUntilChanged)()));
13616
13650
  }
13617
13651
  /** Observable of custom metadata for this participant. */
13618
13652
  get meta$() {
13619
- return this.cachedObservable("meta$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.meta), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13653
+ return this.cachedObservable("meta$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.meta), (0, import_operators$1.distinctUntilChanged)()));
13620
13654
  }
13621
13655
  /** Observable of the participant's subscriber ID. */
13622
13656
  get subscriberId$() {
13623
- return this.cachedObservable("subscriberId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.subscriber_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13657
+ return this.cachedObservable("subscriberId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.subscriber_id), (0, import_operators$1.distinctUntilChanged)()));
13624
13658
  }
13625
13659
  /** Observable of the participant's address ID. */
13626
13660
  get addressId$() {
13627
- return this.cachedObservable("addressId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.address_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13661
+ return this.cachedObservable("addressId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.address_id), (0, import_operators$1.distinctUntilChanged)()));
13628
13662
  }
13629
13663
  /** Observable of the server node ID for this participant. */
13630
13664
  get nodeId$() {
13631
- return this.cachedObservable("nodeId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.node_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13665
+ return this.cachedObservable("nodeId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.node_id), (0, import_operators$1.distinctUntilChanged)()));
13632
13666
  }
13633
13667
  /** Observable indicating whether the participant is currently speaking. */
13634
13668
  get isTalking$() {
13635
- return this.cachedObservable("isTalking$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.talking), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13669
+ return this.cachedObservable("isTalking$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.talking), (0, import_operators$1.distinctUntilChanged)()));
13636
13670
  }
13637
13671
  /** Whether the participant is currently speaking. */
13638
13672
  get isTalking() {
@@ -13640,7 +13674,7 @@ var Participant = class extends Destroyable {
13640
13674
  }
13641
13675
  /** Observable of the participant's layout position. */
13642
13676
  get position$() {
13643
- return this.cachedObservable("position$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.position), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13677
+ return this.cachedObservable("position$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.position), (0, import_operators$1.distinctUntilChanged)()));
13644
13678
  }
13645
13679
  /** Current layout position. */
13646
13680
  get position() {
@@ -14136,6 +14170,23 @@ function isLayoutChangedPayload(value) {
14136
14170
  return isObject(value) && hasProperty(value, "room_id") && hasProperty(value, "room_session_id") && hasProperty(value, "layout");
14137
14171
  }
14138
14172
 
14173
+ //#endregion
14174
+ //#region src/operators/filterNull.ts
14175
+ var import_cjs$21 = require_cjs();
14176
+ /**
14177
+ * RxJS operator that filters out `null` and `undefined` values with type narrowing.
14178
+ *
14179
+ * @example
14180
+ * ```ts
14181
+ * source$.pipe(filterNull()).subscribe(value => {
14182
+ * // value is guaranteed non-null
14183
+ * });
14184
+ * ```
14185
+ */
14186
+ function filterNull() {
14187
+ return (0, import_cjs$21.filter)((value) => value != null);
14188
+ }
14189
+
14139
14190
  //#endregion
14140
14191
  //#region src/utils/getValueFrom.ts
14141
14192
  const getValueFrom = (obj, path, defaultValue) => {
@@ -14148,7 +14199,7 @@ const getValueFrom = (obj, path, defaultValue) => {
14148
14199
 
14149
14200
  //#endregion
14150
14201
  //#region src/operators/filterEventAs.ts
14151
- var import_cjs$19 = require_cjs();
14202
+ var import_cjs$20 = require_cjs();
14152
14203
  var import_operators = require_operators();
14153
14204
  /**
14154
14205
  * RxJS operator that filters events based on a predicate and maps matching events.
@@ -14182,7 +14233,7 @@ var import_operators = require_operators();
14182
14233
  * ```
14183
14234
  */
14184
14235
  function ifIsMap(predicate, mapFn) {
14185
- return (0, import_cjs$19.pipe)((0, import_operators.filter)(predicate), (0, import_operators.map)(mapFn));
14236
+ return (0, import_cjs$20.pipe)((0, import_operators.filter)(predicate), (0, import_operators.map)(mapFn));
14186
14237
  }
14187
14238
  /**
14188
14239
  * Generic RxJS operator that filters events using a type guard and extracts a property.
@@ -14224,21 +14275,21 @@ function ifIsMap(predicate, mapFn) {
14224
14275
  * ```
14225
14276
  */
14226
14277
  function filterAs(predicate, resultPath) {
14227
- return (0, import_cjs$19.pipe)(ifIsMap(predicate, (event) => {
14278
+ return (0, import_cjs$20.pipe)(ifIsMap(predicate, (event) => {
14228
14279
  return getValueFrom(event, resultPath);
14229
14280
  }), (0, import_operators.filter)((value) => value !== void 0));
14230
14281
  }
14231
14282
 
14232
14283
  //#endregion
14233
14284
  //#region src/operators/throwOnRPCError.ts
14234
- var import_cjs$18 = require_cjs();
14285
+ var import_cjs$19 = require_cjs();
14235
14286
  const logger$20 = getLogger();
14236
14287
  /**
14237
14288
  * RxJS operator that throws a {@link JSONRPCError} when the RPC response contains an error.
14238
14289
  * Passes successful responses through unchanged.
14239
14290
  */
14240
14291
  function throwOnRPCError() {
14241
- return (0, import_cjs$18.map)((response) => {
14292
+ return (0, import_cjs$19.map)((response) => {
14242
14293
  if (response.error) {
14243
14294
  logger$20.error("[throwOnRPCError] RPC error response:", {
14244
14295
  code: response.error.code,
@@ -14254,7 +14305,7 @@ function throwOnRPCError() {
14254
14305
 
14255
14306
  //#endregion
14256
14307
  //#region src/managers/CallEventsManager.ts
14257
- var import_cjs$17 = require_cjs();
14308
+ var import_cjs$18 = require_cjs();
14258
14309
  const logger$19 = getLogger();
14259
14310
  const initialSessionState = {};
14260
14311
  /** @internal */
@@ -14271,7 +14322,7 @@ var CallEventsManager = class extends Destroyable {
14271
14322
  this.initSubscriptions();
14272
14323
  }
14273
14324
  get participants$() {
14274
- return this.cachedObservable("participants$", () => this._participants$.asObservable().pipe((0, import_cjs$17.map)((participantsRecord) => Object.values(participantsRecord))));
14325
+ return this.cachedObservable("participants$", () => this._participants$.asObservable().pipe((0, import_cjs$18.map)((participantsRecord) => Object.values(participantsRecord))));
14275
14326
  }
14276
14327
  get participants() {
14277
14328
  return Object.values(this._participants$.value);
@@ -14289,40 +14340,40 @@ var CallEventsManager = class extends Destroyable {
14289
14340
  return this.callIds.has(callId);
14290
14341
  }
14291
14342
  get recording$() {
14292
- return this.cachedObservable("recording$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.recording), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14343
+ return this.cachedObservable("recording$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.recording), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14293
14344
  }
14294
14345
  get recordings$() {
14295
- return this.cachedObservable("recordings$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.recordings), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14346
+ return this.cachedObservable("recordings$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.recordings), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14296
14347
  }
14297
14348
  get streaming$() {
14298
- return this.cachedObservable("streaming$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.streaming), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14349
+ return this.cachedObservable("streaming$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.streaming), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14299
14350
  }
14300
14351
  get streams$() {
14301
- return this.cachedObservable("streams$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.streams), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14352
+ return this.cachedObservable("streams$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.streams), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14302
14353
  }
14303
14354
  get playbacks$() {
14304
- return this.cachedObservable("playbacks$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.playbacks), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14355
+ return this.cachedObservable("playbacks$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.playbacks), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14305
14356
  }
14306
14357
  get raiseHandPriority$() {
14307
- return this.cachedObservable("raiseHandPriority$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.prioritize_handraise), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14358
+ return this.cachedObservable("raiseHandPriority$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.prioritize_handraise), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14308
14359
  }
14309
14360
  get locked$() {
14310
- return this.cachedObservable("locked$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.locked), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14361
+ return this.cachedObservable("locked$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.locked), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14311
14362
  }
14312
14363
  get meta$() {
14313
- return this.cachedObservable("meta$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.meta), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14364
+ return this.cachedObservable("meta$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.meta), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14314
14365
  }
14315
14366
  get capabilities$() {
14316
- return this.cachedObservable("capabilities$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.capabilities), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14367
+ return this.cachedObservable("capabilities$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.capabilities), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14317
14368
  }
14318
14369
  get layout$() {
14319
- return this.cachedObservable("layout$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layout_name), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14370
+ return this.cachedObservable("layout$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layout_name), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14320
14371
  }
14321
14372
  get layouts$() {
14322
- return this.cachedObservable("layouts$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layouts), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14373
+ return this.cachedObservable("layouts$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layouts), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14323
14374
  }
14324
14375
  get layoutLayers$() {
14325
- return this.cachedObservable("layoutLayers$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layout_layers), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14376
+ return this.cachedObservable("layoutLayers$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layout_layers), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14326
14377
  }
14327
14378
  get self() {
14328
14379
  return this._self$.value;
@@ -14364,7 +14415,7 @@ var CallEventsManager = class extends Destroyable {
14364
14415
  roomSessionId: callJoinedEvent.room_session_id
14365
14416
  });
14366
14417
  const sessionState = callJoinedEvent.room_session;
14367
- const { capabilities } = callJoinedEvent;
14418
+ const capabilities = callJoinedEvent.capabilities;
14368
14419
  this.selfId = this.selfId ?? callJoinedEvent.member_id;
14369
14420
  this.originCallId = this.originCallId ?? callJoinedEvent.origin_call_id;
14370
14421
  this.callIds.add(callJoinedEvent.call_id);
@@ -14477,17 +14528,17 @@ var CallEventsManager = class extends Destroyable {
14477
14528
  this._participants$.next(this._participants$.value);
14478
14529
  }
14479
14530
  get callJoinedEvent$() {
14480
- return this.cachedObservable("callJoinedEvent$", () => this.webRtcCallSession.callEvent$.pipe((0, import_cjs$17.filter)(isCallJoinedPayload), (0, import_cjs$17.tap)((event) => {
14531
+ return this.cachedObservable("callJoinedEvent$", () => this.webRtcCallSession.callEvent$.pipe((0, import_cjs$18.filter)(isCallJoinedPayload), (0, import_cjs$18.tap)((event) => {
14481
14532
  logger$19.debug("[CallEventsManager] Call joined event:", event);
14482
14533
  })));
14483
14534
  }
14484
14535
  get layoutChangedEvent$() {
14485
- return this.cachedObservable("layoutChangedEvent$", () => this.webRtcCallSession.callEvent$.pipe(filterAs(isLayoutChangedPayload, "layout"), (0, import_cjs$17.tap)((event) => {
14536
+ return this.cachedObservable("layoutChangedEvent$", () => this.webRtcCallSession.callEvent$.pipe(filterAs(isLayoutChangedPayload, "layout"), (0, import_cjs$18.tap)((event) => {
14486
14537
  logger$19.debug("[CallEventsManager] Layout changed event:", event);
14487
14538
  })));
14488
14539
  }
14489
14540
  get memberUpdates$() {
14490
- return this.cachedObservable("memberUpdates$", () => (0, import_cjs$17.merge)(this.webRtcCallSession.memberJoined$, this.webRtcCallSession.memberUpdated$, this.webRtcCallSession.memberTalking$).pipe((0, import_cjs$17.map)((event) => event.member), (0, import_cjs$17.tap)((event) => {
14541
+ return this.cachedObservable("memberUpdates$", () => (0, import_cjs$18.merge)(this.webRtcCallSession.memberJoined$, this.webRtcCallSession.memberUpdated$, this.webRtcCallSession.memberTalking$).pipe((0, import_cjs$18.map)((event) => event.member), (0, import_cjs$18.tap)((event) => {
14491
14542
  logger$19.debug("[CallEventsManager] Member update event:", event);
14492
14543
  })));
14493
14544
  }
@@ -14744,7 +14795,7 @@ function appendStereoParams(fmtpLine, maxBitrate) {
14744
14795
 
14745
14796
  //#endregion
14746
14797
  //#region src/controllers/ICEGatheringController.ts
14747
- var import_cjs$16 = require_cjs();
14798
+ var import_cjs$17 = require_cjs();
14748
14799
  const logger$18 = getLogger();
14749
14800
  var ICEGatheringController = class extends Destroyable {
14750
14801
  constructor(peerConnection, peerConnectionControllerNegotiating$, options = {}) {
@@ -14782,7 +14833,7 @@ var ICEGatheringController = class extends Destroyable {
14782
14833
  this.iceGatheringTimeout = options.iceGatheringTimeout ?? DEFAULT_ICE_GATHERING_TIMEOUT_MS;
14783
14834
  this.relayOnly = options.relayOnly ?? false;
14784
14835
  this.setupEventListeners();
14785
- this.subscribeTo(this.peerConnectionControllerNegotiating$.pipe((0, import_cjs$16.filter)((isNegotiating) => isNegotiating)), (isNegotiating) => {
14836
+ this.subscribeTo(this.peerConnectionControllerNegotiating$.pipe((0, import_cjs$17.filter)((isNegotiating) => isNegotiating)), (isNegotiating) => {
14786
14837
  if (isNegotiating) {
14787
14838
  this.setupEventListeners();
14788
14839
  this.iceGatheringTimer = setTimeout(() => {
@@ -14801,7 +14852,7 @@ var ICEGatheringController = class extends Destroyable {
14801
14852
  this.peerConnection.addEventListener("icegatheringstatechange", this.onicegatheringstatechangeHandler);
14802
14853
  }
14803
14854
  get iceCandidatesState$() {
14804
- return this._iceCandidatesState.pipe((0, import_cjs$16.withLatestFrom)(this.peerConnectionControllerNegotiating$), (0, import_cjs$16.filter)(([_, isNegotiating]) => isNegotiating), (0, import_cjs$16.map)(([state, _]) => state.state));
14855
+ return this._iceCandidatesState.pipe((0, import_cjs$17.withLatestFrom)(this.peerConnectionControllerNegotiating$), (0, import_cjs$17.filter)(([_, isNegotiating]) => isNegotiating), (0, import_cjs$17.map)(([state, _]) => state.state));
14805
14856
  }
14806
14857
  get hasValidLocalDescriptionSDP() {
14807
14858
  const sdp = this.peerConnection.localDescription?.sdp;
@@ -14888,7 +14939,7 @@ var ICEGatheringController = class extends Destroyable {
14888
14939
 
14889
14940
  //#endregion
14890
14941
  //#region src/controllers/LocalStreamController.ts
14891
- var import_cjs$15 = require_cjs();
14942
+ var import_cjs$16 = require_cjs();
14892
14943
  const logger$17 = getLogger();
14893
14944
  var LocalStreamController = class extends Destroyable {
14894
14945
  constructor(options) {
@@ -14903,16 +14954,16 @@ var LocalStreamController = class extends Destroyable {
14903
14954
  this._mediaTrackEnded$ = this.createSubject();
14904
14955
  }
14905
14956
  get localStream$() {
14906
- return this._localStream$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14957
+ return this._localStream$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14907
14958
  }
14908
14959
  get localAudioTracks$() {
14909
- return this._localAudioTracks$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14960
+ return this._localAudioTracks$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14910
14961
  }
14911
14962
  get localVideoTracks$() {
14912
- return this._localVideoTracks$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14963
+ return this._localVideoTracks$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14913
14964
  }
14914
14965
  get mediaTrackEnded$() {
14915
- return this._mediaTrackEnded$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14966
+ return this._mediaTrackEnded$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14916
14967
  }
14917
14968
  get localStream() {
14918
14969
  return this._localStream$.value;
@@ -15301,7 +15352,7 @@ var TransceiverController = class extends Destroyable {
15301
15352
 
15302
15353
  //#endregion
15303
15354
  //#region src/controllers/RTCPeerConnectionController.ts
15304
- var import_cjs$14 = require_cjs();
15355
+ var import_cjs$15 = require_cjs();
15305
15356
  const logger$15 = getLogger();
15306
15357
  var RTCPeerConnectionController = class extends Destroyable {
15307
15358
  constructor(options = {}, remoteSessionDescription, deviceController) {
@@ -15309,11 +15360,11 @@ var RTCPeerConnectionController = class extends Destroyable {
15309
15360
  this.options = options;
15310
15361
  this.firstSDPExchangeCompleted = false;
15311
15362
  this.negotiationNeeded$ = this.createSubject();
15312
- this.localDescription$ = (0, import_cjs$14.defer)(() => (0, import_cjs$14.from)(this.init())).pipe((0, import_cjs$14.switchMap)(() => this.iceGatheringController.iceCandidatesState$.pipe((0, import_cjs$14.filter)((iceCandidateState) => !["new", "gathering"].includes(iceCandidateState)), (0, import_cjs$14.tap)(() => {
15363
+ this.localDescription$ = (0, import_cjs$15.defer)(() => (0, import_cjs$15.from)(this.init())).pipe((0, import_cjs$15.switchMap)(() => this.iceGatheringController.iceCandidatesState$.pipe((0, import_cjs$15.filter)((iceCandidateState) => !["new", "gathering"].includes(iceCandidateState)), (0, import_cjs$15.tap)(() => {
15313
15364
  this.negotiationEnded();
15314
- }), (0, import_cjs$14.filter)(() => this.shouldEmitLocalDescription), (0, import_cjs$14.map)(() => this.peerConnection?.localDescription), filterNull(), (0, import_cjs$14.tap)((desc) => {
15365
+ }), (0, import_cjs$15.filter)(() => this.shouldEmitLocalDescription), (0, import_cjs$15.map)(() => this.peerConnection?.localDescription), filterNull(), (0, import_cjs$15.tap)((desc) => {
15315
15366
  if (desc.type === "answer") this._type = "offer";
15316
- }))), (0, import_cjs$14.shareReplay)(1), (0, import_cjs$14.takeUntil)(this.destroyed$));
15367
+ }))), (0, import_cjs$15.shareReplay)(1), (0, import_cjs$15.takeUntil)(this.destroyed$));
15317
15368
  this.connectionTimeout = 3e3;
15318
15369
  this.oniceconnectionstatechangeHandler = () => {
15319
15370
  if (this.peerConnection) {
@@ -15371,7 +15422,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15371
15422
  logger$15.debug(`[RTCPeerConnectionController] ${kind} input device selected:`, deviceInfo?.label);
15372
15423
  } catch (error) {
15373
15424
  logger$15.error(`[RTCPeerConnectionController] Failed to select ${kind} input device:`, error);
15374
- this._errors$.next(error);
15425
+ this._errors$.next(toError(error));
15375
15426
  throw error;
15376
15427
  }
15377
15428
  };
@@ -15456,43 +15507,43 @@ var RTCPeerConnectionController = class extends Destroyable {
15456
15507
  };
15457
15508
  }
15458
15509
  get iceGatheringState$() {
15459
- return this.cachedObservable("iceGatheringState$", () => this._iceGatheringState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15510
+ return this.cachedObservable("iceGatheringState$", () => this._iceGatheringState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15460
15511
  }
15461
15512
  get mediaTrackEnded$() {
15462
- return this.cachedObservable("mediaTrackEnded$", () => this.localStreamController.mediaTrackEnded$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15513
+ return this.cachedObservable("mediaTrackEnded$", () => this.localStreamController.mediaTrackEnded$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15463
15514
  }
15464
15515
  get errors$() {
15465
- return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15516
+ return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15466
15517
  }
15467
15518
  get iceCandidates$() {
15468
- return this.cachedObservable("iceCandidates$", () => this._iceCandidates$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15519
+ return this.cachedObservable("iceCandidates$", () => this._iceCandidates$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15469
15520
  }
15470
15521
  get initialized$() {
15471
- return this.cachedObservable("initialized$", () => this._initialized$.asObservable().pipe((0, import_cjs$14.filter)((initialized) => initialized), (0, import_cjs$14.takeUntil)(this.destroyed$)));
15522
+ return this.cachedObservable("initialized$", () => this._initialized$.asObservable().pipe((0, import_cjs$15.filter)((initialized) => initialized), (0, import_cjs$15.takeUntil)(this.destroyed$)));
15472
15523
  }
15473
15524
  get remoteDescription$() {
15474
- return this.cachedObservable("remoteDescription$", () => this._remoteDescription$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15525
+ return this.cachedObservable("remoteDescription$", () => this._remoteDescription$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15475
15526
  }
15476
15527
  get localStream$() {
15477
- return this.cachedObservable("localStream$", () => this.localStreamController.localStream$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15528
+ return this.cachedObservable("localStream$", () => this.localStreamController.localStream$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15478
15529
  }
15479
15530
  get remoteStream$() {
15480
- return this.cachedObservable("remoteStream$", () => this._remoteStream$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15531
+ return this.cachedObservable("remoteStream$", () => this._remoteStream$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15481
15532
  }
15482
15533
  get localAudioTracks$() {
15483
- return this.cachedObservable("localAudioTracks$", () => this.localStreamController.localAudioTracks$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15534
+ return this.cachedObservable("localAudioTracks$", () => this.localStreamController.localAudioTracks$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15484
15535
  }
15485
15536
  get localVideoTracks$() {
15486
- return this.cachedObservable("localVideoTracks$", () => this.localStreamController.localVideoTracks$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15537
+ return this.cachedObservable("localVideoTracks$", () => this.localStreamController.localVideoTracks$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15487
15538
  }
15488
15539
  get iceConnectionState$() {
15489
- return this.cachedObservable("iceConnectionState$", () => this._iceConnectionState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15540
+ return this.cachedObservable("iceConnectionState$", () => this._iceConnectionState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15490
15541
  }
15491
15542
  get connectionState$() {
15492
- return this.cachedObservable("connectionState$", () => this._connectionState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15543
+ return this.cachedObservable("connectionState$", () => this._connectionState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15493
15544
  }
15494
15545
  get signalingState$() {
15495
- return this.cachedObservable("signalingState$", () => this._signalingState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15546
+ return this.cachedObservable("signalingState$", () => this._signalingState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15496
15547
  }
15497
15548
  get type() {
15498
15549
  return this._type;
@@ -15605,16 +15656,16 @@ var RTCPeerConnectionController = class extends Destroyable {
15605
15656
  async doInit() {
15606
15657
  try {
15607
15658
  this.setupPeerConnection();
15608
- this.subscribeTo(this.negotiationNeeded$.pipe((0, import_cjs$14.auditTime)(0), (0, import_cjs$14.exhaustMap)(async () => this.startNegotiation())), {
15659
+ this.subscribeTo(this.negotiationNeeded$.pipe((0, import_cjs$15.auditTime)(0), (0, import_cjs$15.exhaustMap)(async () => this.startNegotiation())), {
15609
15660
  next: () => {
15610
15661
  logger$15.debug("[RTCPeerConnectionController] Start Negotiation completed successfully");
15611
15662
  },
15612
15663
  error: (error) => {
15613
15664
  logger$15.error("[RTCPeerConnectionController] Start Negotiation error:", error);
15614
- this._errors$.next(error);
15665
+ this._errors$.next(toError(error));
15615
15666
  }
15616
15667
  });
15617
- this.subscribeTo((0, import_cjs$14.merge)(this.deviceController.selectedAudioInputDevice$.pipe((0, import_cjs$14.map)((deviceInfo) => ["audio", deviceInfo])), this.deviceController.selectedVideoInputDevice$.pipe((0, import_cjs$14.map)((deviceInfo) => ["video", deviceInfo]))).pipe((0, import_cjs$14.skipWhile)(() => !this.localStreamController.localStream)), async ([kind, deviceInfo]) => {
15668
+ this.subscribeTo((0, import_cjs$15.merge)(this.deviceController.selectedAudioInputDevice$.pipe((0, import_cjs$15.map)((deviceInfo) => ["audio", deviceInfo])), this.deviceController.selectedVideoInputDevice$.pipe((0, import_cjs$15.map)((deviceInfo) => ["video", deviceInfo]))).pipe((0, import_cjs$15.skipWhile)(() => !this.localStreamController.localStream)), async ([kind, deviceInfo]) => {
15618
15669
  logger$15.debug(`[RTCPeerConnectionController] Selected input device changed for:`, {
15619
15670
  kind,
15620
15671
  deviceInfo
@@ -15633,7 +15684,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15633
15684
  }
15634
15685
  } catch (error) {
15635
15686
  logger$15.error("[RTCPeerConnectionController] Initialization error:", error);
15636
- this._errors$.next(error);
15687
+ this._errors$.next(toError(error));
15637
15688
  this.destroy();
15638
15689
  }
15639
15690
  }
@@ -15680,7 +15731,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15680
15731
  await this.createOffer(offerOptions);
15681
15732
  } catch (error) {
15682
15733
  logger$15.error("[RTCPeerConnectionController] Error during negotiation:", error);
15683
- this._errors$.next(error);
15734
+ this._errors$.next(toError(error));
15684
15735
  }
15685
15736
  }
15686
15737
  /**
@@ -15703,7 +15754,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15703
15754
  }
15704
15755
  } catch (error) {
15705
15756
  logger$15.error("[RTCPeerConnectionController] Error updating answer status:", error);
15706
- this._errors$.next(error);
15757
+ this._errors$.next(toError(error));
15707
15758
  readyToConnect = false;
15708
15759
  } finally {
15709
15760
  if (readyToConnect) this.readyToConnect();
@@ -15869,7 +15920,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15869
15920
  await this.setLocalDescription(offer);
15870
15921
  } catch (error) {
15871
15922
  logger$15.error("[RTCPeerConnectionController] ICE restart offer failed:", error);
15872
- this._errors$.next(error);
15923
+ this._errors$.next(toError(error));
15873
15924
  this.negotiationEnded();
15874
15925
  if (policyChanged) this.restoreIceTransportPolicy();
15875
15926
  throw error;
@@ -15964,7 +16015,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15964
16015
  logger$15.debug(`[RTCPeerConnectionController] ${track.kind} track added:`, track.id);
15965
16016
  } catch (error) {
15966
16017
  logger$15.error(`[RTCPeerConnectionController] Failed to add ${track.kind} track:`, error);
15967
- this._errors$.next(error);
16018
+ this._errors$.next(toError(error));
15968
16019
  throw error;
15969
16020
  }
15970
16021
  }
@@ -15989,7 +16040,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15989
16040
  logger$15.debug(`[RTCPeerConnectionController] ${sender.track?.kind} track removed:`, trackId);
15990
16041
  } catch (error) {
15991
16042
  logger$15.error(`[RTCPeerConnectionController] Failed to remove ${sender.track?.kind} track:`, error);
15992
- this._errors$.next(error);
16043
+ this._errors$.next(toError(error));
15993
16044
  throw error;
15994
16045
  }
15995
16046
  }
@@ -16120,7 +16171,7 @@ function isVertoPingInnerParams(value) {
16120
16171
 
16121
16172
  //#endregion
16122
16173
  //#region src/managers/VertoManager.ts
16123
- var import_cjs$13 = require_cjs();
16174
+ var import_cjs$14 = require_cjs();
16124
16175
  const logger$14 = getLogger();
16125
16176
  var VertoManager = class extends Destroyable {
16126
16177
  constructor(callSession) {
@@ -16141,7 +16192,7 @@ var WebRTCVertoManager = class extends VertoManager {
16141
16192
  this.webRTCApiProvider = webRTCApiProvider;
16142
16193
  this._rtcPeerConnections$ = this.createBehaviorSubject([]);
16143
16194
  this._selfId$ = this.createBehaviorSubject(null);
16144
- this._signalingStatus$ = this.createBehaviorSubject(null);
16195
+ this._signalingStatus$ = this.createReplaySubject(1);
16145
16196
  this._screenShareStatus$ = this.createBehaviorSubject("none");
16146
16197
  this._rtcPeerConnectionsMap = /* @__PURE__ */ new Map();
16147
16198
  this._screenShareTimeoutMs = 5e4;
@@ -16213,7 +16264,7 @@ var WebRTCVertoManager = class extends VertoManager {
16213
16264
  return rtcPeerConnection;
16214
16265
  }
16215
16266
  get signalingStatus$() {
16216
- return this.cachedObservable("signalingStatus$", () => (0, import_cjs$13.merge)(this._signalingStatus$.pipe(filterNull()), this.mainPeerConnection.connectionState$.pipe((0, import_cjs$13.filter)((connectionState) => [
16267
+ return this.cachedObservable("signalingStatus$", () => (0, import_cjs$14.merge)(this._signalingStatus$.asObservable(), this.mainPeerConnection.connectionState$.pipe((0, import_cjs$14.filter)((connectionState) => [
16217
16268
  "connected",
16218
16269
  "disconnected",
16219
16270
  "failed"
@@ -16426,25 +16477,25 @@ var WebRTCVertoManager = class extends VertoManager {
16426
16477
  }
16427
16478
  }
16428
16479
  get callJoinedEvent$() {
16429
- return this.webRtcCallSession.callEvent$.pipe((0, import_cjs$13.filter)(isCallJoinedPayload), (0, import_cjs$13.takeUntil)(this.destroyed$));
16480
+ return this.webRtcCallSession.callEvent$.pipe((0, import_cjs$14.filter)(isCallJoinedPayload), (0, import_cjs$14.takeUntil)(this.destroyed$));
16430
16481
  }
16431
16482
  get vertoMedia$() {
16432
- return this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$));
16483
+ return this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$));
16433
16484
  }
16434
16485
  get vertoAnswer$() {
16435
- return this.cachedObservable("vertoAnswer$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAnswerInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16486
+ return this.cachedObservable("vertoAnswer$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAnswerInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16436
16487
  }
16437
16488
  get vertoMediaParams$() {
16438
- return this.cachedObservable("vertoMediaParams$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaParamsInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16489
+ return this.cachedObservable("vertoMediaParams$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaParamsInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16439
16490
  }
16440
16491
  get vertoBye$() {
16441
- return this.cachedObservable("vertoBye$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoByeMessage, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16492
+ return this.cachedObservable("vertoBye$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoByeMessage, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16442
16493
  }
16443
16494
  get vertoAttach$() {
16444
- return this.cachedObservable("vertoAttach$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAttachMessage, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16495
+ return this.cachedObservable("vertoAttach$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAttachMessage, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16445
16496
  }
16446
16497
  get vertoPing$() {
16447
- return this.cachedObservable("vertoPing$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoPingInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16498
+ return this.cachedObservable("vertoPing$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoPingInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16448
16499
  }
16449
16500
  async executeVerto(message, optionals = {}) {
16450
16501
  const webrtcVertoMessage = WebrtcVerto({
@@ -16572,7 +16623,7 @@ var WebRTCVertoManager = class extends VertoManager {
16572
16623
  }
16573
16624
  async handleInboundAnswer(rtcPeerConnController) {
16574
16625
  logger$14.debug("[WebRTCManager] Waiting for inbound call to be accepted or rejected");
16575
- const vertoByeOrAccepted = await (0, import_cjs$13.firstValueFrom)((0, import_cjs$13.race)(this.vertoBye$, this.webRtcCallSession.answered$).pipe((0, import_cjs$13.takeUntil)(this.destroyed$))).catch(() => null);
16626
+ const vertoByeOrAccepted = await (0, import_cjs$14.firstValueFrom)((0, import_cjs$14.race)(this.vertoBye$, this.webRtcCallSession.answered$).pipe((0, import_cjs$14.takeUntil)(this.destroyed$))).catch(() => null);
16576
16627
  if (vertoByeOrAccepted === null) {
16577
16628
  logger$14.debug("[WebRTCManager] Inbound answer handler aborted (destroyed).");
16578
16629
  return;
@@ -16615,12 +16666,12 @@ var WebRTCVertoManager = class extends VertoManager {
16615
16666
  });
16616
16667
  }
16617
16668
  initObservables(rtcPeerConnController) {
16618
- this.mediaDirections$ = rtcPeerConnController.connectionState$.pipe((0, import_cjs$13.filter)((state) => state === "connected"), (0, import_cjs$13.map)(() => rtcPeerConnController.mediaDirections), (0, import_cjs$13.startWith)(rtcPeerConnController.mediaDirections), (0, import_cjs$13.takeUntil)(this.destroyed$));
16619
- this.localStream$ = rtcPeerConnController.localStream$.pipe(filterNull(), (0, import_cjs$13.takeUntil)(this.destroyed$));
16620
- this.remoteStream$ = rtcPeerConnController.remoteStream$.pipe(filterNull(), (0, import_cjs$13.takeUntil)(this.destroyed$));
16669
+ this.mediaDirections$ = rtcPeerConnController.connectionState$.pipe((0, import_cjs$14.filter)((state) => state === "connected"), (0, import_cjs$14.map)(() => rtcPeerConnController.mediaDirections), (0, import_cjs$14.startWith)(rtcPeerConnController.mediaDirections), (0, import_cjs$14.takeUntil)(this.destroyed$));
16670
+ this.localStream$ = rtcPeerConnController.localStream$.pipe(filterNull(), (0, import_cjs$14.takeUntil)(this.destroyed$));
16671
+ this.remoteStream$ = rtcPeerConnController.remoteStream$.pipe(filterNull(), (0, import_cjs$14.takeUntil)(this.destroyed$));
16621
16672
  }
16622
16673
  setupLocalDescriptionHandler(rtcPeerConnController) {
16623
- this.subscribeTo(rtcPeerConnController.localDescription$.pipe((0, import_cjs$13.filter)((description) => description !== null), (0, import_cjs$13.takeUntil)(this.destroyed$)), (description) => {
16674
+ this.subscribeTo(rtcPeerConnController.localDescription$.pipe((0, import_cjs$14.filter)((description) => description !== null), (0, import_cjs$14.takeUntil)(this.destroyed$)), (description) => {
16624
16675
  const { type, sdp } = description;
16625
16676
  const dialogParams = this.dialogParams(rtcPeerConnController);
16626
16677
  const initial = !rtcPeerConnController.firstSDPExchangeCompleted;
@@ -16671,7 +16722,11 @@ var WebRTCVertoManager = class extends VertoManager {
16671
16722
  }
16672
16723
  async sendLocalDescriptionOnceAccepted(vertoMessageRequest, rtcPeerConnectionController) {
16673
16724
  logger$14.debug("[WebRTCManager] Waiting for call to be accepted or ended before sending answer");
16674
- const vertoByeOrAccepted = await (0, import_cjs$13.firstValueFrom)((0, import_cjs$13.race)(this.vertoBye$, this.webRtcCallSession.answered$));
16725
+ const vertoByeOrAccepted = await (0, import_cjs$14.firstValueFrom)((0, import_cjs$14.race)(this.vertoBye$, this.webRtcCallSession.answered$).pipe((0, import_cjs$14.takeUntil)(this.destroyed$))).catch(() => null);
16726
+ if (vertoByeOrAccepted === null) {
16727
+ logger$14.debug("[WebRTCManager] Destroyed while waiting for call acceptance");
16728
+ return;
16729
+ }
16675
16730
  if (isVertoByeMessage(vertoByeOrAccepted)) {
16676
16731
  logger$14.info("[WebRTCManager] Call ended before answer was sent.");
16677
16732
  this.callSession?.destroy();
@@ -16780,7 +16835,7 @@ var WebRTCVertoManager = class extends VertoManager {
16780
16835
  this.subscribeTo(rtcPeerConnController.errors$, (error) => {
16781
16836
  this.onError?.(error);
16782
16837
  });
16783
- await (0, import_cjs$13.firstValueFrom)(rtcPeerConnController.connectionState$.pipe((0, import_cjs$13.filter)((state) => state === "connected"), (0, import_cjs$13.take)(1), (0, import_cjs$13.timeout)(this._screenShareTimeoutMs)));
16838
+ await (0, import_cjs$14.firstValueFrom)(rtcPeerConnController.connectionState$.pipe((0, import_cjs$14.filter)((state) => state === "connected"), (0, import_cjs$14.take)(1), (0, import_cjs$14.timeout)(this._screenShareTimeoutMs), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16784
16839
  this._screenShareStatus$.next("started");
16785
16840
  logger$14.info("[WebRTCManager] Screen share started successfully.");
16786
16841
  return rtcPeerConnController.id;
@@ -16883,7 +16938,7 @@ var WebRTCVertoManager = class extends VertoManager {
16883
16938
 
16884
16939
  //#endregion
16885
16940
  //#region src/controllers/RTCStatsMonitor.ts
16886
- var import_cjs$12 = require_cjs();
16941
+ var import_cjs$13 = require_cjs();
16887
16942
  const logger$13 = getLogger();
16888
16943
  const DEFAULT_POLLING_INTERVAL_MS = 1e3;
16889
16944
  const DEFAULT_BASELINE_SAMPLES = 10;
@@ -16946,7 +17001,7 @@ var RTCStatsMonitor = class extends Destroyable {
16946
17001
  }
16947
17002
  /** Simple boolean health indicator. */
16948
17003
  get isNetworkHealthy$() {
16949
- return this.cachedObservable("isNetworkHealthy$", () => this._networkIssues$.pipe((0, import_cjs$12.map)((issues) => issues.length === 0), (0, import_cjs$12.distinctUntilChanged)(), (0, import_cjs$12.takeUntil)(this.destroyed$)));
17004
+ return this.cachedObservable("isNetworkHealthy$", () => this._networkIssues$.pipe((0, import_cjs$13.map)((issues) => issues.length === 0), (0, import_cjs$13.distinctUntilChanged)(), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16950
17005
  }
16951
17006
  /** Whether the network is currently healthy. */
16952
17007
  get isNetworkHealthy() {
@@ -16962,7 +17017,7 @@ var RTCStatsMonitor = class extends Destroyable {
16962
17017
  }
16963
17018
  /** Emits individual critical issues for the recovery pipeline. */
16964
17019
  get criticalIssue$() {
16965
- return this.cachedObservable("criticalIssue$", () => this._networkIssues$.pipe((0, import_cjs$12.mergeMap)((issues) => (0, import_cjs$12.from)(issues.filter((i) => i.severity === "critical"))), (0, import_cjs$12.takeUntil)(this.destroyed$)));
17020
+ return this.cachedObservable("criticalIssue$", () => this._networkIssues$.pipe((0, import_cjs$13.mergeMap)((issues) => (0, import_cjs$13.from)(issues.filter((i) => i.severity === "critical"))), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16966
17021
  }
16967
17022
  /** Emits each raw stats sample extracted from the peer connection. */
16968
17023
  get sample$() {
@@ -16975,11 +17030,11 @@ var RTCStatsMonitor = class extends Destroyable {
16975
17030
  this.lastAudioPacketChangeTime = now;
16976
17031
  this.lastVideoPacketChangeTime = now;
16977
17032
  logger$13.debug("[RTCStatsMonitor] Starting stats monitoring");
16978
- this.subscribeTo((0, import_cjs$12.interval)(this.pollingIntervalMs).pipe((0, import_cjs$12.filter)(() => this.running), (0, import_cjs$12.switchMap)(() => (0, import_cjs$12.from)(this.peerConnection.getStats()).pipe((0, import_cjs$12.catchError)((err) => {
17033
+ this.subscribeTo((0, import_cjs$13.interval)(this.pollingIntervalMs).pipe((0, import_cjs$13.filter)(() => this.running), (0, import_cjs$13.switchMap)(() => (0, import_cjs$13.from)(this.peerConnection.getStats()).pipe((0, import_cjs$13.catchError)((err) => {
16979
17034
  logger$13.warn("[RTCStatsMonitor] Failed to get stats:", err);
16980
- return import_cjs$12.EMPTY;
16981
- }))), (0, import_cjs$12.filter)(() => this.running), (0, import_cjs$12.map)((report) => this.extractSample(report))), (sample$1) => this._sample$.next(sample$1));
16982
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.take)(this.baselineSampleCount), (0, import_cjs$12.toArray)(), (0, import_cjs$12.map)((samples) => ({
17035
+ return import_cjs$13.EMPTY;
17036
+ }))), (0, import_cjs$13.filter)(() => this.running), (0, import_cjs$13.map)((report) => this.extractSample(report))), (sample$1) => this._sample$.next(sample$1));
17037
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.take)(this.baselineSampleCount), (0, import_cjs$13.toArray)(), (0, import_cjs$13.map)((samples) => ({
16983
17038
  rtt: samples.reduce((s, b) => s + b.roundTripTime, 0) / samples.length,
16984
17039
  jitter: samples.reduce((s, b) => s + b.audioJitter, 0) / samples.length,
16985
17040
  ready: true
@@ -16987,19 +17042,19 @@ var RTCStatsMonitor = class extends Destroyable {
16987
17042
  logger$13.debug(`[RTCStatsMonitor] Baseline established: rtt=${baseline.rtt.toFixed(1)}ms, jitter=${baseline.jitter.toFixed(1)}ms`);
16988
17043
  this._baseline$.next(baseline);
16989
17044
  });
16990
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.scan)((acc, sample$1) => ({
17045
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.scan)((acc, sample$1) => ({
16991
17046
  prev: acc.current,
16992
17047
  current: sample$1
16993
17048
  }), {
16994
17049
  prev: null,
16995
17050
  current: null
16996
- }), (0, import_cjs$12.filter)((pair) => pair.current !== null)), ({ prev, current }) => {
17051
+ }), (0, import_cjs$13.filter)((pair) => pair.current !== null)), ({ prev, current }) => {
16997
17052
  const now$1 = current.timestamp;
16998
17053
  this.updatePacketTracking(current, now$1);
16999
17054
  const issues = this.detectIssues(current, prev, now$1);
17000
17055
  this._networkIssues$.next(issues);
17001
17056
  });
17002
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.scan)((history, sample$1) => {
17057
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.scan)((history, sample$1) => {
17003
17058
  const cutoff = sample$1.timestamp - this.historyWindowSeconds * 1e3;
17004
17059
  const metrics = {
17005
17060
  timestamp: sample$1.timestamp,
@@ -17152,7 +17207,7 @@ var RTCStatsMonitor = class extends Destroyable {
17152
17207
 
17153
17208
  //#endregion
17154
17209
  //#region src/managers/CallRecoveryManager.ts
17155
- var import_cjs$11 = require_cjs();
17210
+ var import_cjs$12 = require_cjs();
17156
17211
  const logger$12 = getLogger();
17157
17212
  const DEFAULT_DEBOUNCE_TIME_MS = 2e3;
17158
17213
  const DEFAULT_COOLDOWN_MS = 1e4;
@@ -17223,16 +17278,16 @@ var CallRecoveryManager = class extends Destroyable {
17223
17278
  this.initDegradationRecoveryPipeline();
17224
17279
  }
17225
17280
  get recoveryState$() {
17226
- return this._recoveryState$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17281
+ return this._recoveryState$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17227
17282
  }
17228
17283
  get recoveryState() {
17229
17284
  return this._recoveryState$.value;
17230
17285
  }
17231
17286
  get recoveryEvent$() {
17232
- return this._recoveryEvent$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17287
+ return this._recoveryEvent$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17233
17288
  }
17234
17289
  get bandwidthConstrained$() {
17235
- return this._bandwidthConstrained$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17290
+ return this._bandwidthConstrained$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17236
17291
  }
17237
17292
  get bandwidthConstrained() {
17238
17293
  return this._bandwidthConstrained$.value;
@@ -17362,9 +17417,9 @@ var CallRecoveryManager = class extends Destroyable {
17362
17417
  super.destroy();
17363
17418
  }
17364
17419
  initPipeline() {
17365
- this.subscribeTo(this._trigger$.pipe((0, import_cjs$11.tap)(() => {
17420
+ this.subscribeTo(this._trigger$.pipe((0, import_cjs$12.tap)(() => {
17366
17421
  if (this._recoveryState$.value === "idle") this.transitionTo("debouncing");
17367
- }), (0, import_cjs$11.debounceTime)(this._config.debounceTimeMs), (0, import_cjs$11.withLatestFrom)(this._inputs.signalingReady$), (0, import_cjs$11.filter)(([, signalingReady]) => this.passGateChecks(signalingReady)), (0, import_cjs$11.map)(([trigger]) => trigger), (0, import_cjs$11.exhaustMap)((trigger) => this.executeTieredRecovery(trigger)), (0, import_cjs$11.takeUntil)((0, import_cjs$11.merge)(this._destroyed$, this._pipelineStop$))), {
17422
+ }), (0, import_cjs$12.debounceTime)(this._config.debounceTimeMs), (0, import_cjs$12.withLatestFrom)(this._inputs.signalingReady$), (0, import_cjs$12.filter)(([, signalingReady]) => this.passGateChecks(signalingReady)), (0, import_cjs$12.map)(([trigger]) => trigger), (0, import_cjs$12.exhaustMap)((trigger) => this.executeTieredRecovery(trigger)), (0, import_cjs$12.takeUntil)((0, import_cjs$12.merge)(this._destroyed$, this._pipelineStop$))), {
17368
17423
  next: () => {},
17369
17424
  error: (err) => {
17370
17425
  logger$12.error("CallRecoveryManager: pipeline error", err);
@@ -17383,10 +17438,10 @@ var CallRecoveryManager = class extends Destroyable {
17383
17438
  initDegradationRecoveryPipeline() {
17384
17439
  if (!this._config.enableAutoDegradation) return;
17385
17440
  const delayMs = this._config.packetLossRecoveryDelaySec * 1e3;
17386
- this.subscribeTo((0, import_cjs$11.combineLatest)([this._bandwidthConstrained$, this._hasPacketLoss$]).pipe((0, import_cjs$11.switchMap)(([constrained, hasPacketLoss]) => {
17387
- if (constrained && !hasPacketLoss) return (0, import_cjs$11.timer)(delayMs);
17388
- return import_cjs$11.EMPTY;
17389
- }), (0, import_cjs$11.takeUntil)(this._destroyed$)), () => {
17441
+ this.subscribeTo((0, import_cjs$12.combineLatest)([this._bandwidthConstrained$, this._hasPacketLoss$]).pipe((0, import_cjs$12.switchMap)(([constrained, hasPacketLoss]) => {
17442
+ if (constrained && !hasPacketLoss) return (0, import_cjs$12.timer)(delayMs);
17443
+ return import_cjs$12.EMPTY;
17444
+ }), (0, import_cjs$12.takeUntil)(this._destroyed$)), () => {
17390
17445
  this._bandwidthConstrained$.next(false);
17391
17446
  this._callbacks.enableVideo();
17392
17447
  this.emitEvent({
@@ -17426,10 +17481,10 @@ var CallRecoveryManager = class extends Destroyable {
17426
17481
  executeTieredRecovery(trigger) {
17427
17482
  this.transitionTo("recovering");
17428
17483
  logger$12.info(`CallRecoveryManager: starting tiered recovery — source=${trigger.source} detail=${trigger.detail}`);
17429
- return (0, import_cjs$11.from)(this.runTiers(trigger)).pipe((0, import_cjs$11.tap)(() => this.startCooldown()), (0, import_cjs$11.catchError)((err) => {
17484
+ return (0, import_cjs$12.from)(this.runTiers(trigger)).pipe((0, import_cjs$12.tap)(() => this.startCooldown()), (0, import_cjs$12.catchError)((err) => {
17430
17485
  logger$12.error("CallRecoveryManager: tiered recovery failed", err);
17431
17486
  this.startCooldown();
17432
- return import_cjs$11.EMPTY;
17487
+ return import_cjs$12.EMPTY;
17433
17488
  }));
17434
17489
  }
17435
17490
  async runTiers(trigger) {
@@ -17549,7 +17604,7 @@ var CallRecoveryManager = class extends Destroyable {
17549
17604
  this._cooldownUntil = Date.now() + this._config.cooldownMs;
17550
17605
  this.transitionTo("cooldown");
17551
17606
  if (this._cooldownSubscription) this._cooldownSubscription.unsubscribe();
17552
- this._cooldownSubscription = (0, import_cjs$11.timer)(this._config.cooldownMs).pipe((0, import_cjs$11.take)(1), (0, import_cjs$11.takeUntil)(this._destroyed$), (0, import_cjs$11.filter)(() => this._recoveryState$.value === "cooldown")).subscribe(() => this.transitionTo("idle"));
17607
+ this._cooldownSubscription = (0, import_cjs$12.timer)(this._config.cooldownMs).pipe((0, import_cjs$12.take)(1), (0, import_cjs$12.takeUntil)(this._destroyed$), (0, import_cjs$12.filter)(() => this._recoveryState$.value === "cooldown")).subscribe(() => this.transitionTo("idle"));
17553
17608
  }
17554
17609
  emitEvent(event) {
17555
17610
  this._recoveryEvent$.next(event);
@@ -17643,7 +17698,7 @@ function mosToQualityLevel(mos) {
17643
17698
 
17644
17699
  //#endregion
17645
17700
  //#region src/core/entities/Call.ts
17646
- var import_cjs$10 = require_cjs();
17701
+ var import_cjs$11 = require_cjs();
17647
17702
  const logger$11 = getLogger();
17648
17703
  /**
17649
17704
  * Ratio between the critical and warning RTT spike multipliers.
@@ -17718,7 +17773,7 @@ var WebRTCCall = class extends Destroyable {
17718
17773
  const { deviceController, networkChange$ } = initialization;
17719
17774
  this._networkChange$ = networkChange$;
17720
17775
  this.participantFactory = new ParticipantFactory(this.executeMethod.bind(this), this.vertoManager, deviceController);
17721
- this.subscribeTo((0, import_cjs$10.merge)(this._status$.asObservable(), this.vertoManager.signalingStatus$).pipe((0, import_cjs$10.distinctUntilChanged)(), (0, import_cjs$10.takeUntil)(this._destroyed$)), (status) => {
17776
+ this.subscribeTo((0, import_cjs$11.merge)(this._status$.asObservable(), this.vertoManager.signalingStatus$).pipe((0, import_cjs$11.distinctUntilChanged)(), (0, import_cjs$11.takeUntil)(this._destroyed$)), (status) => {
17722
17777
  this._lastMergedStatus = status;
17723
17778
  if (status === "connected" && !this._statsMonitor) this.initResilienceSubsystems();
17724
17779
  else if (status === "disconnected") {
@@ -17753,7 +17808,7 @@ var WebRTCCall = class extends Destroyable {
17753
17808
  }
17754
17809
  /** Observable of the address associated with this call. */
17755
17810
  get address$() {
17756
- return this.deferEmission((0, import_cjs$10.from)([this.address])).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17811
+ return this.deferEmission((0, import_cjs$11.from)([this.address])).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17757
17812
  }
17758
17813
  /** Display name of the caller. */
17759
17814
  get fromName() {
@@ -17832,7 +17887,7 @@ var WebRTCCall = class extends Destroyable {
17832
17887
  }
17833
17888
  /** Observable of layout layer positions for all participants. */
17834
17889
  get layoutLayers$() {
17835
- return this.deferEmission(this.callEventsManager.layoutLayers$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17890
+ return this.deferEmission(this.callEventsManager.layoutLayers$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17836
17891
  }
17837
17892
  /** Current snapshot of layout layers. */
17838
17893
  get layoutLayers() {
@@ -17887,45 +17942,45 @@ var WebRTCCall = class extends Destroyable {
17887
17942
  }
17888
17943
  /** Observable of the current call status (e.g. `'ringing'`, `'connected'`). */
17889
17944
  get status$() {
17890
- return this.publicCachedObservable("status$", () => (0, import_cjs$10.merge)(this._status$.asObservable(), this.vertoManager.signalingStatus$).pipe((0, import_cjs$10.distinctUntilChanged)(), (0, import_cjs$10.tap)((status) => {
17945
+ return this.publicCachedObservable("status$", () => (0, import_cjs$11.merge)(this._status$.asObservable(), this.vertoManager.signalingStatus$).pipe((0, import_cjs$11.distinctUntilChanged)(), (0, import_cjs$11.tap)((status) => {
17891
17946
  this._lastMergedStatus = status;
17892
17947
  })));
17893
17948
  }
17894
17949
  /** Observable of the participants list, emits on join/leave/update. */
17895
17950
  get participants$() {
17896
- return this.deferEmission(this.callEventsManager.participants$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17951
+ return this.deferEmission(this.callEventsManager.participants$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17897
17952
  }
17898
17953
  /** Observable of the local (self) participant. */
17899
17954
  get self$() {
17900
- return this.deferEmission(this.callEventsManager.self$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17955
+ return this.deferEmission(this.callEventsManager.self$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17901
17956
  }
17902
17957
  /** Observable indicating whether the call is being recorded. */
17903
17958
  get recording$() {
17904
- return this.deferEmission(this.callEventsManager.recording$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17959
+ return this.deferEmission(this.callEventsManager.recording$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17905
17960
  }
17906
17961
  /** Observable indicating whether the call is being streamed. */
17907
17962
  get streaming$() {
17908
- return this.deferEmission(this.callEventsManager.streaming$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17963
+ return this.deferEmission(this.callEventsManager.streaming$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17909
17964
  }
17910
17965
  /** Observable indicating whether raise-hand priority is active. */
17911
17966
  get raiseHandPriority$() {
17912
- return this.deferEmission(this.callEventsManager.raiseHandPriority$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17967
+ return this.deferEmission(this.callEventsManager.raiseHandPriority$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17913
17968
  }
17914
17969
  /** Observable indicating whether the call room is locked. */
17915
17970
  get locked$() {
17916
- return this.deferEmission(this.callEventsManager.locked$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17971
+ return this.deferEmission(this.callEventsManager.locked$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17917
17972
  }
17918
17973
  /** Observable of custom metadata associated with the call. */
17919
17974
  get meta$() {
17920
- return this.deferEmission(this.callEventsManager.meta$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17975
+ return this.deferEmission(this.callEventsManager.meta$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17921
17976
  }
17922
17977
  /** Observable of the call's capability flags. */
17923
17978
  get capabilities$() {
17924
- return this.deferEmission(this.callEventsManager.capabilities$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17979
+ return this.deferEmission(this.callEventsManager.capabilities$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17925
17980
  }
17926
17981
  /** Observable of the current layout name. */
17927
17982
  get layout$() {
17928
- return this.deferEmission(this.callEventsManager.layout$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17983
+ return this.deferEmission(this.callEventsManager.layout$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17929
17984
  }
17930
17985
  /** Current call status. */
17931
17986
  get status() {
@@ -17957,7 +18012,7 @@ var WebRTCCall = class extends Destroyable {
17957
18012
  }
17958
18013
  /** Observable of available layout names. */
17959
18014
  get layouts$() {
17960
- return this.deferEmission(this.callEventsManager.layouts$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18015
+ return this.deferEmission(this.callEventsManager.layouts$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17961
18016
  }
17962
18017
  /** Current snapshot of available layout names. */
17963
18018
  get layouts() {
@@ -17965,7 +18020,7 @@ var WebRTCCall = class extends Destroyable {
17965
18020
  }
17966
18021
  /** Observable of the local media stream (camera/microphone). */
17967
18022
  get localStream$() {
17968
- return this.deferEmission(this.vertoManager.localStream$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18023
+ return this.deferEmission(this.vertoManager.localStream$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17969
18024
  }
17970
18025
  /** Current local media stream, or `null` if not available. */
17971
18026
  get localStream() {
@@ -17973,7 +18028,7 @@ var WebRTCCall = class extends Destroyable {
17973
18028
  }
17974
18029
  /** Observable of the remote media stream from the far end. */
17975
18030
  get remoteStream$() {
17976
- return this.deferEmission(this.vertoManager.remoteStream$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18031
+ return this.deferEmission(this.vertoManager.remoteStream$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17977
18032
  }
17978
18033
  /** Current remote media stream, or `null` if not available. */
17979
18034
  get remoteStream() {
@@ -18176,7 +18231,7 @@ var WebRTCCall = class extends Destroyable {
18176
18231
  });
18177
18232
  else if (event.type === "online") this._recoveryManager?.handleWebSocketReconnect();
18178
18233
  });
18179
- this.subscribeTo(this.clientSession.authenticated$.pipe((0, import_cjs$10.skip)(1), (0, import_cjs$10.filter)(Boolean)), () => {
18234
+ this.subscribeTo(this.clientSession.authenticated$.pipe((0, import_cjs$11.skip)(1), (0, import_cjs$11.filter)(Boolean)), () => {
18180
18235
  logger$11.debug("[Call] WebSocket reconnected — notifying recovery manager");
18181
18236
  this._recoveryManager?.handleWebSocketReconnect();
18182
18237
  });
@@ -18205,14 +18260,14 @@ var WebRTCCall = class extends Destroyable {
18205
18260
  }
18206
18261
  /** Observable of the current audio/video send/receive directions. */
18207
18262
  get mediaDirections$() {
18208
- return this.deferEmission(this.vertoManager.mediaDirections$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18263
+ return this.deferEmission(this.vertoManager.mediaDirections$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
18209
18264
  }
18210
18265
  /** Current audio/video send/receive directions. */
18211
18266
  get mediaDirections() {
18212
18267
  return this.vertoManager.mediaDirections;
18213
18268
  }
18214
18269
  get participantsId$() {
18215
- return this.cachedObservable("participantsId$", () => this.participants$.pipe((0, import_cjs$10.map)((participants) => participants.map((participant) => participant.id))));
18270
+ return this.cachedObservable("participantsId$", () => this.participants$.pipe((0, import_cjs$11.map)((participants) => participants.map((participant) => participant.id))));
18216
18271
  }
18217
18272
  /**
18218
18273
  * Executes a raw JSON-RPC request on the client session.
@@ -18256,37 +18311,37 @@ var WebRTCCall = class extends Destroyable {
18256
18311
  }
18257
18312
  }
18258
18313
  get callSessionEvents$() {
18259
- return this.cachedObservable("callSessionEvents$", () => this.clientSession.signalingEvent$.pipe((0, import_cjs$10.filter)((event) => this.isCallSessionEvent(event)), (0, import_cjs$10.tap)((event) => {
18314
+ return this.cachedObservable("callSessionEvents$", () => this.clientSession.signalingEvent$.pipe((0, import_cjs$11.filter)((event) => this.isCallSessionEvent(event)), (0, import_cjs$11.tap)((event) => {
18260
18315
  logger$11.debug("[Call] Received call session event:", event);
18261
- }), (0, import_cjs$10.takeUntil)(this.destroyed$), (0, import_cjs$10.share)()));
18316
+ }), (0, import_cjs$11.takeUntil)(this.destroyed$), (0, import_cjs$11.share)()));
18262
18317
  }
18263
18318
  /** Observable of call-updated events. */
18264
18319
  get callUpdated$() {
18265
- return this.publicCachedObservable("callUpdated$", () => this.callSessionEvents$.pipe(filterAs(isCallUpdatedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18320
+ return this.publicCachedObservable("callUpdated$", () => this.callSessionEvents$.pipe(filterAs(isCallUpdatedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18266
18321
  }
18267
18322
  /** Observable of member-joined events, emitted when a remote participant joins the call. */
18268
18323
  get memberJoined$() {
18269
- return this.publicCachedObservable("memberJoined$", () => this.callSessionEvents$.pipe(filterAs(isMemberJoinedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18324
+ return this.publicCachedObservable("memberJoined$", () => this.callSessionEvents$.pipe(filterAs(isMemberJoinedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18270
18325
  }
18271
18326
  /** Observable of member-left events, emitted when a participant leaves the call. */
18272
18327
  get memberLeft$() {
18273
- return this.publicCachedObservable("memberLeft$", () => this.callSessionEvents$.pipe(filterAs(isMemberLeftMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18328
+ return this.publicCachedObservable("memberLeft$", () => this.callSessionEvents$.pipe(filterAs(isMemberLeftMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18274
18329
  }
18275
18330
  /** Observable of member-updated events (mute, volume, etc.). */
18276
18331
  get memberUpdated$() {
18277
- return this.publicCachedObservable("memberUpdated$", () => this.callSessionEvents$.pipe(filterAs(isMemberUpdatedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18332
+ return this.publicCachedObservable("memberUpdated$", () => this.callSessionEvents$.pipe(filterAs(isMemberUpdatedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18278
18333
  }
18279
18334
  /** Observable of member-talking events (speech start/stop). */
18280
18335
  get memberTalking$() {
18281
- return this.publicCachedObservable("memberTalking$", () => this.callSessionEvents$.pipe(filterAs(isMemberTalkingMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18336
+ return this.publicCachedObservable("memberTalking$", () => this.callSessionEvents$.pipe(filterAs(isMemberTalkingMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18282
18337
  }
18283
18338
  /** Observable of call state-change events. */
18284
18339
  get callStates$() {
18285
- return this.publicCachedObservable("callStates$", () => this.callSessionEvents$.pipe(filterAs(isCallStateMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18340
+ return this.publicCachedObservable("callStates$", () => this.callSessionEvents$.pipe(filterAs(isCallStateMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18286
18341
  }
18287
18342
  /** Observable of layout-changed events. */
18288
18343
  get layoutUpdates$() {
18289
- return this.publicCachedObservable("layoutUpdates$", () => this.callSessionEvents$.pipe(filterAs(isLayoutChangedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18344
+ return this.publicCachedObservable("layoutUpdates$", () => this.callSessionEvents$.pipe(filterAs(isLayoutChangedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18290
18345
  }
18291
18346
  /** Underlying `RTCPeerConnection`, for advanced use cases. */
18292
18347
  get rtcPeerConnection() {
@@ -18294,7 +18349,7 @@ var WebRTCCall = class extends Destroyable {
18294
18349
  }
18295
18350
  /** Observable of raw signaling events as plain objects. */
18296
18351
  get signalingEvent$() {
18297
- return this.publicCachedObservable("signalingEvent$", () => this.callEvent$.pipe((0, import_cjs$10.map)((event) => JSON.parse(JSON.stringify(event)))));
18352
+ return this.publicCachedObservable("signalingEvent$", () => this.callEvent$.pipe((0, import_cjs$11.map)((event) => JSON.parse(JSON.stringify(event)))));
18298
18353
  }
18299
18354
  /**
18300
18355
  * Subscribe to a custom signaling event type on this call.
@@ -18322,16 +18377,16 @@ var WebRTCCall = class extends Destroyable {
18322
18377
  subscribe(eventType) {
18323
18378
  const cached = this._customSubscriptions.get(eventType);
18324
18379
  if (cached) return cached;
18325
- const filtered$ = this.callSessionEvents$.pipe((0, import_cjs$10.filter)((event) => event.event_type === eventType), (0, import_cjs$10.map)((event) => JSON.parse(JSON.stringify(event))), (0, import_cjs$10.takeUntil)(this._destroyed$));
18380
+ const filtered$ = this.callSessionEvents$.pipe((0, import_cjs$11.filter)((event) => event.event_type === eventType), (0, import_cjs$11.map)((event) => JSON.parse(JSON.stringify(event))), (0, import_cjs$11.takeUntil)(this._destroyed$));
18326
18381
  this._customSubscriptions.set(eventType, filtered$);
18327
18382
  this._sendVertoSubscribe(eventType);
18328
18383
  return filtered$;
18329
18384
  }
18330
18385
  get webrtcMessages$() {
18331
- return this.cachedObservable("webrtcMessages$", () => this.callSessionEvents$.pipe(filterAs(isWebrtcMessageMetadata, "params"), (0, import_cjs$10.tap)((event) => logger$11.debug("[Call] Event is a WebRTC message event:", event)), (0, import_cjs$10.takeUntil)(this.destroyed$), (0, import_cjs$10.share)()));
18386
+ return this.cachedObservable("webrtcMessages$", () => this.callSessionEvents$.pipe(filterAs(isWebrtcMessageMetadata, "params"), (0, import_cjs$11.tap)((event) => logger$11.debug("[Call] Event is a WebRTC message event:", event)), (0, import_cjs$11.takeUntil)(this.destroyed$), (0, import_cjs$11.share)()));
18332
18387
  }
18333
18388
  get callEvent$() {
18334
- return this.cachedObservable("callEvent$", () => this.callSessionEvents$.pipe(filterAs(isSignalwireCallMetadata, "params"), (0, import_cjs$10.tap)((event) => logger$11.debug("[Call] Event is a call event:", event)), (0, import_cjs$10.takeUntil)(this.destroyed$), (0, import_cjs$10.share)()));
18389
+ return this.cachedObservable("callEvent$", () => this.callSessionEvents$.pipe(filterAs(isSignalwireCallMetadata, "params"), (0, import_cjs$11.tap)((event) => logger$11.debug("[Call] Event is a call event:", event)), (0, import_cjs$11.takeUntil)(this.destroyed$), (0, import_cjs$11.share)()));
18335
18390
  }
18336
18391
  get layoutEvent$() {
18337
18392
  return this.cachedObservable("layoutEvent$", () => this.callEvent$.pipe(filterAs(isLayoutChangedMetadata, "params")));
@@ -18424,7 +18479,7 @@ var WebRTCCall = class extends Destroyable {
18424
18479
  */
18425
18480
  async setLayout(layout, positions) {
18426
18481
  if (!this.layouts.includes(layout)) throw new InvalidParams(`Layout ${layout} is not available in the current call layouts: ${this.layouts.join(", ")}`);
18427
- const selfId = await (0, import_cjs$10.firstValueFrom)(this.selfId$.pipe((0, import_cjs$10.filter)((id) => id !== null)));
18482
+ const selfId = await (0, import_cjs$11.firstValueFrom)(this.selfId$.pipe((0, import_cjs$11.filter)((id) => id !== null)));
18428
18483
  await this.executeMethod(selfId, "call.layout.set", {
18429
18484
  layout,
18430
18485
  positions
@@ -18538,7 +18593,7 @@ var CallFactory = class {
18538
18593
 
18539
18594
  //#endregion
18540
18595
  //#region src/behaviors/Collection.ts
18541
- var import_cjs$9 = require_cjs();
18596
+ var import_cjs$10 = require_cjs();
18542
18597
  const logger$10 = getLogger();
18543
18598
  var Fetcher = class {
18544
18599
  constructor(endpoint, params, http) {
@@ -18580,8 +18635,6 @@ var EntityCollection = class extends Destroyable {
18580
18635
  this.fetchController = fetchController;
18581
18636
  this.update$ = update$;
18582
18637
  this.onError = onError;
18583
- this.loading$ = this.createBehaviorSubject(false);
18584
- this.values$ = this.createReplaySubject(1);
18585
18638
  this.collectionData = /* @__PURE__ */ new Map();
18586
18639
  this.observablesRegistry = /* @__PURE__ */ new Map();
18587
18640
  this.upsertData = (data) => {
@@ -18601,22 +18654,28 @@ var EntityCollection = class extends Destroyable {
18601
18654
  }
18602
18655
  this.collectionData.set(data.id, updated);
18603
18656
  this.observablesRegistry.get(data.id)?.next(updated);
18604
- this.values$.next(Array.from(this.collectionData.values()));
18657
+ this._values$.next(Array.from(this.collectionData.values()));
18605
18658
  };
18659
+ this._loading$ = this.createBehaviorSubject(false);
18660
+ this._values$ = this.createReplaySubject(1);
18606
18661
  this._hasMore$ = this.createBehaviorSubject(true);
18607
- this._destroy$ = new import_cjs$9.Subject();
18608
- this.updateSubscription = this.update$.subscribe(this.upsertData);
18609
- this.loading$.next(false);
18610
- this.hasMore$ = (0, import_cjs$9.defer)(() => (0, import_cjs$9.from)(this.init())).pipe((0, import_cjs$9.switchMap)(() => this._hasMore$), (0, import_cjs$9.distinctUntilChanged)(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.takeUntil)(this._destroy$));
18662
+ this.subscribeTo(this.update$, this.upsertData);
18663
+ this.hasMore$ = (0, import_cjs$10.defer)(() => (0, import_cjs$10.from)(this.init())).pipe((0, import_cjs$10.switchMap)(() => this._hasMore$), (0, import_cjs$10.distinctUntilChanged)(), (0, import_cjs$10.shareReplay)(1), (0, import_cjs$10.takeUntil)(this.destroyed$));
18664
+ }
18665
+ get loading$() {
18666
+ return this._loading$.asObservable();
18611
18667
  }
18612
18668
  get loading() {
18613
- return this.loading$.value;
18669
+ return this._loading$.value;
18670
+ }
18671
+ get values$() {
18672
+ return this._values$.asObservable();
18614
18673
  }
18615
18674
  get hasMore() {
18616
18675
  return this.fetchController.hasMore ?? true;
18617
18676
  }
18618
18677
  get updated$() {
18619
- return this.cachedObservable("updated$", () => this.loading$.pipe((0, import_cjs$9.distinctUntilChanged)(), (0, import_cjs$9.skip)(1), (0, import_cjs$9.filter)((loading) => !loading), (0, import_cjs$9.map)(() => void 0), (0, import_cjs$9.takeUntil)(this._destroy$)));
18678
+ return this.cachedObservable("updated$", () => this._loading$.pipe((0, import_cjs$10.distinctUntilChanged)(), (0, import_cjs$10.skip)(1), (0, import_cjs$10.filter)((loading) => !loading), (0, import_cjs$10.map)(() => void 0), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18620
18679
  }
18621
18680
  get values() {
18622
18681
  return Array.from(this.collectionData.values());
@@ -18630,33 +18689,33 @@ var EntityCollection = class extends Destroyable {
18630
18689
  }
18631
18690
  async fetchMore() {
18632
18691
  try {
18633
- this.loading$.next(true);
18692
+ this._loading$.next(true);
18634
18693
  (await this.fetchController.next()).forEach(this.upsertData);
18635
18694
  this._hasMore$.next(this.fetchController.hasMore ?? false);
18636
- this.loading$.next(false);
18695
+ this._loading$.next(false);
18637
18696
  } catch (error) {
18638
18697
  logger$10.error(`Failed to fetch initial collection data`, error);
18639
18698
  this._hasMore$.next(this.fetchController.hasMore ?? false);
18640
- this.loading$.next(false);
18699
+ this._loading$.next(false);
18641
18700
  this.onError?.(new CollectionFetchError("fetchMore", error));
18642
18701
  }
18643
18702
  }
18644
18703
  async tryFetch(key, value) {
18645
18704
  try {
18646
- this.loading$.next(true);
18705
+ this._loading$.next(true);
18647
18706
  const data = await this.fetchController[key]?.(value);
18648
- this.loading$.next(false);
18707
+ this._loading$.next(false);
18649
18708
  if (data) this.upsertData(data);
18650
18709
  return data;
18651
18710
  } catch (error) {
18652
18711
  logger$10.error(`Failed to fetch data for (${String(key)}:${String(value)}) :`, error);
18653
- this.loading$.next(false);
18712
+ this._loading$.next(false);
18654
18713
  this.onError?.(new CollectionFetchError(`tryFetch(${String(key)})`, error));
18655
18714
  }
18656
18715
  }
18657
18716
  get$(id) {
18658
18717
  if (!this.observablesRegistry.has(id)) {
18659
- this.observablesRegistry.set(id, new import_cjs$9.ReplaySubject(1));
18718
+ this.observablesRegistry.set(id, new import_cjs$10.ReplaySubject(1));
18660
18719
  const data = this.collectionData.get(id);
18661
18720
  if (data) this.observablesRegistry.get(id)?.next(data);
18662
18721
  else this.tryFetch("id", id);
@@ -18671,11 +18730,8 @@ var EntityCollection = class extends Destroyable {
18671
18730
  if (this.fetchController.hasMore !== false) this.fetchMore();
18672
18731
  }
18673
18732
  destroy() {
18674
- this._destroy$.next();
18675
- this._destroy$.complete();
18676
- this.updateSubscription.unsubscribe();
18677
- this.loading$.complete();
18678
18733
  this.observablesRegistry.forEach((subject) => subject.complete());
18734
+ this.observablesRegistry.clear();
18679
18735
  super.destroy();
18680
18736
  }
18681
18737
  };
@@ -18701,15 +18757,15 @@ var EntityCollectionTransformed = class {
18701
18757
  return this.originalCollection.values.filter(this.filter).map(this.mapper);
18702
18758
  }
18703
18759
  get values$() {
18704
- return this._values$ ??= this.originalCollection.values$.pipe((0, import_cjs$9.map)((values) => values.filter(this.filter).map(this.mapper)));
18760
+ return this._values$ ??= this.originalCollection.values$.pipe((0, import_cjs$10.map)((values) => values.filter(this.filter).map(this.mapper)));
18705
18761
  }
18706
18762
  get$(id) {
18707
18763
  const original$ = this.originalCollection.get$(id);
18708
- return !original$ ? original$ : original$.pipe((0, import_cjs$9.pipe)((0, import_cjs$9.filter)(this.filter), (0, import_cjs$9.map)(this.mapper)));
18764
+ return !original$ ? original$ : original$.pipe((0, import_cjs$10.pipe)((0, import_cjs$10.filter)(this.filter), (0, import_cjs$10.map)(this.mapper)));
18709
18765
  }
18710
18766
  async find$(key, value) {
18711
18767
  const original$ = await this.originalCollection.find$(key, value);
18712
- return !original$ ? original$ : original$.pipe((0, import_cjs$9.pipe)((0, import_cjs$9.filter)(this.filter), (0, import_cjs$9.map)(this.mapper)));
18768
+ return !original$ ? original$ : original$.pipe((0, import_cjs$10.pipe)((0, import_cjs$10.filter)(this.filter), (0, import_cjs$10.map)(this.mapper)));
18713
18769
  }
18714
18770
  loadMore() {
18715
18771
  this.originalCollection.loadMore();
@@ -18721,7 +18777,7 @@ var EntityCollectionTransformed = class {
18721
18777
 
18722
18778
  //#endregion
18723
18779
  //#region src/core/entities/Address.ts
18724
- var import_cjs$8 = require_cjs();
18780
+ var import_cjs$9 = require_cjs();
18725
18781
  /**
18726
18782
  * Represents a contact or room in the directory.
18727
18783
  *
@@ -18739,8 +18795,8 @@ var Address = class extends Destroyable {
18739
18795
  if (this._conversationMessages.hasMore) this._conversationMessages.loadMore();
18740
18796
  return this._conversationMessages;
18741
18797
  };
18742
- this.textMessages$ = (0, import_cjs$8.defer)(this.initConversationMessages).pipe((0, import_cjs$8.map)(() => this.textMessage), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.takeUntil)(this.destroyed$));
18743
- this.history$ = (0, import_cjs$8.defer)(this.initConversationMessages).pipe((0, import_cjs$8.map)(() => this.history), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.takeUntil)(this.destroyed$));
18798
+ this.textMessages$ = (0, import_cjs$9.defer)(this.initConversationMessages).pipe((0, import_cjs$9.map)(() => this.textMessage), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.takeUntil)(this.destroyed$));
18799
+ this.history$ = (0, import_cjs$9.defer)(this.initConversationMessages).pipe((0, import_cjs$9.map)(() => this.history), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.takeUntil)(this.destroyed$));
18744
18800
  this._state$ = this.createBehaviorSubject(null);
18745
18801
  }
18746
18802
  /** @internal */
@@ -18775,7 +18831,7 @@ var Address = class extends Destroyable {
18775
18831
  }
18776
18832
  /** Observable of the human-readable display name. */
18777
18833
  get displayName$() {
18778
- return this.cachedObservable("displayName$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.map)((state) => state.display_name), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18834
+ return this.cachedObservable("displayName$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.map)((state) => state.display_name), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18779
18835
  }
18780
18836
  /** Human-readable display name. */
18781
18837
  get displayName() {
@@ -18784,7 +18840,7 @@ var Address = class extends Destroyable {
18784
18840
  }
18785
18841
  /** Observable of the preview image URL. */
18786
18842
  get previewUrl$() {
18787
- return this.cachedObservable("previewUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.map)((state) => state.preview_url), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18843
+ return this.cachedObservable("previewUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.map)((state) => state.preview_url), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18788
18844
  }
18789
18845
  /** Preview image URL. */
18790
18846
  get previewUrl() {
@@ -18793,7 +18849,7 @@ var Address = class extends Destroyable {
18793
18849
  }
18794
18850
  /** Observable of the cover image URL. */
18795
18851
  get coverUrl$() {
18796
- return this.cachedObservable("coverUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.map)((state) => state.cover_url), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18852
+ return this.cachedObservable("coverUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.map)((state) => state.cover_url), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18797
18853
  }
18798
18854
  /** Cover image URL. */
18799
18855
  get coverUrl() {
@@ -18802,7 +18858,7 @@ var Address = class extends Destroyable {
18802
18858
  }
18803
18859
  /** Observable of the underlying resource ID. */
18804
18860
  get resourceId$() {
18805
- return this.cachedObservable("resourceId$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.map)((state) => state.resource_id), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18861
+ return this.cachedObservable("resourceId$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.map)((state) => state.resource_id), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18806
18862
  }
18807
18863
  /** Underlying resource ID. */
18808
18864
  get resourceId() {
@@ -18811,7 +18867,7 @@ var Address = class extends Destroyable {
18811
18867
  }
18812
18868
  /** Observable of the resource type (e.g. `'room'`, `'subscriber'`). */
18813
18869
  get type$() {
18814
- return this.cachedObservable("type$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.map)((state) => state.type), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18870
+ return this.cachedObservable("type$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.map)((state) => state.type), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18815
18871
  }
18816
18872
  /** Resource type (e.g. `'room'`, `'subscriber'`). */
18817
18873
  get type() {
@@ -18820,7 +18876,7 @@ var Address = class extends Destroyable {
18820
18876
  }
18821
18877
  /** Observable of available communication channels (audio, video, messaging). */
18822
18878
  get channels$() {
18823
- return this.cachedObservable("channels$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.map)((state) => state.channels), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18879
+ return this.cachedObservable("channels$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.map)((state) => state.channels), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18824
18880
  }
18825
18881
  /** Available communication channels. */
18826
18882
  get channels() {
@@ -18834,7 +18890,7 @@ var Address = class extends Destroyable {
18834
18890
  }
18835
18891
  /** Observable indicating whether the address (room) is locked. */
18836
18892
  get locked$() {
18837
- return this.cachedObservable("locked$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.shareReplay)(1), (0, import_cjs$8.map)((state) => state.locked), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18893
+ return this.cachedObservable("locked$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.shareReplay)(1), (0, import_cjs$9.map)((state) => state.locked), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18838
18894
  }
18839
18895
  /**
18840
18896
  * Sends a text message to this address.
@@ -18900,7 +18956,7 @@ var Address = class extends Destroyable {
18900
18956
 
18901
18957
  //#endregion
18902
18958
  //#region src/core/utils.ts
18903
- var import_cjs$7 = require_cjs();
18959
+ var import_cjs$8 = require_cjs();
18904
18960
  const logger$9 = getLogger();
18905
18961
  const isRPCConnectResult = (e) => {
18906
18962
  logger$9.debug("isRPCConnectResult check:", e);
@@ -18926,18 +18982,18 @@ var PendingRPC = class PendingRPC {
18926
18982
  return;
18927
18983
  }
18928
18984
  let isSettled = false;
18929
- const subscription = (0, import_cjs$7.race)(responses$.pipe((0, import_cjs$7.filter)((result) => result.id === request.id), (0, import_cjs$7.take)(1)), new import_cjs$7.Observable((subscriber) => {
18985
+ const subscription = (0, import_cjs$8.race)(responses$.pipe((0, import_cjs$8.filter)((result) => result.id === request.id), (0, import_cjs$8.take)(1)), new import_cjs$8.Observable((subscriber) => {
18930
18986
  const timer$3 = setTimeout(() => {
18931
18987
  subscriber.error(new RPCTimeoutError(request.id, timeoutMs));
18932
18988
  }, timeoutMs);
18933
18989
  return () => clearTimeout(timer$3);
18934
- }), signal ? new import_cjs$7.Observable((subscriber) => {
18990
+ }), signal ? new import_cjs$8.Observable((subscriber) => {
18935
18991
  const abortHandler = () => {
18936
18992
  subscriber.error(new DOMException("The operation was aborted", "AbortError"));
18937
18993
  };
18938
18994
  signal.addEventListener("abort", abortHandler);
18939
18995
  return () => signal.removeEventListener("abort", abortHandler);
18940
- }) : import_cjs$7.NEVER).subscribe({
18996
+ }) : import_cjs$8.NEVER).subscribe({
18941
18997
  next: (response) => {
18942
18998
  isSettled = true;
18943
18999
  if (response.error) {
@@ -18977,7 +19033,7 @@ var PendingRPC = class PendingRPC {
18977
19033
 
18978
19034
  //#endregion
18979
19035
  //#region src/managers/ClientSessionManager.ts
18980
- var import_cjs$6 = require_cjs();
19036
+ var import_cjs$7 = require_cjs();
18981
19037
  const logger$8 = getLogger();
18982
19038
  const getAddressSearchURI = (options) => {
18983
19039
  const to = options.to?.split("?")[0];
@@ -19006,17 +19062,17 @@ var ClientSessionManager = class extends Destroyable {
19006
19062
  };
19007
19063
  this._authorization$ = this.createBehaviorSubject(void 0);
19008
19064
  this._errors$ = this.createReplaySubject(1);
19009
- this._authenticated$ = this.createBehaviorSubject(false);
19010
- this._clientBound = false;
19065
+ this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
19066
+ this._wasClientBound = false;
19011
19067
  this._subscriberInfo$ = this.createBehaviorSubject(null);
19012
19068
  this._calls$ = this.createBehaviorSubject({});
19013
19069
  this._iceServers$ = this.createBehaviorSubject([]);
19014
19070
  attachManager.setSession(this);
19015
19071
  this.callFactory = new CallFactory(this, deviceController, attachManager, webRTCApiProvider, networkChange$);
19016
- this.initialized$ = (0, import_cjs$6.defer)(() => (0, import_cjs$6.from)(this.init())).pipe((0, import_cjs$6.shareReplay)(1), (0, import_cjs$6.takeUntil)(this.destroyed$));
19072
+ this.initialized$ = (0, import_cjs$7.defer)(() => (0, import_cjs$7.from)(this.init())).pipe((0, import_cjs$7.shareReplay)(1), (0, import_cjs$7.takeUntil)(this.destroyed$));
19017
19073
  }
19018
19074
  get incomingCalls$() {
19019
- return this.cachedObservable("incomingCalls$", () => this.calls$.pipe((0, import_cjs$6.map)((calls) => calls.filter((call) => call.direction === "inbound"))));
19075
+ return this.cachedObservable("incomingCalls$", () => this.calls$.pipe((0, import_cjs$7.map)((calls) => calls.filter((call) => call.direction === "inbound"))));
19020
19076
  }
19021
19077
  get incomingCalls() {
19022
19078
  return Object.values(this._calls$.value).filter((call) => call.direction === "inbound");
@@ -19028,7 +19084,7 @@ var ClientSessionManager = class extends Destroyable {
19028
19084
  return this._subscriberInfo$.value;
19029
19085
  }
19030
19086
  get calls$() {
19031
- return this.cachedObservable("calls$", () => this._calls$.pipe((0, import_cjs$6.map)((calls) => Object.values(calls))));
19087
+ return this.cachedObservable("calls$", () => this._calls$.pipe((0, import_cjs$7.map)((calls) => Object.values(calls))));
19032
19088
  }
19033
19089
  get calls() {
19034
19090
  return Object.values(this._calls$.value);
@@ -19046,10 +19102,10 @@ var ClientSessionManager = class extends Destroyable {
19046
19102
  return this._errors$.asObservable();
19047
19103
  }
19048
19104
  get authenticated$() {
19049
- return this._authenticated$.asObservable();
19105
+ return this._authState$.pipe((0, import_cjs$7.map)((state) => state.kind === "authenticated"), (0, import_cjs$7.distinctUntilChanged)());
19050
19106
  }
19051
19107
  get authenticated() {
19052
- return this._authenticated$.value;
19108
+ return this._authState$.value.kind === "authenticated";
19053
19109
  }
19054
19110
  /**
19055
19111
  * Whether this session is client-bound (using a Client Bound SAT).
@@ -19058,7 +19114,11 @@ var ClientSessionManager = class extends Destroyable {
19058
19114
  * @internal
19059
19115
  */
19060
19116
  get clientBound() {
19061
- return this._clientBound;
19117
+ return this._wasClientBound;
19118
+ }
19119
+ /** @internal Current auth state for debugging/testing. */
19120
+ get authState() {
19121
+ return this._authState$.value;
19062
19122
  }
19063
19123
  /**
19064
19124
  * Set the directory instance
@@ -19096,13 +19156,16 @@ var ClientSessionManager = class extends Destroyable {
19096
19156
  this._errors$.next(new AuthStateHandlerError(error));
19097
19157
  }
19098
19158
  });
19099
- this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$6.filter)((status) => status === "connected"), (0, import_cjs$6.exhaustMap)(() => {
19159
+ this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$7.filter)((status) => status === "disconnected" || status === "reconnecting")), () => {
19160
+ if (this._authState$.value.kind === "authenticated") this._authState$.next({ kind: "unauthenticated" });
19161
+ });
19162
+ this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$7.filter)((status) => status === "connected"), (0, import_cjs$7.exhaustMap)(() => {
19100
19163
  logger$8.debug("[Session] Connection established, initiating authentication");
19101
- return (0, import_cjs$6.from)(this.authenticate()).pipe((0, import_cjs$6.catchError)((error) => {
19164
+ return (0, import_cjs$7.from)(this.authenticate()).pipe((0, import_cjs$7.catchError)((error) => {
19102
19165
  this.handleAuthenticationError(error).catch((err) => {
19103
19166
  logger$8.error("[Session] Error handling authentication failure:", err);
19104
19167
  });
19105
- return import_cjs$6.EMPTY;
19168
+ return import_cjs$7.EMPTY;
19106
19169
  }));
19107
19170
  })), void 0);
19108
19171
  this.subscribeTo(this.vertoInvite$, async (invite) => {
@@ -19155,23 +19218,23 @@ var ClientSessionManager = class extends Destroyable {
19155
19218
  }
19156
19219
  }
19157
19220
  get authStateEvent$() {
19158
- return this.cachedObservable("authStateEvent$", () => this.signalingEvent$.pipe((0, import_cjs$6.tap)((msg) => {
19221
+ return this.cachedObservable("authStateEvent$", () => this.signalingEvent$.pipe((0, import_cjs$7.tap)((msg) => {
19159
19222
  logger$8.debug("[Session] Received incoming message:", msg);
19160
- }), filterAs(isSignalwireAuthorizationStateMetadata, "params"), (0, import_cjs$6.tap)((event) => {
19223
+ }), filterAs(isSignalwireAuthorizationStateMetadata, "params"), (0, import_cjs$7.tap)((event) => {
19161
19224
  logger$8.debug("[Session] Authorization state event received:", event.authorization_state);
19162
19225
  })));
19163
19226
  }
19164
19227
  get signalingEvent$() {
19165
- return this.cachedObservable("signalingEvent$", () => this.transport.incomingEvent$.pipe(filterAs(isSignalwireRequest, "params"), (0, import_cjs$6.share)()));
19228
+ return this.cachedObservable("signalingEvent$", () => this.transport.incomingEvent$.pipe(filterAs(isSignalwireRequest, "params"), (0, import_cjs$7.share)()));
19166
19229
  }
19167
19230
  get vertoInvite$() {
19168
- return this.cachedObservable("vertoInvite$", () => this.signalingEvent$.pipe((0, import_cjs$6.filter)(isWebrtcMessageMetadata), (0, import_cjs$6.filter)((event) => isVertoInviteMessage(event.params)), (0, import_cjs$6.map)((event) => ({
19231
+ return this.cachedObservable("vertoInvite$", () => this.signalingEvent$.pipe((0, import_cjs$7.filter)(isWebrtcMessageMetadata), (0, import_cjs$7.filter)((event) => isVertoInviteMessage(event.params)), (0, import_cjs$7.map)((event) => ({
19169
19232
  node_id: event.node_id,
19170
19233
  ...event.params.params
19171
19234
  }))));
19172
19235
  }
19173
19236
  get vertoAttach$() {
19174
- return this.cachedObservable("vertoAttach$", () => this.signalingEvent$.pipe((0, import_cjs$6.filter)(isWebrtcMessageMetadata), (0, import_cjs$6.filter)((event) => isVertoAttachMessage(event.params)), (0, import_cjs$6.map)((event) => ({
19237
+ return this.cachedObservable("vertoAttach$", () => this.signalingEvent$.pipe((0, import_cjs$7.filter)(isWebrtcMessageMetadata), (0, import_cjs$7.filter)((event) => isVertoAttachMessage(event.params)), (0, import_cjs$7.map)((event) => ({
19175
19238
  node_id: event.node_id,
19176
19239
  ...event.params.params
19177
19240
  }))));
@@ -19191,14 +19254,14 @@ var ClientSessionManager = class extends Destroyable {
19191
19254
  return { jwt_token: credential.token };
19192
19255
  }
19193
19256
  async connect() {
19194
- await (0, import_cjs$6.firstValueFrom)(this.initialized$);
19257
+ await (0, import_cjs$7.firstValueFrom)(this.initialized$);
19195
19258
  await this.transport.connect();
19196
- await (0, import_cjs$6.firstValueFrom)(this.authenticated$.pipe((0, import_cjs$6.takeUntil)(this.destroyed$), (0, import_cjs$6.filter)(Boolean), (0, import_cjs$6.take)(1), (0, import_cjs$6.timeout)({ first: 15e3 })));
19259
+ await (0, import_cjs$7.firstValueFrom)(this.authenticated$.pipe((0, import_cjs$7.takeUntil)(this.destroyed$), (0, import_cjs$7.filter)(Boolean), (0, import_cjs$7.take)(1), (0, import_cjs$7.timeout)({ first: 15e3 })));
19197
19260
  }
19198
19261
  async handleAuthenticationError(error) {
19199
19262
  logger$8.error("Authentication error:", error);
19200
19263
  const isRecoverableAuthError = error instanceof JSONRPCError && (error.code === RPC_ERROR_REQUESTER_VALIDATION_FAILED || error.code === RPC_ERROR_INVALID_PARAMS || error.code === RPC_ERROR_AUTHENTICATION_FAILED);
19201
- const hasStoredState = await (0, import_cjs$6.firstValueFrom)(this.authorizationState$.pipe((0, import_cjs$6.take)(1))) !== void 0;
19264
+ const hasStoredState = await (0, import_cjs$7.firstValueFrom)(this.authorizationState$.pipe((0, import_cjs$7.take)(1))) !== void 0;
19202
19265
  if (isRecoverableAuthError && hasStoredState) {
19203
19266
  logger$8.debug("[Session] Recoverable auth error — cleaning up stored state and reconnecting fresh");
19204
19267
  try {
@@ -19230,7 +19293,7 @@ var ClientSessionManager = class extends Destroyable {
19230
19293
  if (!resolvedDpopToken && this.dpopManager?.initialized) try {
19231
19294
  resolvedDpopToken = await this.dpopManager.createRpcProof({ method: "signalwire.reauthenticate" });
19232
19295
  } catch (error) {
19233
- if (this._clientBound) throw error;
19296
+ if (this.clientBound) throw error;
19234
19297
  logger$8.warn("[Session] Failed to create DPoP proof for reauthenticate:", error);
19235
19298
  }
19236
19299
  const request = RPCReauthenticate({
@@ -19238,11 +19301,11 @@ var ClientSessionManager = class extends Destroyable {
19238
19301
  jwt_token: token,
19239
19302
  ...resolvedDpopToken ? { dpop_token: resolvedDpopToken } : {}
19240
19303
  });
19241
- await (0, import_cjs$6.lastValueFrom)((0, import_cjs$6.from)(this.transport.execute(request)).pipe(throwOnRPCError(), (0, import_cjs$6.take)(1), (0, import_cjs$6.catchError)((err) => {
19304
+ await (0, import_cjs$7.lastValueFrom)((0, import_cjs$7.from)(this.transport.execute(request)).pipe(throwOnRPCError(), (0, import_cjs$7.take)(1), (0, import_cjs$7.catchError)((err) => {
19242
19305
  logger$8.error("[Session] Re-authentication RPC failed:", err);
19243
19306
  throw err;
19244
19307
  })));
19245
- if (options?.clientBound) this._clientBound = true;
19308
+ if (options?.clientBound) this._wasClientBound = true;
19246
19309
  logger$8.debug("[Session] Re-authentication successful, updating stored auth state");
19247
19310
  } catch (error) {
19248
19311
  logger$8.error("[Session] Re-authentication failed:", error);
@@ -19252,10 +19315,10 @@ var ClientSessionManager = class extends Destroyable {
19252
19315
  }
19253
19316
  async authenticate() {
19254
19317
  logger$8.debug("[Session] Starting authentication process");
19255
- const persistedParams = await (0, import_cjs$6.firstValueFrom)((0, import_cjs$6.combineLatest)({
19318
+ const persistedParams = await (0, import_cjs$7.firstValueFrom)((0, import_cjs$7.combineLatest)({
19256
19319
  protocol: this.transport.protocol$,
19257
19320
  authorization_state: this.authorizationState$
19258
- }).pipe((0, import_cjs$6.take)(1)));
19321
+ }).pipe((0, import_cjs$7.take)(1)));
19259
19322
  logger$8.debug("[Session] Persisted params:\n", {
19260
19323
  protocol: persistedParams.protocol,
19261
19324
  authStateLength: persistedParams.authorization_state?.length
@@ -19265,14 +19328,14 @@ var ClientSessionManager = class extends Destroyable {
19265
19328
  const isReconnect = hasReconnectState && storedToken;
19266
19329
  let dpopToken;
19267
19330
  if (isReconnect) logger$8.debug("[Session] Reconnecting with stored jwt_token + authorization_state");
19268
- else if (this.onBeforeReconnect && this._clientBound) {
19331
+ else if (this.onBeforeReconnect && this.clientBound) {
19269
19332
  logger$8.debug("[Session] Refreshing credentials before fresh connect");
19270
19333
  await this.onBeforeReconnect();
19271
19334
  }
19272
- if ((!isReconnect || this._clientBound) && this.dpopManager?.initialized) try {
19335
+ if ((!isReconnect || this.clientBound) && this.dpopManager?.initialized) try {
19273
19336
  dpopToken = await this.dpopManager.createRpcProof({ method: "signalwire.connect" });
19274
19337
  } catch (error) {
19275
- if (this._clientBound) throw error;
19338
+ if (this.clientBound) throw error;
19276
19339
  logger$8.warn("[Session] Failed to create DPoP proof for connect, proceeding without:", error);
19277
19340
  }
19278
19341
  const rpcConnectRequest = RPCConnect({
@@ -19289,9 +19352,9 @@ var ClientSessionManager = class extends Destroyable {
19289
19352
  protocol: persistedParams.protocol
19290
19353
  } : {}
19291
19354
  });
19292
- const response = await (0, import_cjs$6.lastValueFrom)((0, import_cjs$6.from)(this.transport.execute(rpcConnectRequest)).pipe(throwOnRPCError(), (0, import_cjs$6.map)((res) => res.result), (0, import_cjs$6.filter)(isRPCConnectResult), (0, import_cjs$6.tap)(() => {
19355
+ const response = await (0, import_cjs$7.lastValueFrom)((0, import_cjs$7.from)(this.transport.execute(rpcConnectRequest)).pipe(throwOnRPCError(), (0, import_cjs$7.map)((res) => res.result), (0, import_cjs$7.filter)(isRPCConnectResult), (0, import_cjs$7.tap)(() => {
19293
19356
  logger$8.debug("[Session] Response passed filter, processing authentication result");
19294
- }), (0, import_cjs$6.take)(1), (0, import_cjs$6.catchError)((err) => {
19357
+ }), (0, import_cjs$7.take)(1), (0, import_cjs$7.catchError)((err) => {
19295
19358
  logger$8.error("[Session] Authentication RPC failed:", err);
19296
19359
  throw err;
19297
19360
  })));
@@ -19303,12 +19366,12 @@ var ClientSessionManager = class extends Destroyable {
19303
19366
  if (response.protocol) await this.transport.setProtocol(response.protocol);
19304
19367
  this._authorization$.next(response.authorization);
19305
19368
  this._iceServers$.next(response.ice_servers ?? []);
19306
- this._authenticated$.next(true);
19369
+ this._authState$.next({ kind: "authenticated" });
19307
19370
  logger$8.debug("[Session] Authentication completed successfully");
19308
19371
  }
19309
19372
  async disconnect() {
19310
19373
  this.transport.disconnect();
19311
- this._authenticated$.next(false);
19374
+ this._authState$.next({ kind: "unauthenticated" });
19312
19375
  await this.cleanupStoredConnectionParams();
19313
19376
  }
19314
19377
  async createInboundCall(invite) {
@@ -19323,7 +19386,7 @@ var ClientSessionManager = class extends Destroyable {
19323
19386
  displayDirection: invite.display_direction,
19324
19387
  userVariables: invite.userVariables
19325
19388
  });
19326
- await (0, import_cjs$6.firstValueFrom)(callSession.status$);
19389
+ await (0, import_cjs$7.firstValueFrom)(callSession.status$);
19327
19390
  this._calls$.next({
19328
19391
  [`${callSession.id}`]: callSession,
19329
19392
  ...this._calls$.value
@@ -19356,7 +19419,7 @@ var ClientSessionManager = class extends Destroyable {
19356
19419
  reattach: true,
19357
19420
  ...storedOptions
19358
19421
  });
19359
- await (0, import_cjs$6.firstValueFrom)(callSession.status$);
19422
+ await (0, import_cjs$7.firstValueFrom)(callSession.status$);
19360
19423
  this._calls$.next({
19361
19424
  [`${callSession.id}`]: callSession,
19362
19425
  ...this._calls$.value
@@ -19370,7 +19433,7 @@ var ClientSessionManager = class extends Destroyable {
19370
19433
  to: destinationURI,
19371
19434
  ...options
19372
19435
  });
19373
- await (0, import_cjs$6.firstValueFrom)((0, import_cjs$6.race)(callSession.selfId$.pipe((0, import_cjs$6.filter)((id) => Boolean(id)), (0, import_cjs$6.take)(1), (0, import_cjs$6.timeout)(this.callCreateTimeout)), callSession.errors$.pipe((0, import_cjs$6.take)(1), (0, import_cjs$6.switchMap)((callError) => (0, import_cjs$6.throwError)(() => callError.error)))));
19436
+ await (0, import_cjs$7.firstValueFrom)((0, import_cjs$7.race)(callSession.selfId$.pipe((0, import_cjs$7.filter)((id) => Boolean(id)), (0, import_cjs$7.take)(1), (0, import_cjs$7.timeout)(this.callCreateTimeout)), callSession.errors$.pipe((0, import_cjs$7.take)(1), (0, import_cjs$7.switchMap)((callError) => (0, import_cjs$7.throwError)(() => callError.error)))));
19374
19437
  this._calls$.next({
19375
19438
  [`${callSession.id}`]: callSession,
19376
19439
  ...this._calls$.value
@@ -19379,7 +19442,7 @@ var ClientSessionManager = class extends Destroyable {
19379
19442
  } catch (error) {
19380
19443
  logger$8.error("[Session] Error creating outbound call:", error);
19381
19444
  callSession?.destroy();
19382
- const callError = new CallCreateError(error instanceof import_cjs$6.TimeoutError ? "Call create timeout" : "Call creation failed", error, "outbound");
19445
+ const callError = new CallCreateError(error instanceof import_cjs$7.TimeoutError ? "Call create timeout" : "Call creation failed", error, "outbound");
19383
19446
  this._errors$.next(callError);
19384
19447
  throw callError;
19385
19448
  }
@@ -19398,7 +19461,7 @@ var ClientSessionManager = class extends Destroyable {
19398
19461
  logger$8.warn(`[Session] Directory lookup failed for ${addressURI}, proceeding with raw URI`);
19399
19462
  }
19400
19463
  const callSession = this.callFactory.createCall(address, { ...options });
19401
- this.subscribeTo(callSession.status$.pipe((0, import_cjs$6.filter)((status) => status === "destroyed"), (0, import_cjs$6.take)(1)), () => {
19464
+ this.subscribeTo(callSession.status$.pipe((0, import_cjs$7.filter)((status) => status === "destroyed"), (0, import_cjs$7.take)(1)), () => {
19402
19465
  const { [`${callSession.id}`]: _, ...remainingCalls } = this._calls$.value;
19403
19466
  this._calls$.next(remainingCalls);
19404
19467
  });
@@ -19452,7 +19515,7 @@ const isString = (obj) => typeof obj === "string";
19452
19515
 
19453
19516
  //#endregion
19454
19517
  //#region src/managers/ConversationsManager.ts
19455
- var import_cjs$5 = require_cjs();
19518
+ var import_cjs$6 = require_cjs();
19456
19519
  const logger$7 = getLogger();
19457
19520
  var ConversationMessagesFetcher = class extends Fetcher {
19458
19521
  constructor(groupId, http) {
@@ -19499,7 +19562,7 @@ var ConversationsManager = class {
19499
19562
  }
19500
19563
  async getConversationMessageCollection(addressId) {
19501
19564
  const groupId = this.groupIds.get(addressId) ?? await this.join(addressId);
19502
- return Promise.resolve(new ConversationMessageCollection(groupId, this.clientSession.signalingEvent$.pipe(filterAs(isConversationMessageMetadata, "params"), (0, import_cjs$5.tap)((event) => logger$7.debug("[ConversationsManager ] Conversation Event:", event)), (0, import_cjs$5.map)((params) => ({ ...params }))), this.http, this.onError));
19565
+ return Promise.resolve(new ConversationMessageCollection(groupId, this.clientSession.signalingEvent$.pipe(filterAs(isConversationMessageMetadata, "params"), (0, import_cjs$6.tap)((event) => logger$7.debug("[ConversationsManager ] Conversation Event:", event)), (0, import_cjs$6.map)((params) => ({ ...params }))), this.http, this.onError));
19503
19566
  }
19504
19567
  async sendText(text, destinationAddressId) {
19505
19568
  const groupId = this.groupIds.get(destinationAddressId) ?? await this.join(destinationAddressId);
@@ -19524,7 +19587,7 @@ var ConversationsManager = class {
19524
19587
 
19525
19588
  //#endregion
19526
19589
  //#region src/managers/DeviceTokenManager.ts
19527
- var import_cjs$4 = require_cjs();
19590
+ var import_cjs$5 = require_cjs();
19528
19591
  const logger$6 = getLogger();
19529
19592
  /**
19530
19593
  * Resolves the token expiry timestamp (epoch seconds) using a 3-tier priority chain:
@@ -19569,11 +19632,11 @@ var DeviceTokenManager = class extends Destroyable {
19569
19632
  this._currentToken$ = this.createBehaviorSubject(null);
19570
19633
  this._refreshInProgress = false;
19571
19634
  this._effectiveExpireIn = DEVICE_TOKEN_DEFAULT_EXPIRE_IN;
19572
- this.subscribeTo(this._currentToken$.pipe((0, import_cjs$4.filter)(Boolean), (0, import_cjs$4.switchMap)((tokenData) => {
19635
+ this.subscribeTo(this._currentToken$.pipe((0, import_cjs$5.filter)(Boolean), (0, import_cjs$5.switchMap)((tokenData) => {
19573
19636
  const expiresAt = resolveExpiresAt(tokenData);
19574
19637
  const refreshIn = Math.max(expiresAt * 1e3 - Date.now() - DEVICE_TOKEN_REFRESH_BUFFER_MS, 1e3);
19575
19638
  logger$6.debug(`[DeviceToken] Scheduling Client Bound SAT refresh in ${refreshIn}ms`);
19576
- return (0, import_cjs$4.timer)(refreshIn);
19639
+ return (0, import_cjs$5.timer)(refreshIn);
19577
19640
  })), () => {
19578
19641
  this.executeRefresh();
19579
19642
  });
@@ -19877,14 +19940,14 @@ const isEmptyArray = (a) => {
19877
19940
 
19878
19941
  //#endregion
19879
19942
  //#region src/utils/warnup.ts
19880
- var import_cjs$3 = require_cjs();
19943
+ var import_cjs$4 = require_cjs();
19881
19944
  const warnup = (observable) => {
19882
- observable.pipe((0, import_cjs$3.take)(1)).subscribe();
19945
+ observable.pipe((0, import_cjs$4.take)(1)).subscribe();
19883
19946
  };
19884
19947
 
19885
19948
  //#endregion
19886
19949
  //#region src/managers/DirectoryManager.ts
19887
- var import_cjs$2 = require_cjs();
19950
+ var import_cjs$3 = require_cjs();
19888
19951
  const logger$4 = getLogger();
19889
19952
  var AddressFetcher = class extends Fetcher {
19890
19953
  constructor(http) {
@@ -19922,7 +19985,7 @@ var DirectoryManager = class extends Destroyable {
19922
19985
  this.onError = onError;
19923
19986
  this.addNewAddress = (id) => {
19924
19987
  const address = new Address(id, this.conversationManager, this);
19925
- const observable = this._statesCollection.get$(id)?.pipe(filterNull(), (0, import_cjs$2.map)((data) => {
19988
+ const observable = this._statesCollection.get$(id)?.pipe(filterNull(), (0, import_cjs$3.map)((data) => {
19926
19989
  address.upnext(data);
19927
19990
  return address;
19928
19991
  }));
@@ -19935,7 +19998,7 @@ var DirectoryManager = class extends Destroyable {
19935
19998
  this._addresses$ = this.createBehaviorSubject([]);
19936
19999
  this._addressesInstances = /* @__PURE__ */ new Map();
19937
20000
  this._observableRegistry = /* @__PURE__ */ new Map();
19938
- this._statesCollection = new AddressStateCollection(clientSession.signalingEvent$.pipe(filterAs(isConversationMessageUpdatedMetadata, "params"), (0, import_cjs$2.map)((_) => ({}))), this.http, this.onError);
20001
+ this._statesCollection = new AddressStateCollection(clientSession.signalingEvent$.pipe(filterAs(isConversationMessageUpdatedMetadata, "params"), (0, import_cjs$3.map)((_) => ({}))), this.http, this.onError);
19939
20002
  this.initSubscriptions();
19940
20003
  }
19941
20004
  /** Whether addresses are currently being loaded from the server. */
@@ -20008,7 +20071,7 @@ var DirectoryManager = class extends Destroyable {
20008
20071
  if (!addressId) {
20009
20072
  const found$ = await this._statesCollection.find$("name", name);
20010
20073
  if (found$) {
20011
- const state = await (0, import_cjs$2.firstValueFrom)(found$);
20074
+ const state = await (0, import_cjs$3.firstValueFrom)(found$);
20012
20075
  this.addNewAddress(state.id);
20013
20076
  addressId = state.id;
20014
20077
  }
@@ -20086,11 +20149,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20086
20149
  }
20087
20150
  send(data) {
20088
20151
  if (this._status$.value === "connected" && this.socket?.readyState === 1) {
20089
- try {
20090
- logger$3.debug(`[WebSocketConnectionManager] Sending message:\n${JSON.stringify(JSON.parse(data), null, 2)}`);
20091
- } catch {
20092
- logger$3.warn(`[WebSocketConnectionManager] Sending non-JSON message:\n${data}`);
20093
- }
20152
+ logger$3.wsTraffic({
20153
+ type: "send",
20154
+ raw: data
20155
+ });
20094
20156
  this.socket.send(data);
20095
20157
  } else this.messageQueue.push(data);
20096
20158
  }
@@ -20153,11 +20215,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20153
20215
  this.handleConnectionError();
20154
20216
  }
20155
20217
  handleMessage(event) {
20156
- try {
20157
- logger$3.debug(`[WebSocketConnectionManager] Received message:\n${JSON.stringify(JSON.parse(event.data), null, 2)}`);
20158
- } catch {
20159
- logger$3.warn(`[WebSocketConnectionManager] Received non-JSON message:\n${event.data}`);
20160
- }
20218
+ logger$3.wsTraffic({
20219
+ type: "recv",
20220
+ raw: event.data
20221
+ });
20161
20222
  this._incomingMessages$.next(event);
20162
20223
  }
20163
20224
  handleConnectionError() {
@@ -20215,7 +20276,7 @@ function isSignalwirePingRequest(value) {
20215
20276
 
20216
20277
  //#endregion
20217
20278
  //#region src/managers/TransportManager.ts
20218
- var import_cjs$1 = require_cjs();
20279
+ var import_cjs$2 = require_cjs();
20219
20280
  const logger$2 = getLogger();
20220
20281
  var TransportManager = class extends Destroyable {
20221
20282
  constructor(storage, protocolKey, webSocketConstructor, relayHost, onError) {
@@ -20227,7 +20288,7 @@ var TransportManager = class extends Destroyable {
20227
20288
  this.isConnecting = false;
20228
20289
  this.isConnected = false;
20229
20290
  this.ackEvent = () => {
20230
- return (0, import_cjs$1.tap)((message) => {
20291
+ return (0, import_cjs$2.tap)((message) => {
20231
20292
  if (isSignalwireRequest(message)) try {
20232
20293
  logger$2.debug("[Transport] Sending event ack", { eventId: message.id });
20233
20294
  this.send(RPCEventAckResponse(message.id));
@@ -20237,7 +20298,7 @@ var TransportManager = class extends Destroyable {
20237
20298
  });
20238
20299
  };
20239
20300
  this.replySignalwirePing = () => {
20240
- return (0, import_cjs$1.filter)((message) => {
20301
+ return (0, import_cjs$2.filter)((message) => {
20241
20302
  if (isSignalwirePingRequest(message)) {
20242
20303
  try {
20243
20304
  logger$2.debug("[Transport] Received ping, sending pong", { pingId: message.id });
@@ -20251,7 +20312,7 @@ var TransportManager = class extends Destroyable {
20251
20312
  });
20252
20313
  };
20253
20314
  this.discardStaleEvents = () => {
20254
- return (0, import_cjs$1.filter)((message) => {
20315
+ return (0, import_cjs$2.filter)((message) => {
20255
20316
  if (!isSignalwireRequest(message)) return true;
20256
20317
  const eventChannel = message.params.event_channel;
20257
20318
  if (!eventChannel) return true;
@@ -20274,8 +20335,8 @@ var TransportManager = class extends Destroyable {
20274
20335
  this.subscribeTo(this._webSocketConnections.errors$, (error) => {
20275
20336
  this.onError?.(error);
20276
20337
  });
20277
- this.initialized$ = (0, import_cjs$1.defer)(() => (0, import_cjs$1.from)(this._init())).pipe((0, import_cjs$1.shareReplay)(1), (0, import_cjs$1.takeUntil)(this.destroyed$));
20278
- this._jsonRPCMessage$ = this._webSocketConnections.incomingMessages$.pipe((0, import_cjs$1.map)((event) => {
20338
+ this.initialized$ = (0, import_cjs$2.defer)(() => (0, import_cjs$2.from)(this._init())).pipe((0, import_cjs$2.shareReplay)(1), (0, import_cjs$2.takeUntil)(this.destroyed$));
20339
+ this._jsonRPCMessage$ = this._webSocketConnections.incomingMessages$.pipe((0, import_cjs$2.map)((event) => {
20279
20340
  try {
20280
20341
  return JSON.parse(event.data);
20281
20342
  } catch (error) {
@@ -20283,13 +20344,13 @@ var TransportManager = class extends Destroyable {
20283
20344
  this.onError?.(new MessageParseError(error));
20284
20345
  return null;
20285
20346
  }
20286
- }), (0, import_cjs$1.filter)((message) => message !== null && (isJSONRPCResponse(message) || isJSONRPCRequest(message))), (0, import_cjs$1.catchError)((error) => {
20347
+ }), (0, import_cjs$2.filter)((message) => message !== null && (isJSONRPCResponse(message) || isJSONRPCRequest(message))), (0, import_cjs$2.catchError)((error) => {
20287
20348
  logger$2.error("[Transport] Message processing error:", error);
20288
20349
  this.onError?.(error instanceof Error ? error : new Error(String(error), { cause: error }));
20289
- return import_cjs$1.EMPTY;
20290
- }), (0, import_cjs$1.share)(), (0, import_cjs$1.takeUntil)(this.destroyed$));
20291
- this._jsonRPCResponse$ = this._jsonRPCMessage$.pipe((0, import_cjs$1.filter)(isJSONRPCResponse));
20292
- this._incomingEvent$ = this._jsonRPCMessage$.pipe(this.ackEvent(), this.replySignalwirePing(), (0, import_cjs$1.filter)((message) => !isJSONRPCResponse(message)), this.discardStaleEvents(), (0, import_cjs$1.share)(), (0, import_cjs$1.takeUntil)(this.destroyed$));
20350
+ return import_cjs$2.EMPTY;
20351
+ }), (0, import_cjs$2.share)(), (0, import_cjs$2.takeUntil)(this.destroyed$));
20352
+ this._jsonRPCResponse$ = this._jsonRPCMessage$.pipe((0, import_cjs$2.filter)(isJSONRPCResponse));
20353
+ this._incomingEvent$ = this._jsonRPCMessage$.pipe(this.ackEvent(), this.replySignalwirePing(), (0, import_cjs$2.filter)((message) => !isJSONRPCResponse(message)), this.discardStaleEvents(), (0, import_cjs$2.share)(), (0, import_cjs$2.takeUntil)(this.destroyed$));
20293
20354
  }
20294
20355
  async setProtocol(protocol) {
20295
20356
  this._currentProtocol = protocol;
@@ -20311,7 +20372,7 @@ var TransportManager = class extends Destroyable {
20311
20372
  this.isConnecting = true;
20312
20373
  this.subscribeTo(this.initialized$, () => {
20313
20374
  this._webSocketConnections.connect();
20314
- const connectionSub = this._webSocketConnections.status$.pipe((0, import_cjs$1.filter)((status) => status === "connected" || status === "disconnected"), (0, import_cjs$1.take)(1), (0, import_cjs$1.timeout)(1e4)).subscribe({
20375
+ const connectionSub = this._webSocketConnections.status$.pipe((0, import_cjs$2.filter)((status) => status === "connected" || status === "disconnected"), (0, import_cjs$2.take)(1), (0, import_cjs$2.timeout)(1e4)).subscribe({
20315
20376
  next: (status) => {
20316
20377
  if (status === "connected") {
20317
20378
  this.isConnecting = false;
@@ -20334,7 +20395,7 @@ var TransportManager = class extends Destroyable {
20334
20395
  }
20335
20396
  });
20336
20397
  this.subscriptions.push(connectionSub);
20337
- this.subscribeTo(this._webSocketConnections.status$.pipe((0, import_cjs$1.filter)((status) => status === "disconnected")), () => {
20398
+ this.subscribeTo(this._webSocketConnections.status$.pipe((0, import_cjs$2.filter)((status) => status === "disconnected")), () => {
20338
20399
  logger$2.debug("[Transport] Disconnected");
20339
20400
  this.isConnected = false;
20340
20401
  });
@@ -20400,7 +20461,7 @@ var TransportManager = class extends Destroyable {
20400
20461
 
20401
20462
  //#endregion
20402
20463
  //#region src/clients/SignalWire.ts
20403
- var import_cjs = require_cjs();
20464
+ var import_cjs$1 = require_cjs();
20404
20465
  const logger$1 = getLogger();
20405
20466
  const buildOptionsFromDestination = (destination) => {
20406
20467
  if (typeof destination === "string") {
@@ -20460,6 +20521,9 @@ var SignalWire = class extends Destroyable {
20460
20521
  if (this._options.webSocketConstructor) this._deps.WebSocket = this._options.webSocketConstructor;
20461
20522
  if (this._options.savePreferences) this.preferences.enableSavePreferences(this._deps.storage);
20462
20523
  if (this._options.webRTCApiProvider) this._deps.webRTCApiProvider = this._options.webRTCApiProvider;
20524
+ if (this._options.logger !== void 0) setLogger(this._options.logger);
20525
+ if (this._options.logLevel) setLogLevel(this._options.logLevel);
20526
+ if (this._options.debug) setDebugOptions(this._options.debug);
20463
20527
  this._deviceController = this._deps.deviceController;
20464
20528
  if (!this._options.skipDeviceMonitoring) this._deviceController.enableDeviceMonitoring();
20465
20529
  this.subscribeTo(this._deviceController.errors$, (error) => {
@@ -20533,28 +20597,7 @@ var SignalWire = class extends Destroyable {
20533
20597
  logger$1.error("[SignalWire] Provided credentials have expired.");
20534
20598
  throw new InvalidCredentialsError("Provided credentials have expired.");
20535
20599
  }
20536
- if (_credentials.expiry_at && credentialProvider?.refresh) {
20537
- const refreshFn = async () => {
20538
- if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20539
- return credentialProvider.refresh();
20540
- };
20541
- const refreshInterval = Math.max(_credentials.expiry_at - Date.now() - 5e3, 1e3);
20542
- this._refreshTimerId = setTimeout(async () => {
20543
- try {
20544
- const newCredentials = await refreshFn();
20545
- this._deps.credential = newCredentials;
20546
- this.persistCredential(newCredentials);
20547
- logger$1.info("[SignalWire] Credentials refreshed successfully.");
20548
- this.validateCredentials(credentialProvider, newCredentials).catch((error) => {
20549
- logger$1.error("[SignalWire] Credential refresh error:", error);
20550
- this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20551
- });
20552
- } catch (error) {
20553
- logger$1.error("[SignalWire] Credential refresh failed:", error);
20554
- this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20555
- }
20556
- }, refreshInterval);
20557
- }
20600
+ if (_credentials.expiry_at && credentialProvider?.refresh) this.scheduleCredentialRefresh(credentialProvider, _credentials.expiry_at);
20558
20601
  this._deps.credential = _credentials;
20559
20602
  this.persistCredential(_credentials);
20560
20603
  if (this.isConnected && this._clientSession.authenticated && _credentials.token) try {
@@ -20565,6 +20608,35 @@ var SignalWire = class extends Destroyable {
20565
20608
  this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20566
20609
  }
20567
20610
  }
20611
+ /**
20612
+ * Schedules credential refresh with exponential backoff retry on failure.
20613
+ * On success, resets attempt counter and schedules the next refresh.
20614
+ * After exhausting retries, emits TokenRefreshError and disconnects.
20615
+ */
20616
+ scheduleCredentialRefresh(credentialProvider, expiresAt, attempt = 0) {
20617
+ if (this._refreshTimerId !== void 0) clearTimeout(this._refreshTimerId);
20618
+ const refreshInterval = attempt === 0 ? Math.max(expiresAt - Date.now() - CREDENTIAL_REFRESH_BUFFER_MS, 1e3) : Math.min(CREDENTIAL_REFRESH_RETRY_BASE_MS * Math.pow(2, attempt) * (.5 + Math.random() * .5), CREDENTIAL_REFRESH_MAX_DELAY_MS);
20619
+ this._refreshTimerId = setTimeout(async () => {
20620
+ try {
20621
+ if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20622
+ const newCredentials = await credentialProvider.refresh();
20623
+ this._deps.credential = newCredentials;
20624
+ this.persistCredential(newCredentials);
20625
+ logger$1.info("[SignalWire] Credentials refreshed successfully.");
20626
+ if (newCredentials.expiry_at) this.scheduleCredentialRefresh(credentialProvider, newCredentials.expiry_at, 0);
20627
+ } catch (error) {
20628
+ const nextAttempt = attempt + 1;
20629
+ logger$1.error(`[SignalWire] Credential refresh failed (attempt ${nextAttempt}/${CREDENTIAL_REFRESH_MAX_RETRIES}):`, error);
20630
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20631
+ if (nextAttempt < CREDENTIAL_REFRESH_MAX_RETRIES) this.scheduleCredentialRefresh(credentialProvider, expiresAt, nextAttempt);
20632
+ else {
20633
+ logger$1.error("[SignalWire] Credential refresh exhausted all retries. Disconnecting.");
20634
+ this._errors$.next(new TokenRefreshError("Credential refresh failed after max retries"));
20635
+ this.disconnect();
20636
+ }
20637
+ }
20638
+ }, refreshInterval);
20639
+ }
20568
20640
  /** Persist credential to localStorage when persistSession is enabled. */
20569
20641
  persistCredential(credential) {
20570
20642
  if (!credential.token) return;
@@ -20606,9 +20678,9 @@ var SignalWire = class extends Destroyable {
20606
20678
  * unexpectedly (e.g. network change, server restart). Reconnection uses an
20607
20679
  * **exponential back-off** strategy:
20608
20680
  *
20609
- * - First retry after `reconnectDelayMin` (default **1 s**).
20681
+ * - First retry after `reconnectDelayMin` (default **0.1 s**).
20610
20682
  * - Each subsequent retry doubles the delay up to `reconnectDelayMax`
20611
- * (default **30 s**).
20683
+ * (default **3 s**).
20612
20684
  * - The delay resets to `reconnectDelayMin` once a connection succeeds.
20613
20685
  * - A per-attempt `connectionTimeout` (default **10 s**) aborts the
20614
20686
  * attempt and schedules the next retry if the server does not respond.
@@ -20637,7 +20709,7 @@ var SignalWire = class extends Destroyable {
20637
20709
  try {
20638
20710
  const subscriber = this._subscriber$.value;
20639
20711
  if (!subscriber) throw new UnexpectedError("Subscriber not initialized before connect");
20640
- if (!await (0, import_cjs.firstValueFrom)(subscriber.fetched$)) throw new UnexpectedError("Failed to fetch subscriber information - fetched$ emitted false");
20712
+ if (!await (0, import_cjs$1.firstValueFrom)(subscriber.fetched$)) throw new UnexpectedError("Failed to fetch subscriber information - fetched$ emitted false");
20641
20713
  this._deps.subscriber = subscriber;
20642
20714
  } catch (error) {
20643
20715
  logger$1.error(`[SignalWire] Failed to fetch subscriber information: ${error instanceof Error ? error.message : "Unknown error"}. This usually means the subscriber token is invalid or expired.`);
@@ -20660,6 +20732,8 @@ var SignalWire = class extends Destroyable {
20660
20732
  logger$1.debug("[SignalWire] Credential refreshed successfully for reconnect");
20661
20733
  } catch (error) {
20662
20734
  logger$1.error("[SignalWire] Failed to refresh credentials for reconnect:", error);
20735
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20736
+ throw error;
20663
20737
  }
20664
20738
  };
20665
20739
  this.subscribeTo(this._clientSession.errors$, (error) => {
@@ -20680,7 +20754,7 @@ var SignalWire = class extends Destroyable {
20680
20754
  };
20681
20755
  });
20682
20756
  }
20683
- this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs.skip)(1), (0, import_cjs.filter)(Boolean)), async () => {
20757
+ this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(1), (0, import_cjs$1.filter)(Boolean)), async () => {
20684
20758
  try {
20685
20759
  if (this._deviceTokenManager) {
20686
20760
  await this._deviceTokenManager.activate(this._deps.subscriber, this._clientSession, (cred) => {
@@ -20710,7 +20784,7 @@ var SignalWire = class extends Destroyable {
20710
20784
  this._clientSession.setDirectory(directory);
20711
20785
  this._isConnected$.next(true);
20712
20786
  this._diagnosticsCollector?.record("connection", "connected");
20713
- this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs.skip)(2), (0, import_cjs.filter)(Boolean)), () => {
20787
+ this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(2), (0, import_cjs$1.filter)(Boolean)), () => {
20714
20788
  this._diagnosticsCollector?.record("connection", "reconnected");
20715
20789
  });
20716
20790
  }
@@ -20772,7 +20846,7 @@ var SignalWire = class extends Destroyable {
20772
20846
  }
20773
20847
  /** Observable that emits `true` when the client is both connected and authenticated. */
20774
20848
  get ready$() {
20775
- return this.publicCachedObservable("ready$", () => this._isConnected$.pipe((0, import_cjs.switchMap)((connected) => connected ? this._clientSession.authenticated$ : (0, import_cjs.of)(false))));
20849
+ return this.publicCachedObservable("ready$", () => this._isConnected$.pipe((0, import_cjs$1.switchMap)((connected) => connected ? this._clientSession.authenticated$ : (0, import_cjs$1.of)(false))));
20776
20850
  }
20777
20851
  /** Observable stream of errors from transport, authentication, and devices. */
20778
20852
  get errors$() {
@@ -20835,7 +20909,7 @@ var SignalWire = class extends Destroyable {
20835
20909
  }
20836
20910
  try {
20837
20911
  this._visibilityController = new VisibilityController();
20838
- this.subscribeTo(this._visibilityController.visibilityChange$.pipe((0, import_cjs.filter)((event) => event.to === "visible" && PreferencesContainer.instance.refreshDevicesOnVisible)), () => {
20912
+ this.subscribeTo(this._visibilityController.visibilityChange$.pipe((0, import_cjs$1.filter)((event) => event.to === "visible" && PreferencesContainer.instance.refreshDevicesOnVisible)), () => {
20839
20913
  logger$1.debug("[SignalWire] Page visible, re-enumerating devices");
20840
20914
  try {
20841
20915
  this._deviceController.disableDeviceMonitoring();
@@ -20858,13 +20932,17 @@ var SignalWire = class extends Destroyable {
20858
20932
  * which creates a fresh transport and session.
20859
20933
  */
20860
20934
  async disconnect() {
20935
+ if (this._refreshTimerId) {
20936
+ clearTimeout(this._refreshTimerId);
20937
+ this._refreshTimerId = void 0;
20938
+ }
20861
20939
  this._diagnosticsCollector?.record("connection", "disconnected");
20862
20940
  await this._clientSession.disconnect();
20863
20941
  this._clientSession.destroy();
20864
20942
  this._isConnected$.next(false);
20865
20943
  }
20866
20944
  async waitAuthentication() {
20867
- await (0, import_cjs.firstValueFrom)(this.ready$.pipe((0, import_cjs.filter)((ready$1) => ready$1 === true)));
20945
+ await (0, import_cjs$1.firstValueFrom)(this.ready$.pipe((0, import_cjs$1.filter)((ready$1) => ready$1 === true)));
20868
20946
  }
20869
20947
  /**
20870
20948
  * Registers the subscriber as online to receive inbound calls and events.
@@ -21259,6 +21337,7 @@ var EmbedTokenCredentialProvider = class {
21259
21337
 
21260
21338
  //#endregion
21261
21339
  //#region src/utils/embeddableCall.ts
21340
+ var import_cjs = require_cjs();
21262
21341
  /**
21263
21342
  * Creates a call using an embed token for simple, embeddable integrations.
21264
21343
  *
@@ -21274,7 +21353,12 @@ async function embeddableCall(options) {
21274
21353
  if (!embedToken) requiredFailed.push("embedToken");
21275
21354
  if (!host) requiredFailed.push("host");
21276
21355
  if (requiredFailed.length > 0) return Promise.reject(new DependencyError(`Missing required options: ${requiredFailed.join(", ")}`));
21277
- return await new SignalWire(new EmbedTokenCredentialProvider(host, embedToken)).dial(to);
21356
+ const client = new SignalWire(new EmbedTokenCredentialProvider(host, embedToken));
21357
+ const call = await client.dial(to);
21358
+ call.status$.pipe((0, import_cjs.first)((status) => status === "destroyed")).subscribe(() => {
21359
+ client.disconnect();
21360
+ });
21361
+ return call;
21278
21362
  }
21279
21363
 
21280
21364
  //#endregion
@@ -21351,5 +21435,5 @@ emitReadyEvent();
21351
21435
  if (typeof process === "undefined") globalThis.process = { env: { NODE_ENV: "production" } };
21352
21436
 
21353
21437
  //#endregion
21354
- export { Address, CallCreateError, ClientPreferences, CollectionFetchError, DPoPInitError, DeviceTokenError, InvalidCredentialsError, MediaTrackError, MessageParseError, OverconstrainedFallbackError, Participant, PreflightError, RecoveryError, SelfCapabilities, SelfParticipant, SignalWire, StaticCredentialProvider, Subscriber, TokenRefreshError, UnexpectedError, VertoPongError, WebRTCCall, embeddableCall, isSelfParticipant, ready, version };
21438
+ export { Address, CallCreateError, ClientPreferences, CollectionFetchError, DPoPInitError, DeviceTokenError, InvalidCredentialsError, MediaTrackError, MessageParseError, OverconstrainedFallbackError, Participant, PreflightError, RecoveryError, SelfCapabilities, SelfParticipant, SignalWire, StaticCredentialProvider, Subscriber, TokenRefreshError, UnexpectedError, VertoPongError, WebRTCCall, embeddableCall, isSelfParticipant, ready, setDebugOptions, setLogLevel, setLogger, version };
21355
21439
  //# sourceMappingURL=browser.mjs.map