Spaces:
Running
Running
Run bootstrap after async SDK load
Browse files
main.js
CHANGED
|
@@ -11,6 +11,14 @@ const transportModule = new URLSearchParams(location.search).get("transport") ==
|
|
| 11 |
? "./reachy-mini-cloud.js"
|
| 12 |
: "./reachy-mini-local.js";
|
| 13 |
const { ReachyMini, rpyToMatrix } = await import(transportModule);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
// MediaPipe Tasks-Vision is a multi-megabyte ESM bundle. Importing it
|
| 16 |
// at the top of the module would block DOMContentLoaded (and therefore
|
|
@@ -1333,7 +1341,7 @@ window.addEventListener("beforeunload", shutdown);
|
|
| 1333 |
// extraction always reads the un-flipped frame; the mapper flips
|
| 1334 |
// head_yaw at the output). Wired here so the CSS class applies
|
| 1335 |
// immediately on click, even before streaming.
|
| 1336 |
-
|
| 1337 |
const t = $("toggleMirror");
|
| 1338 |
if (t) t.addEventListener("change", applyMirrorClass);
|
| 1339 |
|
|
@@ -1417,4 +1425,4 @@ async function bootstrap() {
|
|
| 1417 |
}
|
| 1418 |
}
|
| 1419 |
|
| 1420 |
-
|
|
|
|
| 11 |
? "./reachy-mini-cloud.js"
|
| 12 |
: "./reachy-mini-local.js";
|
| 13 |
const { ReachyMini, rpyToMatrix } = await import(transportModule);
|
| 14 |
+
|
| 15 |
+
function onDomReady(callback) {
|
| 16 |
+
if (document.readyState === "loading") {
|
| 17 |
+
document.addEventListener("DOMContentLoaded", callback, { once: true });
|
| 18 |
+
} else {
|
| 19 |
+
callback();
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
|
| 23 |
// MediaPipe Tasks-Vision is a multi-megabyte ESM bundle. Importing it
|
| 24 |
// at the top of the module would block DOMContentLoaded (and therefore
|
|
|
|
| 1341 |
// extraction always reads the un-flipped frame; the mapper flips
|
| 1342 |
// head_yaw at the output). Wired here so the CSS class applies
|
| 1343 |
// immediately on click, even before streaming.
|
| 1344 |
+
onDomReady(() => {
|
| 1345 |
const t = $("toggleMirror");
|
| 1346 |
if (t) t.addEventListener("change", applyMirrorClass);
|
| 1347 |
|
|
|
|
| 1425 |
}
|
| 1426 |
}
|
| 1427 |
|
| 1428 |
+
onDomReady(bootstrap);
|