File size: 2,589 Bytes
1d21c88
 
 
 
 
112ac2f
 
 
27f8642
112ac2f
1d21c88
27f8642
 
 
 
 
 
 
 
 
 
1d21c88
 
27f8642
1d21c88
 
27f8642
 
 
 
 
1d21c88
112ac2f
 
 
 
 
 
 
1d21c88
 
 
 
27f8642
1d21c88
 
 
 
 
 
 
 
 
6469764
1d21c88
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Single entry point for both the host shell and the embedded app.
 *
 * Rendering decision
 * ──────────────────
 *   url has `?embedded=1`  β†’  we're inside the host's iframe; load
 *                            `./embed` (the actual emotions UI).
 *   otherwise               β†’  we're the top-level visit; load the
 *                            host shell from `@pollen-robotics/reachy-mini-sdk/host/auto`
 *                            and let it iframe us back via `?embedded=1`.
 *
 * SDK bootstrapping
 * ─────────────────
 * The host shell and the embed client both consume `window.ReachyMini`
 * (constructor injected by the SDK). Historically that global was set
 * by a `<script type="module">` tag in `index.html` pointing at a
 * jsdelivr CDN URL; this file now statically imports the SDK from
 * the `@pollen-robotics/reachy-mini-sdk` npm package and assigns the
 * constructor onto `window` synchronously, BEFORE the dynamic import
 * of the host module resolves. We still dispatch the `reachymini:ready`
 * event so the embed's wait loop takes its fast path immediately.
 *
 * This file is intentionally tiny - everything heavy lives in
 * `./embed` (the app) or `@pollen-robotics/reachy-mini-sdk/host` (the shell).
 */

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);
// Accept both `?embedded=1` (current, legacy-compatible naming) and
// `?embed=1` (transient name used by an intermediate host refactor).
// Tolerating both means mobile builds and host vendor dist that
// pre-date this revert can still boot the embed entry correctly,
// regardless of redeploy order.
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 }) => {
    mountHost({
      appName: 'Emotions',
      appIconUrl: '/icon.svg',
      appEmoji: 'πŸ’œ',
      enableMicrophone: false,
      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,
      clientId: import.meta.env.VITE_HF_OAUTH_CLIENT_ID as string | undefined,
    });
  });
}