@pagelines/sdk 1.0.915 → 1.0.916

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/provider2.js CHANGED
@@ -2,7 +2,7 @@ import "./rolldown-runtime.js";
2
2
  import { c as e } from "./sdkClient.js";
3
3
  import { r as t } from "./provider.js";
4
4
  import { voiceBudgets as n, zVoiceSessionEnd as r } from "@pagelines/core";
5
- //#region ../../node_modules/.pnpm/livekit-client@2.22.3_@types+dom-mediacapture-record@1.0.22/node_modules/livekit-client/dist/livekit-client.esm.mjs
5
+ // ../../node_modules/.pnpm/livekit-client@2.22.3_@types+dom-mediacapture-record@1.0.22/node_modules/livekit-client/dist/livekit-client.esm.mjs
6
6
  function _mergeNamespaces(e, t) {
7
7
  return t.forEach(function(t) {
8
8
  t && typeof t != "string" && !Array.isArray(t) && Object.keys(t).forEach(function(n) {
@@ -798,7 +798,7 @@ function setExtension(e, t, n, r) {
798
798
  for (let t of n) e.getType().runtime.bin.onUnknownField(e, t.no, t.wireType, t.data);
799
799
  }
800
800
  let c = a.writerFactory(), l = t.field;
801
- !l.opt && !l.repeated && (l.kind == "enum" || l.kind == "scalar") && (l = Object.assign(Object.assign({}, t.field), { opt: !0 })), t.runtime.bin.writeField(l, n, c, a);
801
+ l.opt || l.repeated || l.kind != "enum" && l.kind != "scalar" || (l = Object.assign(Object.assign({}, t.field), { opt: !0 })), t.runtime.bin.writeField(l, n, c, a);
802
802
  let u = i.readerFactory(c.finish());
803
803
  for (; u.pos < u.len;) {
804
804
  let t = _slicedToArray(u.tag(), 2), n = t[0], r = t[1], i = u.skip(r, n);
@@ -1205,25 +1205,19 @@ function makeBinaryFormat() {
1205
1205
  var d = _slicedToArray(t.tag(), 2);
1206
1206
  if (l = d[0], u = d[1], i === !0 && u == v.EndGroup) break;
1207
1207
  let n = a.fields.find(l);
1208
- if (!n) {
1208
+ if (n) readField(e, t, n, u, r);
1209
+ else {
1209
1210
  let n = t.skip(u, l);
1210
1211
  r.readUnknownFields && this.onUnknownField(e, l, u, n);
1211
- continue;
1212
1212
  }
1213
- readField(e, t, n, u, r);
1214
1213
  }
1215
1214
  if (i && (u != v.EndGroup || l !== n)) throw Error("invalid end group tag");
1216
1215
  },
1217
1216
  readField,
1218
1217
  writeMessage(e, t, n) {
1219
1218
  let r = e.getType();
1220
- for (let i of r.fields.byNumber()) {
1221
- if (!isFieldSet(i, e)) {
1222
- if (i.req) throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);
1223
- continue;
1224
- }
1225
- writeField(i, i.oneof ? e[i.oneof.localName].value : e[i.localName], t, n);
1226
- }
1219
+ for (let i of r.fields.byNumber()) if (isFieldSet(i, e)) writeField(i, i.oneof ? e[i.oneof.localName].value : e[i.localName], t, n);
1220
+ else if (i.req) throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);
1227
1221
  return n.writeUnknownFields && this.writeUnknownFields(e, t), t;
1228
1222
  },
1229
1223
  writeField(e, t, n, r) {
@@ -1648,7 +1642,7 @@ function normalizeFieldInfos(e, t) {
1648
1642
  let e = t;
1649
1643
  if (e.localName = localFieldName(t.name, t.oneof !== void 0), e.jsonName = t.jsonName ?? de(t.name), e.repeated = t.repeated ?? !1, t.kind == "scalar" && (e.L = t.L ?? ee.BIGINT), e.delimited = t.delimited ?? !1, e.req = t.req ?? !1, e.opt = t.opt ?? !1, t.packed === void 0 && (e.packed = t.kind == "enum" || t.kind == "scalar" && t.T != g.BYTES && t.T != g.STRING), t.oneof !== void 0) {
1650
1644
  let n = typeof t.oneof == "string" ? t.oneof : t.oneof.name;
1651
- (!r || r.name != n) && (r = new InternalOneofInfo(n)), e.oneof = r, r.addField(e);
1645
+ r && r.name == n || (r = new InternalOneofInfo(n)), e.oneof = r, r.addField(e);
1652
1646
  }
1653
1647
  n.push(e);
1654
1648
  }
@@ -1658,11 +1652,8 @@ var y = makeProtoRuntime("proto3", (e) => new InternalFieldList(e, (e) => normal
1658
1652
  for (let t of e.getType().fields.byMember()) {
1659
1653
  if (t.opt) continue;
1660
1654
  let n = t.localName, r = e;
1661
- if (t.repeated) {
1662
- r[n] = [];
1663
- continue;
1664
- }
1665
- switch (t.kind) {
1655
+ if (t.repeated) r[n] = [];
1656
+ else switch (t.kind) {
1666
1657
  case "oneof":
1667
1658
  r[n] = { case: void 0 };
1668
1659
  break;
@@ -5599,7 +5590,7 @@ function getDefaultExportFromCjs(e) {
5599
5590
  }
5600
5591
  var Ln = { exports: {} }, Rn = Ln.exports, zn;
5601
5592
  function requireLoglevel() {
5602
- return zn ? Ln.exports : (zn = 1, (function(e) {
5593
+ return zn || (zn = 1, (function(e) {
5603
5594
  (function(t, n) {
5604
5595
  e.exports ? e.exports = n() : t.log = n();
5605
5596
  })(Rn, function() {
@@ -5722,7 +5713,7 @@ function requireLoglevel() {
5722
5713
  return r;
5723
5714
  }, i.default = i, i;
5724
5715
  });
5725
- })(Ln), Ln.exports);
5716
+ })(Ln)), Ln.exports;
5726
5717
  }
5727
5718
  var Bn = requireLoglevel(), Vn;
5728
5719
  (function(e) {
@@ -6881,7 +6872,7 @@ var er = /*#__PURE__*/ Object.freeze({
6881
6872
  shimTrackEventTransceiver
6882
6873
  }), tr = { exports: {} }, nr;
6883
6874
  function requireSdp() {
6884
- return nr ? tr.exports : (nr = 1, (function(e) {
6875
+ return nr || (nr = 1, (function(e) {
6885
6876
  let t = {};
6886
6877
  t.generateIdentifier = function() {
6887
6878
  return Math.random().toString(36).substring(2, 12);
@@ -7187,7 +7178,7 @@ function requireSdp() {
7187
7178
  for (let e = 0; e < n.length; e++) if (n[e].length < 2 || n[e].charAt(1) !== "=") return !1;
7188
7179
  return !0;
7189
7180
  }, e.exports = t;
7190
- })(tr), tr.exports);
7181
+ })(tr)), tr.exports;
7191
7182
  }
7192
7183
  var rr = requireSdp(), ir = /*@__PURE__*/ getDefaultExportFromCjs(rr), ar = /*#__PURE__*/ _mergeNamespaces({
7193
7184
  __proto__: null,
@@ -8047,7 +8038,7 @@ function attachToElement(e, t) {
8047
8038
  let r;
8048
8039
  r = e.kind === "audio" ? n.getAudioTracks() : n.getVideoTracks(), r.includes(e) || (r.forEach((e) => {
8049
8040
  n.removeTrack(e);
8050
- }), n.addTrack(e)), (!isSafari() || !(t instanceof HTMLVideoElement)) && (t.autoplay = !0), t.muted = n.getAudioTracks().length === 0, t instanceof HTMLVideoElement && (t.playsInline = !0), t.srcObject !== n && (t.srcObject = n, (isSafari() || isFireFox()) && t instanceof HTMLVideoElement && setTimeout(() => {
8041
+ }), n.addTrack(e)), isSafari() && t instanceof HTMLVideoElement || (t.autoplay = !0), t.muted = n.getAudioTracks().length === 0, t instanceof HTMLVideoElement && (t.playsInline = !0), t.srcObject !== n && (t.srcObject = n, (isSafari() || isFireFox()) && t instanceof HTMLVideoElement && setTimeout(() => {
8051
8042
  t.srcObject = n, t.play().catch(() => {});
8052
8043
  }, 0));
8053
8044
  }
@@ -8775,15 +8766,9 @@ var RemoteTrack = class extends z {
8775
8766
  }
8776
8767
  updateVisibility(e) {
8777
8768
  let t = this.elementInfos.reduce((e, t) => Math.max(e, t.visibilityChangedAt || 0), 0), n = this.adaptiveStreamSettings?.pauseVideoInBackground ?? !0 ? this.isInBackground : !1, r = this.elementInfos.some((e) => e.pictureInPicture), i = this.elementInfos.some((e) => e.visible) && !n || r;
8778
- if (this.lastVisible !== i || e) {
8779
- if (!i && Date.now() - t < Rr) {
8780
- CriticalTimers.setTimeout(() => {
8781
- this.updateVisibility();
8782
- }, Rr);
8783
- return;
8784
- }
8785
- this.lastVisible = i, this.emit(L.VisibilityChanged, i, this);
8786
- }
8769
+ (this.lastVisible !== i || e) && (!i && Date.now() - t < Rr ? CriticalTimers.setTimeout(() => {
8770
+ this.updateVisibility();
8771
+ }, Rr) : (this.lastVisible = i, this.emit(L.VisibilityChanged, i, this)));
8787
8772
  }
8788
8773
  updateDimensions() {
8789
8774
  let e = 0, t = 0, n = this.getPixelDensity();
@@ -8940,14 +8925,10 @@ var zr = class E2EEManager extends A.EventEmitter {
8940
8925
  let e = new WeakRef(this.worker);
8941
8926
  t = onWorkerLogLevelChanged((n) => {
8942
8927
  let r = e.deref();
8943
- if (!r) {
8944
- t?.();
8945
- return;
8946
- }
8947
- r.postMessage({
8928
+ r ? r.postMessage({
8948
8929
  kind: "setLogLevel",
8949
8930
  data: { level: n }
8950
- });
8931
+ }) : t?.();
8951
8932
  }), E2EEManager.disposeRegistry.register(this, t, this);
8952
8933
  } else {
8953
8934
  let e = this.worker;
@@ -9119,11 +9100,7 @@ var zr = class E2EEManager extends A.EventEmitter {
9119
9100
  this.worker.postMessage(t);
9120
9101
  }
9121
9102
  setParticipantCryptorEnabledForPublication(e, t) {
9122
- if (!e.trackInfo) {
9123
- this.log.warn("skipping e2ee enabled update for publication without trackInfo", { trackSid: e.trackSid });
9124
- return;
9125
- }
9126
- this.setParticipantCryptorEnabled(e.trackInfo.encryption !== w.NONE, t);
9103
+ e.trackInfo ? this.setParticipantCryptorEnabled(e.trackInfo.encryption !== w.NONE, t) : this.log.warn("skipping e2ee enabled update for publication without trackInfo", { trackSid: e.trackSid });
9127
9104
  }
9128
9105
  setupE2EEReceiver(e, t, n) {
9129
9106
  if (!e.receiver) return;
@@ -9132,11 +9109,7 @@ var zr = class E2EEManager extends A.EventEmitter {
9132
9109
  this.handleReceiver(e.receiver, e.mediaStreamID, t, e.kind === "video" ? mimeTypeToVideoCodecString(n.mimeType) : void 0, r);
9133
9110
  }
9134
9111
  setupE2EESender(e, t) {
9135
- if (!isLocalTrack(e) || !t) {
9136
- t || this.log.warn("early return because sender is not ready");
9137
- return;
9138
- }
9139
- this.handleSender(t, e.mediaStreamID, void 0, isVideoTrack(e) ? e.publishOptions?.frameMetadata ?? e.publishOptions?.packetTrailer : void 0);
9112
+ !isLocalTrack(e) || !t ? t || this.log.warn("early return because sender is not ready") : this.handleSender(t, e.mediaStreamID, void 0, isVideoTrack(e) ? e.publishOptions?.frameMetadata ?? e.publishOptions?.packetTrailer : void 0);
9140
9113
  }
9141
9114
  handleReceiver(e, t, n, r, i) {
9142
9115
  return __awaiter(this, void 0, void 0, function* () {
@@ -9277,15 +9250,7 @@ var Br = 300, FrameMetadataExtractor = class {
9277
9250
  this.extractors.set(i, r), e.frameMetadataExtractor = r, !this.room?.hasE2EESetup && this.setupWorkerReceiver(n, i, !0);
9278
9251
  }
9279
9252
  setupPassthroughReceiver(e, t) {
9280
- if (shouldUseFrameMetadataScriptTransform()) {
9281
- "transform" in e && (e.transform = null);
9282
- return;
9283
- }
9284
- if (this.worker && isFrameMetadataSupported({ worker: this.worker }) && !this.workerPipelines.has(e)) {
9285
- this.setupWorkerReceiver(e, t, !1);
9286
- return;
9287
- }
9288
- this.worker && this.workerPipelines.has(e) && this.setupWorkerReceiver(e, t, !1);
9253
+ shouldUseFrameMetadataScriptTransform() ? "transform" in e && (e.transform = null) : (this.worker && isFrameMetadataSupported({ worker: this.worker }) && !this.workerPipelines.has(e) || this.worker && this.workerPipelines.has(e)) && this.setupWorkerReceiver(e, t, !1);
9289
9254
  }
9290
9255
  setupWorkerReceiver(e, t) {
9291
9256
  let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !0, r = this.worker;
@@ -9416,11 +9381,8 @@ var Wr = "default", B = class DeviceManager {
9416
9381
  return;
9417
9382
  }
9418
9383
  let a = r.find((e) => e.deviceId !== Wr && e.groupId === (n ?? i.groupId));
9419
- if (!a) {
9420
- k.warn("could not reliably determine default device");
9421
- return;
9422
- }
9423
- return a?.deviceId;
9384
+ if (!a) k.warn("could not reliably determine default device");
9385
+ else return a?.deviceId;
9424
9386
  });
9425
9387
  }
9426
9388
  hasDeviceInUse(e) {
@@ -9695,15 +9657,12 @@ var AsyncQueue = class {
9695
9657
  var r = [...arguments].slice(2);
9696
9658
  n.currentActionArgs = r;
9697
9659
  let i = this.states[n.state]?._child;
9698
- if (i && i.canHandle(e, t)) {
9699
- try {
9700
- i.handle(e, t, ...r);
9701
- } finally {
9702
- n.currentActionArgs = void 0;
9703
- }
9704
- return;
9660
+ if (i && i.canHandle(e, t)) try {
9661
+ i.handle(e, t, ...r);
9662
+ } finally {
9663
+ n.currentActionArgs = void 0;
9705
9664
  }
9706
- this.handleLocally(e, t, r, n);
9665
+ else this.handleLocally(e, t, r, n);
9707
9666
  }
9708
9667
  canHandle(e, t) {
9709
9668
  if (this.disposed) return !1;
@@ -9722,37 +9681,36 @@ var AsyncQueue = class {
9722
9681
  if (this.disposed) return;
9723
9682
  let n = this.getOrCreateClientMeta(e), r = n.state;
9724
9683
  if (t !== r) {
9725
- if (!Object.hasOwn(this.states, t)) {
9726
- this.emitter.emit("invalidstate", {
9727
- stateName: t,
9728
- client: e
9729
- });
9730
- return;
9731
- }
9732
- if (this.transitionDepth++, this.transitionDepth > ii) throw this.transitionDepth = 0, Error(`Max transition depth (${ii}) exceeded in FSM "${this.id}". Likely an infinite _onEnter → transition loop.`);
9733
- try {
9734
- let i = this.states[r], a = this.states[t];
9735
- if (i != null && i._onExit && typeof i._onExit == "function") {
9736
- let t = this.buildHandlerArgs(e, "", n);
9737
- i._onExit(t);
9738
- }
9739
- n.state = t;
9740
- let c = {
9741
- fromState: r,
9742
- toState: t,
9743
- client: e
9744
- };
9745
- this.emitter.emit("transitioning", c);
9746
- let l;
9747
- if (a != null && a._onEnter && typeof a._onEnter == "function") {
9748
- let t = this.buildHandlerArgs(e, "", n);
9749
- l = a._onEnter(t);
9684
+ if (!Object.hasOwn(this.states, t)) this.emitter.emit("invalidstate", {
9685
+ stateName: t,
9686
+ client: e
9687
+ });
9688
+ else {
9689
+ if (this.transitionDepth++, this.transitionDepth > ii) throw this.transitionDepth = 0, Error(`Max transition depth (${ii}) exceeded in FSM "${this.id}". Likely an infinite _onEnter → transition loop.`);
9690
+ try {
9691
+ let i = this.states[r], a = this.states[t];
9692
+ if (i != null && i._onExit && typeof i._onExit == "function") {
9693
+ let t = this.buildHandlerArgs(e, "", n);
9694
+ i._onExit(t);
9695
+ }
9696
+ n.state = t;
9697
+ let c = {
9698
+ fromState: r,
9699
+ toState: t,
9700
+ client: e
9701
+ };
9702
+ this.emitter.emit("transitioning", c);
9703
+ let l;
9704
+ if (a != null && a._onEnter && typeof a._onEnter == "function") {
9705
+ let t = this.buildHandlerArgs(e, "", n);
9706
+ l = a._onEnter(t);
9707
+ }
9708
+ this.emitter.emit("transitioned", c);
9709
+ let u = a?._child;
9710
+ u && u.reset(e), this.processQueue(e, n), typeof l == "string" && n.state === t && this.transition(e, l);
9711
+ } finally {
9712
+ this.transitionDepth--;
9750
9713
  }
9751
- this.emitter.emit("transitioned", c);
9752
- let u = a?._child;
9753
- u && u.reset(e), this.processQueue(e, n), typeof l == "string" && n.state === t && this.transition(e, l);
9754
- } finally {
9755
- this.transitionDepth--;
9756
9714
  }
9757
9715
  }
9758
9716
  }
@@ -9897,11 +9855,7 @@ var AsyncQueue = class {
9897
9855
  if (e.client !== void 0) this.bubbleNohandler(e.client, n, e.inputName, e.args ?? []);
9898
9856
  else for (let t of this.knownClients) {
9899
9857
  let r = t.deref();
9900
- if (r === void 0) {
9901
- this.knownClients.delete(t);
9902
- continue;
9903
- }
9904
- this.bubbleNohandler(r, n, e.inputName, e.args ?? []);
9858
+ r === void 0 ? this.knownClients.delete(t) : this.bubbleNohandler(r, n, e.inputName, e.args ?? []);
9905
9859
  }
9906
9860
  return;
9907
9861
  }
@@ -9909,11 +9863,8 @@ var AsyncQueue = class {
9909
9863
  if (r && typeof r == "object" && "client" in r) this.isChildActiveForClient(r.client, n) && this.emitter.emit(e, t);
9910
9864
  else for (let r of this.knownClients) {
9911
9865
  let i = r.deref();
9912
- if (!i) {
9913
- this.knownClients.delete(r);
9914
- continue;
9915
- }
9916
- if (this.isChildActiveForClient(i, n)) {
9866
+ if (!i) this.knownClients.delete(r);
9867
+ else if (this.isChildActiveForClient(i, n)) {
9917
9868
  this.emitter.emit(e, t);
9918
9869
  break;
9919
9870
  }
@@ -9934,15 +9885,12 @@ var AsyncQueue = class {
9934
9885
  }
9935
9886
  handleLocally(e, t, n, r) {
9936
9887
  let i = this.states[r.state], a = i?.[t] ?? i?.["*"];
9937
- if (!a) {
9938
- this.emitter.emit("nohandler", {
9939
- inputName: t,
9940
- args: n,
9941
- client: e
9942
- }), r.currentActionArgs = void 0;
9943
- return;
9944
- }
9945
- try {
9888
+ if (!a) this.emitter.emit("nohandler", {
9889
+ inputName: t,
9890
+ args: n,
9891
+ client: e
9892
+ }), r.currentActionArgs = void 0;
9893
+ else try {
9946
9894
  this.emitter.emit("handling", {
9947
9895
  inputName: t,
9948
9896
  client: e
@@ -10325,24 +10273,23 @@ var pi = 250, mi = 5e3, SignalClient = class {
10325
10273
  }
10326
10274
  reconnect(e, t, n, r) {
10327
10275
  return __awaiter(this, void 0, void 0, function* () {
10328
- if (!this.options) {
10329
- this.log.warn("attempted to reconnect without signal options being set, ignoring");
10330
- return;
10331
- }
10332
- if (this.lifecycleState === "disconnecting" && (yield this.settleInFlightClose()), !this.sendLifecycleInput({ type: "reconnect" })) throw M.internal(`cannot resume the signal session from '${this.lifecycleState}'`);
10333
- this.clearPingInterval();
10334
- try {
10335
- return yield this.connect(e, t, Object.assign(Object.assign({}, this.options), {
10336
- reconnect: !0,
10337
- sid: n,
10338
- reconnectReason: r
10339
- }), void 0, this.useV0SignalPath);
10340
- } catch (e) {
10341
- throw this.sendLifecycleInput({
10342
- type: "reconnectFailed",
10343
- error: e,
10344
- recoverable: isRecoverableReconnectError(e)
10345
- }), e;
10276
+ if (!this.options) this.log.warn("attempted to reconnect without signal options being set, ignoring");
10277
+ else {
10278
+ if (this.lifecycleState === "disconnecting" && (yield this.settleInFlightClose()), !this.sendLifecycleInput({ type: "reconnect" })) throw M.internal(`cannot resume the signal session from '${this.lifecycleState}'`);
10279
+ this.clearPingInterval();
10280
+ try {
10281
+ return yield this.connect(e, t, Object.assign(Object.assign({}, this.options), {
10282
+ reconnect: !0,
10283
+ sid: n,
10284
+ reconnectReason: r
10285
+ }), void 0, this.useV0SignalPath);
10286
+ } catch (e) {
10287
+ throw this.sendLifecycleInput({
10288
+ type: "reconnectFailed",
10289
+ error: e,
10290
+ recoverable: isRecoverableReconnectError(e)
10291
+ }), e;
10292
+ }
10346
10293
  }
10347
10294
  });
10348
10295
  }
@@ -10395,11 +10342,7 @@ var pi = 250, mi = 5e3, SignalClient = class {
10395
10342
  this.isEstablishingConnection && !u && t(M.internal(`Websocket error during a (re)connection attempt: ${e}`));
10396
10343
  });
10397
10344
  let r = yield this.ws.opened.catch((e) => __awaiter(this, void 0, void 0, function* () {
10398
- if (this.lifecycleState !== "connected") {
10399
- clearTimeout(a), t(yield this.handleConnectionError(e, f));
10400
- return;
10401
- }
10402
- this.handleWSError(e), t(e);
10345
+ this.lifecycleState === "connected" ? (this.handleWSError(e), t(e)) : (clearTimeout(a), t(yield this.handleConnectionError(e, f)));
10403
10346
  }));
10404
10347
  if (clearTimeout(a), !r) return;
10405
10348
  let i = r.readable.getReader();
@@ -10705,19 +10648,15 @@ var pi = 250, mi = 5e3, SignalClient = class {
10705
10648
  let n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.attemptId;
10706
10649
  return function* () {
10707
10650
  let r = t.onClose;
10708
- if (!t.sendLifecycleInput({
10651
+ t.sendLifecycleInput({
10709
10652
  type: "transportFailed",
10710
10653
  attemptId: n,
10711
10654
  reason: e
10712
- })) {
10713
- t.log.debug(`ignoring transport close in state ${t.lifecycleState}`, {
10714
- reason: e,
10715
- attemptId: n,
10716
- currentAttemptId: t.attemptId
10717
- });
10718
- return;
10719
- }
10720
- yield t.teardownTransport(e), t.log.info(`websocket connection closed: ${e}`, { reason: e }), r && r(e);
10655
+ }) ? (yield t.teardownTransport(e), t.log.info(`websocket connection closed: ${e}`, { reason: e }), r && r(e)) : t.log.debug(`ignoring transport close in state ${t.lifecycleState}`, {
10656
+ reason: e,
10657
+ attemptId: n,
10658
+ currentAttemptId: t.attemptId
10659
+ });
10721
10660
  }();
10722
10661
  });
10723
10662
  }
@@ -10725,45 +10664,33 @@ var pi = 250, mi = 5e3, SignalClient = class {
10725
10664
  this.log.error("websocket error", { error: e });
10726
10665
  }
10727
10666
  resetPingTimeout() {
10728
- if (this.clearPingTimeout(), !this.pingTimeoutDuration) {
10729
- this.log.warn("ping timeout duration not set");
10730
- return;
10731
- }
10732
- this.pingTimeout = CriticalTimers.setTimeout(() => {
10667
+ this.clearPingTimeout(), this.pingTimeoutDuration ? this.pingTimeout = CriticalTimers.setTimeout(() => {
10733
10668
  this.log.warn(`ping timeout triggered. last pong received at: ${(/* @__PURE__ */ new Date(Date.now() - this.pingTimeoutDuration * 1e3)).toUTCString()}`), this.handleOnClose("ping timeout");
10734
- }, this.pingTimeoutDuration * 1e3);
10669
+ }, this.pingTimeoutDuration * 1e3) : this.log.warn("ping timeout duration not set");
10735
10670
  }
10736
10671
  clearPingTimeout() {
10737
10672
  this.pingTimeout && CriticalTimers.clearTimeout(this.pingTimeout);
10738
10673
  }
10739
10674
  startPingInterval() {
10740
- if (this.clearPingInterval(), this.resetPingTimeout(), !this.pingIntervalDuration) {
10741
- this.log.warn("ping interval duration not set");
10742
- return;
10743
- }
10744
- this.log.debug("start ping interval"), this.pingInterval = CriticalTimers.setInterval(() => {
10675
+ this.clearPingInterval(), this.resetPingTimeout(), this.pingIntervalDuration ? (this.log.debug("start ping interval"), this.pingInterval = CriticalTimers.setInterval(() => {
10745
10676
  this.sendPing();
10746
- }, this.pingIntervalDuration * 1e3);
10677
+ }, this.pingIntervalDuration * 1e3)) : this.log.warn("ping interval duration not set");
10747
10678
  }
10748
10679
  clearPingInterval() {
10749
10680
  this.log.debug("clearing ping interval"), this.clearPingTimeout(), this.pingInterval && CriticalTimers.clearInterval(this.pingInterval);
10750
10681
  }
10751
10682
  handleSignalConnected(e, t, n, r) {
10752
- if (clearTimeout(t), !this.sendLifecycleInput(this.lifecycleState === "reconnecting" ? {
10683
+ clearTimeout(t), this.sendLifecycleInput(this.lifecycleState === "reconnecting" ? {
10753
10684
  type: "reconnectComplete",
10754
10685
  attemptId: n
10755
10686
  } : {
10756
10687
  type: "connectComplete",
10757
10688
  attemptId: n
10758
- })) {
10759
- this.log.debug("discarding a connection whose attempt no longer owns the session", {
10760
- attemptId: n,
10761
- currentAttemptId: this.attemptId,
10762
- state: this.lifecycleState
10763
- });
10764
- return;
10765
- }
10766
- this.log.info("signal connected"), this.startPingInterval(), this.startReadingLoop(e.readable.getReader(), r);
10689
+ }) ? (this.log.info("signal connected"), this.startPingInterval(), this.startReadingLoop(e.readable.getReader(), r)) : this.log.debug("discarding a connection whose attempt no longer owns the session", {
10690
+ attemptId: n,
10691
+ currentAttemptId: this.attemptId,
10692
+ state: this.lifecycleState
10693
+ });
10767
10694
  }
10768
10695
  validateFirstMessage(e, t) {
10769
10696
  return e.message?.case === "join" ? {
@@ -10889,11 +10816,8 @@ var TTLMap = class {
10889
10816
  get(e) {
10890
10817
  let t = this._map.get(e);
10891
10818
  if (t) {
10892
- if (t.expiresAt < Date.now()) {
10893
- this._map.delete(e);
10894
- return;
10895
- }
10896
- return t.value;
10819
+ if (t.expiresAt < Date.now()) this._map.delete(e);
10820
+ else return t.value;
10897
10821
  }
10898
10822
  }
10899
10823
  has(e) {
@@ -11385,7 +11309,7 @@ function requireGrammar() {
11385
11309
  }
11386
11310
  var vi;
11387
11311
  function requireParser() {
11388
- return vi ? hi : (vi = 1, (function(e) {
11312
+ return vi || (vi = 1, (function(e) {
11389
11313
  var toIntIfInt = function(e) {
11390
11314
  return String(Number(e)) === e ? Number(e) : e;
11391
11315
  }, attachProperties = function(e, t, n, r) {
@@ -11441,7 +11365,7 @@ function requireParser() {
11441
11365
  });
11442
11366
  });
11443
11367
  };
11444
- })(hi), hi);
11368
+ })(hi)), hi;
11445
11369
  }
11446
11370
  var writer, yi;
11447
11371
  function requireWriter() {
@@ -12169,11 +12093,7 @@ var PCTransportManager = class {
12169
12093
  }, cleanup = () => {
12170
12094
  e.removeEventListener("bufferedamountlow", onBufferedAmountLow), e.removeEventListener("close", onDCClose), t.removeEventListener("abort", onAbort);
12171
12095
  };
12172
- if (t.aborted) {
12173
- onAbort();
12174
- return;
12175
- }
12176
- e.addEventListener("bufferedamountlow", onBufferedAmountLow), e.addEventListener("close", onDCClose), t.addEventListener("abort", onAbort);
12096
+ t.aborted ? onAbort() : (e.addEventListener("bufferedamountlow", onBufferedAmountLow), e.addEventListener("close", onDCClose), t.addEventListener("abort", onAbort));
12177
12097
  });
12178
12098
  });
12179
12099
  }
@@ -12294,19 +12214,15 @@ var PCTransportManager = class {
12294
12214
  });
12295
12215
  return;
12296
12216
  }
12297
- if (this.isDeferringSends()) {
12298
- this.messageBuffer.push({
12299
- data: e,
12300
- sequence: t,
12301
- sent: !1
12302
- });
12303
- return;
12304
- }
12305
- this.messageBuffer.push({
12217
+ this.isDeferringSends() ? this.messageBuffer.push({
12218
+ data: e,
12219
+ sequence: t,
12220
+ sent: !1
12221
+ }) : (this.messageBuffer.push({
12306
12222
  data: e,
12307
12223
  sequence: t,
12308
12224
  sent: !0
12309
- }), n.send(e), this.refreshBufferStatus();
12225
+ }), n.send(e), this.refreshBufferStatus());
12310
12226
  }
12311
12227
  });
12312
12228
  }
@@ -12733,21 +12649,17 @@ var Bi = 1e3, Vi = 1e4, LocalTrack = class extends z {
12733
12649
  }
12734
12650
  startPreConnectBuffer() {
12735
12651
  let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 100;
12736
- if (!isRecordingSupported()) {
12737
- this.log.warn("MediaRecorder is not available, cannot start preconnect buffer", this.logContext);
12738
- return;
12739
- }
12740
- if (this.localTrackRecorder) {
12741
- this.log.warn("preconnect buffer already started");
12742
- return;
12743
- }
12744
- {
12745
- let e = "audio/webm;codecs=opus";
12746
- MediaRecorder.isTypeSupported(e) || (e = "video/mp4"), this.localTrackRecorder = new LocalTrackRecorder(this, { mimeType: e });
12652
+ if (!isRecordingSupported()) this.log.warn("MediaRecorder is not available, cannot start preconnect buffer", this.logContext);
12653
+ else if (this.localTrackRecorder) this.log.warn("preconnect buffer already started");
12654
+ else {
12655
+ {
12656
+ let e = "audio/webm;codecs=opus";
12657
+ MediaRecorder.isTypeSupported(e) || (e = "video/mp4"), this.localTrackRecorder = new LocalTrackRecorder(this, { mimeType: e });
12658
+ }
12659
+ this.localTrackRecorder.start(e), this.autoStopPreConnectBuffer = setTimeout(() => {
12660
+ this.log.warn("preconnect buffer timed out, stopping recording automatically", this.logContext), this.stopPreConnectBuffer();
12661
+ }, Vi);
12747
12662
  }
12748
- this.localTrackRecorder.start(e), this.autoStopPreConnectBuffer = setTimeout(() => {
12749
- this.log.warn("preconnect buffer timed out, stopping recording automatically", this.logContext), this.stopPreConnectBuffer();
12750
- }, Vi);
12751
12663
  }
12752
12664
  stopPreConnectBuffer() {
12753
12665
  clearTimeout(this.autoStopPreConnectBuffer), this.localTrackRecorder && (this.localTrackRecorder.stop(), this.localTrackRecorder = void 0);
@@ -13357,11 +13269,7 @@ var Ji = 5e3, LocalVideoTrack = class extends LocalTrack {
13357
13269
  }
13358
13270
  setPublishingLayers(e, t) {
13359
13271
  return __awaiter(this, void 0, void 0, function* () {
13360
- if (this.optimizeForPerformance) {
13361
- this.log.info("skipping setPublishingLayers due to optimized publishing performance", Object.assign(Object.assign({}, this.logContext), { qualities: t }));
13362
- return;
13363
- }
13364
- this.log.debug("setting publishing layers", Object.assign(Object.assign({}, this.logContext), { qualities: t })), this.sender && this.encodings && (yield setPublishingLayersForSender(this.sender, this.encodings, t, this.senderLock, e, this.log, this.logContext));
13272
+ this.optimizeForPerformance ? this.log.info("skipping setPublishingLayers due to optimized publishing performance", Object.assign(Object.assign({}, this.logContext), { qualities: t })) : (this.log.debug("setting publishing layers", Object.assign(Object.assign({}, this.logContext), { qualities: t })), this.sender && this.encodings && (yield setPublishingLayersForSender(this.sender, this.encodings, t, this.senderLock, e, this.log, this.logContext)));
13365
13273
  });
13366
13274
  }
13367
13275
  prioritizePerformance() {
@@ -13555,11 +13463,7 @@ var ta = 64e3, RTCEngine = class extends A.EventEmitter {
13555
13463
  elapsedMs: n,
13556
13464
  retryCount: this.reconnectAttempts
13557
13465
  });
13558
- if (r === null) {
13559
- disconnect(n);
13560
- return;
13561
- }
13562
- e === Xi && (r = 0), this.log.debug(`reconnecting in ${r}ms`), this.clearReconnectTimeout(), this.token && this.emit(I.TokenRefreshed, this.token), this.reconnectTimeout = CriticalTimers.setTimeout(() => this.attemptReconnect(t).finally(() => this.reconnectTimeout = void 0), r);
13466
+ r === null ? disconnect(n) : (e === Xi && (r = 0), this.log.debug(`reconnecting in ${r}ms`), this.clearReconnectTimeout(), this.token && this.emit(I.TokenRefreshed, this.token), this.reconnectTimeout = CriticalTimers.setTimeout(() => this.attemptReconnect(t).finally(() => this.reconnectTimeout = void 0), r));
13563
13467
  }, this.waitForRestarted = () => new Promise((e, t) => {
13564
13468
  this.pcState === K.Connected && e();
13565
13469
  let onRestarted = () => {
@@ -13651,11 +13555,8 @@ var ta = 64e3, RTCEngine = class extends A.EventEmitter {
13651
13555
  close(e) {
13652
13556
  return __awaiter(this, void 0, void 0, function* () {
13653
13557
  let t = yield this.closingLock.lock();
13654
- if (this.isClosed) {
13655
- t();
13656
- return;
13657
- }
13658
- try {
13558
+ if (this.isClosed) t();
13559
+ else try {
13659
13560
  this._isClosed = !0, this.joinAttempts = 0, this.emit(I.Closing), this.removeAllListeners(), this.deregisterOnLineListener(), this.clearPendingReconnect(), this.clearLostQualityTimeout(), this.cleanupLossyDataStats(), yield this.cleanupPeerConnections(), yield this.cleanupClient(e);
13660
13561
  } finally {
13661
13562
  t();
@@ -14107,7 +14008,7 @@ var ta = 64e3, RTCEngine = class extends A.EventEmitter {
14107
14008
  let r = n ? t.pcManager.subscriber : t.pcManager.publisher, i = n ? "Subscriber" : "Publisher";
14108
14009
  if (!r) throw M.internal(`${i} connection not set`);
14109
14010
  let a = !1;
14110
- if (!n && !t.dataChannelForKind(e, n) && (t.createDataChannels(), a = !0), !a && !n && !t.pcManager.publisher.isICEConnected && t.pcManager.publisher.getICEConnectionState() !== "checking" && (a = !0), a && t.negotiate().catch((e) => {
14011
+ if (!n && !t.dataChannelForKind(e, n) && (t.createDataChannels(), a = !0), a || n || t.pcManager.publisher.isICEConnected || t.pcManager.publisher.getICEConnectionState() === "checking" || (a = !0), a && t.negotiate().catch((e) => {
14111
14012
  t.log.error(e);
14112
14013
  }), t.dataChannelForKind(e, n)?.readyState === "open") return;
14113
14014
  let c = (/* @__PURE__ */ new Date()).getTime() + t.peerConnectionTimeout;
@@ -14591,14 +14492,11 @@ var oa = 15e3, sa = 5e9, BaseStreamReader = class {
14591
14492
  }
14592
14493
  }
14593
14494
  handleDataStreamPacket(e, t) {
14594
- if (!this.isConnected) {
14595
- this.bufferedPackets.push({
14596
- packet: e,
14597
- encryptionType: t
14598
- });
14599
- return;
14600
- }
14601
- switch (e.value.case) {
14495
+ if (!this.isConnected) this.bufferedPackets.push({
14496
+ packet: e,
14497
+ encryptionType: t
14498
+ });
14499
+ else switch (e.value.case) {
14602
14500
  case "streamHeader": return this.handleStreamHeader(e.value.value, e.participantIdentity, t);
14603
14501
  case "streamChunk": return this.handleStreamChunk(e.value.value, t);
14604
14502
  case "streamTrailer": return this.handleStreamTrailer(e.value.value, t);
@@ -14733,12 +14631,11 @@ function ensureOrderedChunks(e) {
14733
14631
  let t = -1;
14734
14632
  return new TransformStream({ transform: (n, r) => {
14735
14633
  let i = bigIntToNumber(n.chunkIndex);
14736
- if (i <= t) {
14737
- k.warn(`ignoring duplicate chunk ${i} ${n.version > 0 ? `(version ${n.version})` : ""} for data stream ${e} (last processed: ${t})`);
14738
- return;
14634
+ if (i <= t) k.warn(`ignoring duplicate chunk ${i} ${n.version > 0 ? `(version ${n.version})` : ""} for data stream ${e} (last processed: ${t})`);
14635
+ else {
14636
+ if (i > t + 1) throw new DataStreamError(`Missing chunk(s) ${t + 1}..${i - 1} for data stream ${e} - cannot reassemble payload`, N.Incomplete);
14637
+ t = i, n.content.length !== 0 && r.enqueue(n);
14739
14638
  }
14740
- if (i > t + 1) throw new DataStreamError(`Missing chunk(s) ${t + 1}..${i - 1} for data stream ${e} - cannot reassemble payload`, N.Incomplete);
14741
- t = i, n.content.length !== 0 && r.enqueue(n);
14742
14639
  } });
14743
14640
  }
14744
14641
  function chunksToBytes() {
@@ -15590,11 +15487,8 @@ var Ua = class DataTrackDepacketizer {
15590
15487
  t.payloads.delete(c.value);
15591
15488
  let i = a.length - l;
15592
15489
  if (r.length > i) throw Error(`Depacketizer.finalize: Expected at least ${r.length} more bytes left in the payload buffer, only got ${i} bytes.`);
15593
- if (a.set(r, l), l += r.length, c.value != n) {
15594
- c.increment();
15595
- continue;
15596
- }
15597
- return this.partials.delete(e), {
15490
+ if (a.set(r, l), l += r.length, c.value != n) c.increment();
15491
+ else return this.partials.delete(e), {
15598
15492
  payload: a,
15599
15493
  extensions: t.extensions
15600
15494
  };
@@ -15679,29 +15573,13 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15679
15573
  }
15680
15574
  setPipelineOptions(e, t) {
15681
15575
  let n = this.descriptors.get(e);
15682
- if (!n) {
15683
- Y.warn(`Unknown track ${e}, cannot set pipeline options.`);
15684
- return;
15685
- }
15686
- n.pipelineOptions = t, n.subscription.type === "active" && n.subscription.pipeline.setOptions(t);
15576
+ n ? (n.pipelineOptions = t, n.subscription.type === "active" && n.subscription.pipeline.setOptions(t)) : Y.warn(`Unknown track ${e}, cannot set pipeline options.`);
15687
15577
  }
15688
15578
  openSubscriptionStream(e, t) {
15689
15579
  let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Ja, r = null, i = new Future(), a = this.descriptors.get(e), detachSignal = () => {
15690
15580
  t?.removeEventListener("abort", onAbort);
15691
15581
  }, cleanup = () => {
15692
- if (detachSignal(), !r) {
15693
- Y.warn(`ReadableStream subscribed to ${e} was not started.`);
15694
- return;
15695
- }
15696
- if (!a || this.descriptors.get(a.info.sid) !== a) {
15697
- Y.warn(`Unknown track ${e}, skipping cancel...`);
15698
- return;
15699
- }
15700
- if (a.subscription.type !== "active") {
15701
- Y.warn(`Subscription for track ${e} is not active, skipping cancel...`);
15702
- return;
15703
- }
15704
- a.subscription.streamControllers.delete(r), a.subscription.streamControllers.size === 0 && this.unSubscribeRequest(a.info.sid);
15582
+ detachSignal(), r ? !a || this.descriptors.get(a.info.sid) !== a ? Y.warn(`Unknown track ${e}, skipping cancel...`) : a.subscription.type === "active" ? (a.subscription.streamControllers.delete(r), a.subscription.streamControllers.size === 0 && this.unSubscribeRequest(a.info.sid)) : Y.warn(`Subscription for track ${e} is not active, skipping cancel...`) : Y.warn(`ReadableStream subscribed to ${e} was not started.`);
15705
15583
  }, onAbort = () => {
15706
15584
  var e;
15707
15585
  r && (a?.subscription.type === "active" && a.subscription.streamControllers.delete(r), r.error(Ga.cancelled()), (e = i.reject) == null || e.call(i, Ga.cancelled()), cleanup());
@@ -15714,19 +15592,11 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15714
15592
  Y.error(`Unknown track ${e}`);
15715
15593
  let t = Ga.disconnected();
15716
15594
  n.error(t), (r = i.reject) == null || r.call(i, t);
15717
- return;
15718
- }
15719
- if (a.subscription.type !== "active") {
15595
+ } else if (a.subscription.type !== "active") {
15720
15596
  Y.error(`Subscription for track ${e} is not active`);
15721
15597
  let t = Ga.disconnected();
15722
15598
  n.error(t), (c = i.reject) == null || c.call(i, t);
15723
- return;
15724
- }
15725
- if (t?.aborted) {
15726
- onAbort();
15727
- return;
15728
- }
15729
- t?.addEventListener("abort", onAbort), a.subscription.streamControllers.set(n, detachSignal), (l = i.resolve) == null || l.call(i);
15599
+ } else t?.aborted ? onAbort() : (t?.addEventListener("abort", onAbort), a.subscription.streamControllers.set(n, detachSignal), (l = i.resolve) == null || l.call(i));
15730
15600
  })).catch((e) => {
15731
15601
  var t;
15732
15602
  n.error(e), (t = i.reject) == null || t.call(i, e);
@@ -15748,17 +15618,7 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15748
15618
  t.subscription.completionFuture.promise.then(() => a.resolve?.call(a)).catch((e) => a.reject?.call(a, e));
15749
15619
  let onAbort = () => {
15750
15620
  var e;
15751
- if (t.subscription.type === "pending") {
15752
- if (--t.subscription.pendingRequestCount, r?.aborted) {
15753
- t.subscription.cancel();
15754
- return;
15755
- }
15756
- if (t.subscription.pendingRequestCount <= 0) {
15757
- t.subscription.cancel();
15758
- return;
15759
- }
15760
- (e = a.reject) == null || e.call(a, Ga.cancelled());
15761
- }
15621
+ t.subscription.type === "pending" && (--t.subscription.pendingRequestCount, r?.aborted || t.subscription.pendingRequestCount <= 0 ? t.subscription.cancel() : (e = a.reject) == null || e.call(a, Ga.cancelled()));
15762
15622
  };
15763
15623
  i.aborted && onAbort(), i.addEventListener("abort", onAbort), yield a.promise, i.removeEventListener("abort", onAbort);
15764
15624
  });
@@ -15829,7 +15689,7 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15829
15689
  for (let r of e.entries()) {
15830
15690
  var n = _slicedToArray(r, 2);
15831
15691
  let e = n[0], i = n[1], a = /* @__PURE__ */ new Set();
15832
- for (let t of i) a.add(t.sid), !this.descriptors.has(t.sid) && (this.handleSidReassigned(e, t) || (yield this.handleTrackPublished(e, t)));
15692
+ for (let t of i) a.add(t.sid), this.descriptors.has(t.sid) || this.handleSidReassigned(e, t) || (yield this.handleTrackPublished(e, t));
15833
15693
  t.set(e, a);
15834
15694
  }
15835
15695
  for (let e of t.entries()) {
@@ -15888,14 +15748,10 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15888
15748
  }
15889
15749
  handleTrackUnpublished(e) {
15890
15750
  let t = this.descriptors.get(e);
15891
- if (!t) {
15892
- Y.error(`Unknown track ${e}`);
15893
- return;
15894
- }
15895
- this.descriptors.delete(e), t.subscription.type === "active" && (this.closeStreamControllers(t.subscription.streamControllers, e), this.subscriptionHandles.delete(t.subscription.subcriptionHandle)), this.emit("trackUnpublished", {
15751
+ t ? (this.descriptors.delete(e), t.subscription.type === "active" && (this.closeStreamControllers(t.subscription.streamControllers, e), this.subscriptionHandles.delete(t.subscription.subcriptionHandle)), this.emit("trackUnpublished", {
15896
15752
  sid: e,
15897
15753
  publisherIdentity: t.publisherIdentity
15898
- });
15754
+ })) : Y.error(`Unknown track ${e}`);
15899
15755
  }
15900
15756
  receivedSfuSubscriberHandles(e) {
15901
15757
  for (let n of e.entries()) {
@@ -15907,11 +15763,8 @@ var Ga = class DataTrackSubscribeError extends LivekitReasonedError {
15907
15763
  registerSubscriberHandle(e, t) {
15908
15764
  var n, r;
15909
15765
  let i = this.descriptors.get(t);
15910
- if (!i) {
15911
- Y.error(`Unknown track ${t}`);
15912
- return;
15913
- }
15914
- switch (i.subscription.type) {
15766
+ if (!i) Y.error(`Unknown track ${t}`);
15767
+ else switch (i.subscription.type) {
15915
15768
  case "none":
15916
15769
  Y.warn(`No subscription for ${t}`);
15917
15770
  return;
@@ -16147,11 +16000,8 @@ var ro = class DataTrackOutgoingPipelineError extends LivekitReasonedError {
16147
16000
  }
16148
16001
  unpublish() {
16149
16002
  return __awaiter(this, void 0, void 0, function* () {
16150
- if (!this.handle) {
16151
- k.warn(`Data track "${this.options.name}" is not published, so unpublishing has no effect.`);
16152
- return;
16153
- }
16154
- try {
16003
+ if (!this.handle) k.warn(`Data track "${this.options.name}" is not published, so unpublishing has no effect.`);
16004
+ else try {
16155
16005
  yield this.manager.unpublishRequest(this.handle);
16156
16006
  } catch (e) {
16157
16007
  throw e;
@@ -16274,11 +16124,7 @@ var X = getLogger(O.DataTracks), oo = {
16274
16124
  let onAbort = () => {
16275
16125
  var e, t;
16276
16126
  let i = this.descriptors.get(n);
16277
- if (!i) {
16278
- X.warn(`No descriptor for ${n}`);
16279
- return;
16280
- }
16281
- this.descriptors.delete(n), this.emit("sfuUnpublishRequest", { handle: n }), i.type === "pending" && ((t = (e = i.completionFuture).reject) == null || t.call(e, r.aborted ? $a.timeout() : $a.cancelled()));
16127
+ i ? (this.descriptors.delete(n), this.emit("sfuUnpublishRequest", { handle: n }), i.type === "pending" && ((t = (e = i.completionFuture).reject) == null || t.call(e, r.aborted ? $a.timeout() : $a.cancelled()))) : X.warn(`No descriptor for ${n}`);
16282
16128
  };
16283
16129
  return i.aborted ? (onAbort(), a.completionFuture.promise.then(() => n)) : (i.addEventListener("abort", onAbort), this.emit("sfuPublishRequest", {
16284
16130
  handle: n,
@@ -16293,25 +16139,14 @@ var X = getLogger(O.DataTracks), oo = {
16293
16139
  unpublishRequest(e) {
16294
16140
  return __awaiter(this, void 0, void 0, function* () {
16295
16141
  let t = this.descriptors.get(e);
16296
- if (!t) {
16297
- X.warn(`No descriptor for ${e}`);
16298
- return;
16299
- }
16300
- if (t.type !== "active") {
16301
- X.warn(`Track ${e} not active`);
16302
- return;
16303
- }
16304
- this.emit("sfuUnpublishRequest", { handle: e }), yield t.unpublishingFuture.promise, this.inFlightPacketCounter.delete(e), this.emit("trackUnpublished", { sid: t.info.sid });
16142
+ t ? t.type === "active" ? (this.emit("sfuUnpublishRequest", { handle: e }), yield t.unpublishingFuture.promise, this.inFlightPacketCounter.delete(e), this.emit("trackUnpublished", { sid: t.info.sid })) : X.warn(`Track ${e} not active`) : X.warn(`No descriptor for ${e}`);
16305
16143
  });
16306
16144
  }
16307
16145
  receivedSfuPublishResponse(e, t) {
16308
16146
  var n, r, i, a;
16309
16147
  let c = this.descriptors.get(e);
16310
- if (!c) {
16311
- X.warn(`No descriptor for ${e}`);
16312
- return;
16313
- }
16314
- switch (this.descriptors.delete(e), c.type) {
16148
+ if (!c) X.warn(`No descriptor for ${e}`);
16149
+ else switch (this.descriptors.delete(e), c.type) {
16315
16150
  case "pending":
16316
16151
  if (t.type === "ok") {
16317
16152
  let i = t.data;
@@ -16335,15 +16170,7 @@ var X = getLogger(O.DataTracks), oo = {
16335
16170
  receivedSfuUnpublishResponse(e) {
16336
16171
  var t, n;
16337
16172
  let r = this.descriptors.get(e);
16338
- if (!r) {
16339
- X.warn(`No descriptor for ${e}`);
16340
- return;
16341
- }
16342
- if (this.descriptors.delete(e), r.type !== "active") {
16343
- X.warn(`Track ${e} not active`);
16344
- return;
16345
- }
16346
- r.publishState = "unpublished", (n = (t = r.unpublishingFuture).resolve) == null || n.call(t);
16173
+ r ? (this.descriptors.delete(e), r.type === "active" ? (r.publishState = "unpublished", (n = (t = r.unpublishingFuture).resolve) == null || n.call(t)) : X.warn(`Track ${e} not active`)) : X.warn(`No descriptor for ${e}`);
16347
16174
  }
16348
16175
  sfuWillRepublishTracks() {
16349
16176
  var e, t;
@@ -16471,20 +16298,16 @@ var RpcClientManager = class extends A.EventEmitter {
16471
16298
  }
16472
16299
  publishRpcRequest(e, t, n, r, i, a) {
16473
16300
  return __awaiter(this, void 0, void 0, function* () {
16474
- if (a >= 1) {
16475
- yield this.outgoingDataStreamManager.sendText(r, {
16476
- topic: uo,
16477
- destinationIdentities: [e],
16478
- attributes: {
16479
- [Q.RPC_REQUEST_ID]: t,
16480
- [Q.RPC_REQUEST_METHOD]: n,
16481
- [Q.RPC_REQUEST_RESPONSE_TIMEOUT_MS]: `${i}`,
16482
- [Q.RPC_REQUEST_VERSION]: `${mo}`
16483
- }
16484
- });
16485
- return;
16486
- }
16487
- this.emit("sendDataPacket", { packet: new T({
16301
+ a >= 1 ? yield this.outgoingDataStreamManager.sendText(r, {
16302
+ topic: uo,
16303
+ destinationIdentities: [e],
16304
+ attributes: {
16305
+ [Q.RPC_REQUEST_ID]: t,
16306
+ [Q.RPC_REQUEST_METHOD]: n,
16307
+ [Q.RPC_REQUEST_RESPONSE_TIMEOUT_MS]: `${i}`,
16308
+ [Q.RPC_REQUEST_VERSION]: `${mo}`
16309
+ }
16310
+ }) : this.emit("sendDataPacket", { packet: new T({
16488
16311
  destinationIdentities: [e],
16489
16312
  kind: Ke.RELIABLE,
16490
16313
  value: {
@@ -16659,19 +16482,11 @@ var RpcClientManager = class extends A.EventEmitter {
16659
16482
  }
16660
16483
  publishRpcResponse(e, t, n) {
16661
16484
  return __awaiter(this, void 0, void 0, function* () {
16662
- if (this.getRemoteParticipantClientProtocol(e) >= 1) {
16663
- yield this.outgoingDataStreamManager.sendText(n, {
16664
- topic: fo,
16665
- destinationIdentities: [e],
16666
- attributes: { [Q.RPC_REQUEST_ID]: t }
16667
- });
16668
- return;
16669
- }
16670
- if (byteLength(n) > lo) {
16671
- this.log.warn(`RPC Response payload too large for request ${t}. To send larger responses, consider updating the sending client.`), this.publishRpcResponsePacket(e, t, null, Z.builtIn("RESPONSE_PAYLOAD_TOO_LARGE"));
16672
- return;
16673
- }
16674
- this.publishRpcResponsePacket(e, t, n, null);
16485
+ this.getRemoteParticipantClientProtocol(e) >= 1 ? yield this.outgoingDataStreamManager.sendText(n, {
16486
+ topic: fo,
16487
+ destinationIdentities: [e],
16488
+ attributes: { [Q.RPC_REQUEST_ID]: t }
16489
+ }) : byteLength(n) > lo ? (this.log.warn(`RPC Response payload too large for request ${t}. To send larger responses, consider updating the sending client.`), this.publishRpcResponsePacket(e, t, null, Z.builtIn("RESPONSE_PAYLOAD_TOO_LARGE"))) : this.publishRpcResponsePacket(e, t, n, null);
16675
16490
  });
16676
16491
  }
16677
16492
  }, RemoteAudioTrack = class extends RemoteTrack {
@@ -16944,10 +16759,10 @@ var Participant = class extends A.EventEmitter {
16944
16759
  }
16945
16760
  }
16946
16761
  waitUntilActive() {
16947
- return this.isActive ? Promise.resolve() : this.activeFuture ? this.activeFuture.promise : (this.activeFuture = new Future(), this.once(F.Active, () => {
16762
+ return this.isActive ? Promise.resolve() : (this.activeFuture || (this.activeFuture = new Future(), this.once(F.Active, () => {
16948
16763
  var e, t;
16949
16764
  (t = (e = this.activeFuture)?.resolve) == null || t.call(e), this.activeFuture = void 0;
16950
- }), this.activeFuture.promise);
16765
+ })), this.activeFuture.promise);
16951
16766
  }
16952
16767
  get connectionQuality() {
16953
16768
  return this._connectionQuality;
@@ -17079,22 +16894,14 @@ var LocalParticipant = class extends Participant {
17079
16894
  }, this.onTrackUnmuted = (e) => {
17080
16895
  this.onTrackMuted(e, e.isUpstreamPaused);
17081
16896
  }, this.onTrackMuted = (e, t) => {
17082
- if (t === void 0 && (t = !0), !e.sid) {
17083
- this.log.error("could not update mute status for unpublished track", getLogContextFromTrack(e));
17084
- return;
17085
- }
17086
- this.engine.updateMuteStatus(e.sid, t);
16897
+ t === void 0 && (t = !0), e.sid ? this.engine.updateMuteStatus(e.sid, t) : this.log.error("could not update mute status for unpublished track", getLogContextFromTrack(e));
17087
16898
  }, this.onTrackUpstreamPaused = (e) => {
17088
16899
  this.log.debug("upstream paused", getLogContextFromTrack(e)), this.onTrackMuted(e, !0);
17089
16900
  }, this.onTrackUpstreamResumed = (e) => {
17090
16901
  this.log.debug("upstream resumed", getLogContextFromTrack(e)), this.onTrackMuted(e, e.isMuted);
17091
16902
  }, this.onTrackFeatureUpdate = (e) => {
17092
16903
  let t = this.audioTrackPublications.get(e.sid);
17093
- if (!t) {
17094
- this.log.warn(`Could not update local audio track settings, missing publication for track ${e.sid}`);
17095
- return;
17096
- }
17097
- this.engine.client.sendUpdateLocalAudioTrack(t.trackSid, t.getTrackFeatures());
16904
+ t ? this.engine.client.sendUpdateLocalAudioTrack(t.trackSid, t.getTrackFeatures()) : this.log.warn(`Could not update local audio track settings, missing publication for track ${e.sid}`);
17098
16905
  }, this.onTrackCpuConstrained = (e, t) => {
17099
16906
  this.log.debug("track cpu constrained", getLogContextFromTrack(t)), this.emit(F.LocalTrackCpuConstrained, e, t);
17100
16907
  }, this.handleSubscribedQualityUpdate = (e) => __awaiter(this, void 0, void 0, function* () {
@@ -17124,11 +16931,7 @@ var LocalParticipant = class extends Participant {
17124
16931
  }
17125
16932
  }), this.handleLocalTrackUnpublished = (e) => {
17126
16933
  let t = this.trackPublications.get(e.trackSid);
17127
- if (!t) {
17128
- this.log.warn("received unpublished event for unknown track", { trackSid: e.trackSid });
17129
- return;
17130
- }
17131
- this.unpublishTrack(t.track);
16934
+ t ? this.unpublishTrack(t.track) : this.log.warn("received unpublished event for unknown track", { trackSid: e.trackSid });
17132
16935
  }, this.handleTrackEnded = (e) => __awaiter(this, void 0, void 0, function* () {
17133
16936
  if (e.source === z.Source.ScreenShare || e.source === z.Source.ScreenShareAudio) this.log.debug("unpublishing local track due to TrackEnded", getLogContextFromTrack(e)), this.unpublishTrack(e);
17134
16937
  else if (e.isUserProvided) yield e.mute();
@@ -18667,11 +18470,7 @@ var _o = 4e3, vo = 3e4, yo = class Room extends A.EventEmitter {
18667
18470
  this.handleParticipantDisconnected(t, e);
18668
18471
  }), this.emit(P.Moved, e.room.name), e.participant ? this.handleParticipantUpdates([e.participant, ...e.otherParticipants]) : this.handleParticipantUpdates(e.otherParticipants);
18669
18472
  }).on(I.PublishDataTrackResponse, (e) => {
18670
- if (!e.info) {
18671
- this.log.warn(`received PublishDataTrackResponse, but event.info was ${e.info}, so skipping.`);
18672
- return;
18673
- }
18674
- this.outgoingDataTrackManager.receivedSfuPublishResponse(e.info.pubHandle, {
18473
+ e.info ? this.outgoingDataTrackManager.receivedSfuPublishResponse(e.info.pubHandle, {
18675
18474
  type: "ok",
18676
18475
  data: {
18677
18476
  sid: e.info.sid,
@@ -18679,13 +18478,9 @@ var _o = 4e3, vo = 3e4, yo = class Room extends A.EventEmitter {
18679
18478
  name: e.info.name,
18680
18479
  usesE2ee: e.info.encryption !== w.NONE
18681
18480
  }
18682
- });
18481
+ }) : this.log.warn(`received PublishDataTrackResponse, but event.info was ${e.info}, so skipping.`);
18683
18482
  }).on(I.UnPublishDataTrackResponse, (e) => {
18684
- if (!e.info) {
18685
- this.log.warn(`received UnPublishDataTrackResponse, but event.info was ${e.info}, so skipping.`);
18686
- return;
18687
- }
18688
- this.outgoingDataTrackManager.receivedSfuUnpublishResponse(e.info.pubHandle);
18483
+ e.info ? this.outgoingDataTrackManager.receivedSfuUnpublishResponse(e.info.pubHandle) : this.log.warn(`received UnPublishDataTrackResponse, but event.info was ${e.info}, so skipping.`);
18689
18484
  }).on(I.DataTrackSubscriberHandles, (e) => {
18690
18485
  let t = new Map(Object.entries(e.subHandles).map((e) => {
18691
18486
  let t = _slicedToArray(e, 2), n = t[0], r = t[1];
@@ -19015,17 +18810,13 @@ var _o = 4e3, vo = 3e4, yo = class Room extends A.EventEmitter {
19015
18810
  let r = kindToSource(n), i = this.localParticipant.getTrackPublication(r);
19016
18811
  if (i && i.track?.isUserProvided) continue;
19017
18812
  let a = t.filter((e) => e.kind === n), c = this.getActiveDevice(n);
19018
- if (c === e.filter((e) => e.kind === n)[0]?.deviceId && a.length > 0 && a[0]?.deviceId !== c) {
19019
- yield this.switchActiveDevice(n, a[0].deviceId);
19020
- continue;
19021
- }
19022
- n === "audioinput" && !isSafariBased() || n === "videoinput" || a.length > 0 && !a.find((e) => e.deviceId === this.getActiveDevice(n)) && (n !== "audiooutput" || !isSafariBased()) && (yield this.switchActiveDevice(n, a[0].deviceId));
18813
+ c === e.filter((e) => e.kind === n)[0]?.deviceId && a.length > 0 && a[0]?.deviceId !== c ? yield this.switchActiveDevice(n, a[0].deviceId) : n === "audioinput" && !isSafariBased() || n === "videoinput" || a.length > 0 && !a.find((e) => e.deviceId === this.getActiveDevice(n)) && (n !== "audiooutput" || !isSafariBased()) && (yield this.switchActiveDevice(n, a[0].deviceId));
19023
18814
  }
19024
18815
  });
19025
18816
  }
19026
18817
  acquireAudioContext() {
19027
18818
  return __awaiter(this, void 0, void 0, function* () {
19028
- if (typeof this.options.webAudioMix != "boolean" && this.options.webAudioMix.audioContext ? this.audioContext = this.options.webAudioMix.audioContext : (!this.audioContext || this.audioContext.state === "closed") && (this.audioContext = getNewAudioContext() ?? void 0), this.options.webAudioMix && this.remoteParticipants.forEach((e) => e.setAudioContext(this.audioContext)), this.localParticipant.setAudioContext(this.audioContext), this.audioContext && this.audioContext.state === "suspended") try {
18819
+ if (typeof this.options.webAudioMix != "boolean" && this.options.webAudioMix.audioContext ? this.audioContext = this.options.webAudioMix.audioContext : this.audioContext && this.audioContext.state !== "closed" || (this.audioContext = getNewAudioContext() ?? void 0), this.options.webAudioMix && this.remoteParticipants.forEach((e) => e.setAudioContext(this.audioContext)), this.localParticipant.setAudioContext(this.audioContext), this.audioContext && this.audioContext.state === "suspended") try {
19029
18820
  yield Promise.race([this.audioContext.resume(), sleep(200)]);
19030
18821
  } catch (e) {
19031
18822
  this.log.warn("Could not resume audio context", { error: e });
@@ -19371,8 +19162,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
19371
19162
  }
19372
19163
  };
19373
19164
  _defineProperty(JWSSignatureVerificationFailed, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
19374
- //#endregion
19375
- //#region bot/voice/providers/livekit/provider.ts
19165
+ // bot/voice/providers/livekit/provider.ts
19376
19166
  var xo = "lk.agent.state", LiveKitVoiceProvider = class {
19377
19167
  constructor(t, n = {}) {
19378
19168
  e(this, "mint", void 0), e(this, "room", void 0), e(this, "createAnalyser", void 0), e(this, "handlers", void 0), e(this, "cancelReadyWait", void 0), e(this, "analysers", []), e(this, "levelSources", []), e(this, "attachedElements", []), e(this, "closing", !1), e(this, "userSpeaking", !1), e(this, "botActiveSpeaker", !1), e(this, "botStateSpeaking", !1), e(this, "lastSpeaking", void 0), e(this, "endReason", void 0), this.mint = t, this.room = n.createRoom?.() ?? new yo(), this.createAnalyser = n.createAnalyser;
@@ -19500,7 +19290,6 @@ var xo = "lk.agent.state", LiveKitVoiceProvider = class {
19500
19290
  function disconnectCause(e) {
19501
19291
  return e === S.ROOM_DELETED || e === S.PARTICIPANT_REMOVED ? "bot" : e === void 0 || e === S.UNKNOWN_REASON ? "unknown" : "network";
19502
19292
  }
19503
- //#endregion
19504
19293
  export { LiveKitVoiceProvider };
19505
19294
 
19506
19295
  //# sourceMappingURL=provider2.js.map