@formant/data-sdk 1.40.0 → 1.41.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.
- package/dist/data-sdk.cjs.js +1 -1
- package/dist/data-sdk.cjs.js.map +1 -1
- package/dist/data-sdk.es.js +149 -135
- package/dist/data-sdk.es.js.map +1 -1
- package/dist/data-sdk.es6.js +149 -135
- package/dist/data-sdk.umd.js +1 -1
- package/dist/types/data-sdk/src/connector/model/IUniverseGridMap.d.ts +1 -1
- package/package.json +1 -1
package/dist/data-sdk.es6.js
CHANGED
|
@@ -31507,7 +31507,7 @@ class QueryStore {
|
|
|
31507
31507
|
...t,
|
|
31508
31508
|
start: n,
|
|
31509
31509
|
end: o
|
|
31510
|
-
}), !s || s === "too much data" || t.latestOnly ? s : filterDataByTime(s, new Date(
|
|
31510
|
+
}), !s || s === "too much data" || t.latestOnly ? s : filterDataByTime(s, new Date(n), new Date(o));
|
|
31511
31511
|
}
|
|
31512
31512
|
queryCache(t) {
|
|
31513
31513
|
return this.queryStoreCache.get(t, async () => {
|
|
@@ -32196,7 +32196,7 @@ class LiveUniverseData extends BasicUniverseDataConnector {
|
|
|
32196
32196
|
rotation: l.info.origin.orientation
|
|
32197
32197
|
},
|
|
32198
32198
|
data: l.data,
|
|
32199
|
-
|
|
32199
|
+
alpha: l.data.map(() => 255)
|
|
32200
32200
|
});
|
|
32201
32201
|
}
|
|
32202
32202
|
};
|
|
@@ -32223,18 +32223,20 @@ class LiveUniverseData extends BasicUniverseDataConnector {
|
|
|
32223
32223
|
if (s && s.map) {
|
|
32224
32224
|
const l = document.createElement("canvas"), u = await this.fetchImage(s.map.url);
|
|
32225
32225
|
l.width = u.width, l.height = u.height;
|
|
32226
|
-
const c = l.getContext("2d"
|
|
32226
|
+
const c = l.getContext("2d", {
|
|
32227
|
+
willReadFrequently: !0
|
|
32228
|
+
});
|
|
32227
32229
|
c && c.drawImage(u, 0, 0);
|
|
32228
32230
|
const p = c == null ? void 0 : c.getImageData(
|
|
32229
32231
|
0,
|
|
32230
32232
|
0,
|
|
32231
32233
|
u.width,
|
|
32232
32234
|
u.height
|
|
32233
|
-
), v = [];
|
|
32235
|
+
), v = [], _ = [];
|
|
32234
32236
|
if (p)
|
|
32235
|
-
for (let
|
|
32236
|
-
const y = p.data[
|
|
32237
|
-
v.push(
|
|
32237
|
+
for (let y = 0; y < p.data.length; y += 4) {
|
|
32238
|
+
const f = p.data[y], h = p.data[y + 3];
|
|
32239
|
+
v.push(f), _.push(h);
|
|
32238
32240
|
}
|
|
32239
32241
|
g = {
|
|
32240
32242
|
width: s.map.width,
|
|
@@ -32242,7 +32244,7 @@ class LiveUniverseData extends BasicUniverseDataConnector {
|
|
|
32242
32244
|
worldToLocal: s.map.worldToLocal,
|
|
32243
32245
|
resolution: s.map.resolution,
|
|
32244
32246
|
origin: s.map.origin,
|
|
32245
|
-
|
|
32247
|
+
alpha: _,
|
|
32246
32248
|
data: v
|
|
32247
32249
|
};
|
|
32248
32250
|
}
|
|
@@ -32337,23 +32339,31 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32337
32339
|
subscribeToPath(r, n, o) {
|
|
32338
32340
|
if (n.sourceType !== "telemetry")
|
|
32339
32341
|
throw new Error("Telemetry sources only supported");
|
|
32340
|
-
|
|
32342
|
+
const s = this.getAvailableDataFetchWorker();
|
|
32343
|
+
if (!s)
|
|
32344
|
+
throw new Error("No available data fetch worker");
|
|
32345
|
+
const g = this.subscribeTelemetry(
|
|
32341
32346
|
r,
|
|
32342
32347
|
n,
|
|
32343
32348
|
"localization",
|
|
32344
|
-
async (
|
|
32345
|
-
if (
|
|
32349
|
+
async (l) => {
|
|
32350
|
+
if (l === "too much data" || l === void 0) {
|
|
32346
32351
|
o(NoData);
|
|
32347
32352
|
return;
|
|
32348
32353
|
}
|
|
32349
|
-
const
|
|
32350
|
-
let
|
|
32351
|
-
|
|
32352
|
-
|
|
32353
|
-
|
|
32354
|
+
const u = l[l.length - 1][1];
|
|
32355
|
+
let c = u;
|
|
32356
|
+
u.url && (s.postMessage({ url: u.url }), s.onmessage = (p) => {
|
|
32357
|
+
c = p.data.response, c.path && o({
|
|
32358
|
+
worldToLocal: c.path.worldToLocal,
|
|
32359
|
+
poses: c.path.poses
|
|
32360
|
+
});
|
|
32354
32361
|
});
|
|
32355
32362
|
}
|
|
32356
32363
|
);
|
|
32364
|
+
return () => {
|
|
32365
|
+
this.releaseDataFetchWorker(s), g();
|
|
32366
|
+
};
|
|
32357
32367
|
}
|
|
32358
32368
|
onTimeChange(r) {
|
|
32359
32369
|
r === "live" ? this.liveIntervalHandle = setInterval(() => {
|
|
@@ -32427,66 +32437,47 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32427
32437
|
const s = this.getAvailablePCDWorker();
|
|
32428
32438
|
if (!s)
|
|
32429
32439
|
throw new Error("No available pointcloud worker");
|
|
32430
|
-
const g =
|
|
32431
|
-
|
|
32432
|
-
|
|
32433
|
-
}, v = {
|
|
32434
|
-
...n,
|
|
32435
|
-
latestDataPoint: !0
|
|
32436
|
-
}, _ = this.subscribeTelemetry(
|
|
32437
|
-
r,
|
|
32438
|
-
v,
|
|
32439
|
-
"point cloud",
|
|
32440
|
-
async (f) => {
|
|
32441
|
-
f !== void 0 && typeof f != "symbol" && p("pointcloud");
|
|
32442
|
-
}
|
|
32443
|
-
), y = this.subscribeTelemetry(
|
|
32444
|
-
r,
|
|
32445
|
-
v,
|
|
32446
|
-
"localization",
|
|
32447
|
-
async (f) => {
|
|
32448
|
-
f !== void 0 && typeof f != "symbol" && p("localization");
|
|
32449
|
-
}
|
|
32450
|
-
);
|
|
32451
|
-
});
|
|
32440
|
+
const g = this.getAvailableDataFetchWorker();
|
|
32441
|
+
if (!g)
|
|
32442
|
+
throw new Error("No available data fetch worker");
|
|
32452
32443
|
let l = () => {
|
|
32453
32444
|
}, u = () => {
|
|
32454
32445
|
};
|
|
32455
|
-
return
|
|
32456
|
-
|
|
32457
|
-
|
|
32458
|
-
|
|
32459
|
-
|
|
32460
|
-
|
|
32461
|
-
|
|
32462
|
-
|
|
32463
|
-
return;
|
|
32464
|
-
}
|
|
32465
|
-
const v = p[p.length - 1][1];
|
|
32466
|
-
if (typeof v == "string")
|
|
32467
|
-
o(JSON.parse(v));
|
|
32468
|
-
else {
|
|
32469
|
-
const { url: _ } = v;
|
|
32470
|
-
s.postMessage({ url: _ }), s.onmessage = (y) => {
|
|
32471
|
-
y.data.url === _ && o({
|
|
32472
|
-
worldToLocal: v.worldToLocal,
|
|
32473
|
-
pcd: y.data.pcd
|
|
32474
|
-
});
|
|
32475
|
-
};
|
|
32476
|
-
}
|
|
32446
|
+
return n.streamType === "point cloud" ? l = this.subscribeTelemetry(
|
|
32447
|
+
r,
|
|
32448
|
+
n,
|
|
32449
|
+
"point cloud",
|
|
32450
|
+
async (c) => {
|
|
32451
|
+
if (c === "too much data" || c === void 0) {
|
|
32452
|
+
o(NoData);
|
|
32453
|
+
return;
|
|
32477
32454
|
}
|
|
32478
|
-
|
|
32479
|
-
|
|
32480
|
-
|
|
32481
|
-
|
|
32482
|
-
|
|
32483
|
-
|
|
32484
|
-
o(
|
|
32485
|
-
|
|
32486
|
-
|
|
32487
|
-
|
|
32488
|
-
|
|
32489
|
-
|
|
32455
|
+
const p = c[c.length - 1][1];
|
|
32456
|
+
if (typeof p == "string")
|
|
32457
|
+
o(JSON.parse(p));
|
|
32458
|
+
else {
|
|
32459
|
+
const { url: v } = p;
|
|
32460
|
+
s.postMessage({ url: v }), s.onmessage = (_) => {
|
|
32461
|
+
_.data.url === v && o({
|
|
32462
|
+
worldToLocal: p.worldToLocal,
|
|
32463
|
+
pcd: _.data.pcd
|
|
32464
|
+
});
|
|
32465
|
+
};
|
|
32466
|
+
}
|
|
32467
|
+
}
|
|
32468
|
+
) : n.streamType === "localization" && (u = this.subscribeTelemetry(
|
|
32469
|
+
r,
|
|
32470
|
+
n,
|
|
32471
|
+
"localization",
|
|
32472
|
+
async (c) => {
|
|
32473
|
+
if (c === "too much data" || c === void 0) {
|
|
32474
|
+
o(NoData);
|
|
32475
|
+
return;
|
|
32476
|
+
}
|
|
32477
|
+
let p = c[c.length - 1][1];
|
|
32478
|
+
p.url && (g.postMessage({ url: p.url }), g.onmessage = (v) => {
|
|
32479
|
+
if (p = v.data.response, p.pointClouds) {
|
|
32480
|
+
const { url: _, worldToLocal: y } = p.pointClouds[0];
|
|
32490
32481
|
s.postMessage({ url: _ }), s.onmessage = (f) => {
|
|
32491
32482
|
f.data.url === _ && o({
|
|
32492
32483
|
worldToLocal: y,
|
|
@@ -32494,10 +32485,10 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32494
32485
|
});
|
|
32495
32486
|
};
|
|
32496
32487
|
}
|
|
32497
|
-
}
|
|
32498
|
-
|
|
32499
|
-
|
|
32500
|
-
this.releasePCDWorker(s), l(), u();
|
|
32488
|
+
});
|
|
32489
|
+
}
|
|
32490
|
+
)), () => {
|
|
32491
|
+
this.releasePCDWorker(s), this.releaseDataFetchWorker(g), l(), u();
|
|
32501
32492
|
};
|
|
32502
32493
|
}
|
|
32503
32494
|
subscribeToOdometry(r, n, o) {
|
|
@@ -32506,31 +32497,31 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32506
32497
|
const s = this.getAvailableDataFetchWorker();
|
|
32507
32498
|
if (!s)
|
|
32508
32499
|
throw new Error("No available data fetch worker");
|
|
32509
|
-
|
|
32500
|
+
const g = this.subscribeTelemetry(
|
|
32510
32501
|
r,
|
|
32511
32502
|
n,
|
|
32512
32503
|
"localization",
|
|
32513
|
-
async (
|
|
32514
|
-
if (
|
|
32504
|
+
async (l) => {
|
|
32505
|
+
if (l === "too much data" || l === void 0) {
|
|
32515
32506
|
o(NoData);
|
|
32516
32507
|
return;
|
|
32517
32508
|
}
|
|
32518
|
-
const
|
|
32519
|
-
let
|
|
32520
|
-
|
|
32521
|
-
|
|
32522
|
-
worldToLocal:
|
|
32509
|
+
const u = l[l.length - 1][1];
|
|
32510
|
+
let c = u;
|
|
32511
|
+
u.url && (s.postMessage({ url: u.url }), s.onmessage = (p) => {
|
|
32512
|
+
c = p.data.response, c.odometry && o({
|
|
32513
|
+
worldToLocal: c.odometry.worldToLocal,
|
|
32523
32514
|
pose: {
|
|
32524
32515
|
translation: {
|
|
32525
|
-
x:
|
|
32526
|
-
y:
|
|
32527
|
-
z:
|
|
32516
|
+
x: c.odometry.pose.translation.x,
|
|
32517
|
+
y: c.odometry.pose.translation.y,
|
|
32518
|
+
z: c.odometry.pose.translation.z
|
|
32528
32519
|
},
|
|
32529
32520
|
rotation: {
|
|
32530
|
-
x:
|
|
32531
|
-
y:
|
|
32532
|
-
z:
|
|
32533
|
-
w:
|
|
32521
|
+
x: c.odometry.pose.rotation.x,
|
|
32522
|
+
y: c.odometry.pose.rotation.y,
|
|
32523
|
+
z: c.odometry.pose.rotation.z,
|
|
32524
|
+
w: c.odometry.pose.rotation.w
|
|
32534
32525
|
}
|
|
32535
32526
|
},
|
|
32536
32527
|
covariance: []
|
|
@@ -32538,6 +32529,9 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32538
32529
|
});
|
|
32539
32530
|
}
|
|
32540
32531
|
);
|
|
32532
|
+
return () => {
|
|
32533
|
+
this.releaseDataFetchWorker(s), g();
|
|
32534
|
+
};
|
|
32541
32535
|
}
|
|
32542
32536
|
subscribeToPose(r, n, o) {
|
|
32543
32537
|
throw new Error("Method not implemented for telemetry universe connector.");
|
|
@@ -32547,16 +32541,24 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32547
32541
|
const s = this.getAvailableDataFetchWorker();
|
|
32548
32542
|
if (!s)
|
|
32549
32543
|
throw new Error("No available data fetch worker");
|
|
32550
|
-
|
|
32551
|
-
|
|
32552
|
-
|
|
32553
|
-
|
|
32544
|
+
const g = this.subscribeTelemetry(
|
|
32545
|
+
r,
|
|
32546
|
+
n,
|
|
32547
|
+
"json",
|
|
32548
|
+
async (l) => {
|
|
32549
|
+
if (l === "too much data" || l === void 0) {
|
|
32550
|
+
o(NoData);
|
|
32551
|
+
return;
|
|
32552
|
+
}
|
|
32553
|
+
let u = l[l.length - 1][1];
|
|
32554
|
+
u.startsWith("http") && (s.postMessage({ url: u }), s.onmessage = (c) => {
|
|
32555
|
+
u = JSON.stringify(c.data), o(JSON.parse(u));
|
|
32556
|
+
});
|
|
32554
32557
|
}
|
|
32555
|
-
|
|
32556
|
-
|
|
32557
|
-
|
|
32558
|
-
|
|
32559
|
-
});
|
|
32558
|
+
);
|
|
32559
|
+
return () => {
|
|
32560
|
+
this.releaseDataFetchWorker(s), g();
|
|
32561
|
+
};
|
|
32560
32562
|
} else
|
|
32561
32563
|
throw new Error("Realtime geometry note supported");
|
|
32562
32564
|
}
|
|
@@ -32564,53 +32566,65 @@ class TelemetryUniverseData extends BasicUniverseDataConnector {
|
|
|
32564
32566
|
return this.subscribeToJson(r, n, o);
|
|
32565
32567
|
}
|
|
32566
32568
|
subscribeToGridMap(r, n, o) {
|
|
32569
|
+
const s = {};
|
|
32567
32570
|
if (n.sourceType !== "telemetry")
|
|
32568
32571
|
throw new Error("Telemetry sources only supported");
|
|
32569
|
-
const
|
|
32570
|
-
if (!
|
|
32572
|
+
const g = this.getAvailableDataFetchWorker();
|
|
32573
|
+
if (!g)
|
|
32571
32574
|
throw new Error("No available data fetch worker");
|
|
32572
|
-
|
|
32575
|
+
const l = this.subscribeTelemetry(
|
|
32573
32576
|
r,
|
|
32574
32577
|
n,
|
|
32575
32578
|
"localization",
|
|
32576
|
-
async (
|
|
32577
|
-
if (
|
|
32579
|
+
async (u) => {
|
|
32580
|
+
if (u === "too much data" || u === void 0) {
|
|
32578
32581
|
o(NoData);
|
|
32579
32582
|
return;
|
|
32580
32583
|
}
|
|
32581
|
-
const
|
|
32582
|
-
|
|
32583
|
-
|
|
32584
|
-
|
|
32585
|
-
|
|
32586
|
-
p.width = v.width, p.height = v.height;
|
|
32587
|
-
const _ = p.getContext("2d");
|
|
32588
|
-
_ && _.drawImage(v, 0, 0);
|
|
32589
|
-
const y = _ == null ? void 0 : _.getImageData(
|
|
32590
|
-
0,
|
|
32591
|
-
0,
|
|
32592
|
-
v.width,
|
|
32593
|
-
v.height
|
|
32594
|
-
), f = [];
|
|
32595
|
-
if (y)
|
|
32596
|
-
for (let w = 0; w < y.data.length; w += 4) {
|
|
32597
|
-
const C = y.data[w];
|
|
32598
|
-
f.push(C);
|
|
32599
|
-
}
|
|
32600
|
-
const h = {
|
|
32601
|
-
width: u.map.width,
|
|
32602
|
-
height: u.map.height,
|
|
32603
|
-
worldToLocal: u.map.worldToLocal,
|
|
32604
|
-
resolution: u.map.resolution,
|
|
32605
|
-
origin: u.map.origin,
|
|
32606
|
-
canvas: p,
|
|
32607
|
-
data: f
|
|
32608
|
-
};
|
|
32609
|
-
o(h);
|
|
32584
|
+
const c = u[u.length - 1][1];
|
|
32585
|
+
if (c.url) {
|
|
32586
|
+
if (s[c.url]) {
|
|
32587
|
+
o(s[c.url]);
|
|
32588
|
+
return;
|
|
32610
32589
|
}
|
|
32611
|
-
|
|
32590
|
+
g.postMessage({ url: c.url }), g.onmessage = async (p) => {
|
|
32591
|
+
const v = p.data.response.map;
|
|
32592
|
+
if (v) {
|
|
32593
|
+
const _ = document.createElement("canvas"), y = await this.fetchImage(v.url);
|
|
32594
|
+
_.width = y.width, _.height = y.height;
|
|
32595
|
+
const f = _.getContext("2d", {
|
|
32596
|
+
willReadFrequently: !0
|
|
32597
|
+
});
|
|
32598
|
+
f && f.drawImage(y, 0, 0);
|
|
32599
|
+
const h = f == null ? void 0 : f.getImageData(
|
|
32600
|
+
0,
|
|
32601
|
+
0,
|
|
32602
|
+
y.width,
|
|
32603
|
+
y.height
|
|
32604
|
+
), w = [], C = [];
|
|
32605
|
+
if (h)
|
|
32606
|
+
for (let E = 0; E < h.data.length; E += 4) {
|
|
32607
|
+
const T = h.data[E], d = h.data[E + 3];
|
|
32608
|
+
w.push(T), C.push(d);
|
|
32609
|
+
}
|
|
32610
|
+
const x = {
|
|
32611
|
+
width: v.width,
|
|
32612
|
+
height: v.height,
|
|
32613
|
+
worldToLocal: v.worldToLocal,
|
|
32614
|
+
resolution: v.resolution,
|
|
32615
|
+
origin: v.origin,
|
|
32616
|
+
alpha: C,
|
|
32617
|
+
data: w
|
|
32618
|
+
};
|
|
32619
|
+
s[c.url] = JSON.parse(JSON.stringify(x)), o(x);
|
|
32620
|
+
}
|
|
32621
|
+
};
|
|
32622
|
+
}
|
|
32612
32623
|
}
|
|
32613
32624
|
);
|
|
32625
|
+
return () => {
|
|
32626
|
+
this.releaseDataFetchWorker(g), l();
|
|
32627
|
+
};
|
|
32614
32628
|
}
|
|
32615
32629
|
subscribeToVideo(r, n, o) {
|
|
32616
32630
|
if (n.sourceType !== "telemetry")
|
package/dist/data-sdk.umd.js
CHANGED
|
@@ -99,4 +99,4 @@ Found: ${s.toString().split(`
|
|
|
99
99
|
|
|
100
100
|
gl_FragColor = vec4(y, u, v, 1) * YUV2RGB;
|
|
101
101
|
}
|
|
102
|
-
`,o=[1.16438,0,1.59603,-.87079,1.16438,-.39176,-.81297,.52959,1.16438,2.01723,0,-1.08139,0,0,0,1],s=t.createShader(t.VERTEX_SHADER);if(!s)throw new Error("Failed to create vertex shader");t.shaderSource(s,r),t.compileShader(s);const g=t.createShader(t.FRAGMENT_SHADER);if(!g)throw new Error("Failed to create fragment shader");t.shaderSource(g,n),t.compileShader(g);const l=t.createProgram();if(!l)throw new Error("Failed to create webgl program");t.attachShader(l,s),t.attachShader(l,g),t.linkProgram(l),t.useProgram(l);const u=t.getUniformLocation(l,"YUV2RGB");return t.uniformMatrix4fv(u,!1,o),l}initBuffers(){const{gl:t,program:r}=this,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),t.STATIC_DRAW);const o=t.getAttribLocation(r,"vertexPos");t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0);const s=t.createBuffer();if(!s)throw new Error("Failed to create WebGL buffer");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),t.STATIC_DRAW);const g=t.getAttribLocation(r,"texturePos");return t.enableVertexAttribArray(g),t.vertexAttribPointer(g,2,t.FLOAT,!1,0,0),{texturePosBuffer:s}}initTextures(){const{gl:t,program:r}=this,n=this.initTexture(),o=t.getUniformLocation(r,"yuvSampler");return t.uniform1i(o,0),{textureRef:n}}initTexture(){const{gl:t}=this,r=t.createTexture();if(!r)throw new Error("Failed to initialize texture");return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null),r}}const decoderNotWorkingThreshold=duration$1.second*2.5,warnPerformanceThreshold=duration$1.second/3,noSignalThreshold=duration$1.second*2,maxQueueSize=5,maxDropRatio=30/25,numRetries=5,hardwareIncompatibleErrorCode=1282;class H264BytestreamCanvasDrawer{constructor(t,r,n,o,s){__publicField(this,"_waitingForDecoder",!0),__publicField(this,"_noSignal",!0),__publicField(this,"_lostSignal",!1),__publicField(this,"_overWaitingThreshold",!1),__publicField(this,"_retries",0),__publicField(this,"_webglYUVSupported"),__publicField(this,"lastDecodedFrameTime"),__publicField(this,"lastReceivedFrameTime"),__publicField(this,"lastNoSignalTime",new Date().getTime()),__publicField(this,"moduleStartTime",Date.now()),__publicField(this,"moduleCreateTime",Date.now()),__publicField(this,"timesRestarted",0),__publicField(this,"canvas"),__publicField(this,"decoder"),__publicField(this,"yuvCanvas"),__publicField(this,"webglContext"),__publicField(this,"frameQueue",[]),__publicField(this,"minFrameSize",1/0),__publicField(this,"maxFrameSize",0),__publicField(this,"decoderQueue",[]),__publicField(this,"decoderQueueLocked",!1),__publicField(this,"decodeNextFrameAttempted",!1),__publicField(this,"numFramesDecoded",0),__publicField(this,"numFramesReceived",0),__publicField(this,"hasReceivedKeyframe",!1),__publicField(this,"medianFrameSize",0),__publicField(this,"currentFrameIndex"),__publicField(this,"frameCheckpointMap",new Map),__publicField(this,"lastDrawnFrameTime"),__publicField(this,"minJitter"),__publicField(this,"maxJitter"),__publicField(this,"start",()=>{const{canvas:g}=this;if(!g)return;const l=g.getContext("webgl");this.webglContext=l||void 0,this.lastDecodedFrameTime=void 0,this.lastReceivedFrameTime=void 0,this.hasReceivedKeyframe=!1,this.currentFrameIndex=void 0,!(!this.canvas||!this.webglContext)&&(this.yuvCanvas||(this.yuvCanvas=new YUVCanvas(this.webglContext)),this.moduleStartTime=Date.now())}),__publicField(this,"stop",()=>{var g;(g=this.decoder)==null||g.release(),this.webglContext=void 0,this.decoderQueueLocked=!1}),__publicField(this,"reset",()=>{this.retries=0,this.restart()}),__publicField(this,"notifyWarningTextChanged",()=>{var g;(g=this.onWarningTextChanged)==null||g.call(this,this.getWarningText())}),__publicField(this,"restart",()=>{console.info("Restarting decoder"),console.info("BytestreamPlayer restarting",__spreadProps(__spreadValues({},this.trackInfo),{Restart:this.timesRestarted})),this.frameQueue=[],this.decoderQueue=[],this.stop(),this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),this.start(),this.retries++,this.timesRestarted++}),__publicField(this,"onTrackTick",()=>{if(this.numFramesDecoded===0){if(this.lastDecodedFrameTime===void 0){const p=Date.now();console.info("BytestreamPlayer waiting for video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Waited":p-this.moduleCreateTime}))}return}this.numFramesReceived/this.numFramesDecoded>maxDropRatio&&this.warnPerformanceProblems(),this.numFramesReceived=0,this.numFramesDecoded=0;const l=Array.from(this.frameCheckpointMap.entries()).reduce((p,[v,_])=>{var y;return!this.currentFrameIndex||v>this.currentFrameIndex-60||_==="FrameDrawn"||(p[_]=((y=p[_])!=null?y:0)+1,this.frameCheckpointMap.delete(v)),p},{});Object.keys(l).map(p=>{console.info("BytestreamPlayer Frame Dropped",__spreadProps(__spreadValues({},this.trackInfo),{"Num Dropped":l[p],"Frame State":p}))});const{minJitter:u,maxJitter:c}=this;u&&c&&(console.info("BytestreamPlayer Jitter",__spreadProps(__spreadValues({},this.trackInfo),{minJitter:u,maxJitter:c})),this.minJitter=void 0,this.maxJitter=void 0)}),__publicField(this,"onTick",()=>{var g;const{lastReceivedFrameTime:l,lastDecodedFrameTime:u,moduleStartTime:c,noSignal:p,retries:v}=this,_=new Date().getTime();p&&(this.lastNoSignalTime=_),this.overWaitingThreshold=_-c>noSignalThreshold;const y=_-c>decoderNotWorkingThreshold;if(!u){l&&y&&v<numRetries&&(this.waitingForDecoder=!0,this.restart());return}if(l){const f=_-l,h=_-u;_-this.lastNoSignalTime>noSignalThreshold&&f<warnPerformanceThreshold&&h>warnPerformanceThreshold&&this.warnPerformanceProblems(),f>noSignalThreshold&&(this.lostSignal=!0)}this.overWaitingThreshold&&(this.waitingForDecoder||this.noSignal||this.lostSignal)&&((g=this.onCanvasDrawerWarning)==null||g.call(this,"ShouldDisableControl"))}),__publicField(this,"receiveEncodedFrame",g=>{if(!g)return;const l=g.index;if(l&&this.frameCheckpointMap.set(l,"FrameReceived"),!(!g||!this.canvas||!this.webglContext)){if(this.isKeyframe(g),!this.hasReceivedKeyframe)return console.info("Dropping frame because no keyframe detected"),!1;this.lastReceivedFrameTime===void 0&&console.debug("Received first frame on bytestream player",__spreadValues({},this.trackInfo)),this.checkOrder(g),this.numFramesReceived++,this.lastReceivedFrameTime=Date.now(),this.lostSignal&&this.restart(),this.noSignal=!1,this.lostSignal=!1,this.frameQueue.push(g),l&&this.frameCheckpointMap.set(l,"FrameQueued"),this.frameQueue.length>maxQueueSize&&(this.frameQueue=this.frameQueue.filter(u=>this.isKeyframe(u))),this.frameQueue.length>maxQueueSize&&(this.frameQueue=[],this.decoderQueue=[]),this.decodeNextFrame()}}),__publicField(this,"onDecoderError",g=>{this.frameQueue=[],this.decoderQueue=[],this.hasReceivedKeyframe=!1,console.info("BytestreamPlayer decode error",__spreadProps(__spreadValues({},this.trackInfo),{"Frame Index":g}))}),__publicField(this,"onReceiveDecodedFrame",g=>{var l,u;const{canvas:c,yuvCanvas:p,decoderQueue:v}=this,{timestamp:_,yuv:y,height:f,width:h,index:w}=g;this.frameCheckpointMap.set(w,"FrameDecoded"),this.numFramesDecoded++;const C=Date.now();if(this.lastDecodedFrameTime===void 0&&console.info("BytestreamPlayer started video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Until Video":C-this.moduleCreateTime})),this.lastDecodedFrameTime=C,this.waitingForDecoder=!1,this.decoderQueue=v.filter(E=>C-E<duration$1.second*.5&&E!==_),!v.includes(_)||C-_>duration$1.second||!p||!c||f===0||h===0)return;f!==c.height&&(c.height=f,p.height=f),h!==c.width&&(c.width=h,p.width=h);const L=p.draw(y),T=Date.now();if(this.lastDrawnFrameTime){const E=T-this.lastDrawnFrameTime;this.minJitter=Math.min(E,(l=this.minJitter)!=null?l:Number.MAX_SAFE_INTEGER),this.maxJitter=Math.max(E,(u=this.maxJitter)!=null?u:0)}this.lastDrawnFrameTime=T,this.frameCheckpointMap.set(w,"FrameDrawn"),L===0&&(this.webglYUVSupported=!0),L===hardwareIncompatibleErrorCode&&(this.webglYUVSupported=!1),this.frameQueue.length>0&&this.decodeNextFrame()}),this.workerFactory=t,this.onWebglYUVSupportedChanged=r,this.onWarningTextChanged=n,this.onCanvasDrawerWarning=o,this.trackInfo=s,this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),setInterval(this.onTick,duration$1.millisecond*200),setInterval(this.onTrackTick,duration$1.second*5)}get waitingForDecoder(){return this._waitingForDecoder}set waitingForDecoder(t){this._waitingForDecoder=t,this.notifyWarningTextChanged()}get noSignal(){return this._noSignal}set noSignal(t){this._noSignal=t,this.notifyWarningTextChanged()}get lostSignal(){return this._lostSignal}set lostSignal(t){this._lostSignal=t,this.notifyWarningTextChanged()}get overWaitingThreshold(){return this._overWaitingThreshold}set overWaitingThreshold(t){this._overWaitingThreshold=t,this.notifyWarningTextChanged()}get retries(){return this._retries}set retries(t){this._retries=t,this.notifyWarningTextChanged()}get webglYUVSupported(){return this._webglYUVSupported}set webglYUVSupported(t){var r;this._webglYUVSupported=t,(r=this.onWebglYUVSupportedChanged)==null||r.call(this,t),this.notifyWarningTextChanged()}setCanvas(t){this.canvas=t}getWarningText(){var t;const{waitingForDecoder:r,noSignal:n,overWaitingThreshold:o,lostSignal:s,retries:g,webglYUVSupported:l}=this,u=l===!1,p=r?g===numRetries?"Decoder failed to start":"Starting decoder":void 0,v=u?"Hardware decoding not supported on this device":void 0,_=s?"Lost signal":n?o?"No signal":"Waiting for signal":void 0;return(t=v!=null?v:_)!=null?t:p}decodeNextFrame(){if(this.decoderQueueLocked&&(this.decodeNextFrameAttempted=!0),this.decoderQueueLocked=!0,this.decoderQueue.length>maxQueueSize){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const t=this.frameQueue.shift();if(!t){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const r=Date.now();this.frameCheckpointMap.set(t.index,"FrameSentToDecoder"),this.decoder.post(r,t.frame_data,t.flags,t.index),this.decoderQueue.push(r),this.decoderQueueLocked=!1,this.decodeNextFrameAttempted&&(this.decodeNextFrameAttempted=!1,this.decodeNextFrame())}warnPerformanceProblems(){var t;this.lastDecodedFrameTime&&this.overWaitingThreshold&&!this.lostSignal&&!this.noSignal&&((t=this.onCanvasDrawerWarning)==null||t.call(this,"ShouldDegradeVideo"))}checkOrder(t){if(this.currentFrameIndex!==void 0&&t.index<this.currentFrameIndex){console.info("Out of order frame detected"),console.info("Frame out of order",__spreadValues({},this.trackInfo));return}this.currentFrameIndex=t.index}isKeyframe(t){const{maxFrameSize:r,minFrameSize:n}=this;if(t.flags===3)return this.hasReceivedKeyframe||(this.frameCheckpointMap=new Map),this.hasReceivedKeyframe=!0,!0;const o=t.frame_data.length;return this.maxFrameSize=Math.max(o,r),this.minFrameSize=Math.min(o,n),this.medianFrameSize=(this.maxFrameSize+this.minFrameSize)/2,this.moduleStartTime+duration$1.second*2>Date.now()?!1:o>this.medianFrameSize?(this.hasReceivedKeyframe=!0,!0):!1}}const millisecond=1,second=1e3,minute=60*second,hour=60*minute,day=24*hour,week=7*day,month=30*day,year=365*day,duration={millisecond,second,minute,hour,day,week,month,year};function filterDataByType(e,t){return e.filter(r=>r.type===t)}function filterDataByTime(e,t,r){const n=t.getTime(),o=r.getTime();return e.map(s=>({...s,points:s.points.filter(([g])=>g>=n&&g<o)})).filter(({points:s})=>s.length>0)}function fork(e){}class StoreCache{constructor({capacity:t,timeout:r}={}){de(this,"entries",new Map);de(this,"metadata",new Map);de(this,"capacity");de(this,"timeout");this.capacity=t||1e4,this.timeout=r||duration.minute}get(t,r){const n=this.keyToCacheKey(t),o=this.entries.get(n),s=this.metadata.get(n);return(o===void 0||s&&(s==null?void 0:s.expiration.getTime())<Date.now())&&!(s!=null&&s.generating)&&r&&this.generate(t,r()),o===void 0&&s&&s.lastValue!==void 0?s.lastValue:o}set(t,r){const n=this.keyToCacheKey(t);this.metadata.set(n,{generating:!1,expiration:new Date(Date.now()+this.timeout),lastValue:r}),this.entries.set(n,r),this.metadata.size>this.capacity&&this.deleteOldestEntry()}clear(){this.entries.clear(),[...this.metadata.values()].forEach(t=>t.generating=!1)}clearKey(t){this.metadata.delete(t),this.entries.delete(t)}keyToCacheKey(t){return JSON.stringify(t)}deleteOldestEntry(){if(this.metadata.size<1)return;const[t]=[...this.metadata.entries()].reduce(([r,n],[o,s])=>s.expiration.getTime()<n.expiration.getTime()?[o,s]:[r,n]);this.clearKey(t)}generate(t,r){const n=this.keyToCacheKey(t),o=this.metadata.get(n)||{};this.metadata.set(n,{...o,generating:!0,expiration:new Date(Date.now()+this.timeout)}),setTimeout(()=>{r.then(s=>{const g=this.metadata.get(n);!(g!=null&&g.generating)||this.set(t,s)})},0)}}function roundToNearestSecond(e){return new Date(Math.round(e.getTime()/1e3)*1e3)}class QueryStore{constructor(){de(this,"queryStoreCache",new StoreCache({capacity:1e4,timeout:20*duration.second}));de(this,"liveQueryStoreCache",new StoreCache({capacity:1e4,timeout:1*duration.second}))}moduleQuery(t,r,n,o,s,g=!1){const l={...t,names:[r],types:[n],start:o.toISOString(),end:s.toISOString(),latestOnly:g},u=this.query(l);return u===void 0||u==="too much data"?u:filterDataByType(u,n)}query(t){const r=new Date(t.end)>addSeconds(new Date,-20),n=startOfMinute(new Date(t.start)).toISOString(),o=t.latestOnly?addSeconds(roundToNearestSecond(new Date(t.end)),5).toISOString():addMinutes(roundToNearestMinutes(new Date(t.end)),1).toISOString();let s;return r?s=this.liveQueryCache({...t,start:n,end:o}):s=this.queryCache({...t,start:n,end:o}),!s||s==="too much data"||t.latestOnly?s:filterDataByTime(s,new Date(t.start),new Date(t.end))}queryCache(t){return this.queryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}liveQueryCache(t){return this.liveQueryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}}const debug=new URLSearchParams(window.location.search).get("debug")==="true",PCD_WORKER_POOL_SIZE=5,DATA_FETCH_WORKER_POOL_SIZE=10;class BasicUniverseDataConnector{constructor(){de(this,"pcdWorkerPool",[]);de(this,"dataFetchWorkerPool",[]);de(this,"pcdWorkerPoolOccupancy",[!1,!1,!1,!1,!1]);de(this,"dataFetchWorkerPoolOccupancy",[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1]);de(this,"subscriberSources",new Map);de(this,"subscriberLoaders",new Map);de(this,"subscriberDistributorsLoaders",new Map);de(this,"mapRealtimeConnections",new Map);de(this,"lastQueriedHistoricTime");de(this,"time");de(this,"timeChangeListeners",[]);de(this,"queryStore",new QueryStore);this.time="live";for(let r=0;r<PCD_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/PcdLoaderWorker-eaac0b31.js",self.location));this.pcdWorkerPool.push(n)}for(let r=0;r<DATA_FETCH_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/DataFetchWorker-0a168933.js",self.location));this.dataFetchWorkerPool.push(n)}const t=async()=>{if(Array.from(this.subscriberLoaders.keys()).length>0){const r=[],n=this.generateTelemetryFilter(),o=this.queryStore.query(n);if(!o||o==="too much data")return;o.forEach(u=>{r.push(u.deviceId)});const s=Array.from(new Set(r)),g=[];s.forEach(u=>{const c=this.subscriberLoaders.get(u);c&&c.forEach(p=>{g.push(p(o))})}),(await Promise.all(g)).forEach(u=>{if(u.data){const c=this.subscriberDistributorsLoaders.get(u.deviceId);if(c){const p=c.get(u.sourceId);p&&p.forEach(v=>{v(u.data)})}}})}setTimeout(()=>t(),0)};setTimeout(()=>t(),0)}setTime(t){t!=="live"&&(this.time=t),this.timeChangeListeners.forEach(r=>r(t))}getAvailablePCDWorker(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)if(!this.pcdWorkerPoolOccupancy[t])return this.pcdWorkerPoolOccupancy[t]=!0,this.pcdWorkerPool[t]}getAvailableDataFetchWorker(){for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)if(!this.dataFetchWorkerPoolOccupancy[t])return this.dataFetchWorkerPoolOccupancy[t]=!0,this.dataFetchWorkerPool[t]}releasePCDWorker(t){const r=this.pcdWorkerPool.indexOf(t);this.pcdWorkerPoolOccupancy[r]=!1}releaseDataFetchWorker(t){const r=this.dataFetchWorkerPool.indexOf(t);this.dataFetchWorkerPoolOccupancy[r]=!1}clearWorkerPool(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)this.pcdWorkerPoolOccupancy[t]=!1;for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)this.dataFetchWorkerPoolOccupancy[t]=!1}generateTelemetryFilter(){const t=Array.from(this.subscriberSources.keys()),r=[];return t.forEach(n=>{const o=this.subscriberSources.get(n);o&&Array.from(o==null?void 0:o.values()).forEach(s=>{s.sourceType==="telemetry"&&r.push(s.streamName)})}),{deviceIds:t,names:r,start:subDays(new Date,20).toISOString(),end:new Date().toISOString(),latestOnly:!0}}async sendRtcMessage(t,r){await this.createRealtimeConnection(t);const n=this.mapRealtimeConnections.get(t);n&&n!=="loading"&&n&&n.sendRealtimeMessage(r,{channelLabel:"stream.reliable"})}async createRealtimeConnection(t,r=signaling_pb.SessionType.TELEOP){const n=this.mapRealtimeConnections.get(t);if(n===void 0){this.mapRealtimeConnections.set(t,"loading");const o=t.startsWith("http");console.log("Creating {} realtime connection",o?"peer":"cloud");let s;o?s=new PeerDevice(t):s=await Fleet.getDevice(t),await s.startRealtimeConnection(r),debug&&s.addRealtimeListener((g,l)=>{console.log("received message from peer",g,l)}),this.mapRealtimeConnections.set(t,s)}else n==="loading"&&await new Promise(o=>{const s=setInterval(()=>{const g=this.mapRealtimeConnections.get(t);g&&g!=="loading"&&(clearInterval(s),o())},100)})}addRemovableTelemetrySubscription(t,r,n,o){let s=this.subscriberLoaders.get(t);s||(s=new Map,this.subscriberLoaders.set(t,s)),s.get(r.id)||s.set(r.id,n);let l=this.subscriberDistributorsLoaders.get(t);l||(l=new Map,this.subscriberDistributorsLoaders.set(t,l));const u=l.get(r.id);u?u.push(o):l.set(r.id,[o]);let c=this.subscriberSources.get(t);return c||(c=new Map,this.subscriberSources.set(t,c)),c.set(r.id,r),()=>{const p=this.subscriberLoaders.get(t);p&&p.delete(r.id);const v=this.subscriberDistributorsLoaders.get(t);if(v){const y=v.get(r.id);if(y){const f=y.indexOf(o);f>-1&&y.splice(f,1)}}const _=this.subscriberSources.get(t);_&&_.delete(r.id)}}createH264Drawer(){return new H264BytestreamCanvasDrawer(()=>new Worker("@formant/ui-sdk-realtime-player-core-worker/dist/ui-sdk-realtime-player-core-worker"),()=>{},()=>{})}async sendCommand(t,r,n){const o=this.mapRealtimeConnections.get(t);if(o==="loading"||o===void 0)throw new Error("Device is not ready or doesnt exist");await o.sendCommand(r,n)}async sendRealtimePose(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"pose"},{pose:n},"vision");await this.sendRtcMessage(t,o)}async sendRealtimeBoolean(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"boolean"},{boolean:n});await this.sendRtcMessage(t,o)}async sendRealtimeBitset(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"bitset"},{bitset:{bits:n.keys.map((s,g)=>({key:s,value:n.values[g]}))}});await this.sendRtcMessage(t,o)}async getUrdfs(t){const n=await(await Fleet.getDevice(t)).getConfiguration();return!n.urdfFiles||n.urdfFiles.length===0?[]:[await Fleet.getFileUrl(n.urdfFiles[0])]}async getTelemetryStreams(t){throw new Error("Not implemented")}async getTeleopRosStreams(t){throw new Error("Not implemented")}async getHardwareStreams(t){throw new Error("Not implemented")}addInteraction(t){throw new Error("Method not implemented.")}removeInteraction(t){throw new Error("Method not implemented.")}getInteractions(){throw new Error("Method not implemented.")}addInteractionsChangedListener(t){throw new Error("Method not implemented.")}addInteractionListener(t){throw new Error("Method not implemented.")}getRealtimeButtons(t){throw new Error("Method not implemented.")}async getLatestTransformTrees(t){throw new Error("Not implemented")}async getLatestLocations(){return[{streamName:"spotLocation",location:{latitude:45.4661989,longitude:-122.5782375}}]}async getDeviceContexts(){return[]}async getDeviceContextName(t){throw new Error("Not implemented")}async getTelemetryStreamType(t,r){throw new Error("Not implemented")}async getStatistics(){return{rtcDevices:[]}}subscribeDataSourceStateChange(t,r,n){return()=>{}}async fetchImage(t){const r=new Image;return r.src=t,r.setAttribute("crossOrigin",""),await new Promise(n=>{r.onload=n}),r}}class LiveUniverseData extends BasicUniverseDataConnector{constructor(){super()}subscribeToPath(t,r,n){throw new Error("Method not implemented.")}subscribeToImage(t,r,n){throw new Error("Method not implemented.")}subcribeToVideo(t,r,n){throw new Error("Method not implemented.")}subscribeToBitset(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.bitset){const l=g.payload.bitset,u={keys:[],values:[]};l.bits.forEach(c=>{u.keys.push(c.key),u.values.push(c.value)}),n(u)}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("Telemetry bitset not implemented")}subscribeToOdometry(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.odometry){const l=g.payload.odometry;n({worldToLocal:l.worldToLocal,pose:{translation:{x:l.pose.translation.x,y:l.pose.translation.y,z:l.pose.translation.z},rotation:{x:l.pose.rotation.x,y:l.pose.rotation.y,z:l.pose.rotation.z,w:l.pose.rotation.w}},covariance:[]})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&s.odometry&&(g={worldToLocal:s.odometry.worldToLocal,pose:{translation:{x:s.odometry.pose.translation.x,y:s.odometry.pose.translation.y,z:s.odometry.pose.translation.z},rotation:{x:s.odometry.pose.rotation.x,y:s.odometry.pose.rotation.y,z:s.odometry.pose.rotation.z,w:s.odometry.pose.rotation.w}},covariance:[]}),{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("unexpected")}subscribeToPose(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.pose&&n(g.payload.pose)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("unexpected")}subscribeToNumeric(t,r,n){if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.numeric&&n([[Date.now(),g.payload.numeric.value]])};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToNumericSet(t,r,n){if(r.sourceType==="telemetry"){let o;const s=setInterval(async()=>{o||(o=await Fleet.getDevice(t));const g=new Date,l=new Date(g.getTime()-15*1e3),u=await o.getTelemetry(r.streamName,l,g);if(u.length>0){const c=u[0].points;n(c)}},1e3);return()=>{clearInterval(s)}}return()=>{}}async subscribeToRealtimeMessages(t,r,n){await this.createRealtimeConnection(t,signaling_pb.SessionType.OBSERVE);const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.startListeningToRealtimeDataStream({name:r}),o.addRealtimeListener((s,g)=>{g.header.stream.streamName===r&&n(s,g)}))}async unsubscribeToRealtimeMessages(t,r,n){const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.stopListeningToRealtimeDataStream({name:r}),o.removeRealtimeListener(n))}subscribeToJson(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="json"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.json())),{deviceId:t,sourceId:r.id,data:g}},n);if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.jsonString&&n(JSON.parse(g.payload.jsonString.value))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToText(t,r,n){return r.sourceType==="telemetry"?this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="text"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.text())),{deviceId:t,sourceId:r.id,data:g}},n):()=>{}}subscribeToPointCloud(t,r,n){const o=this.getAvailablePCDWorker();if(!o)throw new Error("No available pointcloud worker");if(r.sourceType==="telemetry"&&r.streamType!=="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="point cloud"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g){const{url:u}=g;l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g==null?void 0:g.worldToLocal,pcd:l}}},n);if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="localization"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g&&g.pointClouds){const{url:u}=g.pointClouds[0];l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g&&(g!=null&&g.pointClouds)&&(g!=null&&g.pointClouds[0])?g.pointClouds[0].worldToLocal:void 0,pcd:l}}},n);if(r.sourceType==="realtime"){const s=async(g,l)=>{var u;if(l.payload.pointCloud){const c=Math.random(),p=await new Promise(v=>{o.postMessage({id:c,pointCloud:defined(l.payload.pointCloud).data}),o.onmessage=_=>{_.data.id===c&&v(_.data.pcd)}});n({worldToLocal:(u=l.payload.pointCloud)==null?void 0:u.world_to_local,pcd:p})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,s),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,s)}}return()=>{}}subscribeToGeometry(t,r,n){throw new Error("type error in realtime sdk")}subscribeToJointState(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.jointState&&n(g.payload.jointState)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToGridMap(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.jsonString){const l=JSON.parse(g.payload.jsonString.value);n({width:l.info.width,height:l.info.height,worldToLocal:{translation:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0,w:1}},resolution:l.info.resolution,origin:{translation:l.info.origin.position,rotation:l.info.origin.orientation},data:l.data,canvas:void 0})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}else if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}if(s&&s.map){const l=document.createElement("canvas"),u=await this.fetchImage(s.map.url);l.width=u.width,l.height=u.height;const c=l.getContext("2d");c&&c.drawImage(u,0,0);const p=c==null?void 0:c.getImageData(0,0,u.width,u.height),v=[];if(p)for(let _=0;_<p.data.length;_+=4){const y=p.data[_];v.push(y)}g={width:s.map.width,height:s.map.height,worldToLocal:s.map.worldToLocal,resolution:s.map.resolution,origin:s.map.origin,canvas:l,data:v}}return{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("Not implemented")}subscribeToVideo(t,r,n){const o=this.createH264Drawer(),s=document.createElement("CANVAS");if(s.width=0,s.height=0,o.setCanvas(s),o.start(),r.sourceType==="realtime"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,g)}}if(r.sourceType==="hardware"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rtcStreamName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rtcStreamName,g)}}return()=>{o.stop()}}subscribeToTransformTree(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s;for(let g=0;g<o.length;g+=1){const l=o[g];if(l.deviceId===t&&l.name===r.streamName&&l.type==="transform tree"){const[u,c]=l.points[l.points.length-1];s=c}}return{deviceId:t,sourceId:r.id,data:s}},n);throw new Error("not implemented for this source type "+r.sourceType)}subscribeToLocation(t,r,n){throw new Error("Not implemented")}}const NoData=Symbol("no_data"),LoadingData=Symbol("loading_data"),FailedData=Symbol("failed_data");class TelemetryUniverseData extends BasicUniverseDataConnector{constructor(){super();de(this,"liveIntervalHandle");de(this,"timeFinders",[]);de(this,"videoCache",new StoreCache({capacity:50}));this.timeChangeListeners.push(this.onTimeChange.bind(this)),this.onTimeChange("live")}subscribeToBitset(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToPath(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"localization",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1];let l=g;g.url&&(l=await(await fetch(g.url)).json()),l.path&&o({worldToLocal:l.path.worldToLocal,poses:l.path.poses})})}onTimeChange(r){r==="live"?this.liveIntervalHandle=setInterval(()=>{this.findDataForTime(new Date)},300):(this.liveIntervalHandle&&clearInterval(this.liveIntervalHandle),this.findDataForTime(r))}findDataForTime(r){this.timeFinders.forEach(n=>{n(r)})}addFinder(r,n,o,s,g){const l=u=>{let c;g?c=addYears(u,-1):c=addSeconds(u,-15);let p;g?p=u:p=addSeconds(u,5);let v=this.queryStore.moduleQuery({deviceIds:[n]},o,s,c,p,g);if(v===void 0)r(void 0);else if(v==="too much data")r("too much data");else if(v.length>0){const y=v[0].points;if(y.length>0){const f=y[y.length-1];if(g){let h=f[0],w=f[1];y.forEach(C=>{const L=C[0],T=C[1];Math.abs(L-u.getTime())<Math.abs(h-u.getTime())&&(h=L,w=T)}),r([[h,w]])}else r(y)}else r(void 0)}else r(void 0)};return this.timeFinders.push(l),l}removeFinder(r){this.timeFinders=this.timeFinders.filter(n=>n!==r)}subscribeTelemetry(r,n,o,s){if(n.sourceType!=="telemetry")throw new Error("Invalid source type");const g=this.addFinder(s,r,n.streamName,o,n.latestDataPoint||!1);return()=>{this.removeFinder(g)}}subscribeToPointCloud(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailablePCDWorker();if(!s)throw new Error("No available pointcloud worker");const g=async()=>new Promise(c=>{const p=f=>{_(),y(),c(f)},v={...n,latestDataPoint:!0},_=this.subscribeTelemetry(r,v,"point cloud",async f=>{f!==void 0&&typeof f!="symbol"&&p("pointcloud")}),y=this.subscribeTelemetry(r,v,"localization",async f=>{f!==void 0&&typeof f!="symbol"&&p("localization")})});let l=()=>{},u=()=>{};return g().then(c=>{c==="pointcloud"?l=this.subscribeTelemetry(r,n,"point cloud",async p=>{if(p==="too much data"||p===void 0){o(NoData);return}const v=p[p.length-1][1];if(typeof v=="string")o(JSON.parse(v));else{const{url:_}=v;s.postMessage({url:_}),s.onmessage=y=>{y.data.url===_&&o({worldToLocal:v.worldToLocal,pcd:y.data.pcd})}}}):c==="localization"&&(u=this.subscribeTelemetry(r,n,"localization",async p=>{if(p==="too much data"||p===void 0){o(NoData);return}let v=p[p.length-1][1];if(v.url&&(v=await(await fetch(v.url)).json()),v.pointClouds){const{url:_,worldToLocal:y}=v.pointClouds[0];s.postMessage({url:_}),s.onmessage=f=>{f.data.url===_&&o({worldToLocal:y,pcd:f.data.pcd})}}}))}),()=>{this.releasePCDWorker(s),l(),u()}}subscribeToOdometry(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"localization",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}const l=g[g.length-1][1];let u=l;l.url&&(s.postMessage({url:l.url}),s.onmessage=c=>{u=c.data.response,u.odometry&&o({worldToLocal:u.odometry.worldToLocal,pose:{translation:{x:u.odometry.pose.translation.x,y:u.odometry.pose.translation.y,z:u.odometry.pose.translation.z},rotation:{x:u.odometry.pose.rotation.x,y:u.odometry.pose.rotation.y,z:u.odometry.pose.rotation.z,w:u.odometry.pose.rotation.w}},covariance:[]})})})}subscribeToPose(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToGeometry(r,n,o){if(n.sourceType==="telemetry"){const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"json",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}let l=g[g.length-1][1];l.startsWith("http")&&(s.postMessage({url:l}),s.onmessage=u=>{l=JSON.stringify(u.data.response),o(JSON.parse(l))})})}else throw new Error("Realtime geometry note supported")}subscribeToJointState(r,n,o){return this.subscribeToJson(r,n,o)}subscribeToGridMap(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"localization",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}const l=g[g.length-1][1];let u=l;l.url&&(s.postMessage({url:l.url}),s.onmessage=async c=>{if(u=c.data.response,u.map){const p=document.createElement("canvas"),v=await this.fetchImage(u.map.url);p.width=v.width,p.height=v.height;const _=p.getContext("2d");_&&_.drawImage(v,0,0);const y=_==null?void 0:_.getImageData(0,0,v.width,v.height),f=[];if(y)for(let w=0;w<y.data.length;w+=4){const C=y.data[w];f.push(C)}const h={width:u.map.width,height:u.map.height,worldToLocal:u.map.worldToLocal,resolution:u.map.resolution,origin:u.map.origin,canvas:p,data:f};o(h)}})})}subscribeToVideo(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"video",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1],{url:l}=g,u=this.videoCache.get(l,async()=>new Promise(c=>{const p=document.createElement("video");p.src=l,p.onload=()=>{}}));if(u){const c=document.createElement("canvas");c.width=u.videoWidth,c.height=u.videoHeight;const p=c.getContext("2d");p&&p.drawImage(u,0,0),o(c)}})}subscribeToTransformTree(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"transform tree",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToLocation(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.subscribeToJson(r,n,o),g=this.subscribeTelemetry(r,n,"location",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];o(u)});return()=>{s(),g()}}subscribeToJson(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"json",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}let g=s[s.length-1][1];g.startsWith("http")&&(g=await(await fetch(g)).text()),o(JSON.parse(g))})}subscribeToText(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"text",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToNumeric(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToNumericSet(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric set",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToImage(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"image",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1].url,l=new Image;l.src=g,l.onload=()=>{const u=document.createElement("canvas");u.width=l.width,u.height=l.height;const c=u.getContext("2d");c&&(c.drawImage(l,0,0),o(u))}})}}exports.Account=Account,exports.App=App,exports.AudioPlayer=AudioPlayer,exports.Authentication=Authentication,exports.BasicUniverseDataConnector=BasicUniverseDataConnector,exports.BinaryRequestDataChannel=BinaryRequestDataChannel,exports.CaptureStream=CaptureStream,exports.DataChannel=DataChannel,exports.Device=Device,exports.FailedData=FailedData,exports.Fleet=Fleet,exports.KeyValue=KeyValue,exports.LiveUniverseData=LiveUniverseData,exports.LoadingData=LoadingData,exports.Manipulator=Manipulator,exports.NoData=NoData,exports.PeerDevice=PeerDevice,exports.QueryStore=QueryStore,exports.Role=Role,exports.SessionType=SessionTypeConstants,exports.TelemetryUniverseData=TelemetryUniverseData,exports.TextRequestDataChannel=TextRequestDataChannel,exports.User=User,exports.accessLevels=accessLevels,exports.administrator=administrator,exports.aggregateByDateFunctions=aggregateByDateFunctions,exports.aggregateFunctionMap=aggregateFunctionMap,exports.aggregateFunctions=aggregateFunctions,exports.aggregateLevels=aggregateLevels,exports.annotationTypes=annotationTypes,exports.createRtcStreamMessage=distExports.createRtcStreamMessage,exports.defined=defined$1,exports.definedAndNotNull=definedAndNotNull,exports.eventTypes=eventTypes,exports.formatTimeFrameText=formatTimeFrameText,exports.getAverage=getAverage,exports.getCount=getCount,exports.getMax=getMax,exports.getMin=getMin,exports.getStandardDeviation=getStandardDeviation,exports.getSum=getSum,exports.getVariance=getVariance,exports.healthStatuses=healthStatuses,exports.interventionTypes=interventionTypes,exports.operator=operator,exports.severities=severities,exports.timeout=timeout,exports.vailableAggregationIntervals=vailableAggregationIntervals,exports.videoMimeTypes=videoMimeTypes,exports.viewer=viewer,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
102
|
+
`,o=[1.16438,0,1.59603,-.87079,1.16438,-.39176,-.81297,.52959,1.16438,2.01723,0,-1.08139,0,0,0,1],s=t.createShader(t.VERTEX_SHADER);if(!s)throw new Error("Failed to create vertex shader");t.shaderSource(s,r),t.compileShader(s);const g=t.createShader(t.FRAGMENT_SHADER);if(!g)throw new Error("Failed to create fragment shader");t.shaderSource(g,n),t.compileShader(g);const l=t.createProgram();if(!l)throw new Error("Failed to create webgl program");t.attachShader(l,s),t.attachShader(l,g),t.linkProgram(l),t.useProgram(l);const u=t.getUniformLocation(l,"YUV2RGB");return t.uniformMatrix4fv(u,!1,o),l}initBuffers(){const{gl:t,program:r}=this,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),t.STATIC_DRAW);const o=t.getAttribLocation(r,"vertexPos");t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0);const s=t.createBuffer();if(!s)throw new Error("Failed to create WebGL buffer");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),t.STATIC_DRAW);const g=t.getAttribLocation(r,"texturePos");return t.enableVertexAttribArray(g),t.vertexAttribPointer(g,2,t.FLOAT,!1,0,0),{texturePosBuffer:s}}initTextures(){const{gl:t,program:r}=this,n=this.initTexture(),o=t.getUniformLocation(r,"yuvSampler");return t.uniform1i(o,0),{textureRef:n}}initTexture(){const{gl:t}=this,r=t.createTexture();if(!r)throw new Error("Failed to initialize texture");return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null),r}}const decoderNotWorkingThreshold=duration$1.second*2.5,warnPerformanceThreshold=duration$1.second/3,noSignalThreshold=duration$1.second*2,maxQueueSize=5,maxDropRatio=30/25,numRetries=5,hardwareIncompatibleErrorCode=1282;class H264BytestreamCanvasDrawer{constructor(t,r,n,o,s){__publicField(this,"_waitingForDecoder",!0),__publicField(this,"_noSignal",!0),__publicField(this,"_lostSignal",!1),__publicField(this,"_overWaitingThreshold",!1),__publicField(this,"_retries",0),__publicField(this,"_webglYUVSupported"),__publicField(this,"lastDecodedFrameTime"),__publicField(this,"lastReceivedFrameTime"),__publicField(this,"lastNoSignalTime",new Date().getTime()),__publicField(this,"moduleStartTime",Date.now()),__publicField(this,"moduleCreateTime",Date.now()),__publicField(this,"timesRestarted",0),__publicField(this,"canvas"),__publicField(this,"decoder"),__publicField(this,"yuvCanvas"),__publicField(this,"webglContext"),__publicField(this,"frameQueue",[]),__publicField(this,"minFrameSize",1/0),__publicField(this,"maxFrameSize",0),__publicField(this,"decoderQueue",[]),__publicField(this,"decoderQueueLocked",!1),__publicField(this,"decodeNextFrameAttempted",!1),__publicField(this,"numFramesDecoded",0),__publicField(this,"numFramesReceived",0),__publicField(this,"hasReceivedKeyframe",!1),__publicField(this,"medianFrameSize",0),__publicField(this,"currentFrameIndex"),__publicField(this,"frameCheckpointMap",new Map),__publicField(this,"lastDrawnFrameTime"),__publicField(this,"minJitter"),__publicField(this,"maxJitter"),__publicField(this,"start",()=>{const{canvas:g}=this;if(!g)return;const l=g.getContext("webgl");this.webglContext=l||void 0,this.lastDecodedFrameTime=void 0,this.lastReceivedFrameTime=void 0,this.hasReceivedKeyframe=!1,this.currentFrameIndex=void 0,!(!this.canvas||!this.webglContext)&&(this.yuvCanvas||(this.yuvCanvas=new YUVCanvas(this.webglContext)),this.moduleStartTime=Date.now())}),__publicField(this,"stop",()=>{var g;(g=this.decoder)==null||g.release(),this.webglContext=void 0,this.decoderQueueLocked=!1}),__publicField(this,"reset",()=>{this.retries=0,this.restart()}),__publicField(this,"notifyWarningTextChanged",()=>{var g;(g=this.onWarningTextChanged)==null||g.call(this,this.getWarningText())}),__publicField(this,"restart",()=>{console.info("Restarting decoder"),console.info("BytestreamPlayer restarting",__spreadProps(__spreadValues({},this.trackInfo),{Restart:this.timesRestarted})),this.frameQueue=[],this.decoderQueue=[],this.stop(),this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),this.start(),this.retries++,this.timesRestarted++}),__publicField(this,"onTrackTick",()=>{if(this.numFramesDecoded===0){if(this.lastDecodedFrameTime===void 0){const p=Date.now();console.info("BytestreamPlayer waiting for video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Waited":p-this.moduleCreateTime}))}return}this.numFramesReceived/this.numFramesDecoded>maxDropRatio&&this.warnPerformanceProblems(),this.numFramesReceived=0,this.numFramesDecoded=0;const l=Array.from(this.frameCheckpointMap.entries()).reduce((p,[v,_])=>{var y;return!this.currentFrameIndex||v>this.currentFrameIndex-60||_==="FrameDrawn"||(p[_]=((y=p[_])!=null?y:0)+1,this.frameCheckpointMap.delete(v)),p},{});Object.keys(l).map(p=>{console.info("BytestreamPlayer Frame Dropped",__spreadProps(__spreadValues({},this.trackInfo),{"Num Dropped":l[p],"Frame State":p}))});const{minJitter:u,maxJitter:c}=this;u&&c&&(console.info("BytestreamPlayer Jitter",__spreadProps(__spreadValues({},this.trackInfo),{minJitter:u,maxJitter:c})),this.minJitter=void 0,this.maxJitter=void 0)}),__publicField(this,"onTick",()=>{var g;const{lastReceivedFrameTime:l,lastDecodedFrameTime:u,moduleStartTime:c,noSignal:p,retries:v}=this,_=new Date().getTime();p&&(this.lastNoSignalTime=_),this.overWaitingThreshold=_-c>noSignalThreshold;const y=_-c>decoderNotWorkingThreshold;if(!u){l&&y&&v<numRetries&&(this.waitingForDecoder=!0,this.restart());return}if(l){const f=_-l,h=_-u;_-this.lastNoSignalTime>noSignalThreshold&&f<warnPerformanceThreshold&&h>warnPerformanceThreshold&&this.warnPerformanceProblems(),f>noSignalThreshold&&(this.lostSignal=!0)}this.overWaitingThreshold&&(this.waitingForDecoder||this.noSignal||this.lostSignal)&&((g=this.onCanvasDrawerWarning)==null||g.call(this,"ShouldDisableControl"))}),__publicField(this,"receiveEncodedFrame",g=>{if(!g)return;const l=g.index;if(l&&this.frameCheckpointMap.set(l,"FrameReceived"),!(!g||!this.canvas||!this.webglContext)){if(this.isKeyframe(g),!this.hasReceivedKeyframe)return console.info("Dropping frame because no keyframe detected"),!1;this.lastReceivedFrameTime===void 0&&console.debug("Received first frame on bytestream player",__spreadValues({},this.trackInfo)),this.checkOrder(g),this.numFramesReceived++,this.lastReceivedFrameTime=Date.now(),this.lostSignal&&this.restart(),this.noSignal=!1,this.lostSignal=!1,this.frameQueue.push(g),l&&this.frameCheckpointMap.set(l,"FrameQueued"),this.frameQueue.length>maxQueueSize&&(this.frameQueue=this.frameQueue.filter(u=>this.isKeyframe(u))),this.frameQueue.length>maxQueueSize&&(this.frameQueue=[],this.decoderQueue=[]),this.decodeNextFrame()}}),__publicField(this,"onDecoderError",g=>{this.frameQueue=[],this.decoderQueue=[],this.hasReceivedKeyframe=!1,console.info("BytestreamPlayer decode error",__spreadProps(__spreadValues({},this.trackInfo),{"Frame Index":g}))}),__publicField(this,"onReceiveDecodedFrame",g=>{var l,u;const{canvas:c,yuvCanvas:p,decoderQueue:v}=this,{timestamp:_,yuv:y,height:f,width:h,index:w}=g;this.frameCheckpointMap.set(w,"FrameDecoded"),this.numFramesDecoded++;const C=Date.now();if(this.lastDecodedFrameTime===void 0&&console.info("BytestreamPlayer started video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Until Video":C-this.moduleCreateTime})),this.lastDecodedFrameTime=C,this.waitingForDecoder=!1,this.decoderQueue=v.filter(E=>C-E<duration$1.second*.5&&E!==_),!v.includes(_)||C-_>duration$1.second||!p||!c||f===0||h===0)return;f!==c.height&&(c.height=f,p.height=f),h!==c.width&&(c.width=h,p.width=h);const L=p.draw(y),T=Date.now();if(this.lastDrawnFrameTime){const E=T-this.lastDrawnFrameTime;this.minJitter=Math.min(E,(l=this.minJitter)!=null?l:Number.MAX_SAFE_INTEGER),this.maxJitter=Math.max(E,(u=this.maxJitter)!=null?u:0)}this.lastDrawnFrameTime=T,this.frameCheckpointMap.set(w,"FrameDrawn"),L===0&&(this.webglYUVSupported=!0),L===hardwareIncompatibleErrorCode&&(this.webglYUVSupported=!1),this.frameQueue.length>0&&this.decodeNextFrame()}),this.workerFactory=t,this.onWebglYUVSupportedChanged=r,this.onWarningTextChanged=n,this.onCanvasDrawerWarning=o,this.trackInfo=s,this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),setInterval(this.onTick,duration$1.millisecond*200),setInterval(this.onTrackTick,duration$1.second*5)}get waitingForDecoder(){return this._waitingForDecoder}set waitingForDecoder(t){this._waitingForDecoder=t,this.notifyWarningTextChanged()}get noSignal(){return this._noSignal}set noSignal(t){this._noSignal=t,this.notifyWarningTextChanged()}get lostSignal(){return this._lostSignal}set lostSignal(t){this._lostSignal=t,this.notifyWarningTextChanged()}get overWaitingThreshold(){return this._overWaitingThreshold}set overWaitingThreshold(t){this._overWaitingThreshold=t,this.notifyWarningTextChanged()}get retries(){return this._retries}set retries(t){this._retries=t,this.notifyWarningTextChanged()}get webglYUVSupported(){return this._webglYUVSupported}set webglYUVSupported(t){var r;this._webglYUVSupported=t,(r=this.onWebglYUVSupportedChanged)==null||r.call(this,t),this.notifyWarningTextChanged()}setCanvas(t){this.canvas=t}getWarningText(){var t;const{waitingForDecoder:r,noSignal:n,overWaitingThreshold:o,lostSignal:s,retries:g,webglYUVSupported:l}=this,u=l===!1,p=r?g===numRetries?"Decoder failed to start":"Starting decoder":void 0,v=u?"Hardware decoding not supported on this device":void 0,_=s?"Lost signal":n?o?"No signal":"Waiting for signal":void 0;return(t=v!=null?v:_)!=null?t:p}decodeNextFrame(){if(this.decoderQueueLocked&&(this.decodeNextFrameAttempted=!0),this.decoderQueueLocked=!0,this.decoderQueue.length>maxQueueSize){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const t=this.frameQueue.shift();if(!t){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const r=Date.now();this.frameCheckpointMap.set(t.index,"FrameSentToDecoder"),this.decoder.post(r,t.frame_data,t.flags,t.index),this.decoderQueue.push(r),this.decoderQueueLocked=!1,this.decodeNextFrameAttempted&&(this.decodeNextFrameAttempted=!1,this.decodeNextFrame())}warnPerformanceProblems(){var t;this.lastDecodedFrameTime&&this.overWaitingThreshold&&!this.lostSignal&&!this.noSignal&&((t=this.onCanvasDrawerWarning)==null||t.call(this,"ShouldDegradeVideo"))}checkOrder(t){if(this.currentFrameIndex!==void 0&&t.index<this.currentFrameIndex){console.info("Out of order frame detected"),console.info("Frame out of order",__spreadValues({},this.trackInfo));return}this.currentFrameIndex=t.index}isKeyframe(t){const{maxFrameSize:r,minFrameSize:n}=this;if(t.flags===3)return this.hasReceivedKeyframe||(this.frameCheckpointMap=new Map),this.hasReceivedKeyframe=!0,!0;const o=t.frame_data.length;return this.maxFrameSize=Math.max(o,r),this.minFrameSize=Math.min(o,n),this.medianFrameSize=(this.maxFrameSize+this.minFrameSize)/2,this.moduleStartTime+duration$1.second*2>Date.now()?!1:o>this.medianFrameSize?(this.hasReceivedKeyframe=!0,!0):!1}}const millisecond=1,second=1e3,minute=60*second,hour=60*minute,day=24*hour,week=7*day,month=30*day,year=365*day,duration={millisecond,second,minute,hour,day,week,month,year};function filterDataByType(e,t){return e.filter(r=>r.type===t)}function filterDataByTime(e,t,r){const n=t.getTime(),o=r.getTime();return e.map(s=>({...s,points:s.points.filter(([g])=>g>=n&&g<o)})).filter(({points:s})=>s.length>0)}function fork(e){}class StoreCache{constructor({capacity:t,timeout:r}={}){de(this,"entries",new Map);de(this,"metadata",new Map);de(this,"capacity");de(this,"timeout");this.capacity=t||1e4,this.timeout=r||duration.minute}get(t,r){const n=this.keyToCacheKey(t),o=this.entries.get(n),s=this.metadata.get(n);return(o===void 0||s&&(s==null?void 0:s.expiration.getTime())<Date.now())&&!(s!=null&&s.generating)&&r&&this.generate(t,r()),o===void 0&&s&&s.lastValue!==void 0?s.lastValue:o}set(t,r){const n=this.keyToCacheKey(t);this.metadata.set(n,{generating:!1,expiration:new Date(Date.now()+this.timeout),lastValue:r}),this.entries.set(n,r),this.metadata.size>this.capacity&&this.deleteOldestEntry()}clear(){this.entries.clear(),[...this.metadata.values()].forEach(t=>t.generating=!1)}clearKey(t){this.metadata.delete(t),this.entries.delete(t)}keyToCacheKey(t){return JSON.stringify(t)}deleteOldestEntry(){if(this.metadata.size<1)return;const[t]=[...this.metadata.entries()].reduce(([r,n],[o,s])=>s.expiration.getTime()<n.expiration.getTime()?[o,s]:[r,n]);this.clearKey(t)}generate(t,r){const n=this.keyToCacheKey(t),o=this.metadata.get(n)||{};this.metadata.set(n,{...o,generating:!0,expiration:new Date(Date.now()+this.timeout)}),setTimeout(()=>{r.then(s=>{const g=this.metadata.get(n);!(g!=null&&g.generating)||this.set(t,s)})},0)}}function roundToNearestSecond(e){return new Date(Math.round(e.getTime()/1e3)*1e3)}class QueryStore{constructor(){de(this,"queryStoreCache",new StoreCache({capacity:1e4,timeout:20*duration.second}));de(this,"liveQueryStoreCache",new StoreCache({capacity:1e4,timeout:1*duration.second}))}moduleQuery(t,r,n,o,s,g=!1){const l={...t,names:[r],types:[n],start:o.toISOString(),end:s.toISOString(),latestOnly:g},u=this.query(l);return u===void 0||u==="too much data"?u:filterDataByType(u,n)}query(t){const r=new Date(t.end)>addSeconds(new Date,-20),n=startOfMinute(new Date(t.start)).toISOString(),o=t.latestOnly?addSeconds(roundToNearestSecond(new Date(t.end)),5).toISOString():addMinutes(roundToNearestMinutes(new Date(t.end)),1).toISOString();let s;return r?s=this.liveQueryCache({...t,start:n,end:o}):s=this.queryCache({...t,start:n,end:o}),!s||s==="too much data"||t.latestOnly?s:filterDataByTime(s,new Date(n),new Date(o))}queryCache(t){return this.queryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}liveQueryCache(t){return this.liveQueryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}}const debug=new URLSearchParams(window.location.search).get("debug")==="true",PCD_WORKER_POOL_SIZE=5,DATA_FETCH_WORKER_POOL_SIZE=10;class BasicUniverseDataConnector{constructor(){de(this,"pcdWorkerPool",[]);de(this,"dataFetchWorkerPool",[]);de(this,"pcdWorkerPoolOccupancy",[!1,!1,!1,!1,!1]);de(this,"dataFetchWorkerPoolOccupancy",[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1]);de(this,"subscriberSources",new Map);de(this,"subscriberLoaders",new Map);de(this,"subscriberDistributorsLoaders",new Map);de(this,"mapRealtimeConnections",new Map);de(this,"lastQueriedHistoricTime");de(this,"time");de(this,"timeChangeListeners",[]);de(this,"queryStore",new QueryStore);this.time="live";for(let r=0;r<PCD_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/PcdLoaderWorker-eaac0b31.js",self.location));this.pcdWorkerPool.push(n)}for(let r=0;r<DATA_FETCH_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/DataFetchWorker-0a168933.js",self.location));this.dataFetchWorkerPool.push(n)}const t=async()=>{if(Array.from(this.subscriberLoaders.keys()).length>0){const r=[],n=this.generateTelemetryFilter(),o=this.queryStore.query(n);if(!o||o==="too much data")return;o.forEach(u=>{r.push(u.deviceId)});const s=Array.from(new Set(r)),g=[];s.forEach(u=>{const c=this.subscriberLoaders.get(u);c&&c.forEach(p=>{g.push(p(o))})}),(await Promise.all(g)).forEach(u=>{if(u.data){const c=this.subscriberDistributorsLoaders.get(u.deviceId);if(c){const p=c.get(u.sourceId);p&&p.forEach(v=>{v(u.data)})}}})}setTimeout(()=>t(),0)};setTimeout(()=>t(),0)}setTime(t){t!=="live"&&(this.time=t),this.timeChangeListeners.forEach(r=>r(t))}getAvailablePCDWorker(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)if(!this.pcdWorkerPoolOccupancy[t])return this.pcdWorkerPoolOccupancy[t]=!0,this.pcdWorkerPool[t]}getAvailableDataFetchWorker(){for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)if(!this.dataFetchWorkerPoolOccupancy[t])return this.dataFetchWorkerPoolOccupancy[t]=!0,this.dataFetchWorkerPool[t]}releasePCDWorker(t){const r=this.pcdWorkerPool.indexOf(t);this.pcdWorkerPoolOccupancy[r]=!1}releaseDataFetchWorker(t){const r=this.dataFetchWorkerPool.indexOf(t);this.dataFetchWorkerPoolOccupancy[r]=!1}clearWorkerPool(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)this.pcdWorkerPoolOccupancy[t]=!1;for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)this.dataFetchWorkerPoolOccupancy[t]=!1}generateTelemetryFilter(){const t=Array.from(this.subscriberSources.keys()),r=[];return t.forEach(n=>{const o=this.subscriberSources.get(n);o&&Array.from(o==null?void 0:o.values()).forEach(s=>{s.sourceType==="telemetry"&&r.push(s.streamName)})}),{deviceIds:t,names:r,start:subDays(new Date,20).toISOString(),end:new Date().toISOString(),latestOnly:!0}}async sendRtcMessage(t,r){await this.createRealtimeConnection(t);const n=this.mapRealtimeConnections.get(t);n&&n!=="loading"&&n&&n.sendRealtimeMessage(r,{channelLabel:"stream.reliable"})}async createRealtimeConnection(t,r=signaling_pb.SessionType.TELEOP){const n=this.mapRealtimeConnections.get(t);if(n===void 0){this.mapRealtimeConnections.set(t,"loading");const o=t.startsWith("http");console.log("Creating {} realtime connection",o?"peer":"cloud");let s;o?s=new PeerDevice(t):s=await Fleet.getDevice(t),await s.startRealtimeConnection(r),debug&&s.addRealtimeListener((g,l)=>{console.log("received message from peer",g,l)}),this.mapRealtimeConnections.set(t,s)}else n==="loading"&&await new Promise(o=>{const s=setInterval(()=>{const g=this.mapRealtimeConnections.get(t);g&&g!=="loading"&&(clearInterval(s),o())},100)})}addRemovableTelemetrySubscription(t,r,n,o){let s=this.subscriberLoaders.get(t);s||(s=new Map,this.subscriberLoaders.set(t,s)),s.get(r.id)||s.set(r.id,n);let l=this.subscriberDistributorsLoaders.get(t);l||(l=new Map,this.subscriberDistributorsLoaders.set(t,l));const u=l.get(r.id);u?u.push(o):l.set(r.id,[o]);let c=this.subscriberSources.get(t);return c||(c=new Map,this.subscriberSources.set(t,c)),c.set(r.id,r),()=>{const p=this.subscriberLoaders.get(t);p&&p.delete(r.id);const v=this.subscriberDistributorsLoaders.get(t);if(v){const y=v.get(r.id);if(y){const f=y.indexOf(o);f>-1&&y.splice(f,1)}}const _=this.subscriberSources.get(t);_&&_.delete(r.id)}}createH264Drawer(){return new H264BytestreamCanvasDrawer(()=>new Worker("@formant/ui-sdk-realtime-player-core-worker/dist/ui-sdk-realtime-player-core-worker"),()=>{},()=>{})}async sendCommand(t,r,n){const o=this.mapRealtimeConnections.get(t);if(o==="loading"||o===void 0)throw new Error("Device is not ready or doesnt exist");await o.sendCommand(r,n)}async sendRealtimePose(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"pose"},{pose:n},"vision");await this.sendRtcMessage(t,o)}async sendRealtimeBoolean(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"boolean"},{boolean:n});await this.sendRtcMessage(t,o)}async sendRealtimeBitset(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"bitset"},{bitset:{bits:n.keys.map((s,g)=>({key:s,value:n.values[g]}))}});await this.sendRtcMessage(t,o)}async getUrdfs(t){const n=await(await Fleet.getDevice(t)).getConfiguration();return!n.urdfFiles||n.urdfFiles.length===0?[]:[await Fleet.getFileUrl(n.urdfFiles[0])]}async getTelemetryStreams(t){throw new Error("Not implemented")}async getTeleopRosStreams(t){throw new Error("Not implemented")}async getHardwareStreams(t){throw new Error("Not implemented")}addInteraction(t){throw new Error("Method not implemented.")}removeInteraction(t){throw new Error("Method not implemented.")}getInteractions(){throw new Error("Method not implemented.")}addInteractionsChangedListener(t){throw new Error("Method not implemented.")}addInteractionListener(t){throw new Error("Method not implemented.")}getRealtimeButtons(t){throw new Error("Method not implemented.")}async getLatestTransformTrees(t){throw new Error("Not implemented")}async getLatestLocations(){return[{streamName:"spotLocation",location:{latitude:45.4661989,longitude:-122.5782375}}]}async getDeviceContexts(){return[]}async getDeviceContextName(t){throw new Error("Not implemented")}async getTelemetryStreamType(t,r){throw new Error("Not implemented")}async getStatistics(){return{rtcDevices:[]}}subscribeDataSourceStateChange(t,r,n){return()=>{}}async fetchImage(t){const r=new Image;return r.src=t,r.setAttribute("crossOrigin",""),await new Promise(n=>{r.onload=n}),r}}class LiveUniverseData extends BasicUniverseDataConnector{constructor(){super()}subscribeToPath(t,r,n){throw new Error("Method not implemented.")}subscribeToImage(t,r,n){throw new Error("Method not implemented.")}subcribeToVideo(t,r,n){throw new Error("Method not implemented.")}subscribeToBitset(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.bitset){const l=g.payload.bitset,u={keys:[],values:[]};l.bits.forEach(c=>{u.keys.push(c.key),u.values.push(c.value)}),n(u)}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("Telemetry bitset not implemented")}subscribeToOdometry(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.odometry){const l=g.payload.odometry;n({worldToLocal:l.worldToLocal,pose:{translation:{x:l.pose.translation.x,y:l.pose.translation.y,z:l.pose.translation.z},rotation:{x:l.pose.rotation.x,y:l.pose.rotation.y,z:l.pose.rotation.z,w:l.pose.rotation.w}},covariance:[]})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&s.odometry&&(g={worldToLocal:s.odometry.worldToLocal,pose:{translation:{x:s.odometry.pose.translation.x,y:s.odometry.pose.translation.y,z:s.odometry.pose.translation.z},rotation:{x:s.odometry.pose.rotation.x,y:s.odometry.pose.rotation.y,z:s.odometry.pose.rotation.z,w:s.odometry.pose.rotation.w}},covariance:[]}),{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("unexpected")}subscribeToPose(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.pose&&n(g.payload.pose)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("unexpected")}subscribeToNumeric(t,r,n){if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.numeric&&n([[Date.now(),g.payload.numeric.value]])};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToNumericSet(t,r,n){if(r.sourceType==="telemetry"){let o;const s=setInterval(async()=>{o||(o=await Fleet.getDevice(t));const g=new Date,l=new Date(g.getTime()-15*1e3),u=await o.getTelemetry(r.streamName,l,g);if(u.length>0){const c=u[0].points;n(c)}},1e3);return()=>{clearInterval(s)}}return()=>{}}async subscribeToRealtimeMessages(t,r,n){await this.createRealtimeConnection(t,signaling_pb.SessionType.OBSERVE);const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.startListeningToRealtimeDataStream({name:r}),o.addRealtimeListener((s,g)=>{g.header.stream.streamName===r&&n(s,g)}))}async unsubscribeToRealtimeMessages(t,r,n){const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.stopListeningToRealtimeDataStream({name:r}),o.removeRealtimeListener(n))}subscribeToJson(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="json"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.json())),{deviceId:t,sourceId:r.id,data:g}},n);if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.jsonString&&n(JSON.parse(g.payload.jsonString.value))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToText(t,r,n){return r.sourceType==="telemetry"?this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="text"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.text())),{deviceId:t,sourceId:r.id,data:g}},n):()=>{}}subscribeToPointCloud(t,r,n){const o=this.getAvailablePCDWorker();if(!o)throw new Error("No available pointcloud worker");if(r.sourceType==="telemetry"&&r.streamType!=="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="point cloud"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g){const{url:u}=g;l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g==null?void 0:g.worldToLocal,pcd:l}}},n);if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="localization"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g&&g.pointClouds){const{url:u}=g.pointClouds[0];l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g&&(g!=null&&g.pointClouds)&&(g!=null&&g.pointClouds[0])?g.pointClouds[0].worldToLocal:void 0,pcd:l}}},n);if(r.sourceType==="realtime"){const s=async(g,l)=>{var u;if(l.payload.pointCloud){const c=Math.random(),p=await new Promise(v=>{o.postMessage({id:c,pointCloud:defined(l.payload.pointCloud).data}),o.onmessage=_=>{_.data.id===c&&v(_.data.pcd)}});n({worldToLocal:(u=l.payload.pointCloud)==null?void 0:u.world_to_local,pcd:p})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,s),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,s)}}return()=>{}}subscribeToGeometry(t,r,n){throw new Error("type error in realtime sdk")}subscribeToJointState(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.jointState&&n(g.payload.jointState)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToGridMap(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.jsonString){const l=JSON.parse(g.payload.jsonString.value);n({width:l.info.width,height:l.info.height,worldToLocal:{translation:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0,w:1}},resolution:l.info.resolution,origin:{translation:l.info.origin.position,rotation:l.info.origin.orientation},data:l.data,alpha:l.data.map(()=>255)})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}else if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}if(s&&s.map){const l=document.createElement("canvas"),u=await this.fetchImage(s.map.url);l.width=u.width,l.height=u.height;const c=l.getContext("2d",{willReadFrequently:!0});c&&c.drawImage(u,0,0);const p=c==null?void 0:c.getImageData(0,0,u.width,u.height),v=[],_=[];if(p)for(let y=0;y<p.data.length;y+=4){const f=p.data[y],h=p.data[y+3];v.push(f),_.push(h)}g={width:s.map.width,height:s.map.height,worldToLocal:s.map.worldToLocal,resolution:s.map.resolution,origin:s.map.origin,alpha:_,data:v}}return{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("Not implemented")}subscribeToVideo(t,r,n){const o=this.createH264Drawer(),s=document.createElement("CANVAS");if(s.width=0,s.height=0,o.setCanvas(s),o.start(),r.sourceType==="realtime"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,g)}}if(r.sourceType==="hardware"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rtcStreamName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rtcStreamName,g)}}return()=>{o.stop()}}subscribeToTransformTree(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s;for(let g=0;g<o.length;g+=1){const l=o[g];if(l.deviceId===t&&l.name===r.streamName&&l.type==="transform tree"){const[u,c]=l.points[l.points.length-1];s=c}}return{deviceId:t,sourceId:r.id,data:s}},n);throw new Error("not implemented for this source type "+r.sourceType)}subscribeToLocation(t,r,n){throw new Error("Not implemented")}}const NoData=Symbol("no_data"),LoadingData=Symbol("loading_data"),FailedData=Symbol("failed_data");class TelemetryUniverseData extends BasicUniverseDataConnector{constructor(){super();de(this,"liveIntervalHandle");de(this,"timeFinders",[]);de(this,"videoCache",new StoreCache({capacity:50}));this.timeChangeListeners.push(this.onTimeChange.bind(this)),this.onTimeChange("live")}subscribeToBitset(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToPath(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"localization",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];let c=u;u.url&&(s.postMessage({url:u.url}),s.onmessage=p=>{c=p.data.response,c.path&&o({worldToLocal:c.path.worldToLocal,poses:c.path.poses})})});return()=>{this.releaseDataFetchWorker(s),g()}}onTimeChange(r){r==="live"?this.liveIntervalHandle=setInterval(()=>{this.findDataForTime(new Date)},300):(this.liveIntervalHandle&&clearInterval(this.liveIntervalHandle),this.findDataForTime(r))}findDataForTime(r){this.timeFinders.forEach(n=>{n(r)})}addFinder(r,n,o,s,g){const l=u=>{let c;g?c=addYears(u,-1):c=addSeconds(u,-15);let p;g?p=u:p=addSeconds(u,5);let v=this.queryStore.moduleQuery({deviceIds:[n]},o,s,c,p,g);if(v===void 0)r(void 0);else if(v==="too much data")r("too much data");else if(v.length>0){const y=v[0].points;if(y.length>0){const f=y[y.length-1];if(g){let h=f[0],w=f[1];y.forEach(C=>{const L=C[0],T=C[1];Math.abs(L-u.getTime())<Math.abs(h-u.getTime())&&(h=L,w=T)}),r([[h,w]])}else r(y)}else r(void 0)}else r(void 0)};return this.timeFinders.push(l),l}removeFinder(r){this.timeFinders=this.timeFinders.filter(n=>n!==r)}subscribeTelemetry(r,n,o,s){if(n.sourceType!=="telemetry")throw new Error("Invalid source type");const g=this.addFinder(s,r,n.streamName,o,n.latestDataPoint||!1);return()=>{this.removeFinder(g)}}subscribeToPointCloud(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailablePCDWorker();if(!s)throw new Error("No available pointcloud worker");const g=this.getAvailableDataFetchWorker();if(!g)throw new Error("No available data fetch worker");let l=()=>{},u=()=>{};return n.streamType==="point cloud"?l=this.subscribeTelemetry(r,n,"point cloud",async c=>{if(c==="too much data"||c===void 0){o(NoData);return}const p=c[c.length-1][1];if(typeof p=="string")o(JSON.parse(p));else{const{url:v}=p;s.postMessage({url:v}),s.onmessage=_=>{_.data.url===v&&o({worldToLocal:p.worldToLocal,pcd:_.data.pcd})}}}):n.streamType==="localization"&&(u=this.subscribeTelemetry(r,n,"localization",async c=>{if(c==="too much data"||c===void 0){o(NoData);return}let p=c[c.length-1][1];p.url&&(g.postMessage({url:p.url}),g.onmessage=v=>{if(p=v.data.response,p.pointClouds){const{url:_,worldToLocal:y}=p.pointClouds[0];s.postMessage({url:_}),s.onmessage=f=>{f.data.url===_&&o({worldToLocal:y,pcd:f.data.pcd})}}})})),()=>{this.releasePCDWorker(s),this.releaseDataFetchWorker(g),l(),u()}}subscribeToOdometry(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"localization",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];let c=u;u.url&&(s.postMessage({url:u.url}),s.onmessage=p=>{c=p.data.response,c.odometry&&o({worldToLocal:c.odometry.worldToLocal,pose:{translation:{x:c.odometry.pose.translation.x,y:c.odometry.pose.translation.y,z:c.odometry.pose.translation.z},rotation:{x:c.odometry.pose.rotation.x,y:c.odometry.pose.rotation.y,z:c.odometry.pose.rotation.z,w:c.odometry.pose.rotation.w}},covariance:[]})})});return()=>{this.releaseDataFetchWorker(s),g()}}subscribeToPose(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToGeometry(r,n,o){if(n.sourceType==="telemetry"){const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"json",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}let u=l[l.length-1][1];u.startsWith("http")&&(s.postMessage({url:u}),s.onmessage=c=>{u=JSON.stringify(c.data),o(JSON.parse(u))})});return()=>{this.releaseDataFetchWorker(s),g()}}else throw new Error("Realtime geometry note supported")}subscribeToJointState(r,n,o){return this.subscribeToJson(r,n,o)}subscribeToGridMap(r,n,o){const s={};if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const g=this.getAvailableDataFetchWorker();if(!g)throw new Error("No available data fetch worker");const l=this.subscribeTelemetry(r,n,"localization",async u=>{if(u==="too much data"||u===void 0){o(NoData);return}const c=u[u.length-1][1];if(c.url){if(s[c.url]){o(s[c.url]);return}g.postMessage({url:c.url}),g.onmessage=async p=>{const v=p.data.response.map;if(v){const _=document.createElement("canvas"),y=await this.fetchImage(v.url);_.width=y.width,_.height=y.height;const f=_.getContext("2d",{willReadFrequently:!0});f&&f.drawImage(y,0,0);const h=f==null?void 0:f.getImageData(0,0,y.width,y.height),w=[],C=[];if(h)for(let T=0;T<h.data.length;T+=4){const E=h.data[T],d=h.data[T+3];w.push(E),C.push(d)}const L={width:v.width,height:v.height,worldToLocal:v.worldToLocal,resolution:v.resolution,origin:v.origin,alpha:C,data:w};s[c.url]=JSON.parse(JSON.stringify(L)),o(L)}}}});return()=>{this.releaseDataFetchWorker(g),l()}}subscribeToVideo(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"video",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1],{url:l}=g,u=this.videoCache.get(l,async()=>new Promise(c=>{const p=document.createElement("video");p.src=l,p.onload=()=>{}}));if(u){const c=document.createElement("canvas");c.width=u.videoWidth,c.height=u.videoHeight;const p=c.getContext("2d");p&&p.drawImage(u,0,0),o(c)}})}subscribeToTransformTree(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"transform tree",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToLocation(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.subscribeToJson(r,n,o),g=this.subscribeTelemetry(r,n,"location",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];o(u)});return()=>{s(),g()}}subscribeToJson(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"json",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}let g=s[s.length-1][1];g.startsWith("http")&&(g=await(await fetch(g)).text()),o(JSON.parse(g))})}subscribeToText(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"text",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToNumeric(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToNumericSet(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric set",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToImage(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"image",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1].url,l=new Image;l.src=g,l.onload=()=>{const u=document.createElement("canvas");u.width=l.width,u.height=l.height;const c=u.getContext("2d");c&&(c.drawImage(l,0,0),o(u))}})}}exports.Account=Account,exports.App=App,exports.AudioPlayer=AudioPlayer,exports.Authentication=Authentication,exports.BasicUniverseDataConnector=BasicUniverseDataConnector,exports.BinaryRequestDataChannel=BinaryRequestDataChannel,exports.CaptureStream=CaptureStream,exports.DataChannel=DataChannel,exports.Device=Device,exports.FailedData=FailedData,exports.Fleet=Fleet,exports.KeyValue=KeyValue,exports.LiveUniverseData=LiveUniverseData,exports.LoadingData=LoadingData,exports.Manipulator=Manipulator,exports.NoData=NoData,exports.PeerDevice=PeerDevice,exports.QueryStore=QueryStore,exports.Role=Role,exports.SessionType=SessionTypeConstants,exports.TelemetryUniverseData=TelemetryUniverseData,exports.TextRequestDataChannel=TextRequestDataChannel,exports.User=User,exports.accessLevels=accessLevels,exports.administrator=administrator,exports.aggregateByDateFunctions=aggregateByDateFunctions,exports.aggregateFunctionMap=aggregateFunctionMap,exports.aggregateFunctions=aggregateFunctions,exports.aggregateLevels=aggregateLevels,exports.annotationTypes=annotationTypes,exports.createRtcStreamMessage=distExports.createRtcStreamMessage,exports.defined=defined$1,exports.definedAndNotNull=definedAndNotNull,exports.eventTypes=eventTypes,exports.formatTimeFrameText=formatTimeFrameText,exports.getAverage=getAverage,exports.getCount=getCount,exports.getMax=getMax,exports.getMin=getMin,exports.getStandardDeviation=getStandardDeviation,exports.getSum=getSum,exports.getVariance=getVariance,exports.healthStatuses=healthStatuses,exports.interventionTypes=interventionTypes,exports.operator=operator,exports.severities=severities,exports.timeout=timeout,exports.vailableAggregationIntervals=vailableAggregationIntervals,exports.videoMimeTypes=videoMimeTypes,exports.viewer=viewer,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ITransform } from "../../model/ITransform";
|
|
2
2
|
export interface IUniverseGridMap {
|
|
3
|
-
canvas: HTMLCanvasElement;
|
|
4
3
|
worldToLocal?: ITransform;
|
|
5
4
|
width: number;
|
|
6
5
|
height: number;
|
|
7
6
|
resolution: number;
|
|
8
7
|
origin: ITransform;
|
|
9
8
|
data: number[];
|
|
9
|
+
alpha: number[];
|
|
10
10
|
}
|