@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.
@@ -1129,9 +1129,9 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1129
1129
  var ObjectUnsubscribedError_1$1 = require_ObjectUnsubscribedError();
1130
1130
  var arrRemove_1$6 = require_arrRemove();
1131
1131
  var errorContext_1 = require_errorContext();
1132
- var Subject$3 = function(_super) {
1133
- __extends$13(Subject$4, _super);
1134
- function Subject$4() {
1132
+ var Subject$2 = function(_super) {
1133
+ __extends$13(Subject$3, _super);
1134
+ function Subject$3() {
1135
1135
  var _this = _super.call(this) || this;
1136
1136
  _this.closed = false;
1137
1137
  _this.currentObservers = null;
@@ -1141,15 +1141,15 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1141
1141
  _this.thrownError = null;
1142
1142
  return _this;
1143
1143
  }
1144
- Subject$4.prototype.lift = function(operator) {
1144
+ Subject$3.prototype.lift = function(operator) {
1145
1145
  var subject = new AnonymousSubject(this, this);
1146
1146
  subject.operator = operator;
1147
1147
  return subject;
1148
1148
  };
1149
- Subject$4.prototype._throwIfClosed = function() {
1149
+ Subject$3.prototype._throwIfClosed = function() {
1150
1150
  if (this.closed) throw new ObjectUnsubscribedError_1$1.ObjectUnsubscribedError();
1151
1151
  };
1152
- Subject$4.prototype.next = function(value) {
1152
+ Subject$3.prototype.next = function(value) {
1153
1153
  var _this = this;
1154
1154
  errorContext_1.errorContext(function() {
1155
1155
  var e_1, _a;
@@ -1170,7 +1170,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1170
1170
  }
1171
1171
  });
1172
1172
  };
1173
- Subject$4.prototype.error = function(err) {
1173
+ Subject$3.prototype.error = function(err) {
1174
1174
  var _this = this;
1175
1175
  errorContext_1.errorContext(function() {
1176
1176
  _this._throwIfClosed();
@@ -1182,7 +1182,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1182
1182
  }
1183
1183
  });
1184
1184
  };
1185
- Subject$4.prototype.complete = function() {
1185
+ Subject$3.prototype.complete = function() {
1186
1186
  var _this = this;
1187
1187
  errorContext_1.errorContext(function() {
1188
1188
  _this._throwIfClosed();
@@ -1193,11 +1193,11 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1193
1193
  }
1194
1194
  });
1195
1195
  };
1196
- Subject$4.prototype.unsubscribe = function() {
1196
+ Subject$3.prototype.unsubscribe = function() {
1197
1197
  this.isStopped = this.closed = true;
1198
1198
  this.observers = this.currentObservers = null;
1199
1199
  };
1200
- Object.defineProperty(Subject$4.prototype, "observed", {
1200
+ Object.defineProperty(Subject$3.prototype, "observed", {
1201
1201
  get: function() {
1202
1202
  var _a;
1203
1203
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
@@ -1205,16 +1205,16 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1205
1205
  enumerable: false,
1206
1206
  configurable: true
1207
1207
  });
1208
- Subject$4.prototype._trySubscribe = function(subscriber) {
1208
+ Subject$3.prototype._trySubscribe = function(subscriber) {
1209
1209
  this._throwIfClosed();
1210
1210
  return _super.prototype._trySubscribe.call(this, subscriber);
1211
1211
  };
1212
- Subject$4.prototype._subscribe = function(subscriber) {
1212
+ Subject$3.prototype._subscribe = function(subscriber) {
1213
1213
  this._throwIfClosed();
1214
1214
  this._checkFinalizedStatuses(subscriber);
1215
1215
  return this._innerSubscribe(subscriber);
1216
1216
  };
1217
- Subject$4.prototype._innerSubscribe = function(subscriber) {
1217
+ Subject$3.prototype._innerSubscribe = function(subscriber) {
1218
1218
  var _this = this;
1219
1219
  var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1220
1220
  if (hasError || isStopped) return Subscription_1$6.EMPTY_SUBSCRIPTION;
@@ -1225,22 +1225,22 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1225
1225
  arrRemove_1$6.arrRemove(observers, subscriber);
1226
1226
  });
1227
1227
  };
1228
- Subject$4.prototype._checkFinalizedStatuses = function(subscriber) {
1228
+ Subject$3.prototype._checkFinalizedStatuses = function(subscriber) {
1229
1229
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1230
1230
  if (hasError) subscriber.error(thrownError);
1231
1231
  else if (isStopped) subscriber.complete();
1232
1232
  };
1233
- Subject$4.prototype.asObservable = function() {
1233
+ Subject$3.prototype.asObservable = function() {
1234
1234
  var observable = new Observable_1$24.Observable();
1235
1235
  observable.source = this;
1236
1236
  return observable;
1237
1237
  };
1238
- Subject$4.create = function(destination, source) {
1238
+ Subject$3.create = function(destination, source) {
1239
1239
  return new AnonymousSubject(destination, source);
1240
1240
  };
1241
- return Subject$4;
1241
+ return Subject$3;
1242
1242
  }(Observable_1$24.Observable);
1243
- exports.Subject = Subject$3;
1243
+ exports.Subject = Subject$2;
1244
1244
  var AnonymousSubject = function(_super) {
1245
1245
  __extends$13(AnonymousSubject$1, _super);
1246
1246
  function AnonymousSubject$1(destination, source) {
@@ -1266,7 +1266,7 @@ var require_Subject = /* @__PURE__ */ __commonJSMin(((exports) => {
1266
1266
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1$6.EMPTY_SUBSCRIPTION;
1267
1267
  };
1268
1268
  return AnonymousSubject$1;
1269
- }(Subject$3);
1269
+ }(Subject$2);
1270
1270
  exports.AnonymousSubject = AnonymousSubject;
1271
1271
  }));
1272
1272
 
@@ -3348,8 +3348,8 @@ var require_timeout = /* @__PURE__ */ __commonJSMin(((exports) => {
3348
3348
  };
3349
3349
  });
3350
3350
  function timeout$4(config, schedulerArg) {
3351
- 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;
3352
- if (first$1 == null && each == null) throw new TypeError("No timeout provided.");
3351
+ 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;
3352
+ if (first$2 == null && each == null) throw new TypeError("No timeout provided.");
3353
3353
  return lift_1$65.operate(function(source, subscriber) {
3354
3354
  var originalSourceSubscription;
3355
3355
  var timerSubscription;
@@ -3378,7 +3378,7 @@ var require_timeout = /* @__PURE__ */ __commonJSMin(((exports) => {
3378
3378
  if (!(timerSubscription === null || timerSubscription === void 0 ? void 0 : timerSubscription.closed)) timerSubscription === null || timerSubscription === void 0 || timerSubscription.unsubscribe();
3379
3379
  lastValue = null;
3380
3380
  }));
3381
- !seen && startTimer(first$1 != null ? typeof first$1 === "number" ? first$1 : +first$1 - scheduler.now() : each);
3381
+ !seen && startTimer(first$2 != null ? typeof first$2 === "number" ? first$2 : +first$2 - scheduler.now() : each);
3382
3382
  });
3383
3383
  }
3384
3384
  exports.timeout = timeout$4;
@@ -3394,7 +3394,7 @@ var require_map = /* @__PURE__ */ __commonJSMin(((exports) => {
3394
3394
  exports.map = void 0;
3395
3395
  var lift_1$64 = require_lift();
3396
3396
  var OperatorSubscriber_1$54 = require_OperatorSubscriber();
3397
- function map$19(project, thisArg) {
3397
+ function map$18(project, thisArg) {
3398
3398
  return lift_1$64.operate(function(source, subscriber) {
3399
3399
  var index = 0;
3400
3400
  source.subscribe(OperatorSubscriber_1$54.createOperatorSubscriber(subscriber, function(value) {
@@ -3402,7 +3402,7 @@ var require_map = /* @__PURE__ */ __commonJSMin(((exports) => {
3402
3402
  }));
3403
3403
  });
3404
3404
  }
3405
- exports.map = map$19;
3405
+ exports.map = map$18;
3406
3406
  }));
3407
3407
 
3408
3408
  //#endregion
@@ -5474,23 +5474,23 @@ var require_distinctUntilChanged = /* @__PURE__ */ __commonJSMin(((exports) => {
5474
5474
  var identity_1$10 = require_identity();
5475
5475
  var lift_1$42 = require_lift();
5476
5476
  var OperatorSubscriber_1$31 = require_OperatorSubscriber();
5477
- function distinctUntilChanged$7(comparator, keySelector) {
5477
+ function distinctUntilChanged$8(comparator, keySelector) {
5478
5478
  if (keySelector === void 0) keySelector = identity_1$10.identity;
5479
5479
  comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
5480
5480
  return lift_1$42.operate(function(source, subscriber) {
5481
5481
  var previousKey;
5482
- var first$1 = true;
5482
+ var first$2 = true;
5483
5483
  source.subscribe(OperatorSubscriber_1$31.createOperatorSubscriber(subscriber, function(value) {
5484
5484
  var currentKey = keySelector(value);
5485
- if (first$1 || !comparator(previousKey, currentKey)) {
5486
- first$1 = false;
5485
+ if (first$2 || !comparator(previousKey, currentKey)) {
5486
+ first$2 = false;
5487
5487
  previousKey = currentKey;
5488
5488
  subscriber.next(value);
5489
5489
  }
5490
5490
  }));
5491
5491
  });
5492
5492
  }
5493
- exports.distinctUntilChanged = distinctUntilChanged$7;
5493
+ exports.distinctUntilChanged = distinctUntilChanged$8;
5494
5494
  function defaultCompare(a, b) {
5495
5495
  return a === b;
5496
5496
  }
@@ -5771,7 +5771,7 @@ var require_first = /* @__PURE__ */ __commonJSMin(((exports) => {
5771
5771
  var defaultIfEmpty_1$3 = require_defaultIfEmpty();
5772
5772
  var throwIfEmpty_1$3 = require_throwIfEmpty();
5773
5773
  var identity_1$8 = require_identity();
5774
- function first(predicate, defaultValue) {
5774
+ function first$1(predicate, defaultValue) {
5775
5775
  var hasDefaultValue = arguments.length >= 2;
5776
5776
  return function(source) {
5777
5777
  return source.pipe(predicate ? filter_1$5.filter(function(v, i) {
@@ -5781,7 +5781,7 @@ var require_first = /* @__PURE__ */ __commonJSMin(((exports) => {
5781
5781
  }));
5782
5782
  };
5783
5783
  }
5784
- exports.first = first;
5784
+ exports.first = first$1;
5785
5785
  }));
5786
5786
 
5787
5787
  //#endregion
@@ -6829,12 +6829,12 @@ var require_skip = /* @__PURE__ */ __commonJSMin(((exports) => {
6829
6829
  Object.defineProperty(exports, "__esModule", { value: true });
6830
6830
  exports.skip = void 0;
6831
6831
  var filter_1$3 = require_filter();
6832
- function skip$4(count$1) {
6832
+ function skip$3(count$1) {
6833
6833
  return filter_1$3.filter(function(_, index) {
6834
6834
  return count$1 <= index;
6835
6835
  });
6836
6836
  }
6837
- exports.skip = skip$4;
6837
+ exports.skip = skip$3;
6838
6838
  }));
6839
6839
 
6840
6840
  //#endregion
@@ -7212,19 +7212,19 @@ var require_timeoutWith = /* @__PURE__ */ __commonJSMin(((exports) => {
7212
7212
  var isDate_1 = require_isDate();
7213
7213
  var timeout_1$2 = require_timeout();
7214
7214
  function timeoutWith(due, withObservable, scheduler) {
7215
- var first$1;
7215
+ var first$2;
7216
7216
  var each;
7217
7217
  var _with;
7218
7218
  scheduler = scheduler !== null && scheduler !== void 0 ? scheduler : async_1$2.async;
7219
- if (isDate_1.isValidDate(due)) first$1 = due;
7219
+ if (isDate_1.isValidDate(due)) first$2 = due;
7220
7220
  else if (typeof due === "number") each = due;
7221
7221
  if (withObservable) _with = function() {
7222
7222
  return withObservable;
7223
7223
  };
7224
7224
  else throw new TypeError("No observable provided to switch to");
7225
- if (first$1 == null && each == null) throw new TypeError("No timeout provided.");
7225
+ if (first$2 == null && each == null) throw new TypeError("No timeout provided.");
7226
7226
  return timeout_1$2.timeout({
7227
- first: first$1,
7227
+ first: first$2,
7228
7228
  each,
7229
7229
  scheduler,
7230
7230
  with: _with
@@ -8937,19 +8937,17 @@ var require_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
8937
8937
 
8938
8938
  //#endregion
8939
8939
  //#region src/behaviors/Destroyable.ts
8940
- var import_cjs$28 = require_cjs();
8940
+ var import_cjs$29 = require_cjs();
8941
8941
  var Destroyable = class {
8942
8942
  constructor() {
8943
8943
  this.subscriptions = [];
8944
8944
  this.subjects = [];
8945
- this._destroyed$ = new import_cjs$28.Subject();
8946
- this._change$ = new import_cjs$28.Subject();
8945
+ this._destroyed$ = new import_cjs$29.Subject();
8947
8946
  }
8948
8947
  destroy() {
8949
8948
  this._observableCache?.clear();
8950
8949
  this.subscriptions.forEach((sub) => sub.unsubscribe());
8951
8950
  this.subjects.forEach((subject) => subject.complete());
8952
- this._change$.complete();
8953
8951
  this._destroyed$.next();
8954
8952
  this._destroyed$.complete();
8955
8953
  }
@@ -8980,7 +8978,7 @@ var Destroyable = class {
8980
8978
  this._observableCache ??= /* @__PURE__ */ new Map();
8981
8979
  let cached = this._observableCache.get(publicKey);
8982
8980
  if (!cached) {
8983
- cached = factory().pipe((0, import_cjs$28.observeOn)(import_cjs$28.asapScheduler));
8981
+ cached = factory().pipe((0, import_cjs$29.observeOn)(import_cjs$29.asapScheduler));
8984
8982
  this._observableCache.set(publicKey, cached);
8985
8983
  }
8986
8984
  return cached;
@@ -8994,33 +8992,27 @@ var Destroyable = class {
8994
8992
  * Do NOT use for observables consumed internally by the SDK.
8995
8993
  */
8996
8994
  deferEmission(observable) {
8997
- return observable.pipe((0, import_cjs$28.observeOn)(import_cjs$28.asapScheduler));
8995
+ return observable.pipe((0, import_cjs$29.observeOn)(import_cjs$29.asapScheduler));
8998
8996
  }
8999
8997
  subscribeTo(observable, observerOrNext) {
9000
8998
  const subscription = observable.subscribe(observerOrNext);
9001
8999
  this.subscriptions.push(subscription);
9002
9000
  }
9003
9001
  createSubject() {
9004
- const subject = new import_cjs$28.Subject();
9002
+ const subject = new import_cjs$29.Subject();
9005
9003
  this.subjects.push(subject);
9006
- this.subscriptions.push(subject.pipe((0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9007
9004
  return subject;
9008
9005
  }
9009
9006
  createReplaySubject(bufferSize, windowTime$1) {
9010
- const subject = new import_cjs$28.ReplaySubject(bufferSize, windowTime$1);
9007
+ const subject = new import_cjs$29.ReplaySubject(bufferSize, windowTime$1);
9011
9008
  this.subjects.push(subject);
9012
- this.subscriptions.push(subject.pipe((0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9013
9009
  return subject;
9014
9010
  }
9015
9011
  createBehaviorSubject(initialValue) {
9016
- const subject = new import_cjs$28.BehaviorSubject(initialValue);
9012
+ const subject = new import_cjs$29.BehaviorSubject(initialValue);
9017
9013
  this.subjects.push(subject);
9018
- this.subscriptions.push(subject.pipe((0, import_cjs$28.skip)(1), (0, import_cjs$28.map)(() => void 0)).subscribe(this._change$));
9019
9014
  return subject;
9020
9015
  }
9021
- get $() {
9022
- return this._change$.pipe((0, import_cjs$28.map)(() => this));
9023
- }
9024
9016
  /**
9025
9017
  * Observable that emits when the instance is destroyed
9026
9018
  */
@@ -9504,33 +9496,70 @@ const originalFactory = defaultLogger.methodFactory;
9504
9496
  defaultLogger.methodFactory = (methodName, logLevel, loggerName) => {
9505
9497
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
9506
9498
  return function(...args) {
9507
- args.unshift(datetime(), "-");
9508
- rawMethod.apply(void 0, args);
9499
+ const prefixed = [
9500
+ datetime(),
9501
+ "-",
9502
+ ...args
9503
+ ];
9504
+ rawMethod.apply(void 0, prefixed);
9509
9505
  };
9510
9506
  };
9511
- const defaultLoggerLevel = defaultLogger.levels.DEBUG;
9507
+ const defaultLoggerLevel = defaultLogger.levels.WARN;
9512
9508
  defaultLogger.setLevel(defaultLoggerLevel);
9513
- let userLogger;
9509
+ let userLogger = null;
9510
+ /** Replace the built-in logger with a custom implementation. Pass `null` to restore defaults. */
9511
+ const setLogger = (logger$30) => {
9512
+ userLogger = logger$30;
9513
+ };
9514
9514
  let debugOptions = {};
9515
+ /** Configure debug options (e.g., `{ logWsTraffic: true }`). */
9516
+ const setDebugOptions = (options) => {
9517
+ if (options == null) {
9518
+ debugOptions = {};
9519
+ return;
9520
+ }
9521
+ debugOptions = {
9522
+ ...debugOptions,
9523
+ ...options
9524
+ };
9525
+ };
9526
+ /**
9527
+ * Set the log level for the built-in logger.
9528
+ * Has no effect when a custom logger is set via `setLogger()`.
9529
+ */
9530
+ const setLogLevel = (level) => {
9531
+ defaultLogger.setLevel(level);
9532
+ };
9515
9533
  const getLoggerInstance = () => {
9516
9534
  return userLogger ?? defaultLogger;
9517
9535
  };
9518
9536
  const shouldStringify = (payload) => {
9519
- if ("method" in payload && payload.method === "signalwire.ping") return false;
9537
+ if (payload != null && typeof payload === "object" && "method" in payload) return payload.method !== "signalwire.ping";
9520
9538
  return true;
9521
9539
  };
9522
- const wsTraffic = ({ type, payload }) => {
9523
- const logger$30 = getLoggerInstance();
9524
- const { logWsTraffic } = debugOptions ?? {};
9540
+ const wsTraffic = (options) => {
9541
+ const { logWsTraffic } = debugOptions;
9525
9542
  if (!logWsTraffic) return;
9543
+ const loggerInstance = getLoggerInstance();
9544
+ let payload;
9545
+ if ("raw" in options) try {
9546
+ payload = JSON.parse(options.raw);
9547
+ } catch {
9548
+ loggerInstance.debug(`[WebSocket] ${options.type.toUpperCase()}: non-JSON message`);
9549
+ return;
9550
+ }
9551
+ else payload = options.payload;
9526
9552
  const msg = shouldStringify(payload) ? JSON.stringify(payload, null, 2) : payload;
9527
- return logger$30.debug(`${type.toUpperCase()}: \n`, msg, "\n");
9553
+ loggerInstance.debug(`${options.type.toUpperCase()}: \n`, msg, "\n");
9528
9554
  };
9529
9555
  const getLogger = () => {
9530
9556
  const logger$30 = getLoggerInstance();
9531
- return new Proxy(logger$30, { get(target, prop, receiver) {
9557
+ return new Proxy(logger$30, { get(_target, prop, _receiver) {
9532
9558
  if (prop === "wsTraffic") return wsTraffic;
9533
- return Reflect.get(target, prop, receiver);
9559
+ const instance = getLoggerInstance();
9560
+ const value = Reflect.get(instance, prop);
9561
+ if (typeof value === "function") return value.bind(instance);
9562
+ return value;
9534
9563
  } });
9535
9564
  };
9536
9565
 
@@ -9577,7 +9606,7 @@ const asyncRetry = async ({ asyncCallable, maxRetries: retries = DEFAULT_MAX_RET
9577
9606
 
9578
9607
  //#endregion
9579
9608
  //#region src/controllers/HTTPRequestController.ts
9580
- var import_cjs$27 = require_cjs();
9609
+ var import_cjs$28 = require_cjs();
9581
9610
  const logger$29 = getLogger();
9582
9611
  const GET_PARAMS = {
9583
9612
  method: "GET",
@@ -9613,9 +9642,9 @@ var HTTPRequestController = class HTTPRequestController {
9613
9642
  constructor(baseURL, getCredential, options = {}) {
9614
9643
  this.baseURL = baseURL;
9615
9644
  this.getCredential = getCredential;
9616
- this._responses$ = new import_cjs$27.Subject();
9617
- this._errors$ = new import_cjs$27.Subject();
9618
- this._status$ = new import_cjs$27.BehaviorSubject("idle");
9645
+ this._responses$ = new import_cjs$28.Subject();
9646
+ this._errors$ = new import_cjs$28.Subject();
9647
+ this._status$ = new import_cjs$28.BehaviorSubject("idle");
9619
9648
  this.maxRetries = options.maxRetries ?? HTTPRequestController.defaultMaxRetries;
9620
9649
  this.retryDelayMin = options.retryDelayMin ?? HTTPRequestController.defaultRetryDelayMinMs;
9621
9650
  this.retryDelayMax = options.retryDelayMax ?? HTTPRequestController.defaultRetryDelayMaxMs;
@@ -9875,6 +9904,14 @@ const DEVICE_TOKEN_REFRESH_BUFFER_MS = 3e4;
9875
9904
  const DEVICE_TOKEN_REFRESH_MAX_RETRIES = 3;
9876
9905
  /** Base delay in milliseconds for exponential backoff on refresh retry. */
9877
9906
  const DEVICE_TOKEN_REFRESH_RETRY_BASE_MS = 1e3;
9907
+ /** Maximum retry attempts for developer credential refresh on transient failure. */
9908
+ const CREDENTIAL_REFRESH_MAX_RETRIES = 5;
9909
+ /** Base delay in milliseconds for exponential backoff on credential refresh retry. */
9910
+ const CREDENTIAL_REFRESH_RETRY_BASE_MS = 1e3;
9911
+ /** Maximum delay in milliseconds for credential refresh backoff. */
9912
+ const CREDENTIAL_REFRESH_MAX_DELAY_MS = 3e4;
9913
+ /** Buffer in milliseconds before token expiry to trigger refresh. */
9914
+ const CREDENTIAL_REFRESH_BUFFER_MS = 5e3;
9878
9915
  /** JSON-RPC error code for requester validation failure (corrupted auth state). */
9879
9916
  const RPC_ERROR_REQUESTER_VALIDATION_FAILED = -32003;
9880
9917
  /** JSON-RPC error code for invalid params (e.g., missing authentication block). */
@@ -10641,9 +10678,23 @@ var ClientPreferences = class {
10641
10678
  }
10642
10679
  };
10643
10680
 
10681
+ //#endregion
10682
+ //#region src/utils/toError.ts
10683
+ /**
10684
+ * Normalizes an unknown caught value into a proper Error instance.
10685
+ *
10686
+ * In catch blocks, the caught value is `unknown` — it could be an Error,
10687
+ * string, number, or any other value. This utility ensures a consistent
10688
+ * Error object is produced.
10689
+ */
10690
+ function toError(value) {
10691
+ if (value instanceof Error) return value;
10692
+ return new Error(String(value));
10693
+ }
10694
+
10644
10695
  //#endregion
10645
10696
  //#region src/controllers/NavigatorDeviceController.ts
10646
- var import_cjs$26 = require_cjs();
10697
+ var import_cjs$27 = require_cjs();
10647
10698
  const logger$27 = getLogger();
10648
10699
  /** Maps a device kind to its storage key. */
10649
10700
  const DEVICE_STORAGE_KEYS = {
@@ -10703,17 +10754,17 @@ var NavigatorDeviceController = class extends Destroyable {
10703
10754
  return {};
10704
10755
  }
10705
10756
  get errors$() {
10706
- return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$26.takeUntil)(this.destroyed$)));
10757
+ return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$27.takeUntil)(this.destroyed$)));
10707
10758
  }
10708
10759
  /** Observable that emits when the SDK auto-switches a device. */
10709
10760
  get deviceRecovered$() {
10710
- return this._deviceRecovered$.asObservable().pipe((0, import_cjs$26.takeUntil)(this.destroyed$));
10761
+ return this._deviceRecovered$.asObservable().pipe((0, import_cjs$27.takeUntil)(this.destroyed$));
10711
10762
  }
10712
10763
  get videoInputDisabled$() {
10713
- return this.cachedObservable("videoInputDisabled$", () => this._videoInputDisabled$.asObservable().pipe((0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10764
+ return this.cachedObservable("videoInputDisabled$", () => this._videoInputDisabled$.asObservable().pipe((0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10714
10765
  }
10715
10766
  get audioInputDisabled$() {
10716
- return this.cachedObservable("audioInputDisabled$", () => this._audioInputDisabled$.asObservable().pipe((0, import_cjs$26.distinctUntilChanged)(), (0, import_cjs$26.takeUntil)(this.destroyed$)));
10767
+ return this.cachedObservable("audioInputDisabled$", () => this._audioInputDisabled$.asObservable().pipe((0, import_cjs$27.distinctUntilChanged)(), (0, import_cjs$27.takeUntil)(this.destroyed$)));
10717
10768
  }
10718
10769
  get videoInputDisabled() {
10719
10770
  return this._videoInputDisabled$.value;
@@ -10722,22 +10773,22 @@ var NavigatorDeviceController = class extends Destroyable {
10722
10773
  return this._audioInputDisabled$.value;
10723
10774
  }
10724
10775
  get audioInputDevices$() {
10725
- 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$)));
10776
+ 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$)));
10726
10777
  }
10727
10778
  get audioOutputDevices$() {
10728
- 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$)));
10779
+ 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$)));
10729
10780
  }
10730
10781
  get videoInputDevices$() {
10731
- 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$)));
10782
+ 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$)));
10732
10783
  }
10733
10784
  get selectedAudioInputDevice$() {
10734
- 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))));
10785
+ 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))));
10735
10786
  }
10736
10787
  get selectedAudioOutputDevice$() {
10737
- 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))));
10788
+ 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))));
10738
10789
  }
10739
10790
  get selectedVideoInputDevice$() {
10740
- 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))));
10791
+ 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))));
10741
10792
  }
10742
10793
  get selectedAudioInputDevice() {
10743
10794
  if (this._audioInputDisabled$.value) return null;
@@ -10833,7 +10884,7 @@ var NavigatorDeviceController = class extends Destroyable {
10833
10884
  }
10834
10885
  init() {
10835
10886
  this.loadPersistedDevices();
10836
- this.subscribeTo(this._devicesState$.pipe((0, import_cjs$26.debounceTime)(PreferencesContainer.instance.deviceDebounceTime)), (devicesState) => {
10887
+ this.subscribeTo(this._devicesState$.pipe((0, import_cjs$27.debounceTime)(PreferencesContainer.instance.deviceDebounceTime)), (devicesState) => {
10837
10888
  const currentSelected = this._selectedDevicesState$.value;
10838
10889
  const newAudioInput = this._audioInputDisabled$.value ? null : this.resolveDevice("audioinput", devicesState.audioinput, currentSelected.audioinput, PreferencesContainer.instance.preferredAudioInput);
10839
10890
  const newAudioOutput = this.resolveDevice("audiooutput", devicesState.audiooutput, currentSelected.audiooutput, PreferencesContainer.instance.preferredAudioOutput);
@@ -10955,7 +11006,7 @@ var NavigatorDeviceController = class extends Destroyable {
10955
11006
  enableDeviceMonitoring() {
10956
11007
  this.disableDeviceMonitoring();
10957
11008
  this.webRTCApiProvider.mediaDevices.addEventListener("devicechange", this.deviceChangeHandler);
10958
- if (PreferencesContainer.instance.devicePollingInterval > 0) this._devicesPoolingSubscription = (0, import_cjs$26.interval)(PreferencesContainer.instance.devicePollingInterval).subscribe(() => {
11009
+ if (PreferencesContainer.instance.devicePollingInterval > 0) this._devicesPoolingSubscription = (0, import_cjs$27.interval)(PreferencesContainer.instance.devicePollingInterval).subscribe(() => {
10959
11010
  logger$27.debug("[DeviceController] Polling devices due to interval");
10960
11011
  this.enumerateDevices();
10961
11012
  });
@@ -10989,7 +11040,7 @@ var NavigatorDeviceController = class extends Destroyable {
10989
11040
  });
10990
11041
  } catch (error) {
10991
11042
  logger$27.error("[DeviceController] Failed to enumerate devices:", error);
10992
- this._errors$.next(error);
11043
+ this._errors$.next(toError(error));
10993
11044
  }
10994
11045
  }
10995
11046
  async getDeviceCapabilities(deviceInfo) {
@@ -11005,7 +11056,7 @@ var NavigatorDeviceController = class extends Destroyable {
11005
11056
  return capabilities;
11006
11057
  } catch (error) {
11007
11058
  logger$27.error("[DeviceController] Failed to get device capabilities:", error);
11008
- this._errors$.next(error);
11059
+ this._errors$.next(toError(error));
11009
11060
  throw error;
11010
11061
  }
11011
11062
  }
@@ -11523,7 +11574,7 @@ var CryptoController = class {
11523
11574
 
11524
11575
  //#endregion
11525
11576
  //#region src/controllers/NetworkMonitor.ts
11526
- var import_cjs$25 = require_cjs();
11577
+ var import_cjs$26 = require_cjs();
11527
11578
  const logger$25 = getLogger();
11528
11579
  /**
11529
11580
  * Safely check whether we are running in a browser environment
@@ -11567,13 +11618,13 @@ var NetworkMonitor = class extends Destroyable {
11567
11618
  this.attachListeners();
11568
11619
  }
11569
11620
  get isOnline$() {
11570
- return this._isOnline$.asObservable().pipe((0, import_cjs$25.takeUntil)(this._destroyed$));
11621
+ return this._isOnline$.asObservable().pipe((0, import_cjs$26.takeUntil)(this._destroyed$));
11571
11622
  }
11572
11623
  get isOnline() {
11573
11624
  return this._isOnline$.value;
11574
11625
  }
11575
11626
  get networkChange$() {
11576
- return this._networkChange$.asObservable().pipe((0, import_cjs$25.takeUntil)(this._destroyed$));
11627
+ return this._networkChange$.asObservable().pipe((0, import_cjs$26.takeUntil)(this._destroyed$));
11577
11628
  }
11578
11629
  destroy() {
11579
11630
  this.removeListeners();
@@ -11736,7 +11787,7 @@ function getNavigatorMediaDevices() {
11736
11787
 
11737
11788
  //#endregion
11738
11789
  //#region src/controllers/PreflightRunner.ts
11739
- var import_cjs$24 = require_cjs();
11790
+ var import_cjs$25 = require_cjs();
11740
11791
  const logger$24 = getLogger();
11741
11792
  const DEFAULT_MEDIA_TEST_DURATION_S = 10;
11742
11793
  const ICE_GATHERING_TIMEOUT_MS = 1e4;
@@ -11905,7 +11956,7 @@ var PreflightRunner = class extends Destroyable {
11905
11956
  audio: true,
11906
11957
  video: false
11907
11958
  });
11908
- 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)));
11959
+ 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)));
11909
11960
  const durationMs = this._options.duration * 1e3;
11910
11961
  await new Promise((resolve) => setTimeout(resolve, durationMs));
11911
11962
  const metrics = call.networkMetrics;
@@ -11934,7 +11985,7 @@ var PreflightRunner = class extends Destroyable {
11934
11985
 
11935
11986
  //#endregion
11936
11987
  //#region src/controllers/VisibilityController.ts
11937
- var import_cjs$23 = require_cjs();
11988
+ var import_cjs$24 = require_cjs();
11938
11989
  const logger$23 = getLogger();
11939
11990
  /**
11940
11991
  * Checks whether the document visibility API is available.
@@ -11980,7 +12031,7 @@ var VisibilityController = class extends Destroyable {
11980
12031
  * Emits 'visible' or 'hidden'. Always starts with the current state.
11981
12032
  */
11982
12033
  get visibility$() {
11983
- return this._visibility$.pipe((0, import_cjs$23.takeUntil)(this._destroyed$));
12034
+ return this._visibility$.pipe((0, import_cjs$24.takeUntil)(this._destroyed$));
11984
12035
  }
11985
12036
  /**
11986
12037
  * The current visibility state value.
@@ -11993,7 +12044,7 @@ var VisibilityController = class extends Destroyable {
11993
12044
  * Each event includes the previous state, new state, and timestamp.
11994
12045
  */
11995
12046
  get visibilityChange$() {
11996
- return this._visibilityChange$.pipe((0, import_cjs$23.takeUntil)(this._destroyed$));
12047
+ return this._visibilityChange$.pipe((0, import_cjs$24.takeUntil)(this._destroyed$));
11997
12048
  }
11998
12049
  destroy() {
11999
12050
  if (this._hasVisibilityApi) {
@@ -12025,13 +12076,13 @@ var VisibilityController = class extends Destroyable {
12025
12076
 
12026
12077
  //#endregion
12027
12078
  //#region src/behaviors/Fetchable.ts
12028
- var import_cjs$22 = require_cjs();
12079
+ var import_cjs$23 = require_cjs();
12029
12080
  var Fetchable = class extends Destroyable {
12030
12081
  constructor(fromPath, http) {
12031
12082
  super();
12032
12083
  this.fromPath = fromPath;
12033
12084
  this.http = http;
12034
- 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$));
12085
+ 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$));
12035
12086
  }
12036
12087
  async fetch() {
12037
12088
  const response = await this.http.request({
@@ -13264,24 +13315,6 @@ var require_operators = /* @__PURE__ */ __commonJSMin(((exports) => {
13264
13315
  });
13265
13316
  }));
13266
13317
 
13267
- //#endregion
13268
- //#region src/operators/filterNull.ts
13269
- var import_operators$1 = require_operators();
13270
- var import_cjs$21 = require_cjs();
13271
- /**
13272
- * RxJS operator that filters out `null` and `undefined` values with type narrowing.
13273
- *
13274
- * @example
13275
- * ```ts
13276
- * source$.pipe(filterNull()).subscribe(value => {
13277
- * // value is guaranteed non-null
13278
- * });
13279
- * ```
13280
- */
13281
- function filterNull() {
13282
- return (0, import_cjs$21.filter)((value) => value != null);
13283
- }
13284
-
13285
13318
  //#endregion
13286
13319
  //#region src/core/capabilities/types.ts
13287
13320
  /**
@@ -13407,7 +13440,7 @@ function computeCapabilities(capabilities) {
13407
13440
 
13408
13441
  //#endregion
13409
13442
  //#region src/core/capabilities/SelfCapabilities.ts
13410
- var import_cjs$20 = require_cjs();
13443
+ var import_cjs$22 = require_cjs();
13411
13444
  /**
13412
13445
  * SelfCapabilities manages the capability state for the self participant.
13413
13446
  *
@@ -13443,7 +13476,7 @@ var SelfCapabilities = class extends Destroyable {
13443
13476
  }
13444
13477
  /** Observable for self member capabilities */
13445
13478
  get self$() {
13446
- return this.cachedObservable("self$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.self), (0, import_cjs$20.distinctUntilChanged)()));
13479
+ return this.cachedObservable("self$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.self), (0, import_cjs$22.distinctUntilChanged)()));
13447
13480
  }
13448
13481
  /** Current self member capabilities */
13449
13482
  get self() {
@@ -13451,7 +13484,7 @@ var SelfCapabilities = class extends Destroyable {
13451
13484
  }
13452
13485
  /** Observable for other member capabilities */
13453
13486
  get member$() {
13454
- return this.cachedObservable("member$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.member), (0, import_cjs$20.distinctUntilChanged)()));
13487
+ return this.cachedObservable("member$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.member), (0, import_cjs$22.distinctUntilChanged)()));
13455
13488
  }
13456
13489
  /** Current other member capabilities */
13457
13490
  get member() {
@@ -13459,7 +13492,7 @@ var SelfCapabilities = class extends Destroyable {
13459
13492
  }
13460
13493
  /** Observable for end call capability */
13461
13494
  get end$() {
13462
- return this.cachedObservable("end$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.end), (0, import_cjs$20.distinctUntilChanged)()));
13495
+ return this.cachedObservable("end$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.end), (0, import_cjs$22.distinctUntilChanged)()));
13463
13496
  }
13464
13497
  /** Current end call capability */
13465
13498
  get end() {
@@ -13467,7 +13500,7 @@ var SelfCapabilities = class extends Destroyable {
13467
13500
  }
13468
13501
  /** Observable for set layout capability */
13469
13502
  get setLayout$() {
13470
- return this.cachedObservable("setLayout$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.setLayout), (0, import_cjs$20.distinctUntilChanged)()));
13503
+ return this.cachedObservable("setLayout$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.setLayout), (0, import_cjs$22.distinctUntilChanged)()));
13471
13504
  }
13472
13505
  /** Current set layout capability */
13473
13506
  get setLayout() {
@@ -13475,7 +13508,7 @@ var SelfCapabilities = class extends Destroyable {
13475
13508
  }
13476
13509
  /** Observable for send digit capability */
13477
13510
  get sendDigit$() {
13478
- return this.cachedObservable("sendDigit$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.sendDigit), (0, import_cjs$20.distinctUntilChanged)()));
13511
+ return this.cachedObservable("sendDigit$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.sendDigit), (0, import_cjs$22.distinctUntilChanged)()));
13479
13512
  }
13480
13513
  /** Current send digit capability */
13481
13514
  get sendDigit() {
@@ -13483,7 +13516,7 @@ var SelfCapabilities = class extends Destroyable {
13483
13516
  }
13484
13517
  /** Observable for vmuted hide capability */
13485
13518
  get vmutedHide$() {
13486
- return this.cachedObservable("vmutedHide$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.vmutedHide), (0, import_cjs$20.distinctUntilChanged)()));
13519
+ return this.cachedObservable("vmutedHide$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.vmutedHide), (0, import_cjs$22.distinctUntilChanged)()));
13487
13520
  }
13488
13521
  /** Current vmuted hide capability */
13489
13522
  get vmutedHide() {
@@ -13491,7 +13524,7 @@ var SelfCapabilities = class extends Destroyable {
13491
13524
  }
13492
13525
  /** Observable for lock capability */
13493
13526
  get lock$() {
13494
- return this.cachedObservable("lock$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.lock), (0, import_cjs$20.distinctUntilChanged)()));
13527
+ return this.cachedObservable("lock$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.lock), (0, import_cjs$22.distinctUntilChanged)()));
13495
13528
  }
13496
13529
  /** Current lock capability */
13497
13530
  get lock() {
@@ -13499,7 +13532,7 @@ var SelfCapabilities = class extends Destroyable {
13499
13532
  }
13500
13533
  /** Observable for device capability */
13501
13534
  get device$() {
13502
- return this.cachedObservable("device$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.device), (0, import_cjs$20.distinctUntilChanged)()));
13535
+ return this.cachedObservable("device$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.device), (0, import_cjs$22.distinctUntilChanged)()));
13503
13536
  }
13504
13537
  /** Current device capability */
13505
13538
  get device() {
@@ -13507,7 +13540,7 @@ var SelfCapabilities = class extends Destroyable {
13507
13540
  }
13508
13541
  /** Observable for screenshare capability */
13509
13542
  get screenshare$() {
13510
- return this.cachedObservable("screenshare$", () => this._state$.pipe((0, import_cjs$20.map)((state) => state.screenshare), (0, import_cjs$20.distinctUntilChanged)()));
13543
+ return this.cachedObservable("screenshare$", () => this._state$.pipe((0, import_cjs$22.map)((state) => state.screenshare), (0, import_cjs$22.distinctUntilChanged)()));
13511
13544
  }
13512
13545
  /** Current screenshare capability */
13513
13546
  get screenshare() {
@@ -13525,6 +13558,7 @@ var SelfCapabilities = class extends Destroyable {
13525
13558
 
13526
13559
  //#endregion
13527
13560
  //#region src/core/RPCMessages/utils.ts
13561
+ var import_operators$1 = require_operators();
13528
13562
  function toggleDeafMethod(is) {
13529
13563
  return is ? "call.undeaf" : "call.deaf";
13530
13564
  }
@@ -13560,83 +13594,83 @@ var Participant = class extends Destroyable {
13560
13594
  }
13561
13595
  /** Observable of the participant's display name. */
13562
13596
  get name$() {
13563
- return this.cachedObservable("name$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.name), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13597
+ return this.cachedObservable("name$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.name), (0, import_operators$1.distinctUntilChanged)()));
13564
13598
  }
13565
13599
  /** Observable of the participant type (e.g. `'member'`, `'screen'`). */
13566
13600
  get type$() {
13567
- return this.cachedObservable("type$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.type), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13601
+ return this.cachedObservable("type$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.type), (0, import_operators$1.distinctUntilChanged)()));
13568
13602
  }
13569
13603
  /** Observable indicating whether the participant has raised their hand. */
13570
13604
  get handraised$() {
13571
- return this.cachedObservable("handraised$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.handraised), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13605
+ return this.cachedObservable("handraised$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.handraised), (0, import_operators$1.distinctUntilChanged)()));
13572
13606
  }
13573
13607
  /** Observable indicating whether the participant is visible in the layout. */
13574
13608
  get visible$() {
13575
- return this.cachedObservable("visible$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.visible), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13609
+ return this.cachedObservable("visible$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.visible), (0, import_operators$1.distinctUntilChanged)()));
13576
13610
  }
13577
13611
  /** Observable indicating whether the participant's audio is muted. */
13578
13612
  get audioMuted$() {
13579
- return this.cachedObservable("audioMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.audio_muted), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13613
+ return this.cachedObservable("audioMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.audio_muted), (0, import_operators$1.distinctUntilChanged)()));
13580
13614
  }
13581
13615
  /** Observable indicating whether the participant's video is muted. */
13582
13616
  get videoMuted$() {
13583
- return this.cachedObservable("videoMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.video_muted), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13617
+ return this.cachedObservable("videoMuted$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.video_muted), (0, import_operators$1.distinctUntilChanged)()));
13584
13618
  }
13585
13619
  /** Observable indicating whether the participant is deafened. */
13586
13620
  get deaf$() {
13587
- return this.cachedObservable("deaf$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.deaf), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13621
+ return this.cachedObservable("deaf$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.deaf), (0, import_operators$1.distinctUntilChanged)()));
13588
13622
  }
13589
13623
  /** Observable of the participant's microphone input volume. */
13590
13624
  get inputVolume$() {
13591
- return this.cachedObservable("inputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_volume), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13625
+ return this.cachedObservable("inputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_volume), (0, import_operators$1.distinctUntilChanged)()));
13592
13626
  }
13593
13627
  /** Observable of the participant's speaker output volume. */
13594
13628
  get outputVolume$() {
13595
- return this.cachedObservable("outputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.output_volume), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13629
+ return this.cachedObservable("outputVolume$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.output_volume), (0, import_operators$1.distinctUntilChanged)()));
13596
13630
  }
13597
13631
  /** Observable of the microphone input sensitivity level. */
13598
13632
  get inputSensitivity$() {
13599
- return this.cachedObservable("inputSensitivity$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_sensitivity), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13633
+ return this.cachedObservable("inputSensitivity$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.input_sensitivity), (0, import_operators$1.distinctUntilChanged)()));
13600
13634
  }
13601
13635
  /** Observable indicating whether echo cancellation is enabled. */
13602
13636
  get echoCancellation$() {
13603
- return this.cachedObservable("echoCancellation$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.echo_cancellation), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13637
+ return this.cachedObservable("echoCancellation$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.echo_cancellation), (0, import_operators$1.distinctUntilChanged)()));
13604
13638
  }
13605
13639
  /** Observable indicating whether auto-gain control is enabled. */
13606
13640
  get autoGain$() {
13607
- return this.cachedObservable("autoGain$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.auto_gain), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13641
+ return this.cachedObservable("autoGain$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.auto_gain), (0, import_operators$1.distinctUntilChanged)()));
13608
13642
  }
13609
13643
  /** Observable indicating whether noise suppression is enabled. */
13610
13644
  get noiseSuppression$() {
13611
- return this.cachedObservable("noiseSuppression$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.noise_suppression), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13645
+ return this.cachedObservable("noiseSuppression$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.noise_suppression), (0, import_operators$1.distinctUntilChanged)()));
13612
13646
  }
13613
13647
  /** Observable indicating whether low-bitrate mode is active. */
13614
13648
  get lowbitrate$() {
13615
- return this.cachedObservable("lowbitrate$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.lowbitrate), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13649
+ return this.cachedObservable("lowbitrate$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.lowbitrate), (0, import_operators$1.distinctUntilChanged)()));
13616
13650
  }
13617
13651
  /** Observable indicating whether noise reduction is active. */
13618
13652
  get denoise$() {
13619
- return this.cachedObservable("denoise$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.denoise), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13653
+ return this.cachedObservable("denoise$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.denoise), (0, import_operators$1.distinctUntilChanged)()));
13620
13654
  }
13621
13655
  /** Observable of custom metadata for this participant. */
13622
13656
  get meta$() {
13623
- return this.cachedObservable("meta$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.meta), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13657
+ return this.cachedObservable("meta$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.meta), (0, import_operators$1.distinctUntilChanged)()));
13624
13658
  }
13625
13659
  /** Observable of the participant's subscriber ID. */
13626
13660
  get subscriberId$() {
13627
- return this.cachedObservable("subscriberId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.subscriber_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13661
+ return this.cachedObservable("subscriberId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.subscriber_id), (0, import_operators$1.distinctUntilChanged)()));
13628
13662
  }
13629
13663
  /** Observable of the participant's address ID. */
13630
13664
  get addressId$() {
13631
- return this.cachedObservable("addressId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.address_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13665
+ return this.cachedObservable("addressId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.address_id), (0, import_operators$1.distinctUntilChanged)()));
13632
13666
  }
13633
13667
  /** Observable of the server node ID for this participant. */
13634
13668
  get nodeId$() {
13635
- return this.cachedObservable("nodeId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.node_id), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13669
+ return this.cachedObservable("nodeId$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.node_id), (0, import_operators$1.distinctUntilChanged)()));
13636
13670
  }
13637
13671
  /** Observable indicating whether the participant is currently speaking. */
13638
13672
  get isTalking$() {
13639
- return this.cachedObservable("isTalking$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.talking), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13673
+ return this.cachedObservable("isTalking$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.talking), (0, import_operators$1.distinctUntilChanged)()));
13640
13674
  }
13641
13675
  /** Whether the participant is currently speaking. */
13642
13676
  get isTalking() {
@@ -13644,7 +13678,7 @@ var Participant = class extends Destroyable {
13644
13678
  }
13645
13679
  /** Observable of the participant's layout position. */
13646
13680
  get position$() {
13647
- return this.cachedObservable("position$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.position), (0, import_operators$1.distinctUntilChanged)(), filterNull()));
13681
+ return this.cachedObservable("position$", () => this._state$.pipe((0, import_operators$1.map)((state) => state.position), (0, import_operators$1.distinctUntilChanged)()));
13648
13682
  }
13649
13683
  /** Current layout position. */
13650
13684
  get position() {
@@ -14140,6 +14174,23 @@ function isLayoutChangedPayload(value) {
14140
14174
  return isObject(value) && hasProperty(value, "room_id") && hasProperty(value, "room_session_id") && hasProperty(value, "layout");
14141
14175
  }
14142
14176
 
14177
+ //#endregion
14178
+ //#region src/operators/filterNull.ts
14179
+ var import_cjs$21 = require_cjs();
14180
+ /**
14181
+ * RxJS operator that filters out `null` and `undefined` values with type narrowing.
14182
+ *
14183
+ * @example
14184
+ * ```ts
14185
+ * source$.pipe(filterNull()).subscribe(value => {
14186
+ * // value is guaranteed non-null
14187
+ * });
14188
+ * ```
14189
+ */
14190
+ function filterNull() {
14191
+ return (0, import_cjs$21.filter)((value) => value != null);
14192
+ }
14193
+
14143
14194
  //#endregion
14144
14195
  //#region src/utils/getValueFrom.ts
14145
14196
  const getValueFrom = (obj, path, defaultValue) => {
@@ -14152,7 +14203,7 @@ const getValueFrom = (obj, path, defaultValue) => {
14152
14203
 
14153
14204
  //#endregion
14154
14205
  //#region src/operators/filterEventAs.ts
14155
- var import_cjs$19 = require_cjs();
14206
+ var import_cjs$20 = require_cjs();
14156
14207
  var import_operators = require_operators();
14157
14208
  /**
14158
14209
  * RxJS operator that filters events based on a predicate and maps matching events.
@@ -14186,7 +14237,7 @@ var import_operators = require_operators();
14186
14237
  * ```
14187
14238
  */
14188
14239
  function ifIsMap(predicate, mapFn) {
14189
- return (0, import_cjs$19.pipe)((0, import_operators.filter)(predicate), (0, import_operators.map)(mapFn));
14240
+ return (0, import_cjs$20.pipe)((0, import_operators.filter)(predicate), (0, import_operators.map)(mapFn));
14190
14241
  }
14191
14242
  /**
14192
14243
  * Generic RxJS operator that filters events using a type guard and extracts a property.
@@ -14228,21 +14279,21 @@ function ifIsMap(predicate, mapFn) {
14228
14279
  * ```
14229
14280
  */
14230
14281
  function filterAs(predicate, resultPath) {
14231
- return (0, import_cjs$19.pipe)(ifIsMap(predicate, (event) => {
14282
+ return (0, import_cjs$20.pipe)(ifIsMap(predicate, (event) => {
14232
14283
  return getValueFrom(event, resultPath);
14233
14284
  }), (0, import_operators.filter)((value) => value !== void 0));
14234
14285
  }
14235
14286
 
14236
14287
  //#endregion
14237
14288
  //#region src/operators/throwOnRPCError.ts
14238
- var import_cjs$18 = require_cjs();
14289
+ var import_cjs$19 = require_cjs();
14239
14290
  const logger$20 = getLogger();
14240
14291
  /**
14241
14292
  * RxJS operator that throws a {@link JSONRPCError} when the RPC response contains an error.
14242
14293
  * Passes successful responses through unchanged.
14243
14294
  */
14244
14295
  function throwOnRPCError() {
14245
- return (0, import_cjs$18.map)((response) => {
14296
+ return (0, import_cjs$19.map)((response) => {
14246
14297
  if (response.error) {
14247
14298
  logger$20.error("[throwOnRPCError] RPC error response:", {
14248
14299
  code: response.error.code,
@@ -14258,7 +14309,7 @@ function throwOnRPCError() {
14258
14309
 
14259
14310
  //#endregion
14260
14311
  //#region src/managers/CallEventsManager.ts
14261
- var import_cjs$17 = require_cjs();
14312
+ var import_cjs$18 = require_cjs();
14262
14313
  const logger$19 = getLogger();
14263
14314
  const initialSessionState = {};
14264
14315
  /** @internal */
@@ -14275,7 +14326,7 @@ var CallEventsManager = class extends Destroyable {
14275
14326
  this.initSubscriptions();
14276
14327
  }
14277
14328
  get participants$() {
14278
- return this.cachedObservable("participants$", () => this._participants$.asObservable().pipe((0, import_cjs$17.map)((participantsRecord) => Object.values(participantsRecord))));
14329
+ return this.cachedObservable("participants$", () => this._participants$.asObservable().pipe((0, import_cjs$18.map)((participantsRecord) => Object.values(participantsRecord))));
14279
14330
  }
14280
14331
  get participants() {
14281
14332
  return Object.values(this._participants$.value);
@@ -14293,40 +14344,40 @@ var CallEventsManager = class extends Destroyable {
14293
14344
  return this.callIds.has(callId);
14294
14345
  }
14295
14346
  get recording$() {
14296
- return this.cachedObservable("recording$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.recording), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14347
+ return this.cachedObservable("recording$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.recording), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14297
14348
  }
14298
14349
  get recordings$() {
14299
- return this.cachedObservable("recordings$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.recordings), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14350
+ return this.cachedObservable("recordings$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.recordings), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14300
14351
  }
14301
14352
  get streaming$() {
14302
- return this.cachedObservable("streaming$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.streaming), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14353
+ return this.cachedObservable("streaming$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.streaming), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14303
14354
  }
14304
14355
  get streams$() {
14305
- return this.cachedObservable("streams$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.streams), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14356
+ return this.cachedObservable("streams$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.streams), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14306
14357
  }
14307
14358
  get playbacks$() {
14308
- return this.cachedObservable("playbacks$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.playbacks), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14359
+ return this.cachedObservable("playbacks$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.playbacks), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14309
14360
  }
14310
14361
  get raiseHandPriority$() {
14311
- return this.cachedObservable("raiseHandPriority$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.prioritize_handraise), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14362
+ return this.cachedObservable("raiseHandPriority$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.prioritize_handraise), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14312
14363
  }
14313
14364
  get locked$() {
14314
- return this.cachedObservable("locked$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.locked), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14365
+ return this.cachedObservable("locked$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.locked), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14315
14366
  }
14316
14367
  get meta$() {
14317
- return this.cachedObservable("meta$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.meta), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14368
+ return this.cachedObservable("meta$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.meta), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14318
14369
  }
14319
14370
  get capabilities$() {
14320
- return this.cachedObservable("capabilities$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.capabilities), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14371
+ return this.cachedObservable("capabilities$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.capabilities), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14321
14372
  }
14322
14373
  get layout$() {
14323
- return this.cachedObservable("layout$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layout_name), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14374
+ return this.cachedObservable("layout$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layout_name), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14324
14375
  }
14325
14376
  get layouts$() {
14326
- return this.cachedObservable("layouts$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layouts), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14377
+ return this.cachedObservable("layouts$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layouts), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14327
14378
  }
14328
14379
  get layoutLayers$() {
14329
- return this.cachedObservable("layoutLayers$", () => this._sessionState$.pipe((0, import_cjs$17.map)((state) => state.layout_layers), (0, import_cjs$17.distinctUntilChanged)(), filterNull()));
14380
+ return this.cachedObservable("layoutLayers$", () => this._sessionState$.pipe((0, import_cjs$18.map)((state) => state.layout_layers), (0, import_cjs$18.distinctUntilChanged)(), filterNull()));
14330
14381
  }
14331
14382
  get self() {
14332
14383
  return this._self$.value;
@@ -14368,7 +14419,7 @@ var CallEventsManager = class extends Destroyable {
14368
14419
  roomSessionId: callJoinedEvent.room_session_id
14369
14420
  });
14370
14421
  const sessionState = callJoinedEvent.room_session;
14371
- const { capabilities } = callJoinedEvent;
14422
+ const capabilities = callJoinedEvent.capabilities;
14372
14423
  this.selfId = this.selfId ?? callJoinedEvent.member_id;
14373
14424
  this.originCallId = this.originCallId ?? callJoinedEvent.origin_call_id;
14374
14425
  this.callIds.add(callJoinedEvent.call_id);
@@ -14481,17 +14532,17 @@ var CallEventsManager = class extends Destroyable {
14481
14532
  this._participants$.next(this._participants$.value);
14482
14533
  }
14483
14534
  get callJoinedEvent$() {
14484
- return this.cachedObservable("callJoinedEvent$", () => this.webRtcCallSession.callEvent$.pipe((0, import_cjs$17.filter)(isCallJoinedPayload), (0, import_cjs$17.tap)((event) => {
14535
+ return this.cachedObservable("callJoinedEvent$", () => this.webRtcCallSession.callEvent$.pipe((0, import_cjs$18.filter)(isCallJoinedPayload), (0, import_cjs$18.tap)((event) => {
14485
14536
  logger$19.debug("[CallEventsManager] Call joined event:", event);
14486
14537
  })));
14487
14538
  }
14488
14539
  get layoutChangedEvent$() {
14489
- return this.cachedObservable("layoutChangedEvent$", () => this.webRtcCallSession.callEvent$.pipe(filterAs(isLayoutChangedPayload, "layout"), (0, import_cjs$17.tap)((event) => {
14540
+ return this.cachedObservable("layoutChangedEvent$", () => this.webRtcCallSession.callEvent$.pipe(filterAs(isLayoutChangedPayload, "layout"), (0, import_cjs$18.tap)((event) => {
14490
14541
  logger$19.debug("[CallEventsManager] Layout changed event:", event);
14491
14542
  })));
14492
14543
  }
14493
14544
  get memberUpdates$() {
14494
- 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) => {
14545
+ 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) => {
14495
14546
  logger$19.debug("[CallEventsManager] Member update event:", event);
14496
14547
  })));
14497
14548
  }
@@ -14748,7 +14799,7 @@ function appendStereoParams(fmtpLine, maxBitrate) {
14748
14799
 
14749
14800
  //#endregion
14750
14801
  //#region src/controllers/ICEGatheringController.ts
14751
- var import_cjs$16 = require_cjs();
14802
+ var import_cjs$17 = require_cjs();
14752
14803
  const logger$18 = getLogger();
14753
14804
  var ICEGatheringController = class extends Destroyable {
14754
14805
  constructor(peerConnection, peerConnectionControllerNegotiating$, options = {}) {
@@ -14786,7 +14837,7 @@ var ICEGatheringController = class extends Destroyable {
14786
14837
  this.iceGatheringTimeout = options.iceGatheringTimeout ?? DEFAULT_ICE_GATHERING_TIMEOUT_MS;
14787
14838
  this.relayOnly = options.relayOnly ?? false;
14788
14839
  this.setupEventListeners();
14789
- this.subscribeTo(this.peerConnectionControllerNegotiating$.pipe((0, import_cjs$16.filter)((isNegotiating) => isNegotiating)), (isNegotiating) => {
14840
+ this.subscribeTo(this.peerConnectionControllerNegotiating$.pipe((0, import_cjs$17.filter)((isNegotiating) => isNegotiating)), (isNegotiating) => {
14790
14841
  if (isNegotiating) {
14791
14842
  this.setupEventListeners();
14792
14843
  this.iceGatheringTimer = setTimeout(() => {
@@ -14805,7 +14856,7 @@ var ICEGatheringController = class extends Destroyable {
14805
14856
  this.peerConnection.addEventListener("icegatheringstatechange", this.onicegatheringstatechangeHandler);
14806
14857
  }
14807
14858
  get iceCandidatesState$() {
14808
- 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));
14859
+ 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));
14809
14860
  }
14810
14861
  get hasValidLocalDescriptionSDP() {
14811
14862
  const sdp = this.peerConnection.localDescription?.sdp;
@@ -14892,7 +14943,7 @@ var ICEGatheringController = class extends Destroyable {
14892
14943
 
14893
14944
  //#endregion
14894
14945
  //#region src/controllers/LocalStreamController.ts
14895
- var import_cjs$15 = require_cjs();
14946
+ var import_cjs$16 = require_cjs();
14896
14947
  const logger$17 = getLogger();
14897
14948
  var LocalStreamController = class extends Destroyable {
14898
14949
  constructor(options) {
@@ -14907,16 +14958,16 @@ var LocalStreamController = class extends Destroyable {
14907
14958
  this._mediaTrackEnded$ = this.createSubject();
14908
14959
  }
14909
14960
  get localStream$() {
14910
- return this._localStream$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14961
+ return this._localStream$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14911
14962
  }
14912
14963
  get localAudioTracks$() {
14913
- return this._localAudioTracks$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14964
+ return this._localAudioTracks$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14914
14965
  }
14915
14966
  get localVideoTracks$() {
14916
- return this._localVideoTracks$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14967
+ return this._localVideoTracks$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14917
14968
  }
14918
14969
  get mediaTrackEnded$() {
14919
- return this._mediaTrackEnded$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$));
14970
+ return this._mediaTrackEnded$.asObservable().pipe((0, import_cjs$16.takeUntil)(this.destroyed$));
14920
14971
  }
14921
14972
  get localStream() {
14922
14973
  return this._localStream$.value;
@@ -15305,7 +15356,7 @@ var TransceiverController = class extends Destroyable {
15305
15356
 
15306
15357
  //#endregion
15307
15358
  //#region src/controllers/RTCPeerConnectionController.ts
15308
- var import_cjs$14 = require_cjs();
15359
+ var import_cjs$15 = require_cjs();
15309
15360
  const logger$15 = getLogger();
15310
15361
  var RTCPeerConnectionController = class extends Destroyable {
15311
15362
  constructor(options = {}, remoteSessionDescription, deviceController) {
@@ -15313,11 +15364,11 @@ var RTCPeerConnectionController = class extends Destroyable {
15313
15364
  this.options = options;
15314
15365
  this.firstSDPExchangeCompleted = false;
15315
15366
  this.negotiationNeeded$ = this.createSubject();
15316
- 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)(() => {
15367
+ 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)(() => {
15317
15368
  this.negotiationEnded();
15318
- }), (0, import_cjs$14.filter)(() => this.shouldEmitLocalDescription), (0, import_cjs$14.map)(() => this.peerConnection?.localDescription), filterNull(), (0, import_cjs$14.tap)((desc) => {
15369
+ }), (0, import_cjs$15.filter)(() => this.shouldEmitLocalDescription), (0, import_cjs$15.map)(() => this.peerConnection?.localDescription), filterNull(), (0, import_cjs$15.tap)((desc) => {
15319
15370
  if (desc.type === "answer") this._type = "offer";
15320
- }))), (0, import_cjs$14.shareReplay)(1), (0, import_cjs$14.takeUntil)(this.destroyed$));
15371
+ }))), (0, import_cjs$15.shareReplay)(1), (0, import_cjs$15.takeUntil)(this.destroyed$));
15321
15372
  this.connectionTimeout = 3e3;
15322
15373
  this.oniceconnectionstatechangeHandler = () => {
15323
15374
  if (this.peerConnection) {
@@ -15375,7 +15426,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15375
15426
  logger$15.debug(`[RTCPeerConnectionController] ${kind} input device selected:`, deviceInfo?.label);
15376
15427
  } catch (error) {
15377
15428
  logger$15.error(`[RTCPeerConnectionController] Failed to select ${kind} input device:`, error);
15378
- this._errors$.next(error);
15429
+ this._errors$.next(toError(error));
15379
15430
  throw error;
15380
15431
  }
15381
15432
  };
@@ -15460,43 +15511,43 @@ var RTCPeerConnectionController = class extends Destroyable {
15460
15511
  };
15461
15512
  }
15462
15513
  get iceGatheringState$() {
15463
- return this.cachedObservable("iceGatheringState$", () => this._iceGatheringState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15514
+ return this.cachedObservable("iceGatheringState$", () => this._iceGatheringState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15464
15515
  }
15465
15516
  get mediaTrackEnded$() {
15466
- return this.cachedObservable("mediaTrackEnded$", () => this.localStreamController.mediaTrackEnded$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15517
+ return this.cachedObservable("mediaTrackEnded$", () => this.localStreamController.mediaTrackEnded$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15467
15518
  }
15468
15519
  get errors$() {
15469
- return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15520
+ return this.cachedObservable("errors$", () => this._errors$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15470
15521
  }
15471
15522
  get iceCandidates$() {
15472
- return this.cachedObservable("iceCandidates$", () => this._iceCandidates$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15523
+ return this.cachedObservable("iceCandidates$", () => this._iceCandidates$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15473
15524
  }
15474
15525
  get initialized$() {
15475
- return this.cachedObservable("initialized$", () => this._initialized$.asObservable().pipe((0, import_cjs$14.filter)((initialized) => initialized), (0, import_cjs$14.takeUntil)(this.destroyed$)));
15526
+ return this.cachedObservable("initialized$", () => this._initialized$.asObservable().pipe((0, import_cjs$15.filter)((initialized) => initialized), (0, import_cjs$15.takeUntil)(this.destroyed$)));
15476
15527
  }
15477
15528
  get remoteDescription$() {
15478
- return this.cachedObservable("remoteDescription$", () => this._remoteDescription$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15529
+ return this.cachedObservable("remoteDescription$", () => this._remoteDescription$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15479
15530
  }
15480
15531
  get localStream$() {
15481
- return this.cachedObservable("localStream$", () => this.localStreamController.localStream$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15532
+ return this.cachedObservable("localStream$", () => this.localStreamController.localStream$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15482
15533
  }
15483
15534
  get remoteStream$() {
15484
- return this.cachedObservable("remoteStream$", () => this._remoteStream$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15535
+ return this.cachedObservable("remoteStream$", () => this._remoteStream$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15485
15536
  }
15486
15537
  get localAudioTracks$() {
15487
- return this.cachedObservable("localAudioTracks$", () => this.localStreamController.localAudioTracks$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15538
+ return this.cachedObservable("localAudioTracks$", () => this.localStreamController.localAudioTracks$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15488
15539
  }
15489
15540
  get localVideoTracks$() {
15490
- return this.cachedObservable("localVideoTracks$", () => this.localStreamController.localVideoTracks$.pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15541
+ return this.cachedObservable("localVideoTracks$", () => this.localStreamController.localVideoTracks$.pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15491
15542
  }
15492
15543
  get iceConnectionState$() {
15493
- return this.cachedObservable("iceConnectionState$", () => this._iceConnectionState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15544
+ return this.cachedObservable("iceConnectionState$", () => this._iceConnectionState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15494
15545
  }
15495
15546
  get connectionState$() {
15496
- return this.cachedObservable("connectionState$", () => this._connectionState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15547
+ return this.cachedObservable("connectionState$", () => this._connectionState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15497
15548
  }
15498
15549
  get signalingState$() {
15499
- return this.cachedObservable("signalingState$", () => this._signalingState$.asObservable().pipe((0, import_cjs$14.takeUntil)(this.destroyed$)));
15550
+ return this.cachedObservable("signalingState$", () => this._signalingState$.asObservable().pipe((0, import_cjs$15.takeUntil)(this.destroyed$)));
15500
15551
  }
15501
15552
  get type() {
15502
15553
  return this._type;
@@ -15609,16 +15660,16 @@ var RTCPeerConnectionController = class extends Destroyable {
15609
15660
  async doInit() {
15610
15661
  try {
15611
15662
  this.setupPeerConnection();
15612
- this.subscribeTo(this.negotiationNeeded$.pipe((0, import_cjs$14.auditTime)(0), (0, import_cjs$14.exhaustMap)(async () => this.startNegotiation())), {
15663
+ this.subscribeTo(this.negotiationNeeded$.pipe((0, import_cjs$15.auditTime)(0), (0, import_cjs$15.exhaustMap)(async () => this.startNegotiation())), {
15613
15664
  next: () => {
15614
15665
  logger$15.debug("[RTCPeerConnectionController] Start Negotiation completed successfully");
15615
15666
  },
15616
15667
  error: (error) => {
15617
15668
  logger$15.error("[RTCPeerConnectionController] Start Negotiation error:", error);
15618
- this._errors$.next(error);
15669
+ this._errors$.next(toError(error));
15619
15670
  }
15620
15671
  });
15621
- 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]) => {
15672
+ 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]) => {
15622
15673
  logger$15.debug(`[RTCPeerConnectionController] Selected input device changed for:`, {
15623
15674
  kind,
15624
15675
  deviceInfo
@@ -15637,7 +15688,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15637
15688
  }
15638
15689
  } catch (error) {
15639
15690
  logger$15.error("[RTCPeerConnectionController] Initialization error:", error);
15640
- this._errors$.next(error);
15691
+ this._errors$.next(toError(error));
15641
15692
  this.destroy();
15642
15693
  }
15643
15694
  }
@@ -15684,7 +15735,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15684
15735
  await this.createOffer(offerOptions);
15685
15736
  } catch (error) {
15686
15737
  logger$15.error("[RTCPeerConnectionController] Error during negotiation:", error);
15687
- this._errors$.next(error);
15738
+ this._errors$.next(toError(error));
15688
15739
  }
15689
15740
  }
15690
15741
  /**
@@ -15707,7 +15758,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15707
15758
  }
15708
15759
  } catch (error) {
15709
15760
  logger$15.error("[RTCPeerConnectionController] Error updating answer status:", error);
15710
- this._errors$.next(error);
15761
+ this._errors$.next(toError(error));
15711
15762
  readyToConnect = false;
15712
15763
  } finally {
15713
15764
  if (readyToConnect) this.readyToConnect();
@@ -15873,7 +15924,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15873
15924
  await this.setLocalDescription(offer);
15874
15925
  } catch (error) {
15875
15926
  logger$15.error("[RTCPeerConnectionController] ICE restart offer failed:", error);
15876
- this._errors$.next(error);
15927
+ this._errors$.next(toError(error));
15877
15928
  this.negotiationEnded();
15878
15929
  if (policyChanged) this.restoreIceTransportPolicy();
15879
15930
  throw error;
@@ -15968,7 +16019,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15968
16019
  logger$15.debug(`[RTCPeerConnectionController] ${track.kind} track added:`, track.id);
15969
16020
  } catch (error) {
15970
16021
  logger$15.error(`[RTCPeerConnectionController] Failed to add ${track.kind} track:`, error);
15971
- this._errors$.next(error);
16022
+ this._errors$.next(toError(error));
15972
16023
  throw error;
15973
16024
  }
15974
16025
  }
@@ -15993,7 +16044,7 @@ var RTCPeerConnectionController = class extends Destroyable {
15993
16044
  logger$15.debug(`[RTCPeerConnectionController] ${sender.track?.kind} track removed:`, trackId);
15994
16045
  } catch (error) {
15995
16046
  logger$15.error(`[RTCPeerConnectionController] Failed to remove ${sender.track?.kind} track:`, error);
15996
- this._errors$.next(error);
16047
+ this._errors$.next(toError(error));
15997
16048
  throw error;
15998
16049
  }
15999
16050
  }
@@ -16124,7 +16175,7 @@ function isVertoPingInnerParams(value) {
16124
16175
 
16125
16176
  //#endregion
16126
16177
  //#region src/managers/VertoManager.ts
16127
- var import_cjs$13 = require_cjs();
16178
+ var import_cjs$14 = require_cjs();
16128
16179
  const logger$14 = getLogger();
16129
16180
  var VertoManager = class extends Destroyable {
16130
16181
  constructor(callSession) {
@@ -16145,7 +16196,7 @@ var WebRTCVertoManager = class extends VertoManager {
16145
16196
  this.webRTCApiProvider = webRTCApiProvider;
16146
16197
  this._rtcPeerConnections$ = this.createBehaviorSubject([]);
16147
16198
  this._selfId$ = this.createBehaviorSubject(null);
16148
- this._signalingStatus$ = this.createBehaviorSubject(null);
16199
+ this._signalingStatus$ = this.createReplaySubject(1);
16149
16200
  this._screenShareStatus$ = this.createBehaviorSubject("none");
16150
16201
  this._rtcPeerConnectionsMap = /* @__PURE__ */ new Map();
16151
16202
  this._screenShareTimeoutMs = 5e4;
@@ -16217,7 +16268,7 @@ var WebRTCVertoManager = class extends VertoManager {
16217
16268
  return rtcPeerConnection;
16218
16269
  }
16219
16270
  get signalingStatus$() {
16220
- return this.cachedObservable("signalingStatus$", () => (0, import_cjs$13.merge)(this._signalingStatus$.pipe(filterNull()), this.mainPeerConnection.connectionState$.pipe((0, import_cjs$13.filter)((connectionState) => [
16271
+ return this.cachedObservable("signalingStatus$", () => (0, import_cjs$14.merge)(this._signalingStatus$.asObservable(), this.mainPeerConnection.connectionState$.pipe((0, import_cjs$14.filter)((connectionState) => [
16221
16272
  "connected",
16222
16273
  "disconnected",
16223
16274
  "failed"
@@ -16430,25 +16481,25 @@ var WebRTCVertoManager = class extends VertoManager {
16430
16481
  }
16431
16482
  }
16432
16483
  get callJoinedEvent$() {
16433
- return this.webRtcCallSession.callEvent$.pipe((0, import_cjs$13.filter)(isCallJoinedPayload), (0, import_cjs$13.takeUntil)(this.destroyed$));
16484
+ return this.webRtcCallSession.callEvent$.pipe((0, import_cjs$14.filter)(isCallJoinedPayload), (0, import_cjs$14.takeUntil)(this.destroyed$));
16434
16485
  }
16435
16486
  get vertoMedia$() {
16436
- return this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$));
16487
+ return this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$));
16437
16488
  }
16438
16489
  get vertoAnswer$() {
16439
- return this.cachedObservable("vertoAnswer$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAnswerInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16490
+ return this.cachedObservable("vertoAnswer$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAnswerInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16440
16491
  }
16441
16492
  get vertoMediaParams$() {
16442
- return this.cachedObservable("vertoMediaParams$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaParamsInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16493
+ return this.cachedObservable("vertoMediaParams$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoMediaParamsInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16443
16494
  }
16444
16495
  get vertoBye$() {
16445
- return this.cachedObservable("vertoBye$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoByeMessage, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16496
+ return this.cachedObservable("vertoBye$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoByeMessage, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16446
16497
  }
16447
16498
  get vertoAttach$() {
16448
- return this.cachedObservable("vertoAttach$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAttachMessage, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16499
+ return this.cachedObservable("vertoAttach$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoAttachMessage, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16449
16500
  }
16450
16501
  get vertoPing$() {
16451
- return this.cachedObservable("vertoPing$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoPingInnerParams, "params"), (0, import_cjs$13.takeUntil)(this.destroyed$)));
16502
+ return this.cachedObservable("vertoPing$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoPingInnerParams, "params"), (0, import_cjs$14.takeUntil)(this.destroyed$)));
16452
16503
  }
16453
16504
  async executeVerto(message, optionals = {}) {
16454
16505
  const webrtcVertoMessage = WebrtcVerto({
@@ -16576,7 +16627,7 @@ var WebRTCVertoManager = class extends VertoManager {
16576
16627
  }
16577
16628
  async handleInboundAnswer(rtcPeerConnController) {
16578
16629
  logger$14.debug("[WebRTCManager] Waiting for inbound call to be accepted or rejected");
16579
- 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);
16630
+ 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);
16580
16631
  if (vertoByeOrAccepted === null) {
16581
16632
  logger$14.debug("[WebRTCManager] Inbound answer handler aborted (destroyed).");
16582
16633
  return;
@@ -16619,12 +16670,12 @@ var WebRTCVertoManager = class extends VertoManager {
16619
16670
  });
16620
16671
  }
16621
16672
  initObservables(rtcPeerConnController) {
16622
- 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$));
16623
- this.localStream$ = rtcPeerConnController.localStream$.pipe(filterNull(), (0, import_cjs$13.takeUntil)(this.destroyed$));
16624
- this.remoteStream$ = rtcPeerConnController.remoteStream$.pipe(filterNull(), (0, import_cjs$13.takeUntil)(this.destroyed$));
16673
+ 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$));
16674
+ this.localStream$ = rtcPeerConnController.localStream$.pipe(filterNull(), (0, import_cjs$14.takeUntil)(this.destroyed$));
16675
+ this.remoteStream$ = rtcPeerConnController.remoteStream$.pipe(filterNull(), (0, import_cjs$14.takeUntil)(this.destroyed$));
16625
16676
  }
16626
16677
  setupLocalDescriptionHandler(rtcPeerConnController) {
16627
- this.subscribeTo(rtcPeerConnController.localDescription$.pipe((0, import_cjs$13.filter)((description) => description !== null), (0, import_cjs$13.takeUntil)(this.destroyed$)), (description) => {
16678
+ this.subscribeTo(rtcPeerConnController.localDescription$.pipe((0, import_cjs$14.filter)((description) => description !== null), (0, import_cjs$14.takeUntil)(this.destroyed$)), (description) => {
16628
16679
  const { type, sdp } = description;
16629
16680
  const dialogParams = this.dialogParams(rtcPeerConnController);
16630
16681
  const initial = !rtcPeerConnController.firstSDPExchangeCompleted;
@@ -16675,7 +16726,11 @@ var WebRTCVertoManager = class extends VertoManager {
16675
16726
  }
16676
16727
  async sendLocalDescriptionOnceAccepted(vertoMessageRequest, rtcPeerConnectionController) {
16677
16728
  logger$14.debug("[WebRTCManager] Waiting for call to be accepted or ended before sending answer");
16678
- const vertoByeOrAccepted = await (0, import_cjs$13.firstValueFrom)((0, import_cjs$13.race)(this.vertoBye$, this.webRtcCallSession.answered$));
16729
+ 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);
16730
+ if (vertoByeOrAccepted === null) {
16731
+ logger$14.debug("[WebRTCManager] Destroyed while waiting for call acceptance");
16732
+ return;
16733
+ }
16679
16734
  if (isVertoByeMessage(vertoByeOrAccepted)) {
16680
16735
  logger$14.info("[WebRTCManager] Call ended before answer was sent.");
16681
16736
  this.callSession?.destroy();
@@ -16784,7 +16839,7 @@ var WebRTCVertoManager = class extends VertoManager {
16784
16839
  this.subscribeTo(rtcPeerConnController.errors$, (error) => {
16785
16840
  this.onError?.(error);
16786
16841
  });
16787
- 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)));
16842
+ 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$)));
16788
16843
  this._screenShareStatus$.next("started");
16789
16844
  logger$14.info("[WebRTCManager] Screen share started successfully.");
16790
16845
  return rtcPeerConnController.id;
@@ -16887,7 +16942,7 @@ var WebRTCVertoManager = class extends VertoManager {
16887
16942
 
16888
16943
  //#endregion
16889
16944
  //#region src/controllers/RTCStatsMonitor.ts
16890
- var import_cjs$12 = require_cjs();
16945
+ var import_cjs$13 = require_cjs();
16891
16946
  const logger$13 = getLogger();
16892
16947
  const DEFAULT_POLLING_INTERVAL_MS = 1e3;
16893
16948
  const DEFAULT_BASELINE_SAMPLES = 10;
@@ -16950,7 +17005,7 @@ var RTCStatsMonitor = class extends Destroyable {
16950
17005
  }
16951
17006
  /** Simple boolean health indicator. */
16952
17007
  get isNetworkHealthy$() {
16953
- 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$)));
17008
+ 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$)));
16954
17009
  }
16955
17010
  /** Whether the network is currently healthy. */
16956
17011
  get isNetworkHealthy() {
@@ -16966,7 +17021,7 @@ var RTCStatsMonitor = class extends Destroyable {
16966
17021
  }
16967
17022
  /** Emits individual critical issues for the recovery pipeline. */
16968
17023
  get criticalIssue$() {
16969
- 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$)));
17024
+ 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$)));
16970
17025
  }
16971
17026
  /** Emits each raw stats sample extracted from the peer connection. */
16972
17027
  get sample$() {
@@ -16979,11 +17034,11 @@ var RTCStatsMonitor = class extends Destroyable {
16979
17034
  this.lastAudioPacketChangeTime = now;
16980
17035
  this.lastVideoPacketChangeTime = now;
16981
17036
  logger$13.debug("[RTCStatsMonitor] Starting stats monitoring");
16982
- 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) => {
17037
+ 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) => {
16983
17038
  logger$13.warn("[RTCStatsMonitor] Failed to get stats:", err);
16984
- return import_cjs$12.EMPTY;
16985
- }))), (0, import_cjs$12.filter)(() => this.running), (0, import_cjs$12.map)((report) => this.extractSample(report))), (sample$1) => this._sample$.next(sample$1));
16986
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.take)(this.baselineSampleCount), (0, import_cjs$12.toArray)(), (0, import_cjs$12.map)((samples) => ({
17039
+ return import_cjs$13.EMPTY;
17040
+ }))), (0, import_cjs$13.filter)(() => this.running), (0, import_cjs$13.map)((report) => this.extractSample(report))), (sample$1) => this._sample$.next(sample$1));
17041
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.take)(this.baselineSampleCount), (0, import_cjs$13.toArray)(), (0, import_cjs$13.map)((samples) => ({
16987
17042
  rtt: samples.reduce((s, b) => s + b.roundTripTime, 0) / samples.length,
16988
17043
  jitter: samples.reduce((s, b) => s + b.audioJitter, 0) / samples.length,
16989
17044
  ready: true
@@ -16991,19 +17046,19 @@ var RTCStatsMonitor = class extends Destroyable {
16991
17046
  logger$13.debug(`[RTCStatsMonitor] Baseline established: rtt=${baseline.rtt.toFixed(1)}ms, jitter=${baseline.jitter.toFixed(1)}ms`);
16992
17047
  this._baseline$.next(baseline);
16993
17048
  });
16994
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.scan)((acc, sample$1) => ({
17049
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.scan)((acc, sample$1) => ({
16995
17050
  prev: acc.current,
16996
17051
  current: sample$1
16997
17052
  }), {
16998
17053
  prev: null,
16999
17054
  current: null
17000
- }), (0, import_cjs$12.filter)((pair) => pair.current !== null)), ({ prev, current }) => {
17055
+ }), (0, import_cjs$13.filter)((pair) => pair.current !== null)), ({ prev, current }) => {
17001
17056
  const now$1 = current.timestamp;
17002
17057
  this.updatePacketTracking(current, now$1);
17003
17058
  const issues = this.detectIssues(current, prev, now$1);
17004
17059
  this._networkIssues$.next(issues);
17005
17060
  });
17006
- this.subscribeTo(this._sample$.pipe((0, import_cjs$12.scan)((history, sample$1) => {
17061
+ this.subscribeTo(this._sample$.pipe((0, import_cjs$13.scan)((history, sample$1) => {
17007
17062
  const cutoff = sample$1.timestamp - this.historyWindowSeconds * 1e3;
17008
17063
  const metrics = {
17009
17064
  timestamp: sample$1.timestamp,
@@ -17156,7 +17211,7 @@ var RTCStatsMonitor = class extends Destroyable {
17156
17211
 
17157
17212
  //#endregion
17158
17213
  //#region src/managers/CallRecoveryManager.ts
17159
- var import_cjs$11 = require_cjs();
17214
+ var import_cjs$12 = require_cjs();
17160
17215
  const logger$12 = getLogger();
17161
17216
  const DEFAULT_DEBOUNCE_TIME_MS = 2e3;
17162
17217
  const DEFAULT_COOLDOWN_MS = 1e4;
@@ -17227,16 +17282,16 @@ var CallRecoveryManager = class extends Destroyable {
17227
17282
  this.initDegradationRecoveryPipeline();
17228
17283
  }
17229
17284
  get recoveryState$() {
17230
- return this._recoveryState$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17285
+ return this._recoveryState$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17231
17286
  }
17232
17287
  get recoveryState() {
17233
17288
  return this._recoveryState$.value;
17234
17289
  }
17235
17290
  get recoveryEvent$() {
17236
- return this._recoveryEvent$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17291
+ return this._recoveryEvent$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17237
17292
  }
17238
17293
  get bandwidthConstrained$() {
17239
- return this._bandwidthConstrained$.asObservable().pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17294
+ return this._bandwidthConstrained$.asObservable().pipe((0, import_cjs$12.takeUntil)(this._destroyed$));
17240
17295
  }
17241
17296
  get bandwidthConstrained() {
17242
17297
  return this._bandwidthConstrained$.value;
@@ -17366,9 +17421,9 @@ var CallRecoveryManager = class extends Destroyable {
17366
17421
  super.destroy();
17367
17422
  }
17368
17423
  initPipeline() {
17369
- this.subscribeTo(this._trigger$.pipe((0, import_cjs$11.tap)(() => {
17424
+ this.subscribeTo(this._trigger$.pipe((0, import_cjs$12.tap)(() => {
17370
17425
  if (this._recoveryState$.value === "idle") this.transitionTo("debouncing");
17371
- }), (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$))), {
17426
+ }), (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$))), {
17372
17427
  next: () => {},
17373
17428
  error: (err) => {
17374
17429
  logger$12.error("CallRecoveryManager: pipeline error", err);
@@ -17387,10 +17442,10 @@ var CallRecoveryManager = class extends Destroyable {
17387
17442
  initDegradationRecoveryPipeline() {
17388
17443
  if (!this._config.enableAutoDegradation) return;
17389
17444
  const delayMs = this._config.packetLossRecoveryDelaySec * 1e3;
17390
- this.subscribeTo((0, import_cjs$11.combineLatest)([this._bandwidthConstrained$, this._hasPacketLoss$]).pipe((0, import_cjs$11.switchMap)(([constrained, hasPacketLoss]) => {
17391
- if (constrained && !hasPacketLoss) return (0, import_cjs$11.timer)(delayMs);
17392
- return import_cjs$11.EMPTY;
17393
- }), (0, import_cjs$11.takeUntil)(this._destroyed$)), () => {
17445
+ this.subscribeTo((0, import_cjs$12.combineLatest)([this._bandwidthConstrained$, this._hasPacketLoss$]).pipe((0, import_cjs$12.switchMap)(([constrained, hasPacketLoss]) => {
17446
+ if (constrained && !hasPacketLoss) return (0, import_cjs$12.timer)(delayMs);
17447
+ return import_cjs$12.EMPTY;
17448
+ }), (0, import_cjs$12.takeUntil)(this._destroyed$)), () => {
17394
17449
  this._bandwidthConstrained$.next(false);
17395
17450
  this._callbacks.enableVideo();
17396
17451
  this.emitEvent({
@@ -17430,10 +17485,10 @@ var CallRecoveryManager = class extends Destroyable {
17430
17485
  executeTieredRecovery(trigger) {
17431
17486
  this.transitionTo("recovering");
17432
17487
  logger$12.info(`CallRecoveryManager: starting tiered recovery — source=${trigger.source} detail=${trigger.detail}`);
17433
- return (0, import_cjs$11.from)(this.runTiers(trigger)).pipe((0, import_cjs$11.tap)(() => this.startCooldown()), (0, import_cjs$11.catchError)((err) => {
17488
+ return (0, import_cjs$12.from)(this.runTiers(trigger)).pipe((0, import_cjs$12.tap)(() => this.startCooldown()), (0, import_cjs$12.catchError)((err) => {
17434
17489
  logger$12.error("CallRecoveryManager: tiered recovery failed", err);
17435
17490
  this.startCooldown();
17436
- return import_cjs$11.EMPTY;
17491
+ return import_cjs$12.EMPTY;
17437
17492
  }));
17438
17493
  }
17439
17494
  async runTiers(trigger) {
@@ -17553,7 +17608,7 @@ var CallRecoveryManager = class extends Destroyable {
17553
17608
  this._cooldownUntil = Date.now() + this._config.cooldownMs;
17554
17609
  this.transitionTo("cooldown");
17555
17610
  if (this._cooldownSubscription) this._cooldownSubscription.unsubscribe();
17556
- 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"));
17611
+ 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"));
17557
17612
  }
17558
17613
  emitEvent(event) {
17559
17614
  this._recoveryEvent$.next(event);
@@ -17647,7 +17702,7 @@ function mosToQualityLevel(mos) {
17647
17702
 
17648
17703
  //#endregion
17649
17704
  //#region src/core/entities/Call.ts
17650
- var import_cjs$10 = require_cjs();
17705
+ var import_cjs$11 = require_cjs();
17651
17706
  const logger$11 = getLogger();
17652
17707
  /**
17653
17708
  * Ratio between the critical and warning RTT spike multipliers.
@@ -17722,7 +17777,7 @@ var WebRTCCall = class extends Destroyable {
17722
17777
  const { deviceController, networkChange$ } = initialization;
17723
17778
  this._networkChange$ = networkChange$;
17724
17779
  this.participantFactory = new ParticipantFactory(this.executeMethod.bind(this), this.vertoManager, deviceController);
17725
- 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) => {
17780
+ 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) => {
17726
17781
  this._lastMergedStatus = status;
17727
17782
  if (status === "connected" && !this._statsMonitor) this.initResilienceSubsystems();
17728
17783
  else if (status === "disconnected") {
@@ -17757,7 +17812,7 @@ var WebRTCCall = class extends Destroyable {
17757
17812
  }
17758
17813
  /** Observable of the address associated with this call. */
17759
17814
  get address$() {
17760
- return this.deferEmission((0, import_cjs$10.from)([this.address])).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17815
+ return this.deferEmission((0, import_cjs$11.from)([this.address])).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17761
17816
  }
17762
17817
  /** Display name of the caller. */
17763
17818
  get fromName() {
@@ -17836,7 +17891,7 @@ var WebRTCCall = class extends Destroyable {
17836
17891
  }
17837
17892
  /** Observable of layout layer positions for all participants. */
17838
17893
  get layoutLayers$() {
17839
- return this.deferEmission(this.callEventsManager.layoutLayers$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17894
+ return this.deferEmission(this.callEventsManager.layoutLayers$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17840
17895
  }
17841
17896
  /** Current snapshot of layout layers. */
17842
17897
  get layoutLayers() {
@@ -17891,45 +17946,45 @@ var WebRTCCall = class extends Destroyable {
17891
17946
  }
17892
17947
  /** Observable of the current call status (e.g. `'ringing'`, `'connected'`). */
17893
17948
  get status$() {
17894
- 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) => {
17949
+ 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) => {
17895
17950
  this._lastMergedStatus = status;
17896
17951
  })));
17897
17952
  }
17898
17953
  /** Observable of the participants list, emits on join/leave/update. */
17899
17954
  get participants$() {
17900
- return this.deferEmission(this.callEventsManager.participants$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17955
+ return this.deferEmission(this.callEventsManager.participants$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17901
17956
  }
17902
17957
  /** Observable of the local (self) participant. */
17903
17958
  get self$() {
17904
- return this.deferEmission(this.callEventsManager.self$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17959
+ return this.deferEmission(this.callEventsManager.self$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17905
17960
  }
17906
17961
  /** Observable indicating whether the call is being recorded. */
17907
17962
  get recording$() {
17908
- return this.deferEmission(this.callEventsManager.recording$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17963
+ return this.deferEmission(this.callEventsManager.recording$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17909
17964
  }
17910
17965
  /** Observable indicating whether the call is being streamed. */
17911
17966
  get streaming$() {
17912
- return this.deferEmission(this.callEventsManager.streaming$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17967
+ return this.deferEmission(this.callEventsManager.streaming$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17913
17968
  }
17914
17969
  /** Observable indicating whether raise-hand priority is active. */
17915
17970
  get raiseHandPriority$() {
17916
- return this.deferEmission(this.callEventsManager.raiseHandPriority$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17971
+ return this.deferEmission(this.callEventsManager.raiseHandPriority$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17917
17972
  }
17918
17973
  /** Observable indicating whether the call room is locked. */
17919
17974
  get locked$() {
17920
- return this.deferEmission(this.callEventsManager.locked$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17975
+ return this.deferEmission(this.callEventsManager.locked$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17921
17976
  }
17922
17977
  /** Observable of custom metadata associated with the call. */
17923
17978
  get meta$() {
17924
- return this.deferEmission(this.callEventsManager.meta$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17979
+ return this.deferEmission(this.callEventsManager.meta$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17925
17980
  }
17926
17981
  /** Observable of the call's capability flags. */
17927
17982
  get capabilities$() {
17928
- return this.deferEmission(this.callEventsManager.capabilities$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17983
+ return this.deferEmission(this.callEventsManager.capabilities$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17929
17984
  }
17930
17985
  /** Observable of the current layout name. */
17931
17986
  get layout$() {
17932
- return this.deferEmission(this.callEventsManager.layout$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
17987
+ return this.deferEmission(this.callEventsManager.layout$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17933
17988
  }
17934
17989
  /** Current call status. */
17935
17990
  get status() {
@@ -17961,7 +18016,7 @@ var WebRTCCall = class extends Destroyable {
17961
18016
  }
17962
18017
  /** Observable of available layout names. */
17963
18018
  get layouts$() {
17964
- return this.deferEmission(this.callEventsManager.layouts$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18019
+ return this.deferEmission(this.callEventsManager.layouts$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17965
18020
  }
17966
18021
  /** Current snapshot of available layout names. */
17967
18022
  get layouts() {
@@ -17969,7 +18024,7 @@ var WebRTCCall = class extends Destroyable {
17969
18024
  }
17970
18025
  /** Observable of the local media stream (camera/microphone). */
17971
18026
  get localStream$() {
17972
- return this.deferEmission(this.vertoManager.localStream$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18027
+ return this.deferEmission(this.vertoManager.localStream$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17973
18028
  }
17974
18029
  /** Current local media stream, or `null` if not available. */
17975
18030
  get localStream() {
@@ -17977,7 +18032,7 @@ var WebRTCCall = class extends Destroyable {
17977
18032
  }
17978
18033
  /** Observable of the remote media stream from the far end. */
17979
18034
  get remoteStream$() {
17980
- return this.deferEmission(this.vertoManager.remoteStream$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18035
+ return this.deferEmission(this.vertoManager.remoteStream$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
17981
18036
  }
17982
18037
  /** Current remote media stream, or `null` if not available. */
17983
18038
  get remoteStream() {
@@ -18180,7 +18235,7 @@ var WebRTCCall = class extends Destroyable {
18180
18235
  });
18181
18236
  else if (event.type === "online") this._recoveryManager?.handleWebSocketReconnect();
18182
18237
  });
18183
- this.subscribeTo(this.clientSession.authenticated$.pipe((0, import_cjs$10.skip)(1), (0, import_cjs$10.filter)(Boolean)), () => {
18238
+ this.subscribeTo(this.clientSession.authenticated$.pipe((0, import_cjs$11.skip)(1), (0, import_cjs$11.filter)(Boolean)), () => {
18184
18239
  logger$11.debug("[Call] WebSocket reconnected — notifying recovery manager");
18185
18240
  this._recoveryManager?.handleWebSocketReconnect();
18186
18241
  });
@@ -18209,14 +18264,14 @@ var WebRTCCall = class extends Destroyable {
18209
18264
  }
18210
18265
  /** Observable of the current audio/video send/receive directions. */
18211
18266
  get mediaDirections$() {
18212
- return this.deferEmission(this.vertoManager.mediaDirections$).pipe((0, import_cjs$10.takeUntil)(this._destroyed$));
18267
+ return this.deferEmission(this.vertoManager.mediaDirections$).pipe((0, import_cjs$11.takeUntil)(this._destroyed$));
18213
18268
  }
18214
18269
  /** Current audio/video send/receive directions. */
18215
18270
  get mediaDirections() {
18216
18271
  return this.vertoManager.mediaDirections;
18217
18272
  }
18218
18273
  get participantsId$() {
18219
- return this.cachedObservable("participantsId$", () => this.participants$.pipe((0, import_cjs$10.map)((participants) => participants.map((participant) => participant.id))));
18274
+ return this.cachedObservable("participantsId$", () => this.participants$.pipe((0, import_cjs$11.map)((participants) => participants.map((participant) => participant.id))));
18220
18275
  }
18221
18276
  /**
18222
18277
  * Executes a raw JSON-RPC request on the client session.
@@ -18260,37 +18315,37 @@ var WebRTCCall = class extends Destroyable {
18260
18315
  }
18261
18316
  }
18262
18317
  get callSessionEvents$() {
18263
- return this.cachedObservable("callSessionEvents$", () => this.clientSession.signalingEvent$.pipe((0, import_cjs$10.filter)((event) => this.isCallSessionEvent(event)), (0, import_cjs$10.tap)((event) => {
18318
+ return this.cachedObservable("callSessionEvents$", () => this.clientSession.signalingEvent$.pipe((0, import_cjs$11.filter)((event) => this.isCallSessionEvent(event)), (0, import_cjs$11.tap)((event) => {
18264
18319
  logger$11.debug("[Call] Received call session event:", event);
18265
- }), (0, import_cjs$10.takeUntil)(this.destroyed$), (0, import_cjs$10.share)()));
18320
+ }), (0, import_cjs$11.takeUntil)(this.destroyed$), (0, import_cjs$11.share)()));
18266
18321
  }
18267
18322
  /** Observable of call-updated events. */
18268
18323
  get callUpdated$() {
18269
- return this.publicCachedObservable("callUpdated$", () => this.callSessionEvents$.pipe(filterAs(isCallUpdatedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18324
+ return this.publicCachedObservable("callUpdated$", () => this.callSessionEvents$.pipe(filterAs(isCallUpdatedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18270
18325
  }
18271
18326
  /** Observable of member-joined events, emitted when a remote participant joins the call. */
18272
18327
  get memberJoined$() {
18273
- return this.publicCachedObservable("memberJoined$", () => this.callSessionEvents$.pipe(filterAs(isMemberJoinedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18328
+ return this.publicCachedObservable("memberJoined$", () => this.callSessionEvents$.pipe(filterAs(isMemberJoinedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18274
18329
  }
18275
18330
  /** Observable of member-left events, emitted when a participant leaves the call. */
18276
18331
  get memberLeft$() {
18277
- return this.publicCachedObservable("memberLeft$", () => this.callSessionEvents$.pipe(filterAs(isMemberLeftMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18332
+ return this.publicCachedObservable("memberLeft$", () => this.callSessionEvents$.pipe(filterAs(isMemberLeftMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18278
18333
  }
18279
18334
  /** Observable of member-updated events (mute, volume, etc.). */
18280
18335
  get memberUpdated$() {
18281
- return this.publicCachedObservable("memberUpdated$", () => this.callSessionEvents$.pipe(filterAs(isMemberUpdatedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18336
+ return this.publicCachedObservable("memberUpdated$", () => this.callSessionEvents$.pipe(filterAs(isMemberUpdatedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18282
18337
  }
18283
18338
  /** Observable of member-talking events (speech start/stop). */
18284
18339
  get memberTalking$() {
18285
- return this.publicCachedObservable("memberTalking$", () => this.callSessionEvents$.pipe(filterAs(isMemberTalkingMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18340
+ return this.publicCachedObservable("memberTalking$", () => this.callSessionEvents$.pipe(filterAs(isMemberTalkingMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18286
18341
  }
18287
18342
  /** Observable of call state-change events. */
18288
18343
  get callStates$() {
18289
- return this.publicCachedObservable("callStates$", () => this.callSessionEvents$.pipe(filterAs(isCallStateMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18344
+ return this.publicCachedObservable("callStates$", () => this.callSessionEvents$.pipe(filterAs(isCallStateMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18290
18345
  }
18291
18346
  /** Observable of layout-changed events. */
18292
18347
  get layoutUpdates$() {
18293
- return this.publicCachedObservable("layoutUpdates$", () => this.callSessionEvents$.pipe(filterAs(isLayoutChangedMetadata, "params"), (0, import_cjs$10.takeUntil)(this.destroyed$)));
18348
+ return this.publicCachedObservable("layoutUpdates$", () => this.callSessionEvents$.pipe(filterAs(isLayoutChangedMetadata, "params"), (0, import_cjs$11.takeUntil)(this.destroyed$)));
18294
18349
  }
18295
18350
  /** Underlying `RTCPeerConnection`, for advanced use cases. */
18296
18351
  get rtcPeerConnection() {
@@ -18298,7 +18353,7 @@ var WebRTCCall = class extends Destroyable {
18298
18353
  }
18299
18354
  /** Observable of raw signaling events as plain objects. */
18300
18355
  get signalingEvent$() {
18301
- return this.publicCachedObservable("signalingEvent$", () => this.callEvent$.pipe((0, import_cjs$10.map)((event) => JSON.parse(JSON.stringify(event)))));
18356
+ return this.publicCachedObservable("signalingEvent$", () => this.callEvent$.pipe((0, import_cjs$11.map)((event) => JSON.parse(JSON.stringify(event)))));
18302
18357
  }
18303
18358
  /**
18304
18359
  * Subscribe to a custom signaling event type on this call.
@@ -18326,16 +18381,16 @@ var WebRTCCall = class extends Destroyable {
18326
18381
  subscribe(eventType) {
18327
18382
  const cached = this._customSubscriptions.get(eventType);
18328
18383
  if (cached) return cached;
18329
- 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$));
18384
+ 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$));
18330
18385
  this._customSubscriptions.set(eventType, filtered$);
18331
18386
  this._sendVertoSubscribe(eventType);
18332
18387
  return filtered$;
18333
18388
  }
18334
18389
  get webrtcMessages$() {
18335
- 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)()));
18390
+ 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)()));
18336
18391
  }
18337
18392
  get callEvent$() {
18338
- 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)()));
18393
+ 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)()));
18339
18394
  }
18340
18395
  get layoutEvent$() {
18341
18396
  return this.cachedObservable("layoutEvent$", () => this.callEvent$.pipe(filterAs(isLayoutChangedMetadata, "params")));
@@ -18428,7 +18483,7 @@ var WebRTCCall = class extends Destroyable {
18428
18483
  */
18429
18484
  async setLayout(layout, positions) {
18430
18485
  if (!this.layouts.includes(layout)) throw new InvalidParams(`Layout ${layout} is not available in the current call layouts: ${this.layouts.join(", ")}`);
18431
- const selfId = await (0, import_cjs$10.firstValueFrom)(this.selfId$.pipe((0, import_cjs$10.filter)((id) => id !== null)));
18486
+ const selfId = await (0, import_cjs$11.firstValueFrom)(this.selfId$.pipe((0, import_cjs$11.filter)((id) => id !== null)));
18432
18487
  await this.executeMethod(selfId, "call.layout.set", {
18433
18488
  layout,
18434
18489
  positions
@@ -18542,7 +18597,7 @@ var CallFactory = class {
18542
18597
 
18543
18598
  //#endregion
18544
18599
  //#region src/behaviors/Collection.ts
18545
- var import_cjs$9 = require_cjs();
18600
+ var import_cjs$10 = require_cjs();
18546
18601
  const logger$10 = getLogger();
18547
18602
  var Fetcher = class {
18548
18603
  constructor(endpoint, params, http) {
@@ -18584,8 +18639,6 @@ var EntityCollection = class extends Destroyable {
18584
18639
  this.fetchController = fetchController;
18585
18640
  this.update$ = update$;
18586
18641
  this.onError = onError;
18587
- this.loading$ = this.createBehaviorSubject(false);
18588
- this.values$ = this.createReplaySubject(1);
18589
18642
  this.collectionData = /* @__PURE__ */ new Map();
18590
18643
  this.observablesRegistry = /* @__PURE__ */ new Map();
18591
18644
  this.upsertData = (data) => {
@@ -18605,22 +18658,28 @@ var EntityCollection = class extends Destroyable {
18605
18658
  }
18606
18659
  this.collectionData.set(data.id, updated);
18607
18660
  this.observablesRegistry.get(data.id)?.next(updated);
18608
- this.values$.next(Array.from(this.collectionData.values()));
18661
+ this._values$.next(Array.from(this.collectionData.values()));
18609
18662
  };
18663
+ this._loading$ = this.createBehaviorSubject(false);
18664
+ this._values$ = this.createReplaySubject(1);
18610
18665
  this._hasMore$ = this.createBehaviorSubject(true);
18611
- this._destroy$ = new import_cjs$9.Subject();
18612
- this.updateSubscription = this.update$.subscribe(this.upsertData);
18613
- this.loading$.next(false);
18614
- 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$));
18666
+ this.subscribeTo(this.update$, this.upsertData);
18667
+ 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$));
18668
+ }
18669
+ get loading$() {
18670
+ return this._loading$.asObservable();
18615
18671
  }
18616
18672
  get loading() {
18617
- return this.loading$.value;
18673
+ return this._loading$.value;
18674
+ }
18675
+ get values$() {
18676
+ return this._values$.asObservable();
18618
18677
  }
18619
18678
  get hasMore() {
18620
18679
  return this.fetchController.hasMore ?? true;
18621
18680
  }
18622
18681
  get updated$() {
18623
- 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$)));
18682
+ 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$)));
18624
18683
  }
18625
18684
  get values() {
18626
18685
  return Array.from(this.collectionData.values());
@@ -18634,33 +18693,33 @@ var EntityCollection = class extends Destroyable {
18634
18693
  }
18635
18694
  async fetchMore() {
18636
18695
  try {
18637
- this.loading$.next(true);
18696
+ this._loading$.next(true);
18638
18697
  (await this.fetchController.next()).forEach(this.upsertData);
18639
18698
  this._hasMore$.next(this.fetchController.hasMore ?? false);
18640
- this.loading$.next(false);
18699
+ this._loading$.next(false);
18641
18700
  } catch (error) {
18642
18701
  logger$10.error(`Failed to fetch initial collection data`, error);
18643
18702
  this._hasMore$.next(this.fetchController.hasMore ?? false);
18644
- this.loading$.next(false);
18703
+ this._loading$.next(false);
18645
18704
  this.onError?.(new CollectionFetchError("fetchMore", error));
18646
18705
  }
18647
18706
  }
18648
18707
  async tryFetch(key, value) {
18649
18708
  try {
18650
- this.loading$.next(true);
18709
+ this._loading$.next(true);
18651
18710
  const data = await this.fetchController[key]?.(value);
18652
- this.loading$.next(false);
18711
+ this._loading$.next(false);
18653
18712
  if (data) this.upsertData(data);
18654
18713
  return data;
18655
18714
  } catch (error) {
18656
18715
  logger$10.error(`Failed to fetch data for (${String(key)}:${String(value)}) :`, error);
18657
- this.loading$.next(false);
18716
+ this._loading$.next(false);
18658
18717
  this.onError?.(new CollectionFetchError(`tryFetch(${String(key)})`, error));
18659
18718
  }
18660
18719
  }
18661
18720
  get$(id) {
18662
18721
  if (!this.observablesRegistry.has(id)) {
18663
- this.observablesRegistry.set(id, new import_cjs$9.ReplaySubject(1));
18722
+ this.observablesRegistry.set(id, new import_cjs$10.ReplaySubject(1));
18664
18723
  const data = this.collectionData.get(id);
18665
18724
  if (data) this.observablesRegistry.get(id)?.next(data);
18666
18725
  else this.tryFetch("id", id);
@@ -18675,11 +18734,8 @@ var EntityCollection = class extends Destroyable {
18675
18734
  if (this.fetchController.hasMore !== false) this.fetchMore();
18676
18735
  }
18677
18736
  destroy() {
18678
- this._destroy$.next();
18679
- this._destroy$.complete();
18680
- this.updateSubscription.unsubscribe();
18681
- this.loading$.complete();
18682
18737
  this.observablesRegistry.forEach((subject) => subject.complete());
18738
+ this.observablesRegistry.clear();
18683
18739
  super.destroy();
18684
18740
  }
18685
18741
  };
@@ -18705,15 +18761,15 @@ var EntityCollectionTransformed = class {
18705
18761
  return this.originalCollection.values.filter(this.filter).map(this.mapper);
18706
18762
  }
18707
18763
  get values$() {
18708
- return this._values$ ??= this.originalCollection.values$.pipe((0, import_cjs$9.map)((values) => values.filter(this.filter).map(this.mapper)));
18764
+ return this._values$ ??= this.originalCollection.values$.pipe((0, import_cjs$10.map)((values) => values.filter(this.filter).map(this.mapper)));
18709
18765
  }
18710
18766
  get$(id) {
18711
18767
  const original$ = this.originalCollection.get$(id);
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
  async find$(key, value) {
18715
18771
  const original$ = await this.originalCollection.find$(key, value);
18716
- return !original$ ? original$ : original$.pipe((0, import_cjs$9.pipe)((0, import_cjs$9.filter)(this.filter), (0, import_cjs$9.map)(this.mapper)));
18772
+ return !original$ ? original$ : original$.pipe((0, import_cjs$10.pipe)((0, import_cjs$10.filter)(this.filter), (0, import_cjs$10.map)(this.mapper)));
18717
18773
  }
18718
18774
  loadMore() {
18719
18775
  this.originalCollection.loadMore();
@@ -18725,7 +18781,7 @@ var EntityCollectionTransformed = class {
18725
18781
 
18726
18782
  //#endregion
18727
18783
  //#region src/core/entities/Address.ts
18728
- var import_cjs$8 = require_cjs();
18784
+ var import_cjs$9 = require_cjs();
18729
18785
  /**
18730
18786
  * Represents a contact or room in the directory.
18731
18787
  *
@@ -18743,8 +18799,8 @@ var Address = class extends Destroyable {
18743
18799
  if (this._conversationMessages.hasMore) this._conversationMessages.loadMore();
18744
18800
  return this._conversationMessages;
18745
18801
  };
18746
- 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$));
18747
- 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$));
18802
+ 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$));
18803
+ 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$));
18748
18804
  this._state$ = this.createBehaviorSubject(null);
18749
18805
  }
18750
18806
  /** @internal */
@@ -18779,7 +18835,7 @@ var Address = class extends Destroyable {
18779
18835
  }
18780
18836
  /** Observable of the human-readable display name. */
18781
18837
  get displayName$() {
18782
- return this.cachedObservable("displayName$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.map)((state) => state.display_name), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18838
+ return this.cachedObservable("displayName$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.map)((state) => state.display_name), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18783
18839
  }
18784
18840
  /** Human-readable display name. */
18785
18841
  get displayName() {
@@ -18788,7 +18844,7 @@ var Address = class extends Destroyable {
18788
18844
  }
18789
18845
  /** Observable of the preview image URL. */
18790
18846
  get previewUrl$() {
18791
- return this.cachedObservable("previewUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$8.map)((state) => state.preview_url), (0, import_cjs$8.takeUntil)(this.destroyed$)));
18847
+ return this.cachedObservable("previewUrl$", () => this._state$.pipe(filterNull(), (0, import_cjs$9.map)((state) => state.preview_url), (0, import_cjs$9.takeUntil)(this.destroyed$)));
18792
18848
  }
18793
18849
  /** Preview image URL. */
18794
18850
  get previewUrl() {
@@ -18797,7 +18853,7 @@ var Address = class extends Destroyable {
18797
18853
  }
18798
18854
  /** Observable of the cover image URL. */
18799
18855
  get coverUrl$() {
18800
- 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$)));
18856
+ 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$)));
18801
18857
  }
18802
18858
  /** Cover image URL. */
18803
18859
  get coverUrl() {
@@ -18806,7 +18862,7 @@ var Address = class extends Destroyable {
18806
18862
  }
18807
18863
  /** Observable of the underlying resource ID. */
18808
18864
  get resourceId$() {
18809
- 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$)));
18865
+ 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$)));
18810
18866
  }
18811
18867
  /** Underlying resource ID. */
18812
18868
  get resourceId() {
@@ -18815,7 +18871,7 @@ var Address = class extends Destroyable {
18815
18871
  }
18816
18872
  /** Observable of the resource type (e.g. `'room'`, `'subscriber'`). */
18817
18873
  get type$() {
18818
- 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$)));
18874
+ 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$)));
18819
18875
  }
18820
18876
  /** Resource type (e.g. `'room'`, `'subscriber'`). */
18821
18877
  get type() {
@@ -18824,7 +18880,7 @@ var Address = class extends Destroyable {
18824
18880
  }
18825
18881
  /** Observable of available communication channels (audio, video, messaging). */
18826
18882
  get channels$() {
18827
- 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$)));
18883
+ 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$)));
18828
18884
  }
18829
18885
  /** Available communication channels. */
18830
18886
  get channels() {
@@ -18838,7 +18894,7 @@ var Address = class extends Destroyable {
18838
18894
  }
18839
18895
  /** Observable indicating whether the address (room) is locked. */
18840
18896
  get locked$() {
18841
- 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$)));
18897
+ 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$)));
18842
18898
  }
18843
18899
  /**
18844
18900
  * Sends a text message to this address.
@@ -18904,7 +18960,7 @@ var Address = class extends Destroyable {
18904
18960
 
18905
18961
  //#endregion
18906
18962
  //#region src/core/utils.ts
18907
- var import_cjs$7 = require_cjs();
18963
+ var import_cjs$8 = require_cjs();
18908
18964
  const logger$9 = getLogger();
18909
18965
  const isRPCConnectResult = (e) => {
18910
18966
  logger$9.debug("isRPCConnectResult check:", e);
@@ -18930,18 +18986,18 @@ var PendingRPC = class PendingRPC {
18930
18986
  return;
18931
18987
  }
18932
18988
  let isSettled = false;
18933
- 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) => {
18989
+ 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) => {
18934
18990
  const timer$3 = setTimeout(() => {
18935
18991
  subscriber.error(new RPCTimeoutError(request.id, timeoutMs));
18936
18992
  }, timeoutMs);
18937
18993
  return () => clearTimeout(timer$3);
18938
- }), signal ? new import_cjs$7.Observable((subscriber) => {
18994
+ }), signal ? new import_cjs$8.Observable((subscriber) => {
18939
18995
  const abortHandler = () => {
18940
18996
  subscriber.error(new DOMException("The operation was aborted", "AbortError"));
18941
18997
  };
18942
18998
  signal.addEventListener("abort", abortHandler);
18943
18999
  return () => signal.removeEventListener("abort", abortHandler);
18944
- }) : import_cjs$7.NEVER).subscribe({
19000
+ }) : import_cjs$8.NEVER).subscribe({
18945
19001
  next: (response) => {
18946
19002
  isSettled = true;
18947
19003
  if (response.error) {
@@ -18981,7 +19037,7 @@ var PendingRPC = class PendingRPC {
18981
19037
 
18982
19038
  //#endregion
18983
19039
  //#region src/managers/ClientSessionManager.ts
18984
- var import_cjs$6 = require_cjs();
19040
+ var import_cjs$7 = require_cjs();
18985
19041
  const logger$8 = getLogger();
18986
19042
  const getAddressSearchURI = (options) => {
18987
19043
  const to = options.to?.split("?")[0];
@@ -19010,17 +19066,17 @@ var ClientSessionManager = class extends Destroyable {
19010
19066
  };
19011
19067
  this._authorization$ = this.createBehaviorSubject(void 0);
19012
19068
  this._errors$ = this.createReplaySubject(1);
19013
- this._authenticated$ = this.createBehaviorSubject(false);
19014
- this._clientBound = false;
19069
+ this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
19070
+ this._wasClientBound = false;
19015
19071
  this._subscriberInfo$ = this.createBehaviorSubject(null);
19016
19072
  this._calls$ = this.createBehaviorSubject({});
19017
19073
  this._iceServers$ = this.createBehaviorSubject([]);
19018
19074
  attachManager.setSession(this);
19019
19075
  this.callFactory = new CallFactory(this, deviceController, attachManager, webRTCApiProvider, networkChange$);
19020
- 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$));
19076
+ 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$));
19021
19077
  }
19022
19078
  get incomingCalls$() {
19023
- return this.cachedObservable("incomingCalls$", () => this.calls$.pipe((0, import_cjs$6.map)((calls) => calls.filter((call) => call.direction === "inbound"))));
19079
+ return this.cachedObservable("incomingCalls$", () => this.calls$.pipe((0, import_cjs$7.map)((calls) => calls.filter((call) => call.direction === "inbound"))));
19024
19080
  }
19025
19081
  get incomingCalls() {
19026
19082
  return Object.values(this._calls$.value).filter((call) => call.direction === "inbound");
@@ -19032,7 +19088,7 @@ var ClientSessionManager = class extends Destroyable {
19032
19088
  return this._subscriberInfo$.value;
19033
19089
  }
19034
19090
  get calls$() {
19035
- return this.cachedObservable("calls$", () => this._calls$.pipe((0, import_cjs$6.map)((calls) => Object.values(calls))));
19091
+ return this.cachedObservable("calls$", () => this._calls$.pipe((0, import_cjs$7.map)((calls) => Object.values(calls))));
19036
19092
  }
19037
19093
  get calls() {
19038
19094
  return Object.values(this._calls$.value);
@@ -19050,10 +19106,10 @@ var ClientSessionManager = class extends Destroyable {
19050
19106
  return this._errors$.asObservable();
19051
19107
  }
19052
19108
  get authenticated$() {
19053
- return this._authenticated$.asObservable();
19109
+ return this._authState$.pipe((0, import_cjs$7.map)((state) => state.kind === "authenticated"), (0, import_cjs$7.distinctUntilChanged)());
19054
19110
  }
19055
19111
  get authenticated() {
19056
- return this._authenticated$.value;
19112
+ return this._authState$.value.kind === "authenticated";
19057
19113
  }
19058
19114
  /**
19059
19115
  * Whether this session is client-bound (using a Client Bound SAT).
@@ -19062,7 +19118,11 @@ var ClientSessionManager = class extends Destroyable {
19062
19118
  * @internal
19063
19119
  */
19064
19120
  get clientBound() {
19065
- return this._clientBound;
19121
+ return this._wasClientBound;
19122
+ }
19123
+ /** @internal Current auth state for debugging/testing. */
19124
+ get authState() {
19125
+ return this._authState$.value;
19066
19126
  }
19067
19127
  /**
19068
19128
  * Set the directory instance
@@ -19100,13 +19160,16 @@ var ClientSessionManager = class extends Destroyable {
19100
19160
  this._errors$.next(new AuthStateHandlerError(error));
19101
19161
  }
19102
19162
  });
19103
- this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$6.filter)((status) => status === "connected"), (0, import_cjs$6.exhaustMap)(() => {
19163
+ this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$7.filter)((status) => status === "disconnected" || status === "reconnecting")), () => {
19164
+ if (this._authState$.value.kind === "authenticated") this._authState$.next({ kind: "unauthenticated" });
19165
+ });
19166
+ this.subscribeTo(this.transport.connectionStatus$.pipe((0, import_cjs$7.filter)((status) => status === "connected"), (0, import_cjs$7.exhaustMap)(() => {
19104
19167
  logger$8.debug("[Session] Connection established, initiating authentication");
19105
- return (0, import_cjs$6.from)(this.authenticate()).pipe((0, import_cjs$6.catchError)((error) => {
19168
+ return (0, import_cjs$7.from)(this.authenticate()).pipe((0, import_cjs$7.catchError)((error) => {
19106
19169
  this.handleAuthenticationError(error).catch((err) => {
19107
19170
  logger$8.error("[Session] Error handling authentication failure:", err);
19108
19171
  });
19109
- return import_cjs$6.EMPTY;
19172
+ return import_cjs$7.EMPTY;
19110
19173
  }));
19111
19174
  })), void 0);
19112
19175
  this.subscribeTo(this.vertoInvite$, async (invite) => {
@@ -19159,23 +19222,23 @@ var ClientSessionManager = class extends Destroyable {
19159
19222
  }
19160
19223
  }
19161
19224
  get authStateEvent$() {
19162
- return this.cachedObservable("authStateEvent$", () => this.signalingEvent$.pipe((0, import_cjs$6.tap)((msg) => {
19225
+ return this.cachedObservable("authStateEvent$", () => this.signalingEvent$.pipe((0, import_cjs$7.tap)((msg) => {
19163
19226
  logger$8.debug("[Session] Received incoming message:", msg);
19164
- }), filterAs(isSignalwireAuthorizationStateMetadata, "params"), (0, import_cjs$6.tap)((event) => {
19227
+ }), filterAs(isSignalwireAuthorizationStateMetadata, "params"), (0, import_cjs$7.tap)((event) => {
19165
19228
  logger$8.debug("[Session] Authorization state event received:", event.authorization_state);
19166
19229
  })));
19167
19230
  }
19168
19231
  get signalingEvent$() {
19169
- return this.cachedObservable("signalingEvent$", () => this.transport.incomingEvent$.pipe(filterAs(isSignalwireRequest, "params"), (0, import_cjs$6.share)()));
19232
+ return this.cachedObservable("signalingEvent$", () => this.transport.incomingEvent$.pipe(filterAs(isSignalwireRequest, "params"), (0, import_cjs$7.share)()));
19170
19233
  }
19171
19234
  get vertoInvite$() {
19172
- 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) => ({
19235
+ 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) => ({
19173
19236
  node_id: event.node_id,
19174
19237
  ...event.params.params
19175
19238
  }))));
19176
19239
  }
19177
19240
  get vertoAttach$() {
19178
- 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) => ({
19241
+ 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) => ({
19179
19242
  node_id: event.node_id,
19180
19243
  ...event.params.params
19181
19244
  }))));
@@ -19195,14 +19258,14 @@ var ClientSessionManager = class extends Destroyable {
19195
19258
  return { jwt_token: credential.token };
19196
19259
  }
19197
19260
  async connect() {
19198
- await (0, import_cjs$6.firstValueFrom)(this.initialized$);
19261
+ await (0, import_cjs$7.firstValueFrom)(this.initialized$);
19199
19262
  await this.transport.connect();
19200
- 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 })));
19263
+ 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 })));
19201
19264
  }
19202
19265
  async handleAuthenticationError(error) {
19203
19266
  logger$8.error("Authentication error:", error);
19204
19267
  const isRecoverableAuthError = error instanceof JSONRPCError && (error.code === RPC_ERROR_REQUESTER_VALIDATION_FAILED || error.code === RPC_ERROR_INVALID_PARAMS || error.code === RPC_ERROR_AUTHENTICATION_FAILED);
19205
- const hasStoredState = await (0, import_cjs$6.firstValueFrom)(this.authorizationState$.pipe((0, import_cjs$6.take)(1))) !== void 0;
19268
+ const hasStoredState = await (0, import_cjs$7.firstValueFrom)(this.authorizationState$.pipe((0, import_cjs$7.take)(1))) !== void 0;
19206
19269
  if (isRecoverableAuthError && hasStoredState) {
19207
19270
  logger$8.debug("[Session] Recoverable auth error — cleaning up stored state and reconnecting fresh");
19208
19271
  try {
@@ -19234,7 +19297,7 @@ var ClientSessionManager = class extends Destroyable {
19234
19297
  if (!resolvedDpopToken && this.dpopManager?.initialized) try {
19235
19298
  resolvedDpopToken = await this.dpopManager.createRpcProof({ method: "signalwire.reauthenticate" });
19236
19299
  } catch (error) {
19237
- if (this._clientBound) throw error;
19300
+ if (this.clientBound) throw error;
19238
19301
  logger$8.warn("[Session] Failed to create DPoP proof for reauthenticate:", error);
19239
19302
  }
19240
19303
  const request = RPCReauthenticate({
@@ -19242,11 +19305,11 @@ var ClientSessionManager = class extends Destroyable {
19242
19305
  jwt_token: token,
19243
19306
  ...resolvedDpopToken ? { dpop_token: resolvedDpopToken } : {}
19244
19307
  });
19245
- 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) => {
19308
+ 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) => {
19246
19309
  logger$8.error("[Session] Re-authentication RPC failed:", err);
19247
19310
  throw err;
19248
19311
  })));
19249
- if (options?.clientBound) this._clientBound = true;
19312
+ if (options?.clientBound) this._wasClientBound = true;
19250
19313
  logger$8.debug("[Session] Re-authentication successful, updating stored auth state");
19251
19314
  } catch (error) {
19252
19315
  logger$8.error("[Session] Re-authentication failed:", error);
@@ -19256,10 +19319,10 @@ var ClientSessionManager = class extends Destroyable {
19256
19319
  }
19257
19320
  async authenticate() {
19258
19321
  logger$8.debug("[Session] Starting authentication process");
19259
- const persistedParams = await (0, import_cjs$6.firstValueFrom)((0, import_cjs$6.combineLatest)({
19322
+ const persistedParams = await (0, import_cjs$7.firstValueFrom)((0, import_cjs$7.combineLatest)({
19260
19323
  protocol: this.transport.protocol$,
19261
19324
  authorization_state: this.authorizationState$
19262
- }).pipe((0, import_cjs$6.take)(1)));
19325
+ }).pipe((0, import_cjs$7.take)(1)));
19263
19326
  logger$8.debug("[Session] Persisted params:\n", {
19264
19327
  protocol: persistedParams.protocol,
19265
19328
  authStateLength: persistedParams.authorization_state?.length
@@ -19269,14 +19332,14 @@ var ClientSessionManager = class extends Destroyable {
19269
19332
  const isReconnect = hasReconnectState && storedToken;
19270
19333
  let dpopToken;
19271
19334
  if (isReconnect) logger$8.debug("[Session] Reconnecting with stored jwt_token + authorization_state");
19272
- else if (this.onBeforeReconnect && this._clientBound) {
19335
+ else if (this.onBeforeReconnect && this.clientBound) {
19273
19336
  logger$8.debug("[Session] Refreshing credentials before fresh connect");
19274
19337
  await this.onBeforeReconnect();
19275
19338
  }
19276
- if ((!isReconnect || this._clientBound) && this.dpopManager?.initialized) try {
19339
+ if ((!isReconnect || this.clientBound) && this.dpopManager?.initialized) try {
19277
19340
  dpopToken = await this.dpopManager.createRpcProof({ method: "signalwire.connect" });
19278
19341
  } catch (error) {
19279
- if (this._clientBound) throw error;
19342
+ if (this.clientBound) throw error;
19280
19343
  logger$8.warn("[Session] Failed to create DPoP proof for connect, proceeding without:", error);
19281
19344
  }
19282
19345
  const rpcConnectRequest = RPCConnect({
@@ -19293,9 +19356,9 @@ var ClientSessionManager = class extends Destroyable {
19293
19356
  protocol: persistedParams.protocol
19294
19357
  } : {}
19295
19358
  });
19296
- 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)(() => {
19359
+ 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)(() => {
19297
19360
  logger$8.debug("[Session] Response passed filter, processing authentication result");
19298
- }), (0, import_cjs$6.take)(1), (0, import_cjs$6.catchError)((err) => {
19361
+ }), (0, import_cjs$7.take)(1), (0, import_cjs$7.catchError)((err) => {
19299
19362
  logger$8.error("[Session] Authentication RPC failed:", err);
19300
19363
  throw err;
19301
19364
  })));
@@ -19307,12 +19370,12 @@ var ClientSessionManager = class extends Destroyable {
19307
19370
  if (response.protocol) await this.transport.setProtocol(response.protocol);
19308
19371
  this._authorization$.next(response.authorization);
19309
19372
  this._iceServers$.next(response.ice_servers ?? []);
19310
- this._authenticated$.next(true);
19373
+ this._authState$.next({ kind: "authenticated" });
19311
19374
  logger$8.debug("[Session] Authentication completed successfully");
19312
19375
  }
19313
19376
  async disconnect() {
19314
19377
  this.transport.disconnect();
19315
- this._authenticated$.next(false);
19378
+ this._authState$.next({ kind: "unauthenticated" });
19316
19379
  await this.cleanupStoredConnectionParams();
19317
19380
  }
19318
19381
  async createInboundCall(invite) {
@@ -19327,7 +19390,7 @@ var ClientSessionManager = class extends Destroyable {
19327
19390
  displayDirection: invite.display_direction,
19328
19391
  userVariables: invite.userVariables
19329
19392
  });
19330
- await (0, import_cjs$6.firstValueFrom)(callSession.status$);
19393
+ await (0, import_cjs$7.firstValueFrom)(callSession.status$);
19331
19394
  this._calls$.next({
19332
19395
  [`${callSession.id}`]: callSession,
19333
19396
  ...this._calls$.value
@@ -19360,7 +19423,7 @@ var ClientSessionManager = class extends Destroyable {
19360
19423
  reattach: true,
19361
19424
  ...storedOptions
19362
19425
  });
19363
- await (0, import_cjs$6.firstValueFrom)(callSession.status$);
19426
+ await (0, import_cjs$7.firstValueFrom)(callSession.status$);
19364
19427
  this._calls$.next({
19365
19428
  [`${callSession.id}`]: callSession,
19366
19429
  ...this._calls$.value
@@ -19374,7 +19437,7 @@ var ClientSessionManager = class extends Destroyable {
19374
19437
  to: destinationURI,
19375
19438
  ...options
19376
19439
  });
19377
- 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)))));
19440
+ 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)))));
19378
19441
  this._calls$.next({
19379
19442
  [`${callSession.id}`]: callSession,
19380
19443
  ...this._calls$.value
@@ -19383,7 +19446,7 @@ var ClientSessionManager = class extends Destroyable {
19383
19446
  } catch (error) {
19384
19447
  logger$8.error("[Session] Error creating outbound call:", error);
19385
19448
  callSession?.destroy();
19386
- const callError = new CallCreateError(error instanceof import_cjs$6.TimeoutError ? "Call create timeout" : "Call creation failed", error, "outbound");
19449
+ const callError = new CallCreateError(error instanceof import_cjs$7.TimeoutError ? "Call create timeout" : "Call creation failed", error, "outbound");
19387
19450
  this._errors$.next(callError);
19388
19451
  throw callError;
19389
19452
  }
@@ -19402,7 +19465,7 @@ var ClientSessionManager = class extends Destroyable {
19402
19465
  logger$8.warn(`[Session] Directory lookup failed for ${addressURI}, proceeding with raw URI`);
19403
19466
  }
19404
19467
  const callSession = this.callFactory.createCall(address, { ...options });
19405
- this.subscribeTo(callSession.status$.pipe((0, import_cjs$6.filter)((status) => status === "destroyed"), (0, import_cjs$6.take)(1)), () => {
19468
+ this.subscribeTo(callSession.status$.pipe((0, import_cjs$7.filter)((status) => status === "destroyed"), (0, import_cjs$7.take)(1)), () => {
19406
19469
  const { [`${callSession.id}`]: _, ...remainingCalls } = this._calls$.value;
19407
19470
  this._calls$.next(remainingCalls);
19408
19471
  });
@@ -19456,7 +19519,7 @@ const isString = (obj) => typeof obj === "string";
19456
19519
 
19457
19520
  //#endregion
19458
19521
  //#region src/managers/ConversationsManager.ts
19459
- var import_cjs$5 = require_cjs();
19522
+ var import_cjs$6 = require_cjs();
19460
19523
  const logger$7 = getLogger();
19461
19524
  var ConversationMessagesFetcher = class extends Fetcher {
19462
19525
  constructor(groupId, http) {
@@ -19503,7 +19566,7 @@ var ConversationsManager = class {
19503
19566
  }
19504
19567
  async getConversationMessageCollection(addressId) {
19505
19568
  const groupId = this.groupIds.get(addressId) ?? await this.join(addressId);
19506
- 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));
19569
+ 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));
19507
19570
  }
19508
19571
  async sendText(text, destinationAddressId) {
19509
19572
  const groupId = this.groupIds.get(destinationAddressId) ?? await this.join(destinationAddressId);
@@ -19528,7 +19591,7 @@ var ConversationsManager = class {
19528
19591
 
19529
19592
  //#endregion
19530
19593
  //#region src/managers/DeviceTokenManager.ts
19531
- var import_cjs$4 = require_cjs();
19594
+ var import_cjs$5 = require_cjs();
19532
19595
  const logger$6 = getLogger();
19533
19596
  /**
19534
19597
  * Resolves the token expiry timestamp (epoch seconds) using a 3-tier priority chain:
@@ -19573,11 +19636,11 @@ var DeviceTokenManager = class extends Destroyable {
19573
19636
  this._currentToken$ = this.createBehaviorSubject(null);
19574
19637
  this._refreshInProgress = false;
19575
19638
  this._effectiveExpireIn = DEVICE_TOKEN_DEFAULT_EXPIRE_IN;
19576
- this.subscribeTo(this._currentToken$.pipe((0, import_cjs$4.filter)(Boolean), (0, import_cjs$4.switchMap)((tokenData) => {
19639
+ this.subscribeTo(this._currentToken$.pipe((0, import_cjs$5.filter)(Boolean), (0, import_cjs$5.switchMap)((tokenData) => {
19577
19640
  const expiresAt = resolveExpiresAt(tokenData);
19578
19641
  const refreshIn = Math.max(expiresAt * 1e3 - Date.now() - DEVICE_TOKEN_REFRESH_BUFFER_MS, 1e3);
19579
19642
  logger$6.debug(`[DeviceToken] Scheduling Client Bound SAT refresh in ${refreshIn}ms`);
19580
- return (0, import_cjs$4.timer)(refreshIn);
19643
+ return (0, import_cjs$5.timer)(refreshIn);
19581
19644
  })), () => {
19582
19645
  this.executeRefresh();
19583
19646
  });
@@ -19881,14 +19944,14 @@ const isEmptyArray = (a) => {
19881
19944
 
19882
19945
  //#endregion
19883
19946
  //#region src/utils/warnup.ts
19884
- var import_cjs$3 = require_cjs();
19947
+ var import_cjs$4 = require_cjs();
19885
19948
  const warnup = (observable) => {
19886
- observable.pipe((0, import_cjs$3.take)(1)).subscribe();
19949
+ observable.pipe((0, import_cjs$4.take)(1)).subscribe();
19887
19950
  };
19888
19951
 
19889
19952
  //#endregion
19890
19953
  //#region src/managers/DirectoryManager.ts
19891
- var import_cjs$2 = require_cjs();
19954
+ var import_cjs$3 = require_cjs();
19892
19955
  const logger$4 = getLogger();
19893
19956
  var AddressFetcher = class extends Fetcher {
19894
19957
  constructor(http) {
@@ -19926,7 +19989,7 @@ var DirectoryManager = class extends Destroyable {
19926
19989
  this.onError = onError;
19927
19990
  this.addNewAddress = (id) => {
19928
19991
  const address = new Address(id, this.conversationManager, this);
19929
- const observable = this._statesCollection.get$(id)?.pipe(filterNull(), (0, import_cjs$2.map)((data) => {
19992
+ const observable = this._statesCollection.get$(id)?.pipe(filterNull(), (0, import_cjs$3.map)((data) => {
19930
19993
  address.upnext(data);
19931
19994
  return address;
19932
19995
  }));
@@ -19939,7 +20002,7 @@ var DirectoryManager = class extends Destroyable {
19939
20002
  this._addresses$ = this.createBehaviorSubject([]);
19940
20003
  this._addressesInstances = /* @__PURE__ */ new Map();
19941
20004
  this._observableRegistry = /* @__PURE__ */ new Map();
19942
- this._statesCollection = new AddressStateCollection(clientSession.signalingEvent$.pipe(filterAs(isConversationMessageUpdatedMetadata, "params"), (0, import_cjs$2.map)((_) => ({}))), this.http, this.onError);
20005
+ this._statesCollection = new AddressStateCollection(clientSession.signalingEvent$.pipe(filterAs(isConversationMessageUpdatedMetadata, "params"), (0, import_cjs$3.map)((_) => ({}))), this.http, this.onError);
19943
20006
  this.initSubscriptions();
19944
20007
  }
19945
20008
  /** Whether addresses are currently being loaded from the server. */
@@ -20012,7 +20075,7 @@ var DirectoryManager = class extends Destroyable {
20012
20075
  if (!addressId) {
20013
20076
  const found$ = await this._statesCollection.find$("name", name);
20014
20077
  if (found$) {
20015
- const state = await (0, import_cjs$2.firstValueFrom)(found$);
20078
+ const state = await (0, import_cjs$3.firstValueFrom)(found$);
20016
20079
  this.addNewAddress(state.id);
20017
20080
  addressId = state.id;
20018
20081
  }
@@ -20090,11 +20153,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20090
20153
  }
20091
20154
  send(data) {
20092
20155
  if (this._status$.value === "connected" && this.socket?.readyState === 1) {
20093
- try {
20094
- logger$3.debug(`[WebSocketConnectionManager] Sending message:\n${JSON.stringify(JSON.parse(data), null, 2)}`);
20095
- } catch {
20096
- logger$3.warn(`[WebSocketConnectionManager] Sending non-JSON message:\n${data}`);
20097
- }
20156
+ logger$3.wsTraffic({
20157
+ type: "send",
20158
+ raw: data
20159
+ });
20098
20160
  this.socket.send(data);
20099
20161
  } else this.messageQueue.push(data);
20100
20162
  }
@@ -20157,11 +20219,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20157
20219
  this.handleConnectionError();
20158
20220
  }
20159
20221
  handleMessage(event) {
20160
- try {
20161
- logger$3.debug(`[WebSocketConnectionManager] Received message:\n${JSON.stringify(JSON.parse(event.data), null, 2)}`);
20162
- } catch {
20163
- logger$3.warn(`[WebSocketConnectionManager] Received non-JSON message:\n${event.data}`);
20164
- }
20222
+ logger$3.wsTraffic({
20223
+ type: "recv",
20224
+ raw: event.data
20225
+ });
20165
20226
  this._incomingMessages$.next(event);
20166
20227
  }
20167
20228
  handleConnectionError() {
@@ -20219,7 +20280,7 @@ function isSignalwirePingRequest(value) {
20219
20280
 
20220
20281
  //#endregion
20221
20282
  //#region src/managers/TransportManager.ts
20222
- var import_cjs$1 = require_cjs();
20283
+ var import_cjs$2 = require_cjs();
20223
20284
  const logger$2 = getLogger();
20224
20285
  var TransportManager = class extends Destroyable {
20225
20286
  constructor(storage, protocolKey, webSocketConstructor, relayHost, onError) {
@@ -20231,7 +20292,7 @@ var TransportManager = class extends Destroyable {
20231
20292
  this.isConnecting = false;
20232
20293
  this.isConnected = false;
20233
20294
  this.ackEvent = () => {
20234
- return (0, import_cjs$1.tap)((message) => {
20295
+ return (0, import_cjs$2.tap)((message) => {
20235
20296
  if (isSignalwireRequest(message)) try {
20236
20297
  logger$2.debug("[Transport] Sending event ack", { eventId: message.id });
20237
20298
  this.send(RPCEventAckResponse(message.id));
@@ -20241,7 +20302,7 @@ var TransportManager = class extends Destroyable {
20241
20302
  });
20242
20303
  };
20243
20304
  this.replySignalwirePing = () => {
20244
- return (0, import_cjs$1.filter)((message) => {
20305
+ return (0, import_cjs$2.filter)((message) => {
20245
20306
  if (isSignalwirePingRequest(message)) {
20246
20307
  try {
20247
20308
  logger$2.debug("[Transport] Received ping, sending pong", { pingId: message.id });
@@ -20255,7 +20316,7 @@ var TransportManager = class extends Destroyable {
20255
20316
  });
20256
20317
  };
20257
20318
  this.discardStaleEvents = () => {
20258
- return (0, import_cjs$1.filter)((message) => {
20319
+ return (0, import_cjs$2.filter)((message) => {
20259
20320
  if (!isSignalwireRequest(message)) return true;
20260
20321
  const eventChannel = message.params.event_channel;
20261
20322
  if (!eventChannel) return true;
@@ -20278,8 +20339,8 @@ var TransportManager = class extends Destroyable {
20278
20339
  this.subscribeTo(this._webSocketConnections.errors$, (error) => {
20279
20340
  this.onError?.(error);
20280
20341
  });
20281
- 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$));
20282
- this._jsonRPCMessage$ = this._webSocketConnections.incomingMessages$.pipe((0, import_cjs$1.map)((event) => {
20342
+ 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$));
20343
+ this._jsonRPCMessage$ = this._webSocketConnections.incomingMessages$.pipe((0, import_cjs$2.map)((event) => {
20283
20344
  try {
20284
20345
  return JSON.parse(event.data);
20285
20346
  } catch (error) {
@@ -20287,13 +20348,13 @@ var TransportManager = class extends Destroyable {
20287
20348
  this.onError?.(new MessageParseError(error));
20288
20349
  return null;
20289
20350
  }
20290
- }), (0, import_cjs$1.filter)((message) => message !== null && (isJSONRPCResponse(message) || isJSONRPCRequest(message))), (0, import_cjs$1.catchError)((error) => {
20351
+ }), (0, import_cjs$2.filter)((message) => message !== null && (isJSONRPCResponse(message) || isJSONRPCRequest(message))), (0, import_cjs$2.catchError)((error) => {
20291
20352
  logger$2.error("[Transport] Message processing error:", error);
20292
20353
  this.onError?.(error instanceof Error ? error : new Error(String(error), { cause: error }));
20293
- return import_cjs$1.EMPTY;
20294
- }), (0, import_cjs$1.share)(), (0, import_cjs$1.takeUntil)(this.destroyed$));
20295
- this._jsonRPCResponse$ = this._jsonRPCMessage$.pipe((0, import_cjs$1.filter)(isJSONRPCResponse));
20296
- 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$));
20354
+ return import_cjs$2.EMPTY;
20355
+ }), (0, import_cjs$2.share)(), (0, import_cjs$2.takeUntil)(this.destroyed$));
20356
+ this._jsonRPCResponse$ = this._jsonRPCMessage$.pipe((0, import_cjs$2.filter)(isJSONRPCResponse));
20357
+ 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$));
20297
20358
  }
20298
20359
  async setProtocol(protocol) {
20299
20360
  this._currentProtocol = protocol;
@@ -20315,7 +20376,7 @@ var TransportManager = class extends Destroyable {
20315
20376
  this.isConnecting = true;
20316
20377
  this.subscribeTo(this.initialized$, () => {
20317
20378
  this._webSocketConnections.connect();
20318
- 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({
20379
+ 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({
20319
20380
  next: (status) => {
20320
20381
  if (status === "connected") {
20321
20382
  this.isConnecting = false;
@@ -20338,7 +20399,7 @@ var TransportManager = class extends Destroyable {
20338
20399
  }
20339
20400
  });
20340
20401
  this.subscriptions.push(connectionSub);
20341
- this.subscribeTo(this._webSocketConnections.status$.pipe((0, import_cjs$1.filter)((status) => status === "disconnected")), () => {
20402
+ this.subscribeTo(this._webSocketConnections.status$.pipe((0, import_cjs$2.filter)((status) => status === "disconnected")), () => {
20342
20403
  logger$2.debug("[Transport] Disconnected");
20343
20404
  this.isConnected = false;
20344
20405
  });
@@ -20404,7 +20465,7 @@ var TransportManager = class extends Destroyable {
20404
20465
 
20405
20466
  //#endregion
20406
20467
  //#region src/clients/SignalWire.ts
20407
- var import_cjs = require_cjs();
20468
+ var import_cjs$1 = require_cjs();
20408
20469
  const logger$1 = getLogger();
20409
20470
  const buildOptionsFromDestination = (destination) => {
20410
20471
  if (typeof destination === "string") {
@@ -20464,6 +20525,9 @@ var SignalWire = class extends Destroyable {
20464
20525
  if (this._options.webSocketConstructor) this._deps.WebSocket = this._options.webSocketConstructor;
20465
20526
  if (this._options.savePreferences) this.preferences.enableSavePreferences(this._deps.storage);
20466
20527
  if (this._options.webRTCApiProvider) this._deps.webRTCApiProvider = this._options.webRTCApiProvider;
20528
+ if (this._options.logger !== void 0) setLogger(this._options.logger);
20529
+ if (this._options.logLevel) setLogLevel(this._options.logLevel);
20530
+ if (this._options.debug) setDebugOptions(this._options.debug);
20467
20531
  this._deviceController = this._deps.deviceController;
20468
20532
  if (!this._options.skipDeviceMonitoring) this._deviceController.enableDeviceMonitoring();
20469
20533
  this.subscribeTo(this._deviceController.errors$, (error) => {
@@ -20537,28 +20601,7 @@ var SignalWire = class extends Destroyable {
20537
20601
  logger$1.error("[SignalWire] Provided credentials have expired.");
20538
20602
  throw new InvalidCredentialsError("Provided credentials have expired.");
20539
20603
  }
20540
- if (_credentials.expiry_at && credentialProvider?.refresh) {
20541
- const refreshFn = async () => {
20542
- if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20543
- return credentialProvider.refresh();
20544
- };
20545
- const refreshInterval = Math.max(_credentials.expiry_at - Date.now() - 5e3, 1e3);
20546
- this._refreshTimerId = setTimeout(async () => {
20547
- try {
20548
- const newCredentials = await refreshFn();
20549
- this._deps.credential = newCredentials;
20550
- this.persistCredential(newCredentials);
20551
- logger$1.info("[SignalWire] Credentials refreshed successfully.");
20552
- this.validateCredentials(credentialProvider, newCredentials).catch((error) => {
20553
- logger$1.error("[SignalWire] Credential refresh error:", error);
20554
- this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20555
- });
20556
- } catch (error) {
20557
- logger$1.error("[SignalWire] Credential refresh failed:", error);
20558
- this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20559
- }
20560
- }, refreshInterval);
20561
- }
20604
+ if (_credentials.expiry_at && credentialProvider?.refresh) this.scheduleCredentialRefresh(credentialProvider, _credentials.expiry_at);
20562
20605
  this._deps.credential = _credentials;
20563
20606
  this.persistCredential(_credentials);
20564
20607
  if (this.isConnected && this._clientSession.authenticated && _credentials.token) try {
@@ -20569,6 +20612,35 @@ var SignalWire = class extends Destroyable {
20569
20612
  this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20570
20613
  }
20571
20614
  }
20615
+ /**
20616
+ * Schedules credential refresh with exponential backoff retry on failure.
20617
+ * On success, resets attempt counter and schedules the next refresh.
20618
+ * After exhausting retries, emits TokenRefreshError and disconnects.
20619
+ */
20620
+ scheduleCredentialRefresh(credentialProvider, expiresAt, attempt = 0) {
20621
+ if (this._refreshTimerId !== void 0) clearTimeout(this._refreshTimerId);
20622
+ 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);
20623
+ this._refreshTimerId = setTimeout(async () => {
20624
+ try {
20625
+ if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
20626
+ const newCredentials = await credentialProvider.refresh();
20627
+ this._deps.credential = newCredentials;
20628
+ this.persistCredential(newCredentials);
20629
+ logger$1.info("[SignalWire] Credentials refreshed successfully.");
20630
+ if (newCredentials.expiry_at) this.scheduleCredentialRefresh(credentialProvider, newCredentials.expiry_at, 0);
20631
+ } catch (error) {
20632
+ const nextAttempt = attempt + 1;
20633
+ logger$1.error(`[SignalWire] Credential refresh failed (attempt ${nextAttempt}/${CREDENTIAL_REFRESH_MAX_RETRIES}):`, error);
20634
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20635
+ if (nextAttempt < CREDENTIAL_REFRESH_MAX_RETRIES) this.scheduleCredentialRefresh(credentialProvider, expiresAt, nextAttempt);
20636
+ else {
20637
+ logger$1.error("[SignalWire] Credential refresh exhausted all retries. Disconnecting.");
20638
+ this._errors$.next(new TokenRefreshError("Credential refresh failed after max retries"));
20639
+ this.disconnect();
20640
+ }
20641
+ }
20642
+ }, refreshInterval);
20643
+ }
20572
20644
  /** Persist credential to localStorage when persistSession is enabled. */
20573
20645
  persistCredential(credential) {
20574
20646
  if (!credential.token) return;
@@ -20610,9 +20682,9 @@ var SignalWire = class extends Destroyable {
20610
20682
  * unexpectedly (e.g. network change, server restart). Reconnection uses an
20611
20683
  * **exponential back-off** strategy:
20612
20684
  *
20613
- * - First retry after `reconnectDelayMin` (default **1 s**).
20685
+ * - First retry after `reconnectDelayMin` (default **0.1 s**).
20614
20686
  * - Each subsequent retry doubles the delay up to `reconnectDelayMax`
20615
- * (default **30 s**).
20687
+ * (default **3 s**).
20616
20688
  * - The delay resets to `reconnectDelayMin` once a connection succeeds.
20617
20689
  * - A per-attempt `connectionTimeout` (default **10 s**) aborts the
20618
20690
  * attempt and schedules the next retry if the server does not respond.
@@ -20641,7 +20713,7 @@ var SignalWire = class extends Destroyable {
20641
20713
  try {
20642
20714
  const subscriber = this._subscriber$.value;
20643
20715
  if (!subscriber) throw new UnexpectedError("Subscriber not initialized before connect");
20644
- if (!await (0, import_cjs.firstValueFrom)(subscriber.fetched$)) throw new UnexpectedError("Failed to fetch subscriber information - fetched$ emitted false");
20716
+ if (!await (0, import_cjs$1.firstValueFrom)(subscriber.fetched$)) throw new UnexpectedError("Failed to fetch subscriber information - fetched$ emitted false");
20645
20717
  this._deps.subscriber = subscriber;
20646
20718
  } catch (error) {
20647
20719
  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.`);
@@ -20664,6 +20736,8 @@ var SignalWire = class extends Destroyable {
20664
20736
  logger$1.debug("[SignalWire] Credential refreshed successfully for reconnect");
20665
20737
  } catch (error) {
20666
20738
  logger$1.error("[SignalWire] Failed to refresh credentials for reconnect:", error);
20739
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
20740
+ throw error;
20667
20741
  }
20668
20742
  };
20669
20743
  this.subscribeTo(this._clientSession.errors$, (error) => {
@@ -20684,7 +20758,7 @@ var SignalWire = class extends Destroyable {
20684
20758
  };
20685
20759
  });
20686
20760
  }
20687
- this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs.skip)(1), (0, import_cjs.filter)(Boolean)), async () => {
20761
+ this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(1), (0, import_cjs$1.filter)(Boolean)), async () => {
20688
20762
  try {
20689
20763
  if (this._deviceTokenManager) {
20690
20764
  await this._deviceTokenManager.activate(this._deps.subscriber, this._clientSession, (cred) => {
@@ -20714,7 +20788,7 @@ var SignalWire = class extends Destroyable {
20714
20788
  this._clientSession.setDirectory(directory);
20715
20789
  this._isConnected$.next(true);
20716
20790
  this._diagnosticsCollector?.record("connection", "connected");
20717
- this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs.skip)(2), (0, import_cjs.filter)(Boolean)), () => {
20791
+ this.subscribeTo(this._clientSession.authenticated$.pipe((0, import_cjs$1.skip)(2), (0, import_cjs$1.filter)(Boolean)), () => {
20718
20792
  this._diagnosticsCollector?.record("connection", "reconnected");
20719
20793
  });
20720
20794
  }
@@ -20776,7 +20850,7 @@ var SignalWire = class extends Destroyable {
20776
20850
  }
20777
20851
  /** Observable that emits `true` when the client is both connected and authenticated. */
20778
20852
  get ready$() {
20779
- return this.publicCachedObservable("ready$", () => this._isConnected$.pipe((0, import_cjs.switchMap)((connected) => connected ? this._clientSession.authenticated$ : (0, import_cjs.of)(false))));
20853
+ return this.publicCachedObservable("ready$", () => this._isConnected$.pipe((0, import_cjs$1.switchMap)((connected) => connected ? this._clientSession.authenticated$ : (0, import_cjs$1.of)(false))));
20780
20854
  }
20781
20855
  /** Observable stream of errors from transport, authentication, and devices. */
20782
20856
  get errors$() {
@@ -20839,7 +20913,7 @@ var SignalWire = class extends Destroyable {
20839
20913
  }
20840
20914
  try {
20841
20915
  this._visibilityController = new VisibilityController();
20842
- this.subscribeTo(this._visibilityController.visibilityChange$.pipe((0, import_cjs.filter)((event) => event.to === "visible" && PreferencesContainer.instance.refreshDevicesOnVisible)), () => {
20916
+ this.subscribeTo(this._visibilityController.visibilityChange$.pipe((0, import_cjs$1.filter)((event) => event.to === "visible" && PreferencesContainer.instance.refreshDevicesOnVisible)), () => {
20843
20917
  logger$1.debug("[SignalWire] Page visible, re-enumerating devices");
20844
20918
  try {
20845
20919
  this._deviceController.disableDeviceMonitoring();
@@ -20862,13 +20936,17 @@ var SignalWire = class extends Destroyable {
20862
20936
  * which creates a fresh transport and session.
20863
20937
  */
20864
20938
  async disconnect() {
20939
+ if (this._refreshTimerId) {
20940
+ clearTimeout(this._refreshTimerId);
20941
+ this._refreshTimerId = void 0;
20942
+ }
20865
20943
  this._diagnosticsCollector?.record("connection", "disconnected");
20866
20944
  await this._clientSession.disconnect();
20867
20945
  this._clientSession.destroy();
20868
20946
  this._isConnected$.next(false);
20869
20947
  }
20870
20948
  async waitAuthentication() {
20871
- await (0, import_cjs.firstValueFrom)(this.ready$.pipe((0, import_cjs.filter)((ready$1) => ready$1 === true)));
20949
+ await (0, import_cjs$1.firstValueFrom)(this.ready$.pipe((0, import_cjs$1.filter)((ready$1) => ready$1 === true)));
20872
20950
  }
20873
20951
  /**
20874
20952
  * Registers the subscriber as online to receive inbound calls and events.
@@ -21263,6 +21341,7 @@ var EmbedTokenCredentialProvider = class {
21263
21341
 
21264
21342
  //#endregion
21265
21343
  //#region src/utils/embeddableCall.ts
21344
+ var import_cjs = require_cjs();
21266
21345
  /**
21267
21346
  * Creates a call using an embed token for simple, embeddable integrations.
21268
21347
  *
@@ -21278,7 +21357,12 @@ async function embeddableCall(options) {
21278
21357
  if (!embedToken) requiredFailed.push("embedToken");
21279
21358
  if (!host) requiredFailed.push("host");
21280
21359
  if (requiredFailed.length > 0) return Promise.reject(new DependencyError(`Missing required options: ${requiredFailed.join(", ")}`));
21281
- return await new SignalWire(new EmbedTokenCredentialProvider(host, embedToken)).dial(to);
21360
+ const client = new SignalWire(new EmbedTokenCredentialProvider(host, embedToken));
21361
+ const call = await client.dial(to);
21362
+ call.status$.pipe((0, import_cjs.first)((status) => status === "destroyed")).subscribe(() => {
21363
+ client.disconnect();
21364
+ });
21365
+ return call;
21282
21366
  }
21283
21367
 
21284
21368
  //#endregion
@@ -21380,6 +21464,9 @@ exports.WebRTCCall = WebRTCCall;
21380
21464
  exports.embeddableCall = embeddableCall;
21381
21465
  exports.isSelfParticipant = isSelfParticipant;
21382
21466
  exports.ready = ready;
21467
+ exports.setDebugOptions = setDebugOptions;
21468
+ exports.setLogLevel = setLogLevel;
21469
+ exports.setLogger = setLogger;
21383
21470
  exports.version = version;
21384
21471
  });
21385
21472
  //# sourceMappingURL=browser.umd.js.map