@vkontakte/calls-sdk 2.8.12-dev.73c9f7fe.0 → 2.8.12-dev.7afbc576.0

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.
Files changed (39) hide show
  1. package/CallsSDK.d.ts +25 -13
  2. package/abstract/BaseApi.d.ts +4 -8
  3. package/calls-sdk.cjs.js +6 -6
  4. package/calls-sdk.esm.js +726 -417
  5. package/classes/AudioFix.d.ts +2 -2
  6. package/classes/AudioOutput.d.ts +2 -2
  7. package/classes/MediaSource.d.ts +2 -2
  8. package/classes/SpecListener.d.ts +2 -2
  9. package/classes/codec/LibVPxDecoder.d.ts +2 -2
  10. package/classes/codec/LibVPxEncoder.d.ts +2 -2
  11. package/classes/codec/WebCodecsDecoder.d.ts +2 -2
  12. package/classes/codec/WebCodecsEncoder.d.ts +2 -2
  13. package/classes/codec/WorkerBase.d.ts +3 -3
  14. package/classes/conversation/Conversation.d.ts +7 -4
  15. package/classes/screenshare/ScreenCaptureReceiver.d.ts +2 -2
  16. package/classes/screenshare/ScreenCaptureSender.d.ts +2 -2
  17. package/classes/screenshare/StreamBuilder.d.ts +2 -2
  18. package/classes/stat/CallLifecycleStats.d.ts +2 -2
  19. package/classes/stat/CodecStatsAggregator.d.ts +2 -2
  20. package/classes/stat/ConversationStats.d.ts +11 -4
  21. package/classes/stat/StatAggregator.d.ts +2 -2
  22. package/classes/stat/StatDrainScheduler.d.ts +78 -0
  23. package/classes/stat/StatEventCollector.d.ts +37 -0
  24. package/classes/stat/StatPings.d.ts +2 -2
  25. package/classes/stat/StatQueue.d.ts +61 -0
  26. package/classes/stat/StatSignalingCommands.d.ts +2 -2
  27. package/classes/stat/StatUnloadJournal.d.ts +30 -0
  28. package/classes/transport/DirectTransport.d.ts +2 -2
  29. package/classes/transport/ServerTransport.d.ts +2 -2
  30. package/classes/transport/SimulcastSender.d.ts +2 -2
  31. package/classes/transport/Transport.d.ts +2 -2
  32. package/default/Api.d.ts +9 -1
  33. package/default/Signaling.d.ts +2 -2
  34. package/enums/SessionError.d.ts +10 -0
  35. package/package.json +1 -1
  36. package/static/Params.d.ts +14 -0
  37. package/static/WebRTCUtils.d.ts +5 -5
  38. package/types/FastHangup.d.ts +66 -0
  39. package/classes/StatsLogger.d.ts +0 -41
package/calls-sdk.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @vkontakte/calls-sdk v2.8.12-dev.73c9f7fe.0
3
- * Wed, 02 Sep 2026 10:23:54 GMT
2
+ * @vkontakte/calls-sdk v2.8.12-dev.7afbc576.0
3
+ * Thu, 03 Sep 2026 16:34:33 GMT
4
4
  * https://calls-sdk.cdn-vk.ru/doc/latest/index.html
5
5
  */
6
6
 
@@ -769,14 +769,14 @@ function zt(e) {
769
769
  });
770
770
  }
