@pollen-robotics/reachy-mini-sdk 1.8.0 → 1.8.1

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.
Files changed (67) hide show
  1. package/APP_CREATION_GUIDE.md +1795 -0
  2. package/README.md +2 -5
  3. package/dist/animation/distance.d.ts +87 -0
  4. package/dist/animation/distance.d.ts.map +1 -0
  5. package/dist/animation/distance.js +140 -0
  6. package/dist/animation/distance.js.map +1 -0
  7. package/dist/animation/index.d.ts +34 -0
  8. package/dist/animation/index.d.ts.map +1 -0
  9. package/dist/animation/index.js +33 -0
  10. package/dist/animation/index.js.map +1 -0
  11. package/dist/animation/pose.d.ts +40 -0
  12. package/dist/animation/pose.d.ts.map +1 -0
  13. package/dist/animation/pose.js +15 -0
  14. package/dist/animation/pose.js.map +1 -0
  15. package/dist/animation/presets.d.ts +85 -0
  16. package/dist/animation/presets.d.ts.map +1 -0
  17. package/dist/animation/presets.js +82 -0
  18. package/dist/animation/presets.js.map +1 -0
  19. package/dist/animation/safe-return.d.ts +90 -0
  20. package/dist/animation/safe-return.d.ts.map +1 -0
  21. package/dist/animation/safe-return.js +123 -0
  22. package/dist/animation/safe-return.js.map +1 -0
  23. package/dist/lib/reachy-mini.d.ts +99 -0
  24. package/dist/lib/reachy-mini.d.ts.map +1 -1
  25. package/dist/lib/reachy-mini.js +314 -9
  26. package/dist/lib/reachy-mini.js.map +1 -1
  27. package/dist/lib/types.d.ts +27 -0
  28. package/dist/lib/types.d.ts.map +1 -1
  29. package/host/README.md +14 -12
  30. package/host/dist/ReachyHost.d.ts +2 -1
  31. package/host/dist/ReachyHost.d.ts.map +1 -1
  32. package/host/dist/chunks/index-lMs2sCXG.js +439 -0
  33. package/host/dist/chunks/{mountHost-D7cgkU9Q.js → mountHost-DjE5zE9R.js} +11142 -11014
  34. package/host/dist/chunks/{reachy-mini-B1hlBmDQ.js → reachy-mini-GHNS4GSp.js} +494 -307
  35. package/host/dist/components/PickerView.d.ts.map +1 -1
  36. package/host/dist/components/PostOAuthSplash.d.ts +25 -0
  37. package/host/dist/components/PostOAuthSplash.d.ts.map +1 -0
  38. package/host/dist/components/ReachyHostShell.d.ts.map +1 -1
  39. package/host/dist/components/TopBar.d.ts +8 -1
  40. package/host/dist/components/TopBar.d.ts.map +1 -1
  41. package/host/dist/components/WelcomeBackOverlay.d.ts.map +1 -1
  42. package/host/dist/embed/index.d.ts +3 -2
  43. package/host/dist/embed/index.d.ts.map +1 -1
  44. package/host/dist/entry/auto.js +2 -2
  45. package/host/dist/entry/embed.js +2 -2
  46. package/host/dist/hooks/useHostBridge.d.ts +6 -0
  47. package/host/dist/hooks/useHostBridge.d.ts.map +1 -1
  48. package/host/dist/hooks/useSdk.d.ts.map +1 -1
  49. package/host/dist/index.js +3 -3
  50. package/host/dist/lib/protocol.d.ts +17 -3
  51. package/host/dist/lib/protocol.d.ts.map +1 -1
  52. package/host/dist/lib/settings.d.ts +3 -2
  53. package/host/dist/lib/settings.d.ts.map +1 -1
  54. package/host/dist/mountHost.d.ts.map +1 -1
  55. package/host/dist/ui/design/IdentityChipBar.d.ts +46 -0
  56. package/host/dist/ui/design/IdentityChipBar.d.ts.map +1 -0
  57. package/host/dist/ui/design/LinkQualityBars.d.ts +32 -0
  58. package/host/dist/ui/design/LinkQualityBars.d.ts.map +1 -0
  59. package/host/dist/ui/design/MetaPill.d.ts +41 -0
  60. package/host/dist/ui/design/MetaPill.d.ts.map +1 -0
  61. package/host/dist/ui/design/TransportChip.d.ts +39 -0
  62. package/host/dist/ui/design/TransportChip.d.ts.map +1 -0
  63. package/package.json +7 -4
  64. package/CHANGELOG.md +0 -188
  65. package/host/APP_AUTHOR_GUIDE.md +0 -646
  66. package/host/SPEC.md +0 -618
  67. package/host/dist/chunks/index-CyLPysJS.js +0 -400
