File size: 1,707 Bytes
bbe099a
 
 
 
 
 
 
 
 
 
 
e7d24ec
bbe099a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
841abfb
bbe099a
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * 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,
    });
  });
}