771
771
  async function Bt(e, t, n = R, r = null) {
772
- n.debug("Try to get media", JSON.parse(JSON.stringify(e.getNative()))), w.releaseFirefoxMicrophonePermissionWarmup();
772
+ n.debug("Try to get media", JSON.parse(JSON.stringify(e.getNative())));
773
773
  let i = (!e.isVideo() || w.hasCameraPermission()) && (!e.isAudio() || w.hasMicrophonePermission());
774
774
  !i && !t && L.onPermissionsRequested();
775
775
  let a = new Pt();
776
776
  try {
777
777
  a.busy(r);
778
778
  let t = await navigator.mediaDevices.getUserMedia(e.getNative());
779
- return a.free(), i || await Ft(), zt(t), t;
779
+ return w.releaseFirefoxMicrophonePermissionWarmup(), a.free(), i || await Ft(), zt(t), t;
780
780
  } catch (i) {
781
781
  switch (a.free(), n.error("getUserMedia error", i), i.name) {
782
782
  case "PermissionDeniedError":
@@ -987,7 +987,7 @@ var w;
987
987
  }
988
988
  e.releaseFirefoxMicrophonePermissionWarmup = ee;
989
989
  async function h(e = !1, t = !0, n = !0, r = R, i = null) {
990
- !e && !t ? await Vt(r) : w.releaseFirefoxMicrophonePermissionWarmup();
990
+ !e && !t && await Vt(r);
991
991
  let s = o() && t, c = a() && e, l;
992
992
  if (!s && !c) l = new MediaStream();
993
993
  else try {
@@ -2155,7 +2155,7 @@ var yn = vn.getInstance(), M = class e {
2155
2155
  return 1.1;
2156
2156
  }
2157
2157
  static get sdkVersion() {
2158
- return "2.8.12-dev.73c9f7fe.0";
2158
+ return "2.8.12-dev.7afbc576.0";
2159
2159
  }
2160
2160
  static get debug() {
2161
2161
  return e._params.debug;
@@ -2175,6 +2175,9 @@ var yn = vn.getInstance(), M = class e {
2175
2175
  static set clientStatsPlatform(t) {
2176
2176
  e._params.clientStatsPlatform = t;
2177
2177
  }
2178
+ static get autoStartStats() {
2179
+ return e._params.autoStartStats;
2180
+ }
2178
2181
  static get clientType() {
2179
2182
  return e._params.clientType;
2180
2183
  }
@@ -2578,6 +2581,7 @@ var yn = vn.getInstance(), M = class e {
2578
2581
  movieShare: e._params.movieShare,
2579
2582
  clientType: e._params.clientType,
2580
2583
  clientStatsPlatform: e._params.clientStatsPlatform,
2584
+ autoStartStats: e._params.autoStartStats,
2581
2585
  consumerScreenDataChannelPacketSize: e._params.consumerScreenDataChannelPacketSize,
2582
2586
  switchVideoAtBadNetwork: e._params.switchVideoAtBadNetwork,
2583
2587
  simulcast: e._params.simulcast,
@@ -2593,6 +2597,7 @@ var yn = vn.getInstance(), M = class e {
2593
2597
  h(M, "_params", {
2594
2598
  platform: "WEB",
2595
2599
  clientStatsPlatform: "",
2600
+ autoStartStats: !0,
2596
2601
  clientType: "PORTAL",
2597
2602
  externalUserType: "",
2598
2603
  device: "browser",
@@ -8569,40 +8574,350 @@ var bo = 90, xo = 3, So = class extends b {
8569
8574
  r && r.platform && (n = r.platform), e.indexOf(n) < 0 && (e.push(n), this._logger?.log(C.CALL_SPEC_ERROR, `${this._transport.getTopology()}_VOLUME_TIMEOUT_${n}`));
8570
8575
  }), e.length && this._debug.warn("There is silent participant, send callSpecError"), this._volumeTimeout = 0;
8571
8576
  }
8572
- }, Fo = class extends f {
8573
- constructor(e, t, n, r = () => void 0) {
8574
- super(), h(this, "_externalLogger", void 0), h(this, "_api", void 0), h(this, "_conversationIdProvider", void 0), h(this, "_topologyProvider", void 0), h(this, "_batchInterval", 3e3), h(this, "_batchedClientStats", []), h(this, "_batchTimeout", null), h(this, "_serverTimeDelta", 0), h(this, "_waitingForServerTime", !0), h(this, "_deferredClientStats", []), this._api = e, this._externalLogger = t, this._conversationIdProvider = n, this._topologyProvider = r, this._calculateServerTimeDelta();
8577
+ }, Fo = /* @__PURE__ */ function(e) {
8578
+ return e[e.PARAM_SESSION_EXPIRED = 102] = "PARAM_SESSION_EXPIRED", e[e.PARAM_SESSION_KEY = 103] = "PARAM_SESSION_KEY", e[e.PARAM_SIGNATURE = 104] = "PARAM_SIGNATURE", e[e.AUTH_LOGIN = 401] = "AUTH_LOGIN", e;
8579
+ }(Fo || {}), Io, Lo = "ok-calls-sdk-stats", Ro = 1, zo = "events", Bo = 100, Vo = 5e3, Ho = 5e3, Uo = class e {
8580
+ static isSupported() {
8581
+ return e._supported;
8582
+ }
8583
+ static async append(t) {
8584
+ let n = await e._open();
8585
+ return !n || !await e._runTransaction(n, "readwrite", (e) => (e.add(t), !0)).catch((e) => (R.error("[StatQueue] failed to append event", e), !1)) ? !1 : (e._appendsSinceEvictCheck += 1, e._appendsSinceEvictCheck >= Bo && (e._appendsSinceEvictCheck = 0, await e.evictToLimit(Vo)), !0);
8586
+ }
8587
+ static async count() {
8588
+ let t = await e._open();
8589
+ return t ? e._runTransaction(t, "readonly", (e) => {
8590
+ let t = e.count();
8591
+ return new Promise((e) => {
8592
+ t.onsuccess = () => e(t.result);
8593
+ });
8594
+ }).catch((e) => (R.error("[StatQueue] failed to count events", e), 0)) : 0;
8595
+ }
8596
+ static async readOldest(t, n) {
8597
+ let r = await e._open();
8598
+ return r ? e._runTransaction(r, "readonly", (e) => {
8599
+ let r = e.index("by_uid").getAll(IDBKeyRange.only(t), n);
8600
+ return new Promise((e) => {
8601
+ r.onsuccess = () => e(r.result);
8602
+ });
8603
+ }).catch((e) => (R.error("[StatQueue] failed to read events", e), [])) : [];
8575
8604
  }
8576
- log(e, t, n = !1) {
8577
- this._externalLogger && this._externalLogger.log(e, t, n);
8605
+ static async remove(t) {
8606
+ if (t.length === 0) return;
8607
+ let n = await e._open();
8608
+ if (n) return e._runTransaction(n, "readwrite", (e) => {
8609
+ t.forEach((t) => e.delete(t));
8610
+ }).catch((e) => {
8611
+ R.error("[StatQueue] failed to remove events", e);
8612
+ });
8578
8613
  }
8579
- logClientStats(e, t = !1) {
8580
- let n = typeof t == "boolean" ? { immediately: t } : t, r = {
8581
- ...e,
8582
- call_topology: e.call_topology ?? this._getCallTopology()
8614
+ static async evictToLimit(t) {
8615
+ let n = await e._open();
8616
+ if (!n) return;
8617
+ let r = 1e3;
8618
+ for (; r > 0;) if (--r, !await e._runTransaction(n, "readwrite", async (n) => {
8619
+ if (await new Promise((e) => {
8620
+ let t = n.count();
8621
+ t.onsuccess = () => e(t.result);
8622
+ }) <= t) return !1;
8623
+ let r = await e._readOldestRecord(n);
8624
+ return r ? r.vcid === null ? (n.delete(r.id), !0) : ((await e._readIdsByConversation(n, r.vcid)).forEach((e) => n.delete(e)), !0) : !1;
8625
+ }).catch((e) => (R.error("[StatQueue] failed to evict events", e), !1))) return;
8626
+ }
8627
+ static async __resetForTests() {
8628
+ e._appendsSinceEvictCheck = 0, e._close(), e._supported = e._checkSupport(), e._supported && await new Promise((e) => {
8629
+ let t = window.indexedDB.deleteDatabase(Lo);
8630
+ t.onsuccess = () => e(), t.onerror = () => e(), t.onblocked = () => e();
8631
+ });
8632
+ }
8633
+ static _checkSupport() {
8634
+ return typeof window < "u" && !!window.indexedDB;
8635
+ }
8636
+ static _open() {
8637
+ if (!e._checkSupport()) return e._supported = !1, Promise.resolve(null);
8638
+ if (e._dbPromise) return e._dbPromise;
8639
+ let t = !1, n = new Promise((n) => {
8640
+ let r = (r, i) => {
8641
+ t || (t = !0, R.error(r, i), e._supported = !1, e._dbPromise = null, n(null));
8642
+ }, i;
8643
+ try {
8644
+ i = window.indexedDB.open(Lo, Ro);
8645
+ } catch (e) {
8646
+ r("[StatQueue] storage is not accessible", e);
8647
+ return;
8648
+ }
8649
+ let a = window.setTimeout(() => r("[StatQueue] storage opening timed out"), Ho);
8650
+ i.onupgradeneeded = () => {
8651
+ e._createSchema(i.result);
8652
+ }, i.onsuccess = () => {
8653
+ if (window.clearTimeout(a), t) {
8654
+ i.result.close();
8655
+ return;
8656
+ }
8657
+ t = !0, e._db = i.result, e._supported = !0, e._db.onversionchange = () => e._close(), n(e._db);
8658
+ }, i.onerror = () => {
8659
+ window.clearTimeout(a), r("[StatQueue] failed to open storage", i.error);
8660
+ }, i.onblocked = () => {
8661
+ R.error("[StatQueue] storage opening is blocked");
8662
+ };
8663
+ });
8664
+ return t || (e._dbPromise = n), n;
8665
+ }
8666
+ static _close() {
8667
+ e._db && (e._db.close(), e._db = null), e._dbPromise = null;
8668
+ }
8669
+ static _createSchema(e) {
8670
+ if (e.objectStoreNames.contains(zo)) return;
8671
+ let t = e.createObjectStore(zo, {
8672
+ keyPath: "id",
8673
+ autoIncrement: !0
8674
+ });
8675
+ t.createIndex("by_uid", "uid", { unique: !1 }), t.createIndex("by_vcid", "vcid", { unique: !1 });
8676
+ }
8677
+ static _runTransaction(e, t, n) {
8678
+ return new Promise((r, i) => {
8679
+ let a = e.transaction(zo, t), o;
8680
+ a.oncomplete = () => r(o), a.onerror = () => i(a.error), a.onabort = () => i(a.error), Promise.resolve(n(a.objectStore(zo))).then((e) => {
8681
+ o = e;
8682
+ }).catch((e) => {
8683
+ a.abort(), i(e);
8684
+ });
8685
+ });
8686
+ }
8687
+ static _readOldestRecord(e) {
8688
+ let t = e.openCursor();
8689
+ return new Promise((e) => {
8690
+ t.onsuccess = () => e(t.result ? t.result.value : null);
8691
+ });
8692
+ }
8693
+ static _readIdsByConversation(e, t) {
8694
+ let n = e.index("by_vcid").getAllKeys(IDBKeyRange.only(t));
8695
+ return new Promise((e) => {
8696
+ n.onsuccess = () => e(n.result);
8697
+ });
8698
+ }
8699
+ };
8700
+ Io = Uo, h(Uo, "_db", null), h(Uo, "_dbPromise", null), h(Uo, "_supported", Io._checkSupport()), h(Uo, "_appendsSinceEvictCheck", 0);
8701
+ //#endregion
8702
+ //#region src/classes/stat/StatUnloadJournal.ts
8703
+ var Wo = "okcls-stat-unload.", Go = class e {
8704
+ static writeSync(t) {
8705
+ let n = e._storage();
8706
+ if (!n) return !1;
8707
+ try {
8708
+ return e._tabKey || (e._tabKey = Wo + Date.now() + "-" + Math.random().toString(36).slice(2, 8)), e._entries.push(t), n.setItem(e._tabKey, JSON.stringify(e._entries)), !0;
8709
+ } catch (e) {
8710
+ return R.error("[StatUnloadJournal] failed to write", e), !1;
8711
+ }
8712
+ }
8713
+ static async drainToQueue() {
8714
+ let t = e._storage();
8715
+ if (!t) return 0;
8716
+ let n = [];
8717
+ try {
8718
+ for (let e = 0; e < t.length; e += 1) {
8719
+ let r = t.key(e);
8720
+ r && r.startsWith(Wo) && n.push(r);
8721
+ }
8722
+ } catch (e) {
8723
+ return R.error("[StatUnloadJournal] failed to scan journals", e), 0;
8724
+ }
8725
+ let r = 0;
8726
+ for (let i of n) {
8727
+ let n = null;
8728
+ try {
8729
+ n = JSON.parse(t.getItem(i) ?? "null");
8730
+ } catch {
8731
+ R.error("[StatUnloadJournal] dropping corrupted journal", i);
8732
+ }
8733
+ if (Array.isArray(n)) for (let t of n) e._isValidEntry(t) && await Uo.append(t) && (r += 1);
8734
+ try {
8735
+ t.removeItem(i);
8736
+ } catch (e) {
8737
+ R.error("[StatUnloadJournal] failed to remove journal", e);
8738
+ }
8739
+ }
8740
+ return r;
8741
+ }
8742
+ static __resetForTests() {
8743
+ e._tabKey = null, e._entries = [];
8744
+ }
8745
+ static _storage() {
8746
+ try {
8747
+ return window.localStorage;
8748
+ } catch {
8749
+ return null;
8750
+ }
8751
+ }
8752
+ static _isValidEntry(e) {
8753
+ let t = e;
8754
+ return typeof t == "object" && !!t && typeof t.uid == "number" && (t.vcid === null || typeof t.vcid == "string") && typeof t.ts == "number" && typeof t.ev == "object" && t.ev !== null;
8755
+ }
8756
+ };
8757
+ h(Go, "_tabKey", null), h(Go, "_entries", []);
8758
+ //#endregion
8759
+ //#region src/classes/stat/StatDrainScheduler.ts
8760
+ var Ko = 500, qo = 100, Jo = 3e4, Yo = 5e3, Xo = "okcls-stat-drain", Zo = class e {
8761
+ static setApi(t) {
8762
+ e._api = t;
8763
+ }
8764
+ static start(t) {
8765
+ e.setApi(t), Go.drainToQueue().catch((e) => R.error("[StatDrainScheduler] failed to import unload journal", e)).then(() => e._drain());
8766
+ }
8767
+ static stop() {
8768
+ e._clearTimer(), e._state = "IDLE", e._localCount = 0;
8769
+ }
8770
+ static notifyAppended() {
8771
+ if (e._api) {
8772
+ if (e._localCount += 1, e._localCount >= qo) {
8773
+ e._drain();
8774
+ return;
8775
+ }
8776
+ e._state === "IDLE" && e._arm(Jo);
8777
+ }
8778
+ }
8779
+ static drainOnce() {
8780
+ return e._withLock(async () => {
8781
+ let t = e._api;
8782
+ if (!t) return !1;
8783
+ let n = e._currentUserId();
8784
+ if (n === null) return !1;
8785
+ let r = await Uo.readOldest(n, Ko);
8786
+ if (r.length === 0) return !1;
8787
+ let i = await e._getServerTimeDelta(), a = r.map((t) => e._toClientStats(t, i)), o = r.map((e) => e.id);
8788
+ try {
8789
+ await t.logClientStats(a);
8790
+ } catch (t) {
8791
+ if (e._isRetryable(t)) throw t;
8792
+ return R.error("[StatDrainScheduler] batch rejected, dropping", t), await Uo.remove(o), r.length === Ko;
8793
+ }
8794
+ return await Uo.remove(o), r.length === Ko;
8795
+ });
8796
+ }
8797
+ static async sendDirect(t) {
8798
+ let n = e._api;
8799
+ if (n) {
8800
+ if (t.uid !== e._currentUserId()) {
8801
+ R.error("[StatDrainScheduler] direct send skipped: event belongs to another user");
8802
+ return;
8803
+ }
8804
+ try {
8805
+ let r = await e._getServerTimeDelta();
8806
+ await n.logClientStats([e._toClientStats(t, r)]);
8807
+ } catch (e) {
8808
+ R.error("[StatDrainScheduler] direct send failed, event lost", e);
8809
+ }
8810
+ }
8811
+ }
8812
+ static __resetForTests() {
8813
+ e._clearTimer(), e._api = null, e._serverTimeDelta = null, e._state = "IDLE", e._localCount = 0;
8814
+ }
8815
+ static _currentUserId() {
8816
+ return y.userId;
8817
+ }
8818
+ static _withLock(e) {
8819
+ return typeof navigator > "u" || !navigator.locks ? e() : navigator.locks.request(Xo, e);
8820
+ }
8821
+ static _isSessionError(e) {
8822
+ let t = e?.error_code;
8823
+ return t === Fo.PARAM_SESSION_EXPIRED || t === Fo.PARAM_SESSION_KEY || t === Fo.PARAM_SIGNATURE;
8824
+ }
8825
+ static _isRetryable(t) {
8826
+ if (e._isSessionError(t)) return !0;
8827
+ let n = t?.callError;
8828
+ return n ? n.scope === "network" ? !0 : !("code" in n) || typeof n.code != "string" ? !1 : n.code.startsWith("http-5") || n.code === "http-429" : !1;
8829
+ }
8830
+ static async _getServerTimeDelta() {
8831
+ if (e._serverTimeDelta !== null) return e._serverTimeDelta;
8832
+ try {
8833
+ let t = await e._api.getServerTime();
8834
+ e._serverTimeDelta = Date.now() - t;
8835
+ } catch {
8836
+ return 0;
8837
+ }
8838
+ return e._serverTimeDelta;
8839
+ }
8840
+ static _toClientStats(e, t) {
8841
+ return {
8842
+ ...e.ev,
8843
+ vcid: e.vcid,
8844
+ timestamp: e.ts - t
8583
8845
  };
8584
- if (n.deferUntilServerTime && this._waitingForServerTime) {
8585
- this._deferredClientStats.push({
8586
- data: r,
8587
- options: { ...n }
8588
- }), n.immediately && this._flushDeferredClientStats();
8589
- return;
8846
+ }
8847
+ static _clearTimer() {
8848
+ e._timer !== null && (window.clearTimeout(e._timer), e._timer = null);
8849
+ }
8850
+ static _arm(t) {
8851
+ e._clearTimer(), e._state = "ARMED", e._timer = window.setTimeout(() => {
8852
+ e._timer = null, e._drain();
8853
+ }, t);
8854
+ }
8855
+ static async _drain() {
8856
+ if (e._state !== "DRAINING") {
8857
+ e._clearTimer(), e._state = "DRAINING", e._localCount = 0;
8858
+ try {
8859
+ if (e._currentUserId() === null) {
8860
+ await Uo.count() > 0 || e._localCount > 0 ? e._arm(Jo) : e._state = "IDLE";
8861
+ return;
8862
+ }
8863
+ if (await e.drainOnce()) {
8864
+ e._arm(Yo);
8865
+ return;
8866
+ }
8867
+ if (e._localCount > 0) {
8868
+ e._arm(Jo);
8869
+ return;
8870
+ }
8871
+ e._state = "IDLE";
8872
+ } catch (t) {
8873
+ R.error("[StatDrainScheduler] drain failed", t), e._arm(Jo);
8874
+ }
8590
8875
  }
8591
- this._logClientStats(r, n);
8592
8876
  }
8593
- destroy() {
8594
- this._flushDeferredClientStats(), this._sendBatch(), this._stopTimeout();
8877
+ };
8878
+ h(Zo, "_api", null), h(Zo, "_serverTimeDelta", null), h(Zo, "_state", "IDLE"), h(Zo, "_timer", null), h(Zo, "_localCount", 0);
8879
+ //#endregion
8880
+ //#region src/classes/stat/StatEventCollector.ts
8881
+ var Qo = class extends f {
8882
+ constructor(e, t, n = () => void 0) {
8883
+ super(), h(this, "_externalLogger", void 0), h(this, "_conversationIdProvider", void 0), h(this, "_topologyProvider", void 0), h(this, "_unloadMode", !1), this._externalLogger = e, this._conversationIdProvider = t, this._topologyProvider = n;
8595
8884
  }
8596
- _logClientStats(e, t) {
8597
- let n = {
8885
+ log(e, t, n = !1) {
8886
+ this._externalLogger && this._externalLogger.log(e, t, n);
8887
+ }
8888
+ enterUnloadMode() {
8889
+ this._unloadMode = !0;
8890
+ }
8891
+ logClientStats(e, t = {}) {
8892
+ let n = y.userId;
8893
+ if (n === null) {
8894
+ R.error("[StatEventCollector] cannot store event before userId is known");
8895
+ return;
8896
+ }
8897
+ let r = {
8598
8898
  ...e,
8899
+ call_topology: e.call_topology ?? this._getCallTopology()
8900
+ };
8901
+ Object.keys(r).forEach((e) => {
8902
+ r[e] === void 0 && delete r[e];
8903
+ });
8904
+ let i = {
8905
+ uid: n,
8599
8906
  vcid: t.conversationId === void 0 ? this._getConversationId() : t.conversationId,
8600
- timestamp: t.occurredAt === void 0 ? this._now() : t.occurredAt - this._serverTimeDelta
8907
+ ts: t.occurredAt === void 0 ? Date.now() : t.occurredAt,
8908
+ ev: r
8601
8909
  };
8602
- Object.keys(n).forEach((e) => {
8603
- n[e] === void 0 && delete n[e];
8604
- }), this._batchedClientStats.push(n), (t.immediately || !this._batchTimeout) && this._sendBatch();
8910
+ this._unloadMode && Go.writeSync(i) || Uo.append(i).then((e) => {
8911
+ if (e) {
8912
+ Zo.notifyAppended();
8913
+ return;
8914
+ }
8915
+ return R.error("[StatEventCollector] failed to store event, sending directly"), Zo.sendDirect(i);
8916
+ }).catch((e) => {
8917
+ R.error("[StatEventCollector] failed to store event", e);
8918
+ });
8605
8919
  }
8920
+ destroy() {}
8606
8921
  _getConversationId() {
8607
8922
  try {
8608
8923
  return this._conversationIdProvider();
@@ -8617,39 +8932,7 @@ var bo = 90, xo = 3, So = class extends b {
8617
8932
  return "D";
8618
8933
  }
8619
8934
  }
8620
- _sendBatch() {
8621
- this._stopTimeout();
8622
- let e = !1;
8623
- this._batchedClientStats.length > 0 && (this._sendClientStats(this._batchedClientStats), this._batchedClientStats = [], e = !0), e && this._startTimeout();
8624
- }
8625
- _startTimeout() {
8626
- this._batchTimeout = window.setTimeout(() => this._sendBatch(), this._batchInterval);
8627
- }
8628
- _stopTimeout() {
8629
- this._batchTimeout && (clearTimeout(this._batchTimeout), this._batchTimeout = null);
8630
- }
8631
- _sendClientStats(e) {
8632
- this._api.logClientStats(e);
8633
- }
8634
- async _calculateServerTimeDelta() {
8635
- try {
8636
- let e = await this._api.getServerTime();
8637
- this._serverTimeDelta = Date.now() - e;
8638
- } catch {} finally {
8639
- this._flushDeferredClientStats();
8640
- }
8641
- }
8642
- _flushDeferredClientStats() {
8643
- if (!this._waitingForServerTime) return;
8644
- this._waitingForServerTime = !1;
8645
- let e = this._deferredClientStats;
8646
- this._deferredClientStats = [];
8647
- for (let { data: t, options: n } of e) this._logClientStats(t, n);
8648
- }
8649
- _now() {
8650
- return Date.now() - this._serverTimeDelta;
8651
- }
8652
- }, Io = "invalid-error-metadata", Lo = 64, Ro = new Set(Object.values(D)), zo = new Set(Object.values(x)), Bo = {
8935
+ }, $o = "invalid-error-metadata", es = 64, ts = new Set(Object.values(D)), ns = new Set(Object.values(x)), rs = {
8653
8936
  [D.CANCELED]: {
8654
8937
  type: "semantic",
8655
8938
  reason: "canceled"
@@ -8770,7 +9053,7 @@ var bo = 90, xo = 3, So = class extends b {
8770
9053
  type: "semantic",
8771
9054
  reason: "obsolete_client"
8772
9055
  }
8773
- }, Vo = {
9056
+ }, is = {
8774
9057
  [x.MIC_CAMERA_PERMISSION]: {
8775
9058
  type: "direct-error",
8776
9059
  error: {
@@ -8859,14 +9142,14 @@ var bo = 90, xo = 3, So = class extends b {
8859
9142
  }
8860
9143
  }
8861
9144
  };
8862
- function Ho(e) {
8863
- if (typeof e != "string" && typeof e != "number" || typeof e == "number" && !Number.isFinite(e)) return Io;
9145
+ function as(e) {
9146
+ if (typeof e != "string" && typeof e != "number" || typeof e == "number" && !Number.isFinite(e)) return $o;
8864
9147
  let t = String(e).trim();
8865
- if (!t) return Io;
9148
+ if (!t) return $o;
8866
9149
  let n = t.toLowerCase().replace(/[\s_:]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
8867
- return !n || !/^[a-z0-9.-]+$/.test(n) ? Io : n.length > Lo ? `${n.slice(0, Lo - 3)}...` : n;
9150
+ return !n || !/^[a-z0-9.-]+$/.test(n) ? $o : n.length > es ? `${n.slice(0, es - 3)}...` : n;
8868
9151
  }
8869
- function Uo(e) {
9152
+ function os(e) {
8870
9153
  if (!e || typeof e != "object") return !1;
8871
9154
  let t = e;
8872
9155
  switch (t.scope) {
@@ -8878,49 +9161,49 @@ function Uo(e) {
8878
9161
  default: return !1;
8879
9162
  }
8880
9163
  }
8881
- function Wo(e) {
8882
- let t = Ho(e.description);
9164
+ function ss(e) {
9165
+ let t = as(e.description);
8883
9166
  if (e.scope === "unknown") return `unknown:${t}`;
8884
- let n = Ho(e.code);
9167
+ let n = as(e.code);
8885
9168
  return e.scope === "internal" ? `internal:${n}:${t}` : `${e.scope}:${e.source}:${n}:${t}`;
8886
9169
  }
8887
- function Go(e, t) {
9170
+ function cs(e, t) {
8888
9171
  return t === null ? e.type === "direct-error" ? {
8889
9172
  reason: "error",
8890
- string_value: Wo(e.error)
8891
- } : { reason: "failed" } : Uo(t) ? {
9173
+ string_value: ss(e.error)
9174
+ } : { reason: "failed" } : os(t) ? {
8892
9175
  reason: "error",
8893
- string_value: Wo(t)
9176
+ string_value: ss(t)
8894
9177
  } : { reason: "failed" };
8895
9178
  }
8896
- function Ko(e) {
9179
+ function ls(e) {
8897
9180
  if (e.hangup) {
8898
- let t = Bo[e.hangup];
9181
+ let t = rs[e.hangup];
8899
9182
  return t ? t.type === "semantic" ? e.hangup === D.OBSOLETE_CLIENT && e.custom_error?.vchat_detailed_api_error.code ? {
8900
9183
  reason: t.reason,
8901
9184
  string_value: e.custom_error.vchat_detailed_api_error.code
8902
- } : { reason: t.reason } : Go(t, e.callError) : { reason: "failed" };
9185
+ } : { reason: t.reason } : cs(t, e.callError) : { reason: "failed" };
8903
9186
  }
8904
9187
  if (e.error) {
8905
- let t = Vo[e.error];
8906
- return t ? Go(t, e.callError) : { reason: "failed" };
9188
+ let t = is[e.error];
9189
+ return t ? cs(t, e.callError) : { reason: "failed" };
8907
9190
  }
8908
9191
  return { reason: "failed" };
8909
9192
  }
8910
- function qo(e) {
8911
- return e instanceof O ? Ko(e) : typeof e == "string" && (Ro.has(e) || zo.has(e)) ? Ko(new O(e)) : { reason: "failed" };
9193
+ function us(e) {
9194
+ return e instanceof O ? ls(e) : typeof e == "string" && (ts.has(e) || ns.has(e)) ? ls(new O(e)) : { reason: "failed" };
8912
9195
  }
8913
9196
  //#endregion
8914
9197
  //#region src/classes/stat/CallLifecycleStats.ts
8915
- var Jo = {
9198
+ var ds = {
8916
9199
  wallNow: () => Date.now(),
8917
9200
  monotonicNow: () => performance.now()
8918
9201
  };
8919
- function Yo(e) {
9202
+ function fs(e) {
8920
9203
  return e === "anonym_join" ? "join" : e;
8921
9204
  }
8922
- var Xo = class {
8923
- constructor(e, t = Jo) {
9205
+ var ps = class {
9206
+ constructor(e, t = ds) {
8924
9207
  h(this, "_logger", void 0), h(this, "_clock", void 0), h(this, "_conversationId", null), h(this, "_callStartLabel", null), h(this, "_lifecycleStartedAtMonotonic", 0), h(this, "_pendingEvents", []), h(this, "_callStarted", !1), h(this, "_accepted", !1), h(this, "_firstMediaSent", !1), h(this, "_finished", !1), h(this, "_destroyed", !1), this._logger = e, this._clock = t;
8925
9208
  }
8926
9209
  get firstMediaSentReported() {
@@ -8932,7 +9215,7 @@ var Xo = class {
8932
9215
  markInitializationStarted({ source: e, conversationId: t }) {
8933
9216
  if (this._destroyed || this._callStartLabel !== null) return;
8934
9217
  let n = this._clock.wallNow();
8935
- this._callStartLabel = Yo(e), this._lifecycleStartedAtMonotonic = this._clock.monotonicNow(), t && (this._conversationId = t), this._record({
9218
+ this._callStartLabel = fs(e), this._lifecycleStartedAtMonotonic = this._clock.monotonicNow(), t && (this._conversationId = t), this._record({
8936
9219
  name: H.CALL_INIT,
8937
9220
  source: e
8938
9221
  }, n);
@@ -8960,7 +9243,7 @@ var Xo = class {
8960
9243
  !this._canRecord() || this._firstMediaSent || (this._firstMediaSent = !0, this._record({ name: H.FIRST_MEDIA_SENT }));
8961
9244
  }
8962
9245
  markFinished(e) {
8963
- this._finish(qo(e));
9246
+ this._finish(us(e));
8964
9247
  }
8965
9248
  markTerminated() {
8966
9249
  this._finish({ reason: "terminated" });
@@ -8979,23 +9262,22 @@ var Xo = class {
8979
9262
  name: H.CALL_FINISH,
8980
9263
  reason: e,
8981
9264
  ...t && { string_value: t }
8982
- }, void 0, !0));
9265
+ }, void 0));
8983
9266
  }
8984
9267
  _ensureConversationId() {
8985
9268
  this._conversationId || (this._conversationId = j.uuid(), this._flushPendingEvents());
8986
9269
  }
8987
- _record(e, t = this._clock.wallNow(), n = !1) {
9270
+ _record(e, t = this._clock.wallNow()) {
8988
9271
  if (this._destroyed) return;
8989
- let r = {
9272
+ let n = {
8990
9273
  data: e,
8991
- occurredAt: t,
8992
- immediately: n
9274
+ occurredAt: t
8993
9275
  };
8994
9276
  if (!this._conversationId) {
8995
- this._pendingEvents.push(r);
9277
+ this._pendingEvents.push(n);
8996
9278
  return;
8997
9279
  }
8998
- this._logEvent(r);
9280
+ this._logEvent(n);
8999
9281
  }
9000
9282
  _flushPendingEvents() {
9001
9283
  if (!this._conversationId || !this._pendingEvents.length) return;
@@ -9003,15 +9285,13 @@ var Xo = class {
9003
9285
  this._pendingEvents = [];
9004
9286
  for (let t of e) this._logEvent(t);
9005
9287
  }
9006
- _logEvent({ data: e, occurredAt: t, immediately: n }) {
9288
+ _logEvent({ data: e, occurredAt: t }) {
9007
9289
  this._logger.logClientStats(e, {
9008
9290
  conversationId: this._conversationId,
9009
- deferUntilServerTime: !0,
9010
- occurredAt: t,
9011
- ...n && { immediately: !0 }
9291
+ occurredAt: t
9012
9292
  });
9013
9293
  }
9014
- }, Zo = class {
9294
+ }, ms = class {
9015
9295
  constructor(e, t) {
9016
9296
  h(this, "_logger", void 0), h(this, "_codecUsages", /* @__PURE__ */ new Map()), h(this, "getCurrentTransportTopology", void 0), this._logger = e, this.getCurrentTransportTopology = t;
9017
9297
  }
@@ -9074,7 +9354,7 @@ var Xo = class {
9074
9354
  this.report(e);
9075
9355
  }), this._codecUsages.clear();
9076
9356
  }
9077
- }, Qo = class {
9357
+ }, hs = class {
9078
9358
  constructor(e) {
9079
9359
  h(this, "_logger", void 0), h(this, "_eventualLogs", /* @__PURE__ */ new Set()), h(this, "_lastCallStatContext", null), this._logger = e;
9080
9360
  }
@@ -9112,7 +9392,7 @@ var Xo = class {
9112
9392
  ...this._lastCallStatContext ?? {}
9113
9393
  }, { occurredAt: t });
9114
9394
  }
9115
- }, $o = class {
9395
+ }, gs = class {
9116
9396
  constructor(e) {
9117
9397
  if (h(this, "q", void 0), h(this, "inits", []), h(this, "n", [
9118
9398
  1,
@@ -9171,7 +9451,7 @@ var Xo = class {
9171
9451
  5
9172
9452
  ];
9173
9453
  }
9174
- }, es = class {
9454
+ }, _s = class {
9175
9455
  constructor() {
9176
9456
  h(this, "n", 0), h(this, "mean", 0);
9177
9457
  }
@@ -9183,9 +9463,9 @@ var Xo = class {
9183
9463
  get avg() {
9184
9464
  return this.n ? this.mean : NaN;
9185
9465
  }
9186
- }, ts = class {
9466
+ }, vs = class {
9187
9467
  constructor() {
9188
- h(this, "count", 0), h(this, "minVal", Infinity), h(this, "maxVal", -Infinity), h(this, "mean", new es()), h(this, "p50", new $o(.5)), h(this, "p95", new $o(.95));
9468
+ h(this, "count", 0), h(this, "minVal", Infinity), h(this, "maxVal", -Infinity), h(this, "mean", new _s()), h(this, "p50", new gs(.5)), h(this, "p95", new gs(.95));
9189
9469
  }
9190
9470
  add(e) {
9191
9471
  e < this.minVal && (this.minVal = e), e > this.maxVal && (this.maxVal = e), this.mean.add(e), this.p50.add(e), this.p95.add(e), this.count++;
@@ -9203,11 +9483,11 @@ var Xo = class {
9203
9483
  get hasData() {
9204
9484
  return this.count > 0;
9205
9485
  }
9206
- }, ns = class {
9486
+ }, ys = class {
9207
9487
  constructor(e) {
9208
9488
  h(this, "_logger", void 0), h(this, "trackerByTransport", {
9209
- ws: new ts(),
9210
- wt: new ts()
9489
+ ws: new vs(),
9490
+ wt: new vs()
9211
9491
  }), h(this, "lastSeen", {}), this._logger = e;
9212
9492
  }
9213
9493
  mark(e) {
@@ -9236,17 +9516,17 @@ var Xo = class {
9236
9516
  }
9237
9517
  destroy() {
9238
9518
  this.trackerByTransport = {
9239
- ws: new ts(),
9240
- wt: new ts()
9519
+ ws: new vs(),
9520
+ wt: new vs()
9241
9521
  }, this.lastSeen = {};
9242
9522
  }
9243
- }, rs = class {
9523
+ }, bs = class {
9244
9524
  constructor(e) {
9245
9525
  h(this, "_logger", void 0), h(this, "trackerByCommand", /* @__PURE__ */ new Map()), this._logger = e;
9246
9526
  }
9247
9527
  mark(e, t, n) {
9248
9528
  let r = `${e}|${n}`, i;
9249
- this.trackerByCommand.has(r) ? i = this.trackerByCommand.get(r) : (i = new ts(), this.trackerByCommand.set(r, i)), i.add(t);
9529
+ this.trackerByCommand.has(r) ? i = this.trackerByCommand.get(r) : (i = new vs(), this.trackerByCommand.set(r, i)), i.add(t);
9250
9530
  }
9251
9531
  logMetrics() {
9252
9532
  for (let [e, t] of this.trackerByCommand.entries()) {
@@ -9268,9 +9548,12 @@ var Xo = class {
9268
9548
  destroy() {
9269
9549
  this.trackerByCommand.clear();
9270
9550
  }
9271
- }, is = class {
9272
- constructor(e, t, n, r) {
9273
- h(this, "logger", void 0), h(this, "lifecycle", void 0), h(this, "statAggregator", void 0), h(this, "codecStatsAggregator", void 0), h(this, "pings", void 0), h(this, "signalingCommands", void 0), this.logger = new Fo(e, t, n, r), this.lifecycle = new Xo(this.logger), this.statAggregator = new Qo(this.logger), this.codecStatsAggregator = new Zo(this.logger, r), this.pings = new ns(this.logger), this.signalingCommands = new rs(this.logger);
9551
+ }, xs = class {
9552
+ constructor(e, t, n) {
9553
+ h(this, "logger", void 0), h(this, "lifecycle", void 0), h(this, "statAggregator", void 0), h(this, "codecStatsAggregator", void 0), h(this, "pings", void 0), h(this, "signalingCommands", void 0), this.logger = new Qo(e, t, n), this.lifecycle = new ps(this.logger), this.statAggregator = new hs(this.logger), this.codecStatsAggregator = new ms(this.logger, n), this.pings = new ys(this.logger), this.signalingCommands = new bs(this.logger);
9554
+ }
9555
+ prepareForUnload() {
9556
+ this.logger.enterUnloadMode(), this.pings.logMetrics(), this.signalingCommands.logMetrics();
9274
9557
  }
9275
9558
  logHangup(e) {
9276
9559
  this.lifecycle.markFinished(e);
@@ -9281,7 +9564,7 @@ var Xo = class {
9281
9564
  destroy() {
9282
9565
  this.lifecycle.markTerminated(), this.lifecycle.destroy(), this.statAggregator.destroy(), this.codecStatsAggregator.destroy(), this.pings.destroy(), this.signalingCommands.destroy(), this.logger.destroy();
9283
9566
  }
9284
- }, as = class {
9567
+ }, Ss = class {
9285
9568
  constructor(e) {
9286
9569
  h(this, "_statAggregator", void 0), h(this, "_isCallMarked", !1), h(this, "_isFinished", !1), h(this, "_callType", null), this._statAggregator = e;
9287
9570
  }
@@ -9306,8 +9589,8 @@ var Xo = class {
9306
9589
  call_type: this._callType
9307
9590
  }));
9308
9591
  }
9309
- }, os = 1e3, ss = 1e4;
9310
- function cs(e, t, n, r) {
9592
+ }, Cs = 1e3, ws = 1e4;
9593
+ function Ts(e, t, n, r) {
9311
9594
  return new O(e, {
9312
9595
  callError: {
9313
9596
  scope: "external",
@@ -9318,9 +9601,9 @@ function cs(e, t, n, r) {
9318
9601
  message: r
9319
9602
  });
9320
9603
  }
9321
- var ls = 15, $ = class e extends b {
9604
+ var Es = 15, $ = class e extends b {
9322
9605
  constructor(e, t) {
9323
- super(), h(this, "_api", void 0), h(this, "_signaling", void 0), h(this, "_signalingActor", void 0), h(this, "_displayLayoutRequester", void 0), h(this, "_mediaSource", null), h(this, "_conversation", null), h(this, "_myLastRequestedLayouts", {}), h(this, "_state", "IDLE"), h(this, "_previousState", null), h(this, "_waitingHallHoldPending", !1), h(this, "_participantState", Z.CALLED), h(this, "_participants", {}), h(this, "_directTransportIsMaster", void 0), h(this, "_transport", null), h(this, "_debugInfo", null), h(this, "_debug", R.createSessionLogger()), h(this, "_volumesDetector", null), h(this, "_speakerDetector", null), h(this, "_localVolumeDetector", null), h(this, "_specListener", null), h(this, "_activeSpeakerId", null), h(this, "_lastSignalledActiveSpeakerId", null), h(this, "_isRealTimeAsrRequested", !1), h(this, "_serverSettings", kr()), h(this, "_serverTimeOffset", 0), h(this, "_delayedHangup", !1), h(this, "_hangupEmitted", !1), h(this, "_hangupPromise", null), h(this, "_abortController", null), h(this, "_registeredPeerReceived", !1), h(this, "_calleeUnavailableTimer", null), h(this, "_reservedId", null), h(this, "_onUnload", void 0), h(this, "_audioOutput", void 0), h(this, "_stats", void 0), h(this, "_lastStalled", {}), h(this, "_audioMixStalled", !1), h(this, "_audioFix", null), h(this, "_streamByStreamId", /* @__PURE__ */ new Map()), h(this, "_streamIdByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_streamWaitTimerByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_sequenceNumberByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_cooldownTimestampByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_cooldownQueueCleanupTimer", null), h(this, "_statFirstMediaReceived", void 0), h(this, "_toggleLocalVideo", mo((e) => {
9606
+ super(), h(this, "_api", void 0), h(this, "_signaling", void 0), h(this, "_signalingActor", void 0), h(this, "_displayLayoutRequester", void 0), h(this, "_mediaSource", null), h(this, "_conversation", null), h(this, "_myLastRequestedLayouts", {}), h(this, "_state", "IDLE"), h(this, "_previousState", null), h(this, "_waitingHallHoldPending", !1), h(this, "_participantState", Z.CALLED), h(this, "_participants", {}), h(this, "_directTransportIsMaster", void 0), h(this, "_transport", null), h(this, "_debugInfo", null), h(this, "_debug", R.createSessionLogger()), h(this, "_volumesDetector", null), h(this, "_speakerDetector", null), h(this, "_localVolumeDetector", null), h(this, "_specListener", null), h(this, "_activeSpeakerId", null), h(this, "_lastSignalledActiveSpeakerId", null), h(this, "_isRealTimeAsrRequested", !1), h(this, "_serverSettings", kr()), h(this, "_serverTimeOffset", 0), h(this, "_delayedHangup", !1), h(this, "_onFastHangup", void 0), h(this, "_hangupEmitted", !1), h(this, "_hangupPromise", null), h(this, "_abortController", null), h(this, "_registeredPeerReceived", !1), h(this, "_calleeUnavailableTimer", null), h(this, "_reservedId", null), h(this, "_onUnload", void 0), h(this, "_audioOutput", void 0), h(this, "_stats", void 0), h(this, "_lastStalled", {}), h(this, "_audioMixStalled", !1), h(this, "_audioFix", null), h(this, "_streamByStreamId", /* @__PURE__ */ new Map()), h(this, "_streamIdByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_streamWaitTimerByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_sequenceNumberByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_cooldownTimestampByStreamDescription", /* @__PURE__ */ new Map()), h(this, "_cooldownQueueCleanupTimer", null), h(this, "_statFirstMediaReceived", void 0), h(this, "_toggleLocalVideo", mo((e) => {
9324
9607
  if (this._mediaSource) return this._stats.logger.log(C.MEDIA_STATUS, e ? "video_1" : "video_0"), this._mediaSource.toggleVideo(e);
9325
9608
  })), h(this, "_toggleLocalAudio", mo((e) => {
9326
9609
  if (this._mediaSource) return this._stats.logger.log(C.MEDIA_STATUS, e ? "audio_1" : "audio_0"), this._mediaSource.toggleAudio(e);
@@ -9334,22 +9617,31 @@ var ls = 15, $ = class e extends b {
9334
9617
  captureAudio: !1
9335
9618
  });
9336
9619
  }
9337
- }, 100)), this._stats = new is(e, t, () => this._conversation?.id || null, () => this._transport?.getTopology() ?? this._conversation?.topology), this._api = e, this._signaling = new za(this._debug, this._stats.logger, this._stats.statAggregator, this._stats.pings, this._stats.signalingCommands), this._signalingActor = new Do(this._onSignalingNotification.bind(this), this._debug), this._displayLayoutRequester = new Co({
9620
+ }, 100)), this._stats = new xs(t, () => this._conversation?.id || null, () => this._transport?.getTopology() ?? this._conversation?.topology), this._api = e, this._signaling = new za(this._debug, this._stats.logger, this._stats.statAggregator, this._stats.pings, this._stats.signalingCommands), this._signalingActor = new Do(this._onSignalingNotification.bind(this), this._debug), this._displayLayoutRequester = new Co({
9338
9621
  api: this._api,
9339
9622
  debug: this._debug,
9340
9623
  getParticipants: () => this._participants,
9341
9624
  isMe: (e) => this._isMe(e),
9342
9625
  updateDisplayLayout: (e) => this.updateDisplayLayout(e)
9343
9626
  }), this._onUnload = () => {
9344
- this._stopFirstMediaSentProbe(), this._conversation && this._api && this._sendHangupApi(this._conversation.id, this._state === "IDLE" ? D.CANCELED : D.HUNGUP), this._stats.destroy();
9345
- }, window.addEventListener("pagehide", this._onUnload), this._statFirstMediaReceived = new as(this._stats.statAggregator), this._audioOutput = new go(this._statFirstMediaReceived, M.transparentAudio, this._debug, this._stats.logger), M.videoTracksCount > 0 && (this._cooldownQueueCleanupTimer = window.setInterval(this._cleanupCooldownQueue.bind(this), os));
9627
+ this._stopFirstMediaSentProbe(), this._conversation && this._api && this._sendHangupApi(this._conversation.id, this._state === "IDLE" ? D.CANCELED : D.HUNGUP), this._stats.prepareForUnload(), this._stats.destroy();
9628
+ }, window.addEventListener("pagehide", this._onUnload), this._statFirstMediaReceived = new Ss(this._stats.statAggregator), this._audioOutput = new go(this._statFirstMediaReceived, M.transparentAudio, this._debug, this._stats.logger), M.videoTracksCount > 0 && (this._cooldownQueueCleanupTimer = window.setInterval(this._cleanupCooldownQueue.bind(this), Cs));
9346
9629
  }
9347
9630
  static current() {
9348
9631
  return z.getActive() ?? (M.hold ? null : z.getFirst());
9349
9632
  }
9350
- static hangupAfterInit() {
9351
- let e = us;
9352
- e && e._delayedHangup === !1 && !e._conversation && (e._delayedHangup = !0, e._abortController?.abort(new O(D.CANCELED)));
9633
+ static hangupAfterInit(e) {
9634
+ let t = Ds;
9635
+ if (t) {
9636
+ if (typeof e == "function" && (t._onFastHangup = e), t._delayedHangup === !1 && !t._conversation) {
9637
+ t._delayedHangup = !0, t._abortController?.abort(new O(D.CANCELED));
9638
+ return;
9639
+ }
9640
+ t._conversation && t.hangup({
9641
+ onFastHangup: e,
9642
+ reason: D.CANCELED
9643
+ });
9644
+ }
9353
9645
  }
9354
9646
  static id() {
9355
9647
  return z.getActiveId();
@@ -9386,12 +9678,24 @@ var ls = 15, $ = class e extends b {
9386
9678
  getCachedRawOkIdByExternalId(e) {
9387
9679
  return this._api.getCachedRawOkIdByExternalId(e);
9388
9680
  }
9681
+ _buildInternalParams() {
9682
+ let e = {
9683
+ deviceId: this._api.deviceId(),
9684
+ sdkVersion: M.sdkVersion,
9685
+ clientAppKey: M.apiKey,
9686
+ platform: M.platform,
9687
+ protocolVersion: M.protocolVersion,
9688
+ domainId: M.domain,
9689
+ capabilities: xa.getFlags()
9690
+ };
9691
+ return JSON.stringify(e);
9692
+ }
9389
9693
  async onStart({ opponentIds: e, opponentType: t, mediaOptions: n, payload: r = "", joiningAllowed: i = !1, requireAuthToJoin: a = !1, onlyAdminCanShareMovie: o, externalIds: s, onFastStart: c, conversationId: l }) {
9390
9694
  let u = l ?? j.uuid(), d = (e?.length ?? 0) + (s?.length ?? 0), f = t === Va.USER && d === 1 ? M.calleeUnavailableWaitingTime : void 0;
9391
9695
  this._stats.lifecycle.markInitializationStarted({
9392
9696
  source: "outgoing",
9393
9697
  conversationId: u
9394
- }), this._debug.setConversationId(u), us = this, this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal);
9698
+ }), this._debug.setConversationId(u), Ds = this, this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal);
9395
9699
  try {
9396
9700
  this._mediaSource = this._createMediaSource(), await this._mediaSource.request(n);
9397
9701
  let l = this._mediaSource.mediaSettings;
@@ -9419,18 +9723,18 @@ var ls = 15, $ = class e extends b {
9419
9723
  opponentIds: e,
9420
9724
  opponentType: t,
9421
9725
  mediaOptions: n
9422
- }), this._processConnectionSharedMovieInfo(d), this._processConversationUrlSharingInfo(d), L.onLocalStream(this._mediaSource.getStream(), this._mediaSource.mediaSettings, this.id), L.onConversation(this._conversation.externalId, this._conversation.mediaModifiers, this._getMuteStatesForCurrentRoom(), this._getMainRoomParticipants(), void 0, this.id), this._onConversationParticipantListChunk(d), this._processPinnedParticipants(d), L.onLocalStatus(N.WAITING, this.id), this._toggleJoinAvailability(), this._changeFeatureSet(), this._changeNeedRate(), z.add(this), await z.setActive(this.id), us = null, this._conversation.concurrent && await this._acceptConcurrent(), f && !this._registeredPeerReceived && this._state !== "CLOSE" && (this._calleeUnavailableTimer = window.setTimeout(() => {
9726
+ }), this._processConnectionSharedMovieInfo(d), this._processConversationUrlSharingInfo(d), L.onLocalStream(this._mediaSource.getStream(), this._mediaSource.mediaSettings, this.id), L.onConversation(this._conversation.externalId, this._conversation.mediaModifiers, this._getMuteStatesForCurrentRoom(), this._getMainRoomParticipants(), void 0, this.id), this._onConversationParticipantListChunk(d), this._processPinnedParticipants(d), L.onLocalStatus(N.WAITING, this.id), this._toggleJoinAvailability(), this._changeFeatureSet(), this._changeNeedRate(), z.add(this), await z.setActive(this.id), Ds = null, this._conversation.concurrent && await this._acceptConcurrent(), f && !this._registeredPeerReceived && this._state !== "CLOSE" && (this._calleeUnavailableTimer = window.setTimeout(() => {
9423
9727
  this._calleeUnavailableTimer = null, this._close(new O(D.CALLEE_UNAVAILABLE), { signalingReason: D.CANCELED });
9424
9728
  }, f)), this._conversation;
9425
9729
  } catch (e) {
9426
- throw us = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to start conversation" }), e;
9730
+ throw Ds = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to start conversation" }), e;
9427
9731
  }
9428
9732
  }
9429
9733
  async onJoin(e) {
9430
9734
  this._stats.lifecycle.markInitializationStarted({
9431
9735
  source: e.anonymous ? "anonym_join" : "join",
9432
9736
  conversationId: e.conversationId
9433
- }), us = this, this._state = "PROCESSING", this._debug.setConversationId(e.conversationId ?? null), this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal);
9737
+ }), Ds = this, this._state = "PROCESSING", this._debug.setConversationId(e.conversationId ?? null), this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal);
9434
9738
  try {
9435
9739
  let t = !!e.observedIds?.length;
9436
9740
  if (t && M.videoTracksCount > 0) throw this._debug.error("Observer mode: please set videoTracksCount=0"), new O(D.UNSUPPORTED, { callError: {
@@ -9447,9 +9751,9 @@ var ls = 15, $ = class e extends b {
9447
9751
  code: "conversation",
9448
9752
  description: "not-initialized-after-join"
9449
9753
  } });
9450
- return this._conversation.observer = t, L.onLocalStream(this._mediaSource.getStream(), n, this.id), this._conversation.waitForAdmin || this._conversation.waitingHall ? (this._debug.log(this._conversation.waitForAdmin ? "Wait for admin" : "In waiting hall"), z.add(this), us = null, this._signaling.readyToSend(), L.onLocalStatus(this._conversation.waitForAdmin ? N.WAIT_FOR_ADMIN : N.WAITING_HALL, this.id), this._conversation) : this._onJoinPart2(r);
9754
+ return this._conversation.observer = t, L.onLocalStream(this._mediaSource.getStream(), n, this.id), this._conversation.waitForAdmin || this._conversation.waitingHall ? (this._debug.log(this._conversation.waitForAdmin ? "Wait for admin" : "In waiting hall"), z.add(this), Ds = null, this._signaling.readyToSend(), L.onLocalStatus(this._conversation.waitForAdmin ? N.WAIT_FOR_ADMIN : N.WAITING_HALL, this.id), this._conversation) : this._onJoinPart2(r);
9451
9755
  } catch (e) {
9452
- throw us = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to join conversation" }), e;
9756
+ throw Ds = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to join conversation" }), e;
9453
9757
  }
9454
9758
  }
9455
9759
  async _onJoinPart2(e, t = !0, n = !1) {
@@ -9464,7 +9768,7 @@ var ls = 15, $ = class e extends b {
9464
9768
  if (this._delayedHangup) throw new O(D.CANCELED);
9465
9769
  this._processConnectionSharedMovieInfo(e), this._processConversationUrlSharingInfo(e), this._processConnectionAsrInfo(e);
9466
9770
  let r = this._extractExternalRoomsData(e.rooms?.rooms, e.rooms?.roomId);
9467
- L.onConversation(this._conversation.externalId, this._conversation.mediaModifiers, this._getMuteStatesForCurrentRoom(), this._getMainRoomParticipants(), r, this.id), this._onConversationParticipantListChunk(e), this._processPinnedParticipants(e), L.onLocalStatus(N.WAITING, this.id), this._toggleJoinAvailability(), this._changeNeedRate(), t && (this._state = "ACTIVE"), this._changeFeatureSet(), t && (z.add(this), n ? await this._holdLocally() : await z.setActive(this.id), us = null);
9771
+ L.onConversation(this._conversation.externalId, this._conversation.mediaModifiers, this._getMuteStatesForCurrentRoom(), this._getMainRoomParticipants(), r, this.id), this._onConversationParticipantListChunk(e), this._processPinnedParticipants(e), L.onLocalStatus(N.WAITING, this.id), this._toggleJoinAvailability(), this._changeNeedRate(), t && (this._state = "ACTIVE"), this._changeFeatureSet(), t && (z.add(this), n ? await this._holdLocally() : await z.setActive(this.id), Ds = null);
9468
9772
  let i = this._extractLocalParticipantFromConnection(e);
9469
9773
  if (i) {
9470
9774
  let e = j.mapParticipantState(i);
@@ -9472,7 +9776,7 @@ var ls = 15, $ = class e extends b {
9472
9776
  }
9473
9777
  return t && this._openTransport(Object.values(this._participants), !1), this._conversation;
9474
9778
  } catch (e) {
9475
- throw us = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to join conversation" }), e;
9779
+ throw Ds = null, this._cleanupRegistry(), this._close(e, { errorText: "Unable to join conversation" }), e;
9476
9780
  }
9477
9781
  }
9478
9782
  _extractExternalRooms(e) {
@@ -9485,10 +9789,10 @@ var ls = 15, $ = class e extends b {
9485
9789
  }
9486
9790
  async onPush(e, t = A.USER, n, r, i, a) {
9487
9791
  if (z.has(e)) throw new O(D.HAS_ACTIVE_CALL);
9488
- z.reserve(e), this._reservedId = e, this._stats.lifecycle.markInitializationStarted({
9792
+ z.reserve(e), this._reservedId = e, a !== void 0 && this._api.setUserId(a), this._stats.lifecycle.markInitializationStarted({
9489
9793
  source: "incoming",
9490
9794
  conversationId: e
9491
- }), this._debug.setConversationId(e), us = this, this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal), a && this._api.setUserId(a);
9795
+ }), this._debug.setConversationId(e), Ds = this, this._abortController = new AbortController(), this._api.setAbortSignal(this._abortController?.signal), this._signaling.setAbortSignal(this._abortController?.signal);
9492
9796
  try {
9493
9797
  let a = await this._prepareConversation(e, t, n, r, i);
9494
9798
  if (this._mediaSource = this._createMediaSource(), !this._conversation) throw new O(D.UNKNOWN_ERROR, { callError: {
@@ -9497,9 +9801,9 @@ var ls = 15, $ = class e extends b {
9497
9801
  description: "incoming-not-initialized"
9498
9802
  } });
9499
9803
  if (!a.conversation.participants.find((e) => e.state === Z.CALLED && e.id === this._conversation?.userId)) throw this._debug.log("Push rejected (there is an active call)"), this._stats.logger.log(C.PUSH, "rejected"), new O(D.REJECTED);
9500
- if (await this._processConnection(a), this._extractConnectionUrlSharingInfo(a), this._allocateTransport(), this._createSpeakerDetector(), this._createSpecListener(), this._processPinnedParticipants(a), this._signaling.readyToSend(), this._stats.lifecycle.markCallStarted(), this._stats.logger.log(C.PUSH, "accepted"), z.add(this), us = null, this._delayedHangup) throw new O(D.CANCELED);
9804
+ if (await this._processConnection(a), this._extractConnectionUrlSharingInfo(a), this._allocateTransport(), this._createSpeakerDetector(), this._createSpecListener(), this._processPinnedParticipants(a), this._signaling.readyToSend(), this._stats.lifecycle.markCallStarted(), this._stats.logger.log(C.PUSH, "accepted"), z.add(this), Ds = null, this._delayedHangup) throw new O(D.CANCELED);
9501
9805
  } catch (e) {
9502
- throw us = null, this._cleanupRegistry(), this._close(e, {
9806
+ throw Ds = null, this._cleanupRegistry(), this._close(e, {
9503
9807
  errorText: "Unable to handle inbound call push",
9504
9808
  signalingReason: e instanceof O && e.hangup === D.BUSY ? D.BUSY : void 0
9505
9809
  }), e;
@@ -9611,17 +9915,23 @@ var ls = 15, $ = class e extends b {
9611
9915
  }
9612
9916
  async decline(e) {
9613
9917
  if (this._state !== "IDLE") throw this._stats.logger.log(C.ERROR, "declineIncoming"), this._debug.error("Unable to decline a call - invalid state"), Error("Unable to decline a call - invalid state");
9918
+ let t = e?.reason;
9614
9919
  this._state = "PROCESSING", this._debug.debug("Decline incoming call"), this._logWithMediaSettings(C.DECLINE_INCOMING, this.mediaSettings), this._participantState = Z.HUNGUP;
9615
- let t = e ?? D.REJECTED, n = new O(t);
9616
- this._finishLifecycle(n), this._close(n, { signalingReason: t });
9920
+ let n = t ?? D.REJECTED, r = new O(n);
9921
+ this._finishLifecycle(r), this._onFastHangup = e?.onFastHangup ?? this._onFastHangup;
9922
+ let i = this._conversation?.id;
9923
+ i && typeof this._onFastHangup == "function" && this._sendHangup(i, n, this._onFastHangup), this._close(r, { signalingReason: n });
9617
9924
  }
9618
9925
  hangup(e) {
9619
9926
  if (this._hangupPromise) return this._hangupPromise;
9927
+ let t = e?.reason;
9620
9928
  this._clearCalleeUnavailableWatchdog(), this._debug.debug("Hangup");
9621
- let t = e ?? (this._state === "ACTIVE" || this._state === "HELD" ? D.HUNGUP : D.CANCELED), n = new O(t), r = this._conversation?.id ?? null;
9622
- return this._stats.logger.log(C.HANGUP, t), this._finishLifecycle(n), this._hangupPromise = this._signaling.hangup(t).then(() => void 0).catch((e) => {
9929
+ let n = t ?? (this._state === "ACTIVE" || this._state === "HELD" ? D.HUNGUP : D.CANCELED), r = new O(n), i = this._conversation?.id ?? null;
9930
+ this._onFastHangup = e?.onFastHangup ?? this._onFastHangup, this._stats.logger.log(C.HANGUP, n), this._finishLifecycle(r);
9931
+ let a = !!i && typeof this._onFastHangup == "function";
9932
+ return i && a && this._sendHangup(i, n, this._onFastHangup), this._hangupPromise = this._signaling.hangup(n).then(() => void 0).catch((e) => {
9623
9933
  if (!(e instanceof wn)) throw e;
9624
- }).finally(() => (r != null && this._sendHangupApi(r, t), this._close(n))), this._emitHangupOnce(n, r), this._cleanupTransport(), this._cleanupMediaSource(), this._hangupPromise;
9934
+ }).finally(() => (i != null && !a && this._sendHangupApi(i, n), this._close(r))), this._emitHangupOnce(r, i), this._cleanupTransport(), this._cleanupMediaSource(), this._hangupPromise;
9625
9935
  }
9626
9936
  async addParticipant(e, t) {
9627
9937
  if (!this._signaling.ready) {
@@ -9718,16 +10028,27 @@ var ls = 15, $ = class e extends b {
9718
10028
  }
9719
10029
  this._state = "CLOSE", this._participantState = Z.HUNGUP, this._changeFeatureSet(), this._cleanupMediaSource(), this._cleanupParticipants(), this._cleanupParticipantAgnosticStreams(), this._cleanupTransport(), this._cleanupSpeakerDetector(), this._cleanupSpecListener(), this._disposeSignaling(r), this._api.cleanup(), this._api.setAbortSignal(void 0), this._stats.destroy(), this._cleanupRegistry(), this._conversation = null, this._myLastRequestedLayouts = {}, this._displayLayoutRequester.clear(), this._delayedHangup = !1, this._abortController = null, this._emitHangupOnce(e || new O(D.UNKNOWN_ERROR), i);
9720
10030
  }
10031
+ _sendHangup(e, t, n) {
10032
+ typeof n == "function" ? n({
10033
+ conversationId: e,
10034
+ reason: t,
10035
+ internalParams: this._buildInternalParams()
10036
+ }, this._abortController?.signal).then((e) => {
10037
+ e?.success || this._debug.error("Fast hangup was not successful", e);
10038
+ }).catch((e) => {
10039
+ this._debug.error("Fast hangup error", e);
10040
+ }) : this._sendHangupApi(e, t);
10041
+ }
9721
10042
  destroy() {
9722
10043
  this._destroy();
9723
10044
  }
9724
10045
  _destroy(e) {
9725
10046
  this._clearCalleeUnavailableWatchdog();
9726
10047
  let t = this._conversation && this._conversation.id;
9727
- if (this._debug.debug("Destroy conversation", { conversationId: t }), this._stopFirstMediaSentProbe(), this._cooldownQueueCleanupTimer !== null && (window.clearInterval(this._cooldownQueueCleanupTimer), this._cooldownQueueCleanupTimer = null), this._state = "CLOSE", this._participantState = Z.HUNGUP, this._cleanupMediaSource(), this._cleanupParticipants(), this._cleanupParticipantAgnosticStreams(), this._cleanupTransport(), this._cleanupSpeakerDetector(), this._cleanupSpecListener(), this._disposeSignaling(e), this._api.cleanup(), this._api.setAbortSignal(void 0), this._delayedHangup && t) try {
9728
- this._sendHangupApi(t, D.CANCELED);
10048
+ if (this._debug.debug("Destroy conversation", { conversationId: t }), this._stopFirstMediaSentProbe(), this._cooldownQueueCleanupTimer !== null && (window.clearInterval(this._cooldownQueueCleanupTimer), this._cooldownQueueCleanupTimer = null), this._state = "CLOSE", this._participantState = Z.HUNGUP, this._cleanupMediaSource(), this._cleanupParticipants(), this._cleanupParticipantAgnosticStreams(), this._cleanupTransport(), this._cleanupSpeakerDetector(), this._cleanupSpecListener(), this._disposeSignaling(e), this._delayedHangup && t) try {
10049
+ this._sendHangup(t, D.CANCELED, this._onFastHangup);
9729
10050
  } catch {}
9730
- this._cleanupListeners(), this._stats.destroy(), this._cleanupRegistry(), this._conversation = null, this._myLastRequestedLayouts = {}, this._displayLayoutRequester.clear(), this._delayedHangup = !1, this._abortController = null;
10051
+ this._api.cleanup(), this._api.setAbortSignal(void 0), this._cleanupListeners(), this._stats.destroy(), this._cleanupRegistry(), this._conversation = null, this._myLastRequestedLayouts = {}, this._displayLayoutRequester.clear(), this._delayedHangup = !1, this._abortController = null;
9731
10052
  }
9732
10053
  async _getConversationParams(e) {
9733
10054
  let t = await this._api.getConversationParams(e);
@@ -9756,18 +10077,10 @@ var ls = 15, $ = class e extends b {
9756
10077
  });
9757
10078
  let f = r.includes(S.VIDEO), p, m;
9758
10079
  if (l) {
9759
- let e = {
9760
- deviceId: this._api.deviceId(),
9761
- sdkVersion: M.sdkVersion,
9762
- clientAppKey: M.apiKey,
9763
- platform: M.platform,
9764
- protocolVersion: M.protocolVersion,
9765
- domainId: M.domain,
9766
- capabilities: xa.getFlags()
9767
- }, n = JSON.stringify(e), s;
10080
+ let e;
9768
10081
  try {
9769
- if (s = await l({
9770
- internalParams: n,
10082
+ if (e = await l({
10083
+ internalParams: this._buildInternalParams(),
9771
10084
  conversationId: d,
9772
10085
  externalIds: c,
9773
10086
  payload: i,
@@ -9776,32 +10089,32 @@ var ls = 15, $ = class e extends b {
9776
10089
  isVideo: f,
9777
10090
  joiningAllowed: a,
9778
10091
  requireAuthToJoin: o
9779
- }, this._abortController?.signal), !s) throw cs(D.FAST_START_ERROR, "invalid-response", "fast-start-response-empty");
9780
- if (!s.internalCallerParams) {
9781
- let e = s.rejectedParticipants[0]?.status;
9782
- throw cs(D.FAST_START_ERROR, e ? "fast-start" : "invalid-response", e ?? "fast-start-internal-caller-params-empty", JSON.stringify(s));
10092
+ }, this._abortController?.signal), !e) throw Ts(D.FAST_START_ERROR, "invalid-response", "fast-start-response-empty");
10093
+ if (!e.internalCallerParams) {
10094
+ let t = e.rejectedParticipants[0]?.status;
10095
+ throw Ts(D.FAST_START_ERROR, t ? "fast-start" : "invalid-response", t ?? "fast-start-internal-caller-params-empty", JSON.stringify(e));
9783
10096
  }
9784
10097
  } catch (e) {
9785
10098
  throw this._delayedHangup && this._abortController?.signal.aborted ? new O(D.CANCELED) : e instanceof O ? e : e instanceof Error ? new O(D.FAST_START_ERROR, { message: e.message }) : new O(D.FAST_START_ERROR, { message: String(e) });
9786
10099
  }
9787
10100
  try {
9788
- let e = JSON.parse(s.internalCallerParams);
10101
+ let t = JSON.parse(e.internalCallerParams);
9789
10102
  p = {
9790
- endpoint: e.endpoint,
9791
- wt_endpoint: e.wtEndpoint,
10103
+ endpoint: t.endpoint,
10104
+ wt_endpoint: t.wtEndpoint,
9792
10105
  id: d,
9793
- is_concurrent: e.isConcurrent,
9794
- client_type: e.clientType,
9795
- rejected_participants: s.rejectedParticipants?.map((e) => ({
10106
+ is_concurrent: t.isConcurrent,
10107
+ client_type: t.clientType,
10108
+ rejected_participants: e.rejectedParticipants?.map((e) => ({
9796
10109
  ...e,
9797
10110
  status: e.status
9798
10111
  })),
9799
- stun_server: e.stun,
9800
- turn_server: e.turn,
9801
- token: new URL(e.endpoint).searchParams.get("token") ?? ""
10112
+ stun_server: t.stun,
10113
+ turn_server: t.turn,
10114
+ token: new URL(t.endpoint).searchParams.get("token") ?? ""
9802
10115
  }, this._debug.debug("FastStart", p), m = "fastStart";
9803
10116
  } catch {
9804
- throw cs(D.FAST_START_ERROR, "invalid-response", "fast-start-internal-caller-params-invalid");
10117
+ throw Ts(D.FAST_START_ERROR, "invalid-response", "fast-start-internal-caller-params-invalid");
9805
10118
  }
9806
10119
  } else p = await this._api.startConversation(d, e, t, f, i, a, o, { onlyAdminCanShareMovie: s }, c), this._debug.debug("Api.startConversation", p), m = "startConversation";
9807
10120
  _o(p, m), this._setConversationParams(p), this._stats.lifecycle.bindConversationId(p.id);
@@ -9823,41 +10136,33 @@ var ls = 15, $ = class e extends b {
9823
10136
  code: "fast-join",
9824
10137
  description: "join-link-required"
9825
10138
  } });
9826
- let e = {
9827
- deviceId: this._api.deviceId(),
9828
- sdkVersion: M.sdkVersion,
9829
- clientAppKey: M.apiKey,
9830
- platform: M.platform,
9831
- protocolVersion: M.protocolVersion,
9832
- domainId: M.domain,
9833
- capabilities: xa.getFlags()
9834
- }, t = JSON.stringify(e), n;
10139
+ let e;
9835
10140
  try {
9836
- if (n = await s({
10141
+ if (e = await s({
9837
10142
  joinLink: i,
9838
10143
  isVideo: c,
9839
- internalParams: t
9840
- }, this._abortController?.signal), !n) throw cs(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-response-empty");
9841
- if (!n.internalCallerParams) throw cs(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-internal-caller-params-empty", JSON.stringify(n));
9842
- if (!n.conversationId) throw cs(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-conversation-id-empty", JSON.stringify(n));
10144
+ internalParams: this._buildInternalParams()
10145
+ }, this._abortController?.signal), !e) throw Ts(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-response-empty");
10146
+ if (!e.internalCallerParams) throw Ts(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-internal-caller-params-empty", JSON.stringify(e));
10147
+ if (!e.conversationId) throw Ts(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-conversation-id-empty", JSON.stringify(e));
9843
10148
  } catch (e) {
9844
10149
  throw this._delayedHangup && this._abortController?.signal.aborted ? new O(D.CANCELED) : e instanceof O ? e : e instanceof Error ? new O(D.FAST_JOIN_ERROR, { message: e.message }) : new O(D.FAST_JOIN_ERROR, { message: String(e) });
9845
10150
  }
9846
10151
  try {
9847
- let e = JSON.parse(n.internalCallerParams);
9848
- if (z.has(n.conversationId)) throw new O(D.HAS_ACTIVE_CALL);
10152
+ let t = JSON.parse(e.internalCallerParams);
10153
+ if (z.has(e.conversationId)) throw new O(D.HAS_ACTIVE_CALL);
9849
10154
  l = {
9850
- endpoint: e.endpoint,
9851
- wt_endpoint: e.wtEndpoint,
9852
- id: n.conversationId,
9853
- is_concurrent: e.isConcurrent,
9854
- client_type: e.clientType,
9855
- stun_server: e.stun,
9856
- turn_server: e.turn,
9857
- token: new URL(e.endpoint).searchParams.get("token") ?? ""
10155
+ endpoint: t.endpoint,
10156
+ wt_endpoint: t.wtEndpoint,
10157
+ id: e.conversationId,
10158
+ is_concurrent: t.isConcurrent,
10159
+ client_type: t.clientType,
10160
+ stun_server: t.stun,
10161
+ turn_server: t.turn,
10162
+ token: new URL(t.endpoint).searchParams.get("token") ?? ""
9858
10163
  }, this._debug.debug("FastJoin", l), u = "fastJoin";
9859
10164
  } catch (e) {
9860
- throw e instanceof O ? e : cs(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-internal-caller-params-invalid");
10165
+ throw e instanceof O ? e : Ts(D.FAST_JOIN_ERROR, "invalid-response", "fast-join-internal-caller-params-invalid");
9861
10166
  }
9862
10167
  } else if (t) l = await this._api.joinConversation(t, c, r), u = "joinConversation";
9863
10168
  else if (i) l = await this._api.joinConversationByLink(i, c, a, o), u = "joinConversationByLink";
@@ -10339,7 +10644,7 @@ var ls = 15, $ = class e extends b {
10339
10644
  _onRemoveParticipant(e) {
10340
10645
  this._debug.debug(`Remove participant [${e}]`);
10341
10646
  let t = [], n = this._participants;
10342
- for (let r = 0; r <= ls; r++) {
10647
+ for (let r = 0; r <= Es; r++) {
10343
10648
  let i = n[j.compose(e, r)];
10344
10649
  i && t.push(i);
10345
10650
  }
@@ -10558,7 +10863,7 @@ var ls = 15, $ = class e extends b {
10558
10863
  });
10559
10864
  }
10560
10865
  }
10561
- if (r && r.length && (this._debug.warn("Could not allocate one or more participants", r), t)) throw new ds("Could not allocate one or more participants", r);
10866
+ if (r && r.length && (this._debug.warn("Could not allocate one or more participants", r), t)) throw new Os("Could not allocate one or more participants", r);
10562
10867
  }
10563
10868
  async _cleanupCooldownQueue() {
10564
10869
  let e = {}, t = this._cooldownTimestampByStreamDescription.entries();
@@ -10566,7 +10871,7 @@ var ls = 15, $ = class e extends b {
10566
10871
  let n = t.next();
10567
10872
  if (n.done) break;
10568
10873
  let r = n.value;
10569
- if (r[1] + ss > Date.now()) break;
10874
+ if (r[1] + ws > Date.now()) break;
10570
10875
  let i = r[0];
10571
10876
  await this._stopStreaming(i), e[i] = { stopStream: !0 };
10572
10877
  } while (!0);
@@ -12064,19 +12369,19 @@ var ls = 15, $ = class e extends b {
12064
12369
  _getParticipant(e) {
12065
12370
  return this._participants[e];
12066
12371
  }
12067
- }, us = null, ds = class e extends Error {
12372
+ }, Ds = null, Os = class e extends Error {
12068
12373
  constructor(t, n) {
12069
12374
  super(t), h(this, "participantErrors", void 0), Object.setPrototypeOf(this, e.prototype), this.participantErrors = n;
12070
12375
  }
12071
- }, fs = null, ps = null, ms = 64 * 1024;
12072
- function hs() {
12073
- fs = null, ps = null;
12376
+ }, ks = null, As = null;
12377
+ function js() {
12378
+ ks = null, As = null;
12074
12379
  }
12075
- function gs(e) {
12380
+ function Ms(e) {
12076
12381
  return e?.endsWith("/") ? e.slice(0, -1) : e;
12077
12382
  }
12078
- async function _s(e = null, t) {
12079
- let n = gs(e ?? M.apiBaseUrl);
12383
+ async function Ns(e = null, t) {
12384
+ let n = Ms(e ?? M.apiBaseUrl);
12080
12385
  if (n) return n;
12081
12386
  if ((t ?? M.apiEnv) !== "AUTO") return M.apiEndpoint(t);
12082
12387
  try {
@@ -12091,25 +12396,20 @@ async function _s(e = null, t) {
12091
12396
  return R.warn("Failed to resolve API endpoint using DNS, default is used", e), M.apiEndpoint(t);
12092
12397
  }
12093
12398
  }
12094
- async function vs() {
12095
- return fs || ps || (ps = _s(), fs = await ps, ps = null, fs);
12399
+ async function Ps() {
12400
+ return ks || As || (As = Ns(), ks = await As, As = null, ks);
12096
12401
  }
12097
- async function ys(e, t = {}, n = !1) {
12402
+ async function Fs(e, t = {}, n = !1) {
12098
12403
  if (!window.Blob || !window.navigator.sendBeacon) return;
12099
- await vs();
12100
- let r = Ts(e, t, n), i = new window.Blob([r], { type: "application/x-www-form-urlencoded" });
12101
- window.navigator.sendBeacon(`${fs}/fb.do`, i);
12102
- }
12103
- async function bs(e, t = {}, n = !1, r) {
12104
- return await vs(), Ss(Ts(e, t, n), r);
12404
+ await Ps();
12405
+ let r = Bs(e, t, n), i = new window.Blob([r], { type: "application/x-www-form-urlencoded" });
12406
+ window.navigator.sendBeacon(`${ks}/fb.do`, i);
12105
12407
  }
12106
- async function xs(e, t = {}, n = !1) {
12107
- await vs();
12108
- let r = Ts(e, t, n);
12109
- return Ss(r, void 0, new Blob([r]).size <= ms);
12408
+ async function Is(e, t = {}, n = !1, r) {
12409
+ return await Ps(), Ls(Bs(e, t, n), r);
12110
12410
  }
12111
- async function Ss(e, t, n = !1) {
12112
- let r = `${t ?? fs}/fb.do`, i = new AbortController(), a = new O(x.NETWORK, { callError: {
12411
+ async function Ls(e, t, n = !1) {
12412
+ let r = `${t ?? ks}/fb.do`, i = new AbortController(), a = new O(x.NETWORK, { callError: {
12113
12413
  scope: "network",
12114
12414
  source: "api",
12115
12415
  code: "timeout",
@@ -12128,16 +12428,16 @@ async function Ss(e, t, n = !1) {
12128
12428
  } catch {
12129
12429
  o = { result: a };
12130
12430
  }
12131
- if (!t.ok && !Cs(o)) throw new O(x.API, { callError: {
12431
+ if (!t.ok && !Rs(o)) throw new O(x.API, { callError: {
12132
12432
  scope: "server",
12133
12433
  source: "api",
12134
12434
  code: `http-${t.status}`,
12135
12435
  description: "http-error"
12136
12436
  } });
12137
- if (Cs(o)) throw o;
12437
+ if (Rs(o)) throw o;
12138
12438
  return o;
12139
12439
  } catch (e) {
12140
- throw e instanceof O ? e : i.signal.aborted ? a : Cs(e) ? e : new O(x.NETWORK, { callError: {
12440
+ throw e instanceof O ? e : i.signal.aborted ? a : Rs(e) ? e : new O(x.NETWORK, { callError: {
12141
12441
  scope: "network",
12142
12442
  source: "api",
12143
12443
  code: "fetch-failed",
@@ -12147,12 +12447,12 @@ async function Ss(e, t, n = !1) {
12147
12447
  clearTimeout(o);
12148
12448
  }
12149
12449
  }
12150
- function Cs(e) {
12450
+ function Rs(e) {
12151
12451
  if (typeof e != "object" || !e) return !1;
12152
12452
  let t = e;
12153
12453
  return typeof t.error_code == "number" && typeof t.error_msg == "string";
12154
12454
  }
12155
- async function ws(e, t) {
12455
+ async function zs(e, t) {
12156
12456
  try {
12157
12457
  let n = await fetch(e, {
12158
12458
  method: "POST",
@@ -12165,7 +12465,7 @@ async function ws(e, t) {
12165
12465
  throw R.warn("Failed to send form data", e), e;
12166
12466
  }
12167
12467
  }
12168
- function Ts(e, t = {}, n = !1) {
12468
+ function Bs(e, t = {}, n = !1) {
12169
12469
  t.method = e, t.format = "JSON", t.application_key || (t.application_key = M.apiKey), n || (y.sessionKey ? t.session_key = y.sessionKey : y.accessToken && (t.access_token = y.accessToken));
12170
12470
  for (let [e, n] of Object.entries(t)) typeof n == "object" && (t[e] = JSON.stringify(n));
12171
12471
  let r = "";
@@ -12174,7 +12474,7 @@ function Ts(e, t = {}, n = !1) {
12174
12474
  }
12175
12475
  //#endregion
12176
12476
  //#region src/abstract/BaseApi.ts
12177
- var Es = class {
12477
+ var Vs = class {
12178
12478
  constructor() {
12179
12479
  h(this, "_abortSignal", void 0);
12180
12480
  }
@@ -12191,7 +12491,9 @@ var Es = class {
12191
12491
  return "";
12192
12492
  }
12193
12493
  log(e) {}
12194
- logClientStats(e) {}
12494
+ logClientStats(e) {
12495
+ return Promise.resolve();
12496
+ }
12195
12497
  getCachedOkIdByExternalId(e) {
12196
12498
  return null;
12197
12499
  }
@@ -12217,7 +12519,7 @@ var Es = class {
12217
12519
  async getInbounds() {
12218
12520
  return [];
12219
12521
  }
12220
- }, Ds = class e {
12522
+ }, Hs = class e {
12221
12523
  constructor() {
12222
12524
  h(this, "_okIdToExternalId", /* @__PURE__ */ new Map()), h(this, "_externalIdToOkId", /* @__PURE__ */ new Map()), h(this, "_decorativeIdToInitialId", /* @__PURE__ */ new Map()), h(this, "_initialIdToDecorativeId", /* @__PURE__ */ new Map());
12223
12525
  }
@@ -12268,27 +12570,27 @@ var Es = class {
12268
12570
  clear() {
12269
12571
  this._okIdToExternalId.clear(), this._externalIdToOkId.clear(), this._decorativeIdToInitialId.clear(), this._initialIdToDecorativeId.clear();
12270
12572
  }
12271
- }, Os = "anonymLogin:", ks = 700, As = 3e3;
12272
- function js(e) {
12573
+ }, Us = "anonymLogin:", Ws = 700, Gs = 3e3;
12574
+ function Ks(e) {
12273
12575
  let t = e.error_code;
12274
12576
  switch (t) {
12275
- case 2: return Ms(D.SERVICE_UNAVAILABLE, t, "service-unavailable");
12276
- case 4: return e.error_msg.includes("participants.limit.exceeded") ? Ms(D.PARTICIPANT_LIMIT_REACHED, t, "participants-limit-exceeded") : Ms(x.API, t, "request-error");
12277
- case 300: return Ms(D.NOT_FOUND, t, "not-found");
12278
- case 1101: return Ms(D.SERVICE_DISABLED, t, "vchat-service-disabled");
12279
- case 1102: return Ms(D.CALLEE_IS_OFFLINE, t, "target-user-unavailable");
12280
- case 1103: return Ms(D.NOT_FRIENDS, t, "friendship-required");
12281
- case 1104: return Ns(t, "youla-api-error");
12282
- case 1106: return Ns(t, "vk-api-error");
12283
- case 1113: return Ms(D.CALLER_IS_REJECTED, t, "caller-is-rejected");
12577
+ case 2: return qs(D.SERVICE_UNAVAILABLE, t, "service-unavailable");
12578
+ case 4: return e.error_msg.includes("participants.limit.exceeded") ? qs(D.PARTICIPANT_LIMIT_REACHED, t, "participants-limit-exceeded") : qs(x.API, t, "request-error");
12579
+ case 300: return qs(D.NOT_FOUND, t, "not-found");
12580
+ case 1101: return qs(D.SERVICE_DISABLED, t, "vchat-service-disabled");
12581
+ case 1102: return qs(D.CALLEE_IS_OFFLINE, t, "target-user-unavailable");
12582
+ case 1103: return qs(D.NOT_FRIENDS, t, "friendship-required");
12583
+ case 1104: return Js(t, "youla-api-error");
12584
+ case 1106: return Js(t, "vk-api-error");
12585
+ case 1113: return qs(D.CALLER_IS_REJECTED, t, "caller-is-rejected");
12284
12586
  case 1114: {
12285
12587
  let n = e.custom_error?.vchat_detailed_api_error?.code, r = n?.startsWith("obsolete_client");
12286
- return Ms(r ? D.OBSOLETE_CLIENT : D.VCHAT_DETAILED_ERROR, t, n ?? "detailed-error", r ? n : void 0);
12588
+ return qs(r ? D.OBSOLETE_CLIENT : D.VCHAT_DETAILED_ERROR, t, n ?? "detailed-error", r ? n : void 0);
12287
12589
  }
12288
- default: return Ms(x.API, t, "api-error");
12590
+ default: return qs(x.API, t, "api-error");
12289
12591
  }
12290
12592
  }
12291
- function Ms(e, t, n, r) {
12593
+ function qs(e, t, n, r) {
12292
12594
  return {
12293
12595
  type: e,
12294
12596
  callError: {
@@ -12300,7 +12602,7 @@ function Ms(e, t, n, r) {
12300
12602
  message: r
12301
12603
  };
12302
12604
  }
12303
- function Ns(e, t) {
12605
+ function Js(e, t) {
12304
12606
  return {
12305
12607
  type: D.EXTERNAL_API_ERROR,
12306
12608
  callError: {
@@ -12311,19 +12613,19 @@ function Ns(e, t) {
12311
12613
  }
12312
12614
  };
12313
12615
  }
12314
- var Ps = class extends Es {
12616
+ var Ys = class extends Vs {
12315
12617
  constructor(...e) {
12316
- super(...e), h(this, "_uuid", void 0), h(this, "_idCache", new Ds());
12618
+ super(...e), h(this, "_uuid", void 0), h(this, "_idCache", new Hs());
12317
12619
  }
12318
12620
  async _callUnsafe(e, t = {}, n = !1) {
12319
12621
  let r = async (i) => {
12320
12622
  try {
12321
- return await bs(e, t, n);
12623
+ return await Is(e, t, n);
12322
12624
  } catch (t) {
12323
12625
  if (!t || typeof t != "object" || !Object.hasOwn(t, "error_msg")) {
12324
12626
  i++;
12325
12627
  let n = t && (typeof t == "object" || typeof t == "function") ? Object.getOwnPropertyNames(t).map((e) => `${e}: ${JSON.stringify(t[e])}`) : [String(t)];
12326
- if (R.debug(`${e} network error, attempt ${i}: ${n.join("\n ")}`), this._abortSignal?.aborted && (R.debug(`${e} aborted`), this._abortSignal.throwIfAborted()), i < M.apiMaxAttempt) return await j.delay(Math.min(i * ks, As), { signal: this._abortSignal }), r(i);
12628
+ if (R.debug(`${e} network error, attempt ${i}: ${n.join("\n ")}`), this._abortSignal?.aborted && (R.debug(`${e} aborted`), this._abortSignal.throwIfAborted()), i < M.apiMaxAttempt) return await j.delay(Math.min(i * Ws, Gs), { signal: this._abortSignal }), r(i);
12327
12629
  }
12328
12630
  throw R.warn(e, "error", t), t;
12329
12631
  }
@@ -12336,9 +12638,9 @@ var Ps = class extends Es {
12336
12638
  } catch (i) {
12337
12639
  if (R.warn("Api call error", i), i instanceof O) throw i;
12338
12640
  switch (i?.error_code) {
12339
- case 102:
12340
- case 103:
12341
- case 104:
12641
+ case Fo.PARAM_SESSION_EXPIRED:
12642
+ case Fo.PARAM_SESSION_KEY:
12643
+ case Fo.PARAM_SIGNATURE:
12342
12644
  if (!r) break;
12343
12645
  return await this._reauthorize(), this._call(e, t, n, !1);
12344
12646
  }
@@ -12346,8 +12648,8 @@ var Ps = class extends Es {
12346
12648
  message: i?.error_msg,
12347
12649
  code: i?.error_code
12348
12650
  };
12349
- if (i.custom_error && (a.custom_error = i.custom_error), Fs(i)) {
12350
- let e = js(i);
12651
+ if (i.custom_error && (a.custom_error = i.custom_error), Xs(i)) {
12652
+ let e = Ks(i);
12351
12653
  throw a.callError = e.callError, a.message = e.message ?? a.message, new O(e.type, a);
12352
12654
  }
12353
12655
  throw new O(x.API, a);
@@ -12380,7 +12682,7 @@ var Ps = class extends Es {
12380
12682
  return M.authToken && (t.session_data.auth_token = M.authToken, t.session_data.version = 3), this._callUnsafe("auth.anonymLogin", t, !0).then((e) => {
12381
12683
  this._applyAnonymLogin(e), this._setCachedAnonymLogin(e);
12382
12684
  }).catch((e) => {
12383
- throw e instanceof O ? e : (e?.error_code === 401 && (this._removeCachedAnonymLogin(), L.onTokenExpired()), new O(x.AUTH, {
12685
+ throw e instanceof O ? e : (e?.error_code === Fo.AUTH_LOGIN && (this._removeCachedAnonymLogin(), L.onTokenExpired()), new O(x.AUTH, {
12384
12686
  message: e?.error_msg,
12385
12687
  code: e?.error_code,
12386
12688
  callError: {
@@ -12393,17 +12695,17 @@ var Ps = class extends Es {
12393
12695
  });
12394
12696
  }
12395
12697
  _getAnonymLoginCacheKey() {
12396
- return M.authToken ? `${Os}${M.authToken}` : null;
12698
+ return M.authToken ? `${Us}${M.authToken}` : null;
12397
12699
  }
12398
12700
  _getCachedAnonymLogin() {
12399
12701
  let e = this._getAnonymLoginCacheKey();
12400
12702
  if (!e) return null;
12401
12703
  let t = at.get(e);
12402
- return Is(t) ? t : (t && at.remove(e), null);
12704
+ return Zs(t) ? t : (t && at.remove(e), null);
12403
12705
  }
12404
12706
  _setCachedAnonymLogin(e) {
12405
12707
  let t = this._getAnonymLoginCacheKey();
12406
- !t || !Is(e) || at.set(t, {
12708
+ !t || !Zs(e) || at.set(t, {
12407
12709
  session_key: e.session_key,
12408
12710
  session_secret_key: e.session_secret_key,
12409
12711
  uid: e.uid
@@ -12421,16 +12723,16 @@ var Ps = class extends Es {
12421
12723
  }
12422
12724
  async _sendClientStats(e, t = !0) {
12423
12725
  try {
12424
- (await xs("vchat.clientStats", e))?.items_responses?.forEach((e) => {
12726
+ (await Is("vchat.clientStats", e))?.items_responses?.forEach((e) => {
12425
12727
  e.errors && R.error("[vchat.clientStats]", e);
12426
12728
  });
12427
12729
  } catch (n) {
12428
- let r = n?.error_code === 102 || n?.error_code === 103 || n?.error_code === 104;
12730
+ let r = n?.error_code === Fo.PARAM_SESSION_EXPIRED || n?.error_code === Fo.PARAM_SESSION_KEY || n?.error_code === Fo.PARAM_SIGNATURE;
12429
12731
  if (!t || !r) throw n;
12430
12732
  await this._reauthorize(), await this._sendClientStats(e, !1);
12431
12733
  }
12432
12734
  }
12433
- logClientStats(e) {
12735
+ async logClientStats(e) {
12434
12736
  let t = {
12435
12737
  app_version: String(M.appVersion),
12436
12738
  sdk_type: "WEB",
@@ -12440,7 +12742,7 @@ var Ps = class extends Es {
12440
12742
  };
12441
12743
  M.clientStatsPlatform && (t.platform = M.clientStatsPlatform);
12442
12744
  let n = { data: JSON.stringify(t) };
12443
- this._sendClientStats(n).catch((e) => R.error("[vchat.clientStats]", e));
12745
+ await this._sendClientStats(n);
12444
12746
  }
12445
12747
  async uploadDebugLogs(e, t, n, r) {
12446
12748
  let i = {
@@ -12451,7 +12753,7 @@ var Ps = class extends Es {
12451
12753
  }, a = await this._callUnsafe("vchat.getLogUploadUrl", i), o = new FormData(), s = new Blob([r], { type: "application/json" });
12452
12754
  o.append("file", s, "log.json");
12453
12755
  let c = new URL(a.upload_url);
12454
- return c.searchParams.append("size", s.size.toString()), ws(c.toString(), o);
12756
+ return c.searchParams.append("size", s.size.toString()), zs(c.toString(), o);
12455
12757
  }
12456
12758
  async joinConversation(e, t = !1, n) {
12457
12759
  let r = {
@@ -12582,7 +12884,7 @@ var Ps = class extends Es {
12582
12884
  conversationId: e,
12583
12885
  reason: t
12584
12886
  };
12585
- M.anonymToken && (r.anonymToken = M.anonymToken), n?.peerId && (r.peerId = n.peerId), ys("vchat.hangupConversation", r);
12887
+ M.anonymToken && (r.anonymToken = M.anonymToken), n?.peerId && (r.peerId = n.peerId), Fs("vchat.hangupConversation", r);
12586
12888
  }
12587
12889
  async removeHistoryRecords(e) {
12588
12890
  await this._call("vchat.removeHistoryRecords", { recordIds: e.join(",") });
@@ -12598,19 +12900,19 @@ var Ps = class extends Es {
12598
12900
  return Array.isArray(e?.inbounds) ? e.inbounds : [];
12599
12901
  }
12600
12902
  };
12601
- function Fs(e) {
12903
+ function Xs(e) {
12602
12904
  return typeof e == "object" && !!e && "error_code" in e && "error_msg" in e;
12603
12905
  }
12604
- function Is(e) {
12906
+ function Zs(e) {
12605
12907
  return typeof e == "object" && !!e && "session_key" in e && "session_secret_key" in e && typeof e.session_key == "string" && e.session_key.length > 0 && typeof e.session_secret_key == "string" && e.session_secret_key.length > 0;
12606
12908
  }
12607
12909
  //#endregion
12608
12910
  //#region src/enums/RecordRole.ts
12609
- var Ls = /* @__PURE__ */ function(e) {
12911
+ var Qs = /* @__PURE__ */ function(e) {
12610
12912
  return e.KING = "KING", e.PAWN = "PAWN", e;
12611
- }(Ls || {}), Rs = /* @__PURE__ */ function(e) {
12913
+ }(Qs || {}), $s = /* @__PURE__ */ function(e) {
12612
12914
  return e.OFF = "0", e.ON = "1", e;
12613
- }({}), zs = class {
12915
+ }({}), ec = class {
12614
12916
  constructor(e) {
12615
12917
  h(this, "_queue", void 0), h(this, "_readCursor", void 0), h(this, "_writeCursor", void 0), h(this, "_moveReadCursor", void 0), h(this, "_left", void 0), this._queue = Array(e).fill(null), this._readCursor = this._writeCursor = this._left = 0, this._moveReadCursor = !1;
12616
12918
  }
@@ -12633,12 +12935,12 @@ var Ls = /* @__PURE__ */ function(e) {
12633
12935
  let e = this._queue[this._readCursor];
12634
12936
  return e && (this._moveReadCursor = !1, this._queue[this._readCursor] = null, this._readCursor = this.nextCursor(this._readCursor), --this._left), e;
12635
12937
  }
12636
- }, Bs = class {
12938
+ }, tc = class {
12637
12939
  constructor(e, t, n, r = null) {
12638
12940
  h(this, "_uuid", void 0), h(this, "_apiKey", void 0), h(this, "_callToken", void 0), h(this, "_apiEnv", void 0), h(this, "_baseApiUrl", void 0), h(this, "_sessionKey", void 0), this._uuid = j.uuid(), this._apiKey = t, this._callToken = n, this._apiEnv = e, this._baseApiUrl = r;
12639
12941
  }
12640
12942
  async authorize() {
12641
- let e = await bs("auth.anonymLogin", {
12943
+ let e = await Is("auth.anonymLogin", {
12642
12944
  session_data: {
12643
12945
  device_id: this._uuid,
12644
12946
  client_version: M.appVersion,
@@ -12647,7 +12949,7 @@ var Ls = /* @__PURE__ */ function(e) {
12647
12949
  version: 3
12648
12950
  },
12649
12951
  application_key: this._apiKey
12650
- }, !0, await _s(this._baseApiUrl, this._apiEnv));
12952
+ }, !0, await Ns(this._baseApiUrl, this._apiEnv));
12651
12953
  return j.isObject(e) && !("error_msg" in e) ? (this._sessionKey = e.session_key, !0) : !1;
12652
12954
  }
12653
12955
  async hangupConversation(e, t) {
@@ -12657,9 +12959,9 @@ var Ls = /* @__PURE__ */ function(e) {
12657
12959
  application_key: this._apiKey,
12658
12960
  session_key: this._sessionKey
12659
12961
  };
12660
- t?.peerId && (n.peerId = t.peerId), await bs("vchat.hangupConversation", n, !0, await _s(this._baseApiUrl, this._apiEnv));
12962
+ t?.peerId && (n.peerId = t.peerId), await Is("vchat.hangupConversation", n, !0, await Ns(this._baseApiUrl, this._apiEnv));
12661
12963
  }
12662
- }, Vs, Hs = null, Us = {
12964
+ }, nc, rc = null, ic = !1, ac = {
12663
12965
  getCameras: T.getCameras,
12664
12966
  getMicrophones: T.getMicrophones,
12665
12967
  getOutput: T.getOutput,
@@ -12685,27 +12987,27 @@ var Ls = /* @__PURE__ */ function(e) {
12685
12987
  baseChromeVersion: T.baseChromeVersion,
12686
12988
  getAudioContext: T.getAudioContext,
12687
12989
  isAudioShareSupported: T.isAudioShareSupported
12688
- }, Ws = { participantMarkerCompare: j.participantMarkerCompare };
12689
- function Gs(e) {
12690
- Hs = e;
12990
+ }, oc = { participantMarkerCompare: j.participantMarkerCompare };
12991
+ function sc(e) {
12992
+ rc = e;
12691
12993
  }
12692
- function Ks(e) {
12994
+ function cc(e) {
12693
12995
  M.videoEffects = e;
12694
12996
  }
12695
- function qs(e) {
12997
+ function lc(e) {
12696
12998
  M.audioEffects = e;
12697
12999
  }
12698
- function Js(e, t = {}) {
13000
+ function uc(e, t = {}) {
12699
13001
  M.vad = e, M.vadOptions = t;
12700
13002
  }
12701
- function Ys(e, t = null, n = {}, r = 1) {
13003
+ function dc(e, t = null, n = {}, r = 1) {
12702
13004
  M.vmoji = e, M.vmojiOptions = {
12703
13005
  protocolVersion: r,
12704
13006
  renderingOptions: n
12705
13007
  }, t && e.setSDK(t);
12706
13008
  }
12707
- async function Xs(t) {
12708
- M.set(t), Vs || (Vs = new Ps()), e.disableLog(!M.debug), R.toggle(M.debug), R.log(`Calls SDK ${M.sdkVersion}`, t), await T.init();
13009
+ async function fc(t) {
13010
+ M.set(t), nc || (nc = new Ys()), M.autoStartStats && vc(), e.disableLog(!M.debug), R.toggle(M.debug), R.log(`Calls SDK ${M.sdkVersion}`, t), await T.init();
12709
13011
  let n = T.getBrowserSupportFailure();
12710
13012
  if (n) throw new O(x.UNSUPPORTED, { callError: {
12711
13013
  scope: "internal",
@@ -12714,13 +13016,13 @@ async function Xs(t) {
12714
13016
  } });
12715
13017
  R.log("UserAgent:", navigator.userAgent), R.log("Screen resolution:", `${window.screen.width}x${window.screen.height}`), R.log("Permissions:", `Camera: ${T.hasCameraPermission()}, Mic: ${T.hasMicrophonePermission()}`), R.log("Simulcast:", `${t.simulcast} => ${M.simulcast}`);
12716
13018
  }
12717
- async function Zs(e, t = [S.AUDIO], n = "", r = !1, i = !1, a, o, s) {
13019
+ async function pc(e, t = [S.AUDIO], n = "", r = !1, i = !1, a, o, s) {
12718
13020
  let c = [];
12719
- return Array.isArray(e) ? c = e.length ? e : [] : e && (c = [e]), Qs([], Va.USER, t, n, r, i, a, c, o, s);
13021
+ return Array.isArray(e) ? c = e.length ? e : [] : e && (c = [e]), mc([], Va.USER, t, n, r, i, a, c, o, s);
12720
13022
  }
12721
- async function Qs(e, t = Va.USER, n, r = "", i = !1, a = !1, o, s, c, l) {
13023
+ async function mc(e, t = Va.USER, n, r = "", i = !1, a = !1, o, s, c, l) {
12722
13024
  if (!M.hold && z.callsLength > 0) throw R.error("There is already active call"), new O(D.HAS_ACTIVE_CALL);
12723
- return new $(new Ps(), Hs).onStart({
13025
+ return new $(new Ys(), rc).onStart({
12724
13026
  opponentIds: e,
12725
13027
  opponentType: t,
12726
13028
  mediaOptions: n,
@@ -12733,40 +13035,47 @@ async function Qs(e, t = Va.USER, n, r = "", i = !1, a = !1, o, s, c, l) {
12733
13035
  conversationId: l
12734
13036
  });
12735
13037
  }
12736
- async function $s(e, t) {
12737
- return ec(e, A.USER, void 0, t);
13038
+ async function hc(e, t) {
13039
+ return gc(e, A.USER, void 0, t);
12738
13040
  }
12739
- async function ec(e, t = A.USER, n, r, i, a) {
13041
+ async function gc(e, t = A.USER, n, r, i, a) {
12740
13042
  if (e === $.id()) throw Error("Push has already been processed");
12741
- return new $(new Ps(), Hs).onPush(e, t, n, r, i, a);
13043
+ return new $(new Ys(), rc).onPush(e, t, n, r, i, a);
13044
+ }
13045
+ async function _c() {
13046
+ return nc.getInbounds();
12742
13047
  }
12743
- async function tc() {
12744
- return Vs.getInbounds();
13048
+ function vc() {
13049
+ if (!nc) {
13050
+ R.error("[CallsSDK] startStats() called before init()");
13051
+ return;
13052
+ }
13053
+ ic || (ic = !0, Zo.start(nc));
12745
13054
  }
12746
- async function nc(e, t) {
12747
- return e && (M.authToken = e), t !== void 0 && M.apiBaseUrl !== t && (M.apiBaseUrl = t, hs()), Vs.authorize();
13055
+ async function yc(e, t) {
13056
+ return e && (M.authToken = e), t !== void 0 && M.apiBaseUrl !== t && (M.apiBaseUrl = t, js()), nc.authorize();
12748
13057
  }
12749
- async function rc(e = [S.AUDIO], t) {
12750
- return El(t).accept(e);
13058
+ async function bc(e = [S.AUDIO], t) {
13059
+ return Ul(t).accept(e);
12751
13060
  }
12752
- async function ic(e, t) {
12753
- let n = Tl(e);
12754
- if (n) return n.decline(t?.reason);
13061
+ async function xc(e) {
13062
+ let t = Hl(e?.conversationId);
13063
+ if (t) return t.decline(e);
12755
13064
  }
12756
- async function ac(e, t = [S.AUDIO]) {
12757
- return oc(e, t);
13065
+ async function Sc(e, t = [S.AUDIO]) {
13066
+ return Cc(e, t);
12758
13067
  }
12759
- async function oc(e, t, n) {
13068
+ async function Cc(e, t, n) {
12760
13069
  if (!M.hold && z.callsLength > 0) throw R.error("There is already active call"), new O(D.HAS_ACTIVE_CALL);
12761
- return new $(new Ps(), Hs).onJoin({
13070
+ return new $(new Ys(), rc).onJoin({
12762
13071
  conversationId: e,
12763
13072
  mediaOptions: t,
12764
13073
  chatId: n
12765
13074
  });
12766
13075
  }
12767
- async function sc(e, t = [S.AUDIO], n, r, i, a) {
13076
+ async function wc(e, t = [S.AUDIO], n, r, i, a) {
12768
13077
  if (!M.hold && z.callsLength > 0) throw R.error("There is already active call"), new O(D.HAS_ACTIVE_CALL);
12769
- return n && (M.anonymToken = n), new $(new Ps(), Hs).onJoin({
13078
+ return n && (M.anonymToken = n), new $(new Ys(), rc).onJoin({
12770
13079
  joinLink: e,
12771
13080
  mediaOptions: t,
12772
13081
  observedIds: r,
@@ -12775,30 +13084,30 @@ async function sc(e, t = [S.AUDIO], n, r, i, a) {
12775
13084
  anonymous: !!M.anonymToken
12776
13085
  });
12777
13086
  }
12778
- function cc(e, t) {
12779
- let n = Tl(e);
12780
- return n ? n.hangup(t?.reason) : ($.hangupAfterInit(), Promise.resolve());
13087
+ function Tc(e) {
13088
+ let t = Hl(e?.conversationId);
13089
+ return t ? t.hangup(e) : ($.hangupAfterInit(e?.onFastHangup), Promise.resolve());
12781
13090
  }
12782
- async function lc(e, t) {
13091
+ async function Ec(e, t) {
12783
13092
  let n = Array.isArray(e) ? e : [e], r = $.current();
12784
13093
  r && await r.addParticipant(n, t);
12785
13094
  }
12786
- async function uc(e, t) {
13095
+ async function Dc(e, t) {
12787
13096
  let n = $.current();
12788
13097
  if (n) {
12789
13098
  let r = e.map((e) => j.composeUserId(e));
12790
13099
  await n.addParticipantLegacy(r, t);
12791
13100
  }
12792
13101
  }
12793
- async function dc(e, t = !1) {
13102
+ async function Oc(e, t = !1) {
12794
13103
  let n = $.current()?.getCachedRawOkIdByExternalId(e) ?? null;
12795
13104
  if (!n) {
12796
13105
  R.warn("removeParticipant: externalId not found in cache", e);
12797
13106
  return;
12798
13107
  }
12799
- return fc(n, t);
13108
+ return kc(n, t);
12800
13109
  }
12801
- async function fc(e, t = !1) {
13110
+ async function kc(e, t = !1) {
12802
13111
  let n = $.current();
12803
13112
  if (n) try {
12804
13113
  await n.removeParticipant(j.composeUserId(e), t);
@@ -12806,13 +13115,13 @@ async function fc(e, t = !1) {
12806
13115
  R.warn(`Failed to remove participant ${e}. Perhaps he is no longer on the call. ${t}`);
12807
13116
  }
12808
13117
  }
12809
- async function pc(e, t) {
13118
+ async function Ac(e, t) {
12810
13119
  let n = $.current();
12811
13120
  if (e === "videoinput" && jt.contains(t)) return M.videoFacingMode = t, n ? (T.isMobile() && n.stopVideoTrack(), n.changeDevice(e)) : void 0;
12812
13121
  if (!await T._saveDeviceId(e, t)) throw Error(`Device not found: ${t}`);
12813
13122
  if (n) return n.changeDevice(e);
12814
13123
  }
12815
- async function mc(e, t) {
13124
+ async function jc(e, t) {
12816
13125
  let n = typeof e == "object" ? {
12817
13126
  ...e,
12818
13127
  fastScreenSharing: e.captureScreen && e.fastScreenSharing,
@@ -12821,34 +13130,34 @@ async function mc(e, t) {
12821
13130
  captureScreen: e,
12822
13131
  fastScreenSharing: !1,
12823
13132
  captureAudio: !1
12824
- }, r = Tl(t);
13133
+ }, r = Hl(t);
12825
13134
  return r ? r.toggleScreenCapturing(n) : Promise.reject();
12826
13135
  }
12827
- function hc(e) {
13136
+ function Mc(e) {
12828
13137
  let t = $.current();
12829
13138
  t && t.toggleAnimojiCapturing(e);
12830
13139
  }
12831
- async function gc(e, t = !1) {
13140
+ async function Nc(e, t = !1) {
12832
13141
  let n = $.current();
12833
13142
  n && await n.setVideoStream(e, t);
12834
13143
  }
12835
- async function _c(e, t) {
12836
- let n = Tl(t);
13144
+ async function Pc(e, t) {
13145
+ let n = Hl(t);
12837
13146
  n && await n.toggleLocalVideo(e);
12838
13147
  }
12839
- async function vc(e, t) {
12840
- let n = Tl(t);
13148
+ async function Fc(e, t) {
13149
+ let n = Hl(t);
12841
13150
  n && await n.toggleLocalAudio(e);
12842
13151
  }
12843
- async function yc(e) {
13152
+ async function Ic(e) {
12844
13153
  let t = $.current();
12845
13154
  if (t) return t.setLocalResolution(e);
12846
13155
  }
12847
- async function bc(e) {
13156
+ async function Lc(e) {
12848
13157
  let t = $.current();
12849
13158
  t && await t.changePriorities(e);
12850
13159
  }
12851
- async function xc(e, t) {
13160
+ async function Rc(e, t) {
12852
13161
  let n = $.current();
12853
13162
  if (n) {
12854
13163
  let r;
@@ -12863,33 +13172,33 @@ async function xc(e, t) {
12863
13172
  await n.changeParticipantState(e, r);
12864
13173
  }
12865
13174
  }
12866
- async function Sc() {
13175
+ async function zc() {
12867
13176
  let e = $.current();
12868
13177
  e && await e.putHandsDown();
12869
13178
  }
12870
- async function Cc(e) {
13179
+ async function Bc(e) {
12871
13180
  let t = $.current();
12872
13181
  t && await t.updateDisplayLayout(e);
12873
13182
  }
12874
- async function wc(e) {
13183
+ async function Vc(e) {
12875
13184
  let t = $.current();
12876
13185
  t && await t.requestDisplayLayout(e);
12877
13186
  }
12878
- async function Tc(e, t, n = !1) {
13187
+ async function Hc(e, t, n = !1) {
12879
13188
  let r = $.current()?.getCachedRawOkIdByExternalId(e) ?? null;
12880
13189
  if (!r) {
12881
13190
  R.warn("grantRoles: externalId not found in cache", e);
12882
13191
  return;
12883
13192
  }
12884
- return Ec(r, Q.getDeviceIdx(e), t, n);
13193
+ return Uc(r, Q.getDeviceIdx(e), t, n);
12885
13194
  }
12886
- async function Ec(e, t, n, r = !1) {
13195
+ async function Uc(e, t, n, r = !1) {
12887
13196
  let i = $.current();
12888
13197
  i && await i.grantRoles(j.composeParticipantId(e, A.USER, t), n, r);
12889
13198
  }
12890
- async function Dc({ externalId: e = null, muteStates: t, requestedMedia: n = [], roomId: r = null }) {
13199
+ async function Wc({ externalId: e = null, muteStates: t, requestedMedia: n = [], roomId: r = null }) {
12891
13200
  let i = null;
12892
- return e && (i = $.current()?.getCachedRawOkIdByExternalId(e) ?? null, i || R.warn("muteParticipant: externalId not found in cache", e)), Oc({
13201
+ return e && (i = $.current()?.getCachedRawOkIdByExternalId(e) ?? null, i || R.warn("muteParticipant: externalId not found in cache", e)), Gc({
12893
13202
  uid: i,
12894
13203
  muteStates: t,
12895
13204
  requestedMedia: n,
@@ -12897,129 +13206,129 @@ async function Dc({ externalId: e = null, muteStates: t, requestedMedia: n = [],
12897
13206
  roomId: r
12898
13207
  });
12899
13208
  }
12900
- async function Oc({ uid: e = null, muteStates: t, requestedMedia: n = [], deviceIdx: r = 0, roomId: i = null }) {
13209
+ async function Gc({ uid: e = null, muteStates: t, requestedMedia: n = [], deviceIdx: r = 0, roomId: i = null }) {
12901
13210
  let a = $.current();
12902
13211
  if (a) {
12903
13212
  let o = e ? j.composeParticipantId(e, A.USER, r) : null;
12904
13213
  await a.muteParticipant(o, t, n, i);
12905
13214
  }
12906
13215
  }
12907
- async function kc(e, t = !1, n = null) {
13216
+ async function Kc(e, t = !1, n = null) {
12908
13217
  let r = $.current()?.getCachedRawOkIdByExternalId(e) ?? null;
12909
13218
  if (!r) {
12910
13219
  R.warn("pinParticipant: externalId not found in cache", e);
12911
13220
  return;
12912
13221
  }
12913
- return Ac(r, t, Q.getDeviceIdx(e), n);
13222
+ return qc(r, t, Q.getDeviceIdx(e), n);
12914
13223
  }
12915
- async function Ac(e, t = !1, n = 0, r = null) {
13224
+ async function qc(e, t = !1, n = 0, r = null) {
12916
13225
  let i = $.current();
12917
13226
  i && await i.pinParticipant(j.composeParticipantId(e, A.USER, n), t, r);
12918
13227
  }
12919
- async function jc(e) {
13228
+ async function Jc(e) {
12920
13229
  let t = $.current();
12921
13230
  t && await t.updateMediaModifiers(e);
12922
13231
  }
12923
- async function Mc(e) {
13232
+ async function Yc(e) {
12924
13233
  let t = $.current();
12925
13234
  t && await t.enableVideoSuspend(e);
12926
13235
  }
12927
- async function Nc(e) {
13236
+ async function Xc(e) {
12928
13237
  let t = $.current();
12929
13238
  t && await t.enableVideoSuspendSuggest(e);
12930
13239
  }
12931
- async function Pc(e) {
13240
+ async function Zc(e) {
12932
13241
  let t = $.current();
12933
13242
  t && await t.changeOptions(e);
12934
13243
  }
12935
- async function Fc(e, t = null) {
13244
+ async function Qc(e, t = null) {
12936
13245
  let n = null;
12937
- return t && (n = $.current()?.getCachedRawOkIdByExternalId(t) ?? null, n || R.warn("chatMessage: externalId not found in cache", t)), Ic(e, n);
13246
+ return t && (n = $.current()?.getCachedRawOkIdByExternalId(t) ?? null, n || R.warn("chatMessage: externalId not found in cache", t)), $c(e, n);
12938
13247
  }
12939
- async function Ic(e, t = null) {
13248
+ async function $c(e, t = null) {
12940
13249
  let n = $.current();
12941
13250
  if (n) {
12942
13251
  let r = t ? j.composeUserId(t) : null;
12943
13252
  await n.chatMessage(e, r);
12944
13253
  }
12945
13254
  }
12946
- async function Lc(e = 10) {
13255
+ async function el(e = 10) {
12947
13256
  let t = $.current();
12948
13257
  if (t) return t.chatHistory(e);
12949
13258
  }
12950
- async function Rc(e, t = null) {
13259
+ async function tl(e, t = null) {
12951
13260
  let n = null;
12952
- return t && (n = $.current()?.getCachedRawOkIdByExternalId(t) ?? null, n || R.warn("customData: externalId not found in cache", t)), zc(e, n, Q.getDeviceIdx(t));
13261
+ return t && (n = $.current()?.getCachedRawOkIdByExternalId(t) ?? null, n || R.warn("customData: externalId not found in cache", t)), nl(e, n, Q.getDeviceIdx(t));
12953
13262
  }
12954
- async function zc(e, t = null, n = 0) {
13263
+ async function nl(e, t = null, n = 0) {
12955
13264
  let r = $.current();
12956
13265
  if (r) {
12957
13266
  let i = t ? j.composeParticipantId(t, A.USER, n) : null;
12958
13267
  await r.customData(e, i);
12959
13268
  }
12960
13269
  }
12961
- async function Bc(e = "", t = !1, { onlyAdminCanShareMovie: n = !1, waitForAdmin: r = !1, closedConversation: i = !1 } = {}, a) {
12962
- return (await Vs.createConversation(a ?? j.uuid(), e, t, {
13270
+ async function rl(e = "", t = !1, { onlyAdminCanShareMovie: n = !1, waitForAdmin: r = !1, closedConversation: i = !1 } = {}, a) {
13271
+ return (await nc.createConversation(a ?? j.uuid(), e, t, {
12963
13272
  onlyAdminCanShareMovie: n,
12964
13273
  waitForAdmin: r,
12965
13274
  closedConversation: i
12966
13275
  })).join_link;
12967
13276
  }
12968
- async function Vc(e = "", t = !1, { onlyAdminCanShareMovie: n = !1, audioOnly: r = !1 } = {}, i) {
13277
+ async function il(e = "", t = !1, { onlyAdminCanShareMovie: n = !1, audioOnly: r = !1 } = {}, i) {
12969
13278
  let a = i.map((e) => Q.fromId(e));
12970
- return (await Vs.createConversation(j.uuid(), e, t, {
13279
+ return (await nc.createConversation(j.uuid(), e, t, {
12971
13280
  onlyAdminCanShareMovie: n,
12972
13281
  audienceMode: !0,
12973
13282
  audioOnly: r
12974
13283
  }, a)).join_link;
12975
13284
  }
12976
- async function Hc() {
13285
+ async function al() {
12977
13286
  let e = $.current();
12978
13287
  return e ? e.createJoinLink() : Promise.reject();
12979
13288
  }
12980
- async function Uc() {
13289
+ async function ol() {
12981
13290
  let e = $.current();
12982
13291
  return e ? e.removeJoinLink() : Promise.reject();
12983
13292
  }
12984
- async function Wc(e, t) {
12985
- return Vs.getAnonymTokenByLink(e, t);
13293
+ async function sl(e, t) {
13294
+ return nc.getAnonymTokenByLink(e, t);
12986
13295
  }
12987
- function Gc(e) {
13296
+ function cl(e) {
12988
13297
  let t = $.current();
12989
13298
  t && t.setVolume(e);
12990
13299
  }
12991
- function Kc(e) {
13300
+ function ll(e) {
12992
13301
  M.forceRelayPolicy = e;
12993
13302
  }
12994
- async function qc(e = !1, t = null, n = null, r = "DIRECT_LINK", i = null, a = null) {
13303
+ async function ul(e = !1, t = null, n = null, r = "DIRECT_LINK", i = null, a = null) {
12995
13304
  let o = $.current();
12996
13305
  return o ? o.startStream(e, t, n, r, i, a) : Promise.reject();
12997
13306
  }
12998
- async function Jc(e = null, t) {
13307
+ async function dl(e = null, t) {
12999
13308
  let n = $.current();
13000
13309
  return n ? n.stopStream(e, t) : Promise.reject();
13001
13310
  }
13002
- async function Yc(e = null) {
13311
+ async function fl(e = null) {
13003
13312
  let t = $.current();
13004
13313
  return t ? t.publishStream(e) : Promise.reject();
13005
13314
  }
13006
- async function Xc() {
13315
+ async function pl() {
13007
13316
  let e = $.current();
13008
13317
  return e ? e.getStreamInfo() : Promise.reject();
13009
13318
  }
13010
- async function Zc(e) {
13319
+ async function ml(e) {
13011
13320
  let t = $.current();
13012
13321
  return t ? t.addMovie(e) : Promise.reject();
13013
13322
  }
13014
- async function Qc(e) {
13323
+ async function hl(e) {
13015
13324
  let t = $.current();
13016
13325
  return t ? t.updateMovie(e) : Promise.reject();
13017
13326
  }
13018
- async function $c(e) {
13327
+ async function gl(e) {
13019
13328
  let t = $.current();
13020
13329
  return t ? t.removeMovie(e) : Promise.reject();
13021
13330
  }
13022
- async function el(e, t) {
13331
+ async function _l(e, t) {
13023
13332
  let n = $.current();
13024
13333
  if (n) {
13025
13334
  let r = [];
@@ -13044,11 +13353,11 @@ async function el(e, t) {
13044
13353
  }
13045
13354
  return Promise.reject();
13046
13355
  }
13047
- async function tl(e, t) {
13356
+ async function vl(e, t) {
13048
13357
  let n = $.current();
13049
13358
  return n ? n.activateRooms(e, t) : Promise.reject();
13050
13359
  }
13051
- async function nl(e = null, t = null) {
13360
+ async function yl(e = null, t = null) {
13052
13361
  let n = $.current();
13053
13362
  if (!n) return Promise.reject();
13054
13363
  let r;
@@ -13063,25 +13372,25 @@ async function nl(e = null, t = null) {
13063
13372
  }
13064
13373
  return n.switchRoom(e, r);
13065
13374
  }
13066
- async function rl(e) {
13375
+ async function bl(e) {
13067
13376
  let t = $.current();
13068
13377
  return t ? t.removeRooms(e) : Promise.reject();
13069
13378
  }
13070
- function il(e) {
13379
+ function xl(e) {
13071
13380
  M.statisticsInterval = e;
13072
13381
  let t = $.current();
13073
13382
  if (t) return t.updateStatisticsInterval();
13074
13383
  }
13075
- function al(t) {
13384
+ function Sl(t) {
13076
13385
  e.disableLog(!t), R.toggle(t);
13077
13386
  }
13078
- function ol(e, ...t) {
13387
+ function Cl(e, ...t) {
13079
13388
  M.debugLog && ($.debugMessage(e, "[external]", ...t) || R.send(e, "[external]", ...t));
13080
13389
  }
13081
- function sl(e, t, ...n) {
13390
+ function wl(e, t, ...n) {
13082
13391
  M.debugLog && ($.debugMessageWithContext(e, t, "[external]", ...n) || R.send(e, "[external]", ...n));
13083
13392
  }
13084
- var cl = {
13393
+ var Tl = {
13085
13394
  list: Ne,
13086
13395
  get: Pe,
13087
13396
  getJson: Fe,
@@ -13089,7 +13398,7 @@ var cl = {
13089
13398
  clear: Le,
13090
13399
  stats: Re
13091
13400
  };
13092
- function ll() {
13401
+ function El() {
13093
13402
  let e = [
13094
13403
  [`Calls SDK ${M.sdkVersion}`, M.toJSON()],
13095
13404
  ["UserAgent:", navigator.userAgent],
@@ -13106,31 +13415,31 @@ function ll() {
13106
13415
  d: e
13107
13416
  }));
13108
13417
  }
13109
- async function ul() {
13418
+ async function Dl() {
13110
13419
  let e = $.id(), t = $.debugSessionId();
13111
13420
  if (!t || !e) throw R.error("[uploadDebugLogs]", "No conversation id found"), Error("No conversation id found");
13112
13421
  let n = await Pe({ sessionId: t });
13113
13422
  if (n.length === 0) throw R.error("[uploadDebugLogs]", "No logs found"), Error("No logs found");
13114
13423
  let r = n[0].t, i = n[n.length - 1].t;
13115
13424
  try {
13116
- return Vs?.uploadDebugLogs(e, r, i, JSON.stringify([...ll(), ...n]));
13425
+ return nc?.uploadDebugLogs(e, r, i, JSON.stringify([...El(), ...n]));
13117
13426
  } catch (e) {
13118
13427
  throw R.error("[uploadDebugLogs]", "Error while uploading logs", e), Error("Error while uploading logs", { cause: e });
13119
13428
  }
13120
13429
  }
13121
- async function dl(e) {
13430
+ async function Ol(e) {
13122
13431
  let t = $.current();
13123
13432
  if (t) return t.videoEffect(e);
13124
13433
  }
13125
- async function fl(e, t) {
13434
+ async function kl(e, t) {
13126
13435
  let n = $.current();
13127
13436
  if (n) return n.audioEffect(e.length > 0 ? e : null, t);
13128
13437
  }
13129
- async function pl(e) {
13438
+ async function Al(e) {
13130
13439
  let t = $.current();
13131
13440
  t && await t.setAudioStream(e);
13132
13441
  }
13133
- async function ml(e, t = null, n = null) {
13442
+ async function jl(e, t = null, n = null) {
13134
13443
  let r = $.current();
13135
13444
  if (!r) return;
13136
13445
  let i = n ?? t?.id, a = null;
@@ -13141,18 +13450,18 @@ async function ml(e, t = null, n = null) {
13141
13450
  }
13142
13451
  r.setAnimojiSvg(e, a, i);
13143
13452
  }
13144
- function hl(e) {
13453
+ function Ml(e) {
13145
13454
  let t = $.current();
13146
13455
  t && t.setAnimojiFill(e);
13147
13456
  }
13148
- async function gl(e = null, t, n = !1) {
13149
- return El().getWaitingHall(e, t, n);
13457
+ async function Nl(e = null, t, n = !1) {
13458
+ return Ul().getWaitingHall(e, t, n);
13150
13459
  }
13151
- async function _l() {
13152
- return El().getAudienceModeHands();
13460
+ async function Pl() {
13461
+ return Ul().getAudienceModeHands();
13153
13462
  }
13154
- async function vl(e, t = !1) {
13155
- let n = El(), r;
13463
+ async function Fl(e, t = !1) {
13464
+ let n = Ul(), r;
13156
13465
  if (e) {
13157
13466
  let t = n.getCachedRawOkIdByExternalId(e);
13158
13467
  if (!t) {
@@ -13163,67 +13472,67 @@ async function vl(e, t = !1) {
13163
13472
  }
13164
13473
  return n.promoteParticipant(r, t);
13165
13474
  }
13166
- async function yl(e = !1) {
13167
- return El().requestPromotion(e);
13475
+ async function Il(e = !1) {
13476
+ return Ul().requestPromotion(e);
13168
13477
  }
13169
- async function bl(e = !1) {
13170
- return El().acceptPromotion(e);
13478
+ async function Ll(e = !1) {
13479
+ return Ul().acceptPromotion(e);
13171
13480
  }
13172
- async function xl(e) {
13173
- return El().getParticipantListChunk(e);
13481
+ async function Rl(e) {
13482
+ return Ul().getParticipantListChunk(e);
13174
13483
  }
13175
- async function Sl(e) {
13176
- return El().getParticipants(e);
13484
+ async function zl(e) {
13485
+ return Ul().getParticipants(e);
13177
13486
  }
13178
- async function Cl(e) {
13179
- return El().feedback(e);
13487
+ async function Bl(e) {
13488
+ return Ul().feedback(e);
13180
13489
  }
13181
- async function wl(e, t, n) {
13182
- return El(n).enableFeatureForRoles(e, t);
13490
+ async function Vl(e, t, n) {
13491
+ return Ul(n).enableFeatureForRoles(e, t);
13183
13492
  }
13184
- function Tl(e) {
13493
+ function Hl(e) {
13185
13494
  return e ? z.get(e) ?? null : $.current() ?? z.getFirst();
13186
13495
  }
13187
- function El(e) {
13188
- let t = Tl(e);
13496
+ function Ul(e) {
13497
+ let t = Hl(e);
13189
13498
  if (!t) throw Error("Conversation not found");
13190
13499
  return t;
13191
13500
  }
13192
- async function Dl(e) {
13193
- await Vs.removeHistoryRecords(e);
13501
+ async function Wl(e) {
13502
+ await nc.removeHistoryRecords(e);
13194
13503
  }
13195
- async function Ol(e) {
13504
+ async function Gl(e) {
13196
13505
  let t = $.current() ?? z.getFirst();
13197
13506
  t && await t.startAsr(e);
13198
13507
  }
13199
- async function kl(e) {
13508
+ async function Kl(e) {
13200
13509
  let t = $.current() ?? z.getFirst();
13201
13510
  t && await t.stopAsr(e);
13202
13511
  }
13203
- async function Al(e) {
13512
+ async function ql(e) {
13204
13513
  let t = $.current() ?? z.getFirst();
13205
13514
  t && await t.requestAsr(e);
13206
13515
  }
13207
- async function jl(e) {
13516
+ async function Jl(e) {
13208
13517
  let t = $.current();
13209
13518
  return t ? t.startUrlSharing(e) : Promise.reject();
13210
13519
  }
13211
- async function Ml() {
13520
+ async function Yl() {
13212
13521
  let e = $.current();
13213
13522
  return e ? e.stopUrlSharing() : Promise.reject();
13214
13523
  }
13215
- async function Nl(e) {
13524
+ async function Xl(e) {
13216
13525
  await z.switchCall(e);
13217
13526
  }
13218
- function Pl() {
13527
+ function Zl() {
13219
13528
  return z.getActiveId();
13220
13529
  }
13221
- function Fl() {
13530
+ function Ql() {
13222
13531
  return $.getSyncedTime();
13223
13532
  }
13224
- function Il() {
13533
+ function $l() {
13225
13534
  return M.sdkVersion;
13226
13535
  }
13227
13536
  typeof window < "u" && (window.__CALLS_SDK = yn);
13228
13537
  //#endregion
13229
- export { Ps as Api, Bs as ApiExternal, zs as ArrayDequeue, y as AuthData, f as BaseLogger, Ba as CallDirection, Va as CallType, Ha as ChatRoomEventType, Ua as ConversationFeature, Wa as ConversationOption, Sn as DebugMessageType, to as ExternalIdType, jt as FacingMode, x as FatalError, O as HangupReason, D as HangupType, S as MediaOption, k as MediaTrackKind, V as MediaType, qa as MuteState, Z as ParticipantState, Rs as ParticipantStateDataValue, N as ParticipantStatus, Ls as RecordRole, Ja as RoomsEventType, za as Signaling, B as SignalingCommandType, vr as SignalingConnectionType, K as SignalingNotification, J as TransportTopology, Za as UserRole, A as UserType, To as VolumeDetector, rc as acceptCall, bl as acceptPromotion, tl as activateRooms, Zc as addMovie, lc as addParticipant, uc as addParticipantInternal, nc as authorize, Us as browser, Qs as callInternal, Zs as callTo, mc as captureScreen, hc as captureVmoji, fl as changeAudioEffect, Pc as changeConversationOptions, pc as changeDevice, xc as changeParticipantState, bc as changePriorities, dl as changeVideoEffect, Lc as chatHistory, Fc as chatMessage, Ic as chatMessageInternal, Hc as createJoinLink, Rc as customData, zc as customDataInternal, al as debug, cl as debugLogs, ol as debugMessage, sl as debugMessageWithContext, ic as declineCall, wl as enableFeatureForRoles, Mc as enableVideoSuspend, Nc as enableVideoSuspendSuggest, Cl as feedback, Kc as forceRelayPolicy, Pl as getActiveCallId, Wc as getAnonymTokenByLink, _l as getAudienceModeHands, tc as getInbounds, xl as getParticipantListChunk, Sl as getParticipants, Xc as getStreamInfo, Fl as getSyncedTime, gl as getWaitingHall, Tc as grantRoles, Ec as grantRolesInternal, cc as hangup, Xs as init, ac as joinCall, sc as joinCallByLink, oc as joinCallInternal, Dc as muteParticipant, Oc as muteParticipantInternal, kc as pinParticipant, Ac as pinParticipantInternal, $s as processPush, ec as processPushInternal, vl as promoteParticipant, Yc as publishStream, Sc as putHandsDown, Dl as removeHistoryRecords, Uc as removeJoinLink, $c as removeMovie, dc as removeParticipant, fc as removeParticipantInternal, rl as removeRooms, Al as requestAsr, wc as requestDisplayLayout, yl as requestPromotion, qs as setAudioEffects, pl as setAudioStream, yc as setLocalResolution, Gs as setLogger, jc as setMediaModifiers, il as setStatisticsInterval, Js as setVad, Ks as setVideoEffects, gc as setVideoStream, Ys as setVmoji, hl as setVmojiFill, ml as setVmojiSvg, Gc as setVolume, Ol as startAsr, Vc as startAudienceConversation, Bc as startConversation, qc as startStream, jl as startUrlSharing, kl as stopAsr, Jc as stopStream, Ml as stopUrlSharing, Nl as switchCall, nl as switchRoom, vc as toggleLocalAudio, _c as toggleLocalVideo, Cc as updateDisplayLayout, Qc as updateMovie, el as updateRooms, ul as uploadDebugLogs, Ws as utils, Il as version };
13538
+ export { Ys as Api, tc as ApiExternal, ec as ArrayDequeue, y as AuthData, f as BaseLogger, Ba as CallDirection, Va as CallType, Ha as ChatRoomEventType, Ua as ConversationFeature, Wa as ConversationOption, Sn as DebugMessageType, to as ExternalIdType, jt as FacingMode, x as FatalError, O as HangupReason, D as HangupType, S as MediaOption, k as MediaTrackKind, V as MediaType, qa as MuteState, Z as ParticipantState, $s as ParticipantStateDataValue, N as ParticipantStatus, Qs as RecordRole, Ja as RoomsEventType, za as Signaling, B as SignalingCommandType, vr as SignalingConnectionType, K as SignalingNotification, J as TransportTopology, Za as UserRole, A as UserType, To as VolumeDetector, bc as acceptCall, Ll as acceptPromotion, vl as activateRooms, ml as addMovie, Ec as addParticipant, Dc as addParticipantInternal, yc as authorize, ac as browser, mc as callInternal, pc as callTo, jc as captureScreen, Mc as captureVmoji, kl as changeAudioEffect, Zc as changeConversationOptions, Ac as changeDevice, Rc as changeParticipantState, Lc as changePriorities, Ol as changeVideoEffect, el as chatHistory, Qc as chatMessage, $c as chatMessageInternal, al as createJoinLink, tl as customData, nl as customDataInternal, Sl as debug, Tl as debugLogs, Cl as debugMessage, wl as debugMessageWithContext, xc as declineCall, Vl as enableFeatureForRoles, Yc as enableVideoSuspend, Xc as enableVideoSuspendSuggest, Bl as feedback, ll as forceRelayPolicy, Zl as getActiveCallId, sl as getAnonymTokenByLink, Pl as getAudienceModeHands, _c as getInbounds, Rl as getParticipantListChunk, zl as getParticipants, pl as getStreamInfo, Ql as getSyncedTime, Nl as getWaitingHall, Hc as grantRoles, Uc as grantRolesInternal, Tc as hangup, fc as init, Sc as joinCall, wc as joinCallByLink, Cc as joinCallInternal, Wc as muteParticipant, Gc as muteParticipantInternal, Kc as pinParticipant, qc as pinParticipantInternal, hc as processPush, gc as processPushInternal, Fl as promoteParticipant, fl as publishStream, zc as putHandsDown, Wl as removeHistoryRecords, ol as removeJoinLink, gl as removeMovie, Oc as removeParticipant, kc as removeParticipantInternal, bl as removeRooms, ql as requestAsr, Vc as requestDisplayLayout, Il as requestPromotion, lc as setAudioEffects, Al as setAudioStream, Ic as setLocalResolution, sc as setLogger, Jc as setMediaModifiers, xl as setStatisticsInterval, uc as setVad, cc as setVideoEffects, Nc as setVideoStream, dc as setVmoji, Ml as setVmojiFill, jl as setVmojiSvg, cl as setVolume, Gl as startAsr, il as startAudienceConversation, rl as startConversation, vc as startStats, ul as startStream, Jl as startUrlSharing, Kl as stopAsr, dl as stopStream, Yl as stopUrlSharing, Xl as switchCall, yl as switchRoom, Fc as toggleLocalAudio, Pc as toggleLocalVideo, Bc as updateDisplayLayout, hl as updateMovie, _l as updateRooms, Dl as uploadDebugLogs, oc as utils, $l as version };