@@ -0,0 +1,439 @@
1
+ import { decodeCredsFromHash as O, PROTOCOL_VERSION as g, PROTOCOL_SOURCE as y, isProtocolMessage as N } from "../lib/protocol.js";
2
+ const _ = 8e3, M = 2e3, R = 900 * 1e3;
3
+ let k = null, S = "*";
4
+ function P() {
5
+ try {
6
+ if (typeof document < "u" && document.referrer)
7
+ return new URL(document.referrer).origin;
8
+ } catch {
9
+ }
10
+ return "*";
11
+ }
12
+ async function q(t = {}) {
13
+ return k || (k = C(t)), await k;
14
+ }
15
+ async function C(t) {
16
+ S = P();
17
+ const r = t.expectedOrigin ?? S, n = O(window.location.hash);
18
+ if (A(), !n)
19
+ throw new Error(
20
+ "[reachy-mini-sdk/host/embed] no creds bundle found in URL hash. Was the embed mounted directly without ?embedded=1#creds=...?"
21
+ );
22
+ if (!await U(_))
23
+ throw new Error(
24
+ `[reachy-mini-sdk/host/embed] window.ReachyMini did not become available within ${_}ms - check the SDK CDN tag.`
25
+ );
26
+ const e = n.userName ?? n.username ?? null;
27
+ n.hfToken && e && D(n.hfToken, e);
28
+ const a = new window.ReachyMini({
29
+ appName: n.appName,
30
+ signalingUrl: n.signalingUrl,
31
+ ...t.sdkOptions
32
+ }), c = H(r);
33
+ b({
34
+ source: y,
35
+ type: "embed:ready",
36
+ version: g
37
+ }), c.start();
38
+ const u = await c.awaitHostInit(M, n);
39
+ w("connecting", "link"), f("boot:link:start", { robotPeerId: u.robotPeerId }), await a.authenticate(), f("boot:authenticate:ok", { state: a.state }), await a.connect(), f("boot:connect:ok", {
40
+ state: a.state,
41
+ robots: (a.robots ?? []).length
42
+ }), w("connecting", "session"), f("boot:session:start", { robotPeerId: u.robotPeerId }), $(a);
43
+ try {
44
+ await a.startSession(u.robotPeerId), f("boot:session:ok");
45
+ } catch (d) {
46
+ throw f("boot:session:error", {
47
+ message: d?.message ?? String(d)
48
+ }), d;
49
+ }
50
+ return w("connecting", "wake"), f("boot:wake:start"), await a.ensureAwake(), f("boot:wake:ok"), c.attachPageHide(a), w("live", null), J(a), c.buildHandle(a, u);
51
+ }
52
+ function L(t) {
53
+ return {
54
+ theme: t.theme,
55
+ config: t.config,
56
+ appName: t.appName,
57
+ hostName: t.hostName,
58
+ userName: t.userName ?? null,
59
+ robotPeerId: t.robotPeerId
60
+ };
61
+ }
62
+ function E(t) {
63
+ return {
64
+ theme: t.theme,
65
+ config: t.config,
66
+ appName: t.appName,
67
+ hostName: t.hostName,
68
+ userName: t.userName ?? null,
69
+ robotPeerId: t.robotPeerId
70
+ };
71
+ }
72
+ function H(t) {
73
+ const r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
74
+ let e = null, a = !1, c = !1, u = null;
75
+ function d(o) {
76
+ switch (o.type) {
77
+ case "host:init": {
78
+ e = E(o), n.forEach((i) => i(e.theme)), l.forEach((i) => i(e.config));
79
+ break;
80
+ }
81
+ case "host:theme-changed": {
82
+ e && (e.theme = o.theme), n.forEach((i) => i(o.theme));
83
+ break;
84
+ }
85
+ case "host:config-changed": {
86
+ e && (e.config = o.config), l.forEach((i) => i(o.config));
87
+ break;
88
+ }
89
+ case "host:leaving": {
90
+ s();
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ function s() {
96
+ a || (a = !0, r.forEach((o) => {
97
+ try {
98
+ o();
99
+ } catch (i) {
100
+ console.warn("[reachy-mini-sdk/host/embed] onLeave threw", i);
101
+ }
102
+ }));
103
+ }
104
+ return {
105
+ start() {
106
+ c || (c = !0, u = (o) => {
107
+ t !== "*" && o.origin !== t || N(o.data) && d(o.data);
108
+ }, window.addEventListener("message", u));
109
+ },
110
+ async awaitHostInit(o, i) {
111
+ return window.parent !== window ? e || new Promise((h) => {
112
+ const p = (v) => {
113
+ if (t !== "*" && v.origin !== t || !N(v.data)) return;
114
+ const T = v.data;
115
+ T.type === "host:init" && (window.removeEventListener("message", p), window.clearTimeout(I), e = E(T), h(e));
116
+ }, I = window.setTimeout(() => {
117
+ window.removeEventListener("message", p), e || (e = L(i)), h(e);
118
+ }, o);
119
+ window.addEventListener("message", p);
120
+ }) : (e = L(i), e);
121
+ },
122
+ attachPageHide(o) {
123
+ const i = () => {
124
+ s();
125
+ try {
126
+ o.stopSession();
127
+ } catch {
128
+ }
129
+ };
130
+ window.addEventListener("pagehide", i, { once: !0 });
131
+ },
132
+ buildHandle(o, i) {
133
+ e = i;
134
+ const m = K(o);
135
+ return {
136
+ reachy: o,
137
+ media: m,
138
+ get theme() {
139
+ return e.theme;
140
+ },
141
+ get config() {
142
+ return e.config;
143
+ },
144
+ get appName() {
145
+ return e.appName;
146
+ },
147
+ get hostName() {
148
+ return e.hostName;
149
+ },
150
+ get userName() {
151
+ return e.userName;
152
+ },
153
+ onLeave(h) {
154
+ return r.add(h), () => r.delete(h);
155
+ },
156
+ onThemeChange(h) {
157
+ return n.add(h), () => n.delete(h);
158
+ },
159
+ onConfigChange(h) {
160
+ const p = (I) => h(I);
161
+ return l.add(p), () => l.delete(p);
162
+ },
163
+ setAppState(h) {
164
+ w(
165
+ h.phase,
166
+ h.connectingStep ?? null,
167
+ h.message ?? null
168
+ );
169
+ },
170
+ requestLeave() {
171
+ b({
172
+ source: y,
173
+ type: "embed:request-leave",
174
+ version: g
175
+ });
176
+ },
177
+ reportError(h, p) {
178
+ b({
179
+ source: y,
180
+ type: "embed:error",
181
+ version: g,
182
+ message: h,
183
+ fatal: p?.fatal === !0,
184
+ detail: p?.detail
185
+ });
186
+ }
187
+ };
188
+ }
189
+ };
190
+ }
191
+ function A() {
192
+ try {
193
+ const t = window.location.pathname + window.location.search;
194
+ history.replaceState(history.state, document.title, t);
195
+ } catch {
196
+ }
197
+ }
198
+ function D(t, r) {
199
+ try {
200
+ sessionStorage.setItem("hf_token", t), sessionStorage.setItem("hf_username", r), sessionStorage.setItem(
201
+ "hf_token_expires",
202
+ new Date(Date.now() + R).toISOString()
203
+ );
204
+ } catch {
205
+ }
206
+ }
207
+ function U(t) {
208
+ return new Promise((r) => {
209
+ if (typeof window > "u") {
210
+ r(!1);
211
+ return;
212
+ }
213
+ if (window.ReachyMini) {
214
+ r(!0);
215
+ return;
216
+ }
217
+ let n = !1;
218
+ const l = () => {
219
+ n || (n = !0, window.removeEventListener("reachymini:ready", l), window.clearTimeout(e), r(!!window.ReachyMini));
220
+ }, e = window.setTimeout(() => {
221
+ n || (n = !0, window.removeEventListener("reachymini:ready", l), r(!1));
222
+ }, t);
223
+ window.addEventListener("reachymini:ready", l);
224
+ });
225
+ }
226
+ function b(t) {
227
+ if (!(typeof window > "u"))
228
+ try {
229
+ window.parent.postMessage(t, S);
230
+ } catch (r) {
231
+ console.warn("[reachy-mini-sdk/host/embed] postMessage to host failed", r);
232
+ }
233
+ }
234
+ function w(t, r, n = null, l = null) {
235
+ b({
236
+ source: y,
237
+ type: "embed:app-state",
238
+ version: g,
239
+ phase: t,
240
+ connectingStep: r,
241
+ message: n,
242
+ rttMs: l
243
+ });
244
+ }
245
+ const j = 1500, F = 6;
246
+ async function V(t) {
247
+ try {
248
+ const r = await t.getStats();
249
+ let n = null;
250
+ return r.forEach((l) => {
251
+ const e = l;
252
+ e.type !== "candidate-pair" || !(e.selected === !0 || e.nominated === !0 && e.state === "succeeded") || typeof e.currentRoundTripTime == "number" && (n = e.currentRoundTripTime * 1e3);
253
+ }), n;
254
+ } catch {
255
+ return null;
256
+ }
257
+ }
258
+ function J(t) {
259
+ if (typeof window > "u") return;
260
+ const r = t._pc;
261
+ if (!r) return;
262
+ const n = [];
263
+ let l = !1;
264
+ const e = async () => {
265
+ if (l) return;
266
+ const u = await V(r);
267
+ u !== null && (n.push(u), n.length > F && n.shift(), w("live", null, null, Math.min(...n)));
268
+ }, a = window.setInterval(() => {
269
+ e();
270
+ }, j);
271
+ window.setTimeout(() => {
272
+ e();
273
+ }, 600);
274
+ const c = () => {
275
+ l || (l = !0, window.clearInterval(a));
276
+ };
277
+ try {
278
+ t.addEventListener("sessionStopped", c);
279
+ } catch {
280
+ }
281
+ window.addEventListener("pagehide", c, { once: !0 });
282
+ }
283
+ function f(t, r = {}) {
284
+ if (!(typeof window > "u")) {
285
+ try {
286
+ window.parent.postMessage(
287
+ {
288
+ source: y,
289
+ type: "embed:debug",
290
+ version: g,
291
+ tag: t,
292
+ payload: r
293
+ },
294
+ S
295
+ );
296
+ } catch {
297
+ }
298
+ try {
299
+ let n = "";
300
+ try {
301
+ n = JSON.stringify(r);
302
+ } catch {
303
+ n = "<unserializable>";
304
+ }
305
+ console.info(`[embed-debug] ${t} ${n}`);
306
+ } catch {
307
+ }
308
+ }
309
+ }
310
+ function K(t) {
311
+ let r = null;
312
+ const n = t, l = () => {
313
+ const c = n._pc;
314
+ if (!c) return null;
315
+ const u = c.getReceivers().map((d) => d.track).filter(
316
+ (d) => d !== null && d.kind !== "" && d.readyState === "live"
317
+ );
318
+ return u.length === 0 ? null : new MediaStream(u);
319
+ }, e = () => r || (r = l(), r && f("media:cache:init", {
320
+ videoTracks: r.getVideoTracks().length,
321
+ audioTracks: r.getAudioTracks().length
322
+ }), r), a = () => {
323
+ r && (r = null, f("media:cache:clear"));
324
+ };
325
+ return t.addEventListener("sessionStopped", a), {
326
+ attachVideo(c) {
327
+ const u = t.attachVideo(c), d = e();
328
+ if (d && c.srcObject !== d)
329
+ try {
330
+ c.srcObject = d, c.play().catch(() => {
331
+ }), f("media:attach:replay", {
332
+ videoTracks: d.getVideoTracks().length,
333
+ audioTracks: d.getAudioTracks().length
334
+ });
335
+ } catch (s) {
336
+ f("media:attach:replay:error", {
337
+ message: s?.message ?? String(s)
338
+ });
339
+ }
340
+ return u;
341
+ },
342
+ get robotStream() {
343
+ return e();
344
+ },
345
+ get micStream() {
346
+ return n._micStream;
347
+ }
348
+ };
349
+ }
350
+ function $(t) {
351
+ const r = [
352
+ "connected",
353
+ "disconnected",
354
+ "streaming",
355
+ "sessionStopped",
356
+ "sessionRejected",
357
+ "robotsChanged",
358
+ "error",
359
+ "state",
360
+ "log",
361
+ "message"
362
+ ];
363
+ for (const e of r)
364
+ try {
365
+ t.addEventListener(e, (a) => {
366
+ let c = {};
367
+ const u = a;
368
+ if (u && typeof u == "object" && "detail" in u)
369
+ try {
370
+ c = JSON.parse(JSON.stringify(u.detail ?? null));
371
+ } catch {
372
+ c = { _unserializable: !0 };
373
+ }
374
+ f(`sdk:${e}`, c);
375
+ });
376
+ } catch {
377
+ }
378
+ try {
379
+ const e = t, a = e._handleSignalingMessage;
380
+ if (typeof a == "function") {
381
+ const c = e._sendToServer;
382
+ typeof c == "function" && (e._sendToServer = async function(d) {
383
+ const s = d, o = { type: s?.type ?? "?" };
384
+ if (s && "peerId" in s && (o.peerId = String(s.peerId)), s && "sessionId" in s && (o.sessionId = String(s.sessionId)), s && "sdp" in s) {
385
+ const i = s.sdp;
386
+ o.sdpType = i?.type ?? "?", o.sdpLen = i?.sdp?.length ?? 0;
387
+ }
388
+ if (s && "ice" in s) {
389
+ const i = s.ice;
390
+ o.iceCand = (i?.candidate ?? "").slice(0, 60) || "<end-of-candidates>";
391
+ }
392
+ f("sdk:send", o);
393
+ try {
394
+ const i = await c.call(this, d), m = i;
395
+ return f("sdk:send:res", {
396
+ inFor: o.type,
397
+ resType: m?.type ?? null,
398
+ keys: m ? Object.keys(m) : []
399
+ }), i;
400
+ } catch (i) {
401
+ throw f("sdk:send:err", {
402
+ inFor: o.type,
403
+ msg: i?.message ?? String(i)
404
+ }), i;
405
+ }
406
+ }), e._handleSignalingMessage = function(d) {
407
+ const s = d, o = { type: s?.type ?? "?" };
408
+ if ("sessionId" in s && (o.sessionId = String(s.sessionId)), "peerId" in s && (o.peerId = String(s.peerId)), "sdp" in s) {
409
+ const i = s.sdp;
410
+ o.sdpType = i?.type ?? "?", o.sdpLen = i?.sdp?.length ?? 0;
411
+ }
412
+ if ("ice" in s) {
413
+ const i = s.ice;
414
+ o.iceCand = (i?.candidate ?? "").slice(0, 60) || "<end-of-candidates>";
415
+ }
416
+ return "reason" in s && (o.reason = String(s.reason)), f("sdk:sse", o), a.call(this, d);
417
+ };
418
+ }
419
+ } catch {
420
+ }
421
+ const n = Date.now(), l = window.setInterval(() => {
422
+ const e = t, a = e._pc, c = e._dc;
423
+ f("sdk:probe", {
424
+ elapsedMs: Date.now() - n,
425
+ myPeerId: e._peerId ?? null,
426
+ state: e._state ?? null,
427
+ sseAborted: e._sseAbortController?.signal?.aborted ?? null,
428
+ pcState: a?.connectionState ?? null,
429
+ iceState: a?.iceConnectionState ?? null,
430
+ iceGather: a?.iceGatheringState ?? null,
431
+ signalingState: a?.signalingState ?? null,
432
+ dcState: c?.readyState ?? null,
433
+ sessionId: e._sessionId ?? null
434
+ }), Date.now() - n > 3e4 && window.clearInterval(l);
435
+ }, 1500);
436
+ }
437
+ export {
438
+ q as c
439
+ };