radio / src /dispatch.ts
tfrere's picture
tfrere HF Staff
Cursor
refactor: move the faceplate stylesheet out of index.html
e7d24ec
Raw History Blame Contribute Delete
1.71 kB
/**
* Single entry point for both the host shell and the embedded app.
* See APP_CREATION_GUIDE §3.2.
*
* 1. Import the SDK from npm and self-assign `window.ReachyMini` so both
* `.../host/auto` (standalone shell) and `.../host/embed` (iframe client)
* find the constructor synchronously, before any await.
* 2. Dispatch `reachymini:ready` so the embed wait loop takes its fast path.
* 3. Branch on `?embedded=1` (legacy alias `?embed=1` accepted).
*/
import "./theme.css";
import "./app.css"; // after theme.css: it builds on those tokens and primitives
import { ReachyMini } from "@pollen-robotics/reachy-mini-sdk";
(window as unknown as { ReachyMini: typeof ReachyMini }).ReachyMini = ReachyMini;
window.dispatchEvent(new Event("reachymini:ready"));
const params = new URLSearchParams(window.location.search);
const isEmbed = params.get("embedded") === "1" || params.get("embed") === "1";
if (isEmbed) {
void import("./embed");
} else {
void import("@pollen-robotics/reachy-mini-sdk/host/auto").then(({ mountHost }) => {
const devToken =
import.meta.env.VITE_HF_TOKEN && import.meta.env.VITE_HF_USERNAME
? {
token: import.meta.env.VITE_HF_TOKEN as string,
userName: import.meta.env.VITE_HF_USERNAME as string,
}
: undefined;
mountHost({
appName: "Radio",
appIconUrl: "/icon.svg",
appEmoji: "📻",
// We push audio onto the robot's outbound audio sender; the sender only
// exists when the session negotiates bidirectional audio, so ask for it.
enableMicrophone: true,
clientId: import.meta.env.VITE_HF_OAUTH_CLIENT_ID as string | undefined,
devToken,
});
});
}