@formant/data-sdk 1.30.0 → 1.32.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.
@@ -26813,10 +26813,11 @@ function WorkerWrapper() {
26813
26813
  e && (window.URL || window.webkitURL).revokeObjectURL(e);
26814
26814
  }
26815
26815
  }
26816
- const debug = new URLSearchParams(window.location.search).get("debug") === "true";
26816
+ const debug = new URLSearchParams(window.location.search).get("debug") === "true", PCD_WORKER_POOL_SIZE = 5;
26817
26817
  class BasicUniverseDataConnector {
26818
26818
  constructor() {
26819
- Fe(this, "pcdWorker", new WorkerWrapper$1());
26819
+ Fe(this, "pcdWorkerPool", []);
26820
+ Fe(this, "pcdWorkerPoolOccupancy", [!1, !1, !1, !1, !1]);
26820
26821
  Fe(this, "subscriberSources", /* @__PURE__ */ new Map());
26821
26822
  Fe(this, "subscriberLoaders", /* @__PURE__ */ new Map());
26822
26823
  Fe(this, "subscriberDistributorsLoaders", /* @__PURE__ */ new Map());
@@ -26825,6 +26826,10 @@ class BasicUniverseDataConnector {
26825
26826
  Fe(this, "time");
26826
26827
  Fe(this, "timeChangeListeners", []);
26827
26828
  this.time = "live";
26829
+ for (let n = 0; n < PCD_WORKER_POOL_SIZE; n++) {
26830
+ const r = new WorkerWrapper$1();
26831
+ this.pcdWorkerPool.push(r);
26832
+ }
26828
26833
  const t = async () => {
26829
26834
  if (Array.from(this.subscriberLoaders.keys()).length > 0) {
26830
26835
  const n = [], r = await Fleet.queryTelemetry(this.generateTelemetryFilter());
@@ -26860,6 +26865,19 @@ class BasicUniverseDataConnector {
26860
26865
  setTime(t) {
26861
26866
  t !== "live" && (this.time = t), this.timeChangeListeners.forEach((n) => n(t));
26862
26867
  }
26868
+ getAvailableWorker() {
26869
+ for (let t = 0; t < PCD_WORKER_POOL_SIZE; t++)
26870
+ if (!this.pcdWorkerPoolOccupancy[t])
26871
+ return this.pcdWorkerPoolOccupancy[t] = !0, this.pcdWorkerPool[t];
26872
+ }
26873
+ releaseWorker(t) {
26874
+ const n = this.pcdWorkerPool.indexOf(t);
26875
+ this.pcdWorkerPoolOccupancy[n] = !1;
26876
+ }
26877
+ clearWorkerPool() {
26878
+ for (let t = 0; t < PCD_WORKER_POOL_SIZE; t++)
26879
+ this.pcdWorkerPoolOccupancy[t] = !1;
26880
+ }
26863
26881
  generateTelemetryFilter() {
26864
26882
  const t = Array.from(this.subscriberSources.keys()), n = [];
26865
26883
  return t.forEach((r) => {
@@ -27291,25 +27309,28 @@ class LiveUniverseData extends BasicUniverseDataConnector {
27291
27309
  };
27292
27310
  }
27293
27311
  subscribeToPointCloud(t, n, r) {
27312
+ const l = this.getAvailableWorker();
27313
+ if (!l)
27314
+ throw new Error("No available pointcloud worker");
27294
27315
  if (n.sourceType === "telemetry" && n.streamType !== "localization")
27295
27316
  return this.addRemovableTelemetrySubscription(
27296
27317
  t,
27297
27318
  n,
27298
- async (l) => {
27299
- let s, c;
27300
- for (let o = 0; o < l.length; o += 1) {
27301
- const d = l[o];
27302
- if (d.deviceId === t && d.name === n.streamName && d.type === "point cloud") {
27303
- const [u, U] = d.points[d.points.length - 1];
27304
- s = U;
27319
+ async (s) => {
27320
+ let c, o;
27321
+ for (let d = 0; d < s.length; d += 1) {
27322
+ const u = s[d];
27323
+ if (u.deviceId === t && u.name === n.streamName && u.type === "point cloud") {
27324
+ const [U, S] = u.points[u.points.length - 1];
27325
+ c = S;
27305
27326
  break;
27306
27327
  }
27307
27328
  }
27308
- if (s) {
27309
- const { url: o } = s;
27310
- c = await new Promise((d) => {
27311
- this.pcdWorker.postMessage({ url: o }), this.pcdWorker.onmessage = (u) => {
27312
- u.data.url === o && d(u.data.pcd);
27329
+ if (c) {
27330
+ const { url: d } = c;
27331
+ o = await new Promise((u) => {
27332
+ l.postMessage({ url: d }), l.onmessage = (U) => {
27333
+ U.data.url === d && u(U.data.pcd);
27313
27334
  };
27314
27335
  });
27315
27336
  }
@@ -27317,8 +27338,8 @@ class LiveUniverseData extends BasicUniverseDataConnector {
27317
27338
  deviceId: t,
27318
27339
  sourceId: n.id,
27319
27340
  data: {
27320
- worldToLocal: s == null ? void 0 : s.worldToLocal,
27321
- pcd: c
27341
+ worldToLocal: c == null ? void 0 : c.worldToLocal,
27342
+ pcd: o
27322
27343
  }
27323
27344
  };
27324
27345
  },
@@ -27328,21 +27349,21 @@ class LiveUniverseData extends BasicUniverseDataConnector {
27328
27349
  return this.addRemovableTelemetrySubscription(
27329
27350
  t,
27330
27351
  n,
27331
- async (l) => {
27332
- let s, c;
27333
- for (let o = 0; o < l.length; o += 1) {
27334
- const d = l[o];
27335
- if (d.deviceId === t && d.name === n.streamName && d.type === "localization") {
27336
- const [u, U] = d.points[d.points.length - 1];
27337
- s = U;
27352
+ async (s) => {
27353
+ let c, o;
27354
+ for (let d = 0; d < s.length; d += 1) {
27355
+ const u = s[d];
27356
+ if (u.deviceId === t && u.name === n.streamName && u.type === "localization") {
27357
+ const [U, S] = u.points[u.points.length - 1];
27358
+ c = S;
27338
27359
  break;
27339
27360
  }
27340
27361
  }
27341
- if (s && s.pointClouds) {
27342
- const { url: o } = s.pointClouds[0];
27343
- c = await new Promise((d) => {
27344
- this.pcdWorker.postMessage({ url: o }), this.pcdWorker.onmessage = (u) => {
27345
- u.data.url === o && d(u.data.pcd);
27362
+ if (c && c.pointClouds) {
27363
+ const { url: d } = c.pointClouds[0];
27364
+ o = await new Promise((u) => {
27365
+ l.postMessage({ url: d }), l.onmessage = (U) => {
27366
+ U.data.url === d && u(U.data.pcd);
27346
27367
  };
27347
27368
  });
27348
27369
  }
@@ -27350,36 +27371,36 @@ class LiveUniverseData extends BasicUniverseDataConnector {
27350
27371
  deviceId: t,
27351
27372
  sourceId: n.id,
27352
27373
  data: {
27353
- worldToLocal: s && (s != null && s.pointClouds) && (s != null && s.pointClouds[0]) ? s.pointClouds[0].worldToLocal : void 0,
27354
- pcd: c
27374
+ worldToLocal: c && (c != null && c.pointClouds) && (c != null && c.pointClouds[0]) ? c.pointClouds[0].worldToLocal : void 0,
27375
+ pcd: o
27355
27376
  }
27356
27377
  };
27357
27378
  },
27358
27379
  r
27359
27380
  );
27360
27381
  if (n.sourceType === "realtime") {
27361
- const l = async (s, c) => {
27362
- var o;
27363
- if (c.payload.pointCloud) {
27364
- const d = Math.random(), u = await new Promise((U) => {
27365
- this.pcdWorker.postMessage({
27366
- id: d,
27367
- pointCloud: defined(c.payload.pointCloud).data
27368
- }), this.pcdWorker.onmessage = (S) => {
27369
- S.data.id === d && U(S.data.pcd);
27382
+ const s = async (c, o) => {
27383
+ var d;
27384
+ if (o.payload.pointCloud) {
27385
+ const u = Math.random(), U = await new Promise((S) => {
27386
+ l.postMessage({
27387
+ id: u,
27388
+ pointCloud: defined(o.payload.pointCloud).data
27389
+ }), l.onmessage = (R) => {
27390
+ R.data.id === u && S(R.data.pcd);
27370
27391
  };
27371
27392
  });
27372
27393
  r({
27373
- worldToLocal: (o = c.payload.pointCloud) == null ? void 0 : o.world_to_local,
27374
- pcd: u
27394
+ worldToLocal: (d = o.payload.pointCloud) == null ? void 0 : d.world_to_local,
27395
+ pcd: U
27375
27396
  });
27376
27397
  }
27377
27398
  };
27378
- return this.subscribeToRealtimeMessages(t, n.rosTopicName, l), () => {
27399
+ return this.subscribeToRealtimeMessages(t, n.rosTopicName, s), () => {
27379
27400
  this.unsubscribeToRealtimeMessages(
27380
27401
  t,
27381
27402
  n.rosTopicName,
27382
- l
27403
+ s
27383
27404
  );
27384
27405
  };
27385
27406
  }
@@ -27780,55 +27801,58 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
27780
27801
  subscribeToPointCloud(n, r, l) {
27781
27802
  if (r.sourceType !== "telemetry")
27782
27803
  throw new Error("Telemetry sources only supported");
27783
- const s = this.subscribeToJson(
27804
+ const s = this.getAvailableWorker();
27805
+ if (!s)
27806
+ throw new Error("No available pointcloud worker");
27807
+ const c = this.subscribeToJson(
27784
27808
  n,
27785
27809
  r,
27786
27810
  l
27787
- ), c = this.subscribeTelemetry(
27811
+ ), o = this.subscribeTelemetry(
27788
27812
  n,
27789
27813
  r,
27790
27814
  "point cloud",
27791
- async (d) => {
27792
- if (d === "too much data" || d === void 0) {
27815
+ async (u) => {
27816
+ if (u === "too much data" || u === void 0) {
27793
27817
  l(NoData);
27794
27818
  return;
27795
27819
  }
27796
- const u = d[d.length - 1][1];
27797
- if (typeof u == "string")
27798
- l(JSON.parse(u));
27820
+ const U = u[u.length - 1][1];
27821
+ if (typeof U == "string")
27822
+ l(JSON.parse(U));
27799
27823
  else {
27800
- const { url: U } = u;
27801
- this.pcdWorker.postMessage({ url: U }), this.pcdWorker.onmessage = (S) => {
27802
- S.data.url === U && l({
27803
- worldToLocal: u.worldToLocal,
27804
- pcd: S.data.pcd
27824
+ const { url: S } = U;
27825
+ s.postMessage({ url: S }), s.onmessage = (R) => {
27826
+ R.data.url === S && l({
27827
+ worldToLocal: U.worldToLocal,
27828
+ pcd: R.data.pcd
27805
27829
  });
27806
27830
  };
27807
27831
  }
27808
27832
  }
27809
- ), o = this.subscribeTelemetry(
27833
+ ), d = this.subscribeTelemetry(
27810
27834
  n,
27811
27835
  r,
27812
27836
  "localization",
27813
- async (d) => {
27814
- if (d === "too much data" || d === void 0) {
27837
+ async (u) => {
27838
+ if (u === "too much data" || u === void 0) {
27815
27839
  l(NoData);
27816
27840
  return;
27817
27841
  }
27818
- let u = d[d.length - 1][1];
27819
- if (u.url && (u = await (await fetch(u.url)).json()), u.pointClouds) {
27820
- const { url: U, worldToLocal: S } = u.pointClouds[0];
27821
- this.pcdWorker.postMessage({ url: U }), this.pcdWorker.onmessage = (R) => {
27822
- R.data.url === U && l({
27823
- worldToLocal: S,
27824
- pcd: R.data.pcd
27842
+ let U = u[u.length - 1][1];
27843
+ if (U.url && (U = await (await fetch(U.url)).json()), U.pointClouds) {
27844
+ const { url: S, worldToLocal: R } = U.pointClouds[0];
27845
+ s.postMessage({ url: S }), s.onmessage = (p) => {
27846
+ p.data.url === S && l({
27847
+ worldToLocal: R,
27848
+ pcd: p.data.pcd
27825
27849
  });
27826
27850
  };
27827
27851
  }
27828
27852
  }
27829
27853
  );
27830
27854
  return () => {
27831
- s(), c(), o();
27855
+ c(), o(), d();
27832
27856
  };
27833
27857
  }
27834
27858
  subscribeToOdometry(n, r, l) {