@pollen-robotics/reachy-mini-sdk 1.10.0-dev.0.main.b50d97e → 1.10.0-dev.0.main.e7f2273
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.
- package/dist/lib/reachy-mini.d.ts +76 -0
- package/dist/lib/reachy-mini.d.ts.map +1 -1
- package/dist/lib/reachy-mini.js +314 -5
- package/dist/lib/reachy-mini.js.map +1 -1
- package/dist/lib/types.d.ts +11 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/host/dist/chunks/{index-lMs2sCXG.js → index-rW7LY0k3.js} +209 -118
- package/host/dist/chunks/{mountHost-DjE5zE9R.js → mountHost-DztGlWwu.js} +21939 -21928
- package/host/dist/chunks/{reachy-mini-CdsdQLIU.js → reachy-mini-DyEhsZnc.js} +330 -140
- package/host/dist/components/ConnectingView.d.ts.map +1 -1
- package/host/dist/components/ErrorView.d.ts.map +1 -1
- package/host/dist/components/LeavingView.d.ts.map +1 -1
- package/host/dist/components/PickerView.d.ts.map +1 -1
- package/host/dist/components/PostOAuthSplash.d.ts.map +1 -1
- package/host/dist/components/TopBar.d.ts.map +1 -1
- package/host/dist/components/WelcomeBackOverlay.d.ts.map +1 -1
- package/host/dist/embed/index.d.ts +60 -0
- package/host/dist/embed/index.d.ts.map +1 -1
- package/host/dist/entry/auto.js +2 -2
- package/host/dist/entry/embed.d.ts +5 -4
- package/host/dist/entry/embed.d.ts.map +1 -1
- package/host/dist/entry/embed.js +5 -4
- package/host/dist/index.d.ts +2 -2
- package/host/dist/index.d.ts.map +1 -1
- package/host/dist/index.js +11 -10
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var F = Object.defineProperty, $ = (r, e, t) => e in r ? F(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, k = (r, e, t) => ($(r, typeof e != "symbol" ? e + "" : e, t), t), H = "https://huggingface.co";
|
|
2
2
|
async function C(r, e) {
|
|
3
3
|
var t, s;
|
|
4
4
|
const i = new O(r.url, r.status, (t = r.headers.get("X-Request-Id")) != null ? t : void 0);
|
|
@@ -18,7 +18,7 @@ var O = class extends Error {
|
|
|
18
18
|
};
|
|
19
19
|
new Promise((r) => {
|
|
20
20
|
});
|
|
21
|
-
function
|
|
21
|
+
function x(r) {
|
|
22
22
|
if (globalThis.Buffer)
|
|
23
23
|
return globalThis.Buffer.from(r).toString("base64");
|
|
24
24
|
{
|
|
@@ -40,28 +40,28 @@ async function M(r) {
|
|
|
40
40
|
throw new Error("Missing oauth code from query parameters in redirected URL");
|
|
41
41
|
if (!a)
|
|
42
42
|
throw new Error("Missing oauth nonce from localStorage");
|
|
43
|
-
const
|
|
44
|
-
if (!c)
|
|
45
|
-
throw new Error("Missing oauth code_verifier from localStorage");
|
|
46
|
-
const l = s.get("state");
|
|
43
|
+
const l = localStorage.getItem("huggingface.co:oauth:code_verifier");
|
|
47
44
|
if (!l)
|
|
45
|
+
throw new Error("Missing oauth code_verifier from localStorage");
|
|
46
|
+
const c = s.get("state");
|
|
47
|
+
if (!c)
|
|
48
48
|
throw new Error("Missing oauth state from query parameters in redirected URL");
|
|
49
49
|
let h;
|
|
50
50
|
try {
|
|
51
|
-
h = JSON.parse(
|
|
51
|
+
h = JSON.parse(c);
|
|
52
52
|
} catch {
|
|
53
|
-
throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: " +
|
|
53
|
+
throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: " + c);
|
|
54
54
|
}
|
|
55
55
|
if (h.nonce !== a)
|
|
56
56
|
throw new Error("Invalid oauth state in redirected URL");
|
|
57
|
-
const d =
|
|
57
|
+
const d = H, m = `${new URL(d).origin}/.well-known/openid-configuration`, f = await fetch(m, {
|
|
58
58
|
headers: {
|
|
59
59
|
Accept: "application/json"
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
if (!f.ok)
|
|
63
63
|
throw await C(f);
|
|
64
|
-
const p = await f.json(),
|
|
64
|
+
const p = await f.json(), y = await fetch(p.token_endpoint, {
|
|
65
65
|
method: "POST",
|
|
66
66
|
headers: {
|
|
67
67
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -70,12 +70,12 @@ async function M(r) {
|
|
|
70
70
|
grant_type: "authorization_code",
|
|
71
71
|
code: n,
|
|
72
72
|
redirect_uri: h.redirectUri,
|
|
73
|
-
code_verifier:
|
|
73
|
+
code_verifier: l
|
|
74
74
|
}).toString()
|
|
75
75
|
});
|
|
76
|
-
if (localStorage.removeItem("huggingface.co:oauth:code_verifier"), localStorage.removeItem("huggingface.co:oauth:nonce"), !
|
|
77
|
-
throw await C(
|
|
78
|
-
const g = await
|
|
76
|
+
if (localStorage.removeItem("huggingface.co:oauth:code_verifier"), localStorage.removeItem("huggingface.co:oauth:nonce"), !y.ok)
|
|
77
|
+
throw await C(y);
|
|
78
|
+
const g = await y.json(), w = new Date(Date.now() + g.expires_in * 1e3), S = await fetch(p.userinfo_endpoint, {
|
|
79
79
|
headers: {
|
|
80
80
|
Authorization: `Bearer ${g.access_token}`
|
|
81
81
|
}
|
|
@@ -109,7 +109,7 @@ async function M(r) {
|
|
|
109
109
|
scope: g.scope
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
112
|
+
async function V(r) {
|
|
113
113
|
if (typeof window > "u")
|
|
114
114
|
throw new Error("oauthHandleRedirect is only available in the browser");
|
|
115
115
|
const e = new URLSearchParams(window.location.search);
|
|
@@ -117,34 +117,34 @@ async function N(r) {
|
|
|
117
117
|
"Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL."
|
|
118
118
|
), !1) : !1;
|
|
119
119
|
}
|
|
120
|
-
async function
|
|
120
|
+
async function B(r) {
|
|
121
121
|
var e, t;
|
|
122
122
|
if (typeof window > "u")
|
|
123
123
|
throw new Error("oauthLogin is only available in the browser");
|
|
124
|
-
const s = r?.hubUrl ||
|
|
124
|
+
const s = r?.hubUrl || H, i = `${new URL(s).origin}/.well-known/openid-configuration`, o = await fetch(i, {
|
|
125
125
|
headers: {
|
|
126
126
|
Accept: "application/json"
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
if (!o.ok)
|
|
130
130
|
throw await C(o);
|
|
131
|
-
const n = await o.json(), a = globalThis.crypto.randomUUID(),
|
|
132
|
-
localStorage.setItem("huggingface.co:oauth:nonce", a), localStorage.setItem("huggingface.co:oauth:code_verifier",
|
|
133
|
-
const
|
|
131
|
+
const n = await o.json(), a = globalThis.crypto.randomUUID(), l = globalThis.crypto.randomUUID() + globalThis.crypto.randomUUID();
|
|
132
|
+
localStorage.setItem("huggingface.co:oauth:nonce", a), localStorage.setItem("huggingface.co:oauth:code_verifier", l);
|
|
133
|
+
const c = r?.redirectUrl || window.location.href, h = JSON.stringify({
|
|
134
134
|
nonce: a,
|
|
135
|
-
redirectUri:
|
|
135
|
+
redirectUri: c,
|
|
136
136
|
state: r?.state
|
|
137
137
|
}), d = (t = (e = window?.huggingface) == null ? void 0 : e.variables) != null ? t : null, m = r?.clientId || d?.OAUTH_CLIENT_ID;
|
|
138
138
|
if (!m)
|
|
139
139
|
throw d ? new Error("Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space") : new Error("Missing clientId");
|
|
140
|
-
const f =
|
|
141
|
-
new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(
|
|
140
|
+
const f = x(
|
|
141
|
+
new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(l)))
|
|
142
142
|
).replace(/[+]/g, "-").replace(/[/]/g, "_").replace(/=/g, "");
|
|
143
143
|
return `${n.authorization_endpoint}?${new URLSearchParams({
|
|
144
144
|
client_id: m,
|
|
145
145
|
scope: r?.scopes || d?.OAUTH_SCOPES || "openid profile",
|
|
146
146
|
response_type: "code",
|
|
147
|
-
redirect_uri:
|
|
147
|
+
redirect_uri: c,
|
|
148
148
|
state: h,
|
|
149
149
|
code_challenge: f,
|
|
150
150
|
code_challenge_method: "S256"
|
|
@@ -153,16 +153,16 @@ async function V(r) {
|
|
|
153
153
|
function R(r) {
|
|
154
154
|
return r * Math.PI / 180;
|
|
155
155
|
}
|
|
156
|
-
function
|
|
157
|
-
const s = R(r), i = R(e), o = R(t), n = Math.cos(o), a = Math.sin(o),
|
|
156
|
+
function G(r, e, t) {
|
|
157
|
+
const s = R(r), i = R(e), o = R(t), n = Math.cos(o), a = Math.sin(o), l = Math.cos(i), c = Math.sin(i), h = Math.cos(s), d = Math.sin(s);
|
|
158
158
|
return [
|
|
159
|
-
[n *
|
|
160
|
-
[a *
|
|
161
|
-
[-
|
|
159
|
+
[n * l, n * c * d - a * h, n * c * h + a * d, 0],
|
|
160
|
+
[a * l, a * c * d + n * h, a * c * h - n * d, 0],
|
|
161
|
+
[-c, l * d, l * h, 0],
|
|
162
162
|
[0, 0, 0, 1]
|
|
163
163
|
];
|
|
164
164
|
}
|
|
165
|
-
function
|
|
165
|
+
function q() {
|
|
166
166
|
if (typeof window > "u" || !window.location.hash) return;
|
|
167
167
|
const r = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
168
168
|
let e;
|
|
@@ -176,8 +176,8 @@ function G() {
|
|
|
176
176
|
const s = e.get("hf_username") || "user", i = e.get("hf_token_expires"), o = i && !Number.isNaN(new Date(i).getTime()) ? i : new Date(Date.now() + 365 * 24 * 60 * 60 * 1e3).toISOString();
|
|
177
177
|
try {
|
|
178
178
|
sessionStorage.setItem("hf_token", t), sessionStorage.setItem("hf_username", s), sessionStorage.setItem("hf_token_expires", o);
|
|
179
|
-
} catch (
|
|
180
|
-
console.warn("[reachy-mini] could not persist pre-seeded HF credentials:",
|
|
179
|
+
} catch (l) {
|
|
180
|
+
console.warn("[reachy-mini] could not persist pre-seeded HF credentials:", l);
|
|
181
181
|
}
|
|
182
182
|
e.delete("hf_token"), e.delete("hf_username"), e.delete("hf_token_expires");
|
|
183
183
|
const n = e.toString(), a = window.location.pathname + window.location.search + (n ? "#" + n : "");
|
|
@@ -186,7 +186,7 @@ function G() {
|
|
|
186
186
|
} catch {
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function W() {
|
|
190
190
|
if (typeof window > "u") return null;
|
|
191
191
|
if (window.location.hash) {
|
|
192
192
|
const r = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
@@ -204,7 +204,7 @@ function q() {
|
|
|
204
204
|
}
|
|
205
205
|
return null;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
207
|
+
function z(r) {
|
|
208
208
|
const e = r.split(`\r
|
|
209
209
|
`);
|
|
210
210
|
let t = !1;
|
|
@@ -212,8 +212,8 @@ function W(r) {
|
|
|
212
212
|
if (s.startsWith("m=audio") ? t = !0 : s.startsWith("m=") && (t = !1), t && s === "a=sendrecv") return !0;
|
|
213
213
|
return !1;
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
function
|
|
215
|
+
const v = 12 * 1024, A = 1 * 1024 * 1024, J = 512 * 1024;
|
|
216
|
+
function X() {
|
|
217
217
|
return typeof CompressionStream < "u";
|
|
218
218
|
}
|
|
219
219
|
function U() {
|
|
@@ -228,17 +228,17 @@ function E(r) {
|
|
|
228
228
|
);
|
|
229
229
|
return btoa(e);
|
|
230
230
|
}
|
|
231
|
-
async function
|
|
231
|
+
async function Y(r) {
|
|
232
232
|
const e = new TextEncoder().encode(r), t = await new Response(
|
|
233
233
|
new Blob([e]).stream().pipeThrough(new CompressionStream("gzip"))
|
|
234
234
|
).arrayBuffer();
|
|
235
235
|
return E(new Uint8Array(t));
|
|
236
236
|
}
|
|
237
|
-
function
|
|
237
|
+
function P(r) {
|
|
238
238
|
const e = Math.round(Number(r) || 0);
|
|
239
239
|
return Math.max(0, Math.min(100, e));
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function L(r) {
|
|
242
242
|
switch ((r.type || "").toLowerCase().split(";")[0]?.trim() ?? "") {
|
|
243
243
|
case "audio/ogg":
|
|
244
244
|
case "application/ogg":
|
|
@@ -261,8 +261,8 @@ function P(r) {
|
|
|
261
261
|
return "wav-base64";
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
const j = 3e3,
|
|
265
|
-
class
|
|
264
|
+
const j = 3e3, N = 1e3, K = 6e4, D = 750, Q = 4e3;
|
|
265
|
+
class Z extends EventTarget {
|
|
266
266
|
// ─── Config ──────────────────────────────────────────────────────────
|
|
267
267
|
_signalingUrl;
|
|
268
268
|
_clientId;
|
|
@@ -274,6 +274,19 @@ class K extends EventTarget {
|
|
|
274
274
|
_state = "disconnected";
|
|
275
275
|
_robots = [];
|
|
276
276
|
_robotState = {};
|
|
277
|
+
// Highest `seq` seen on the unordered `pose` channel. Frames that arrive
|
|
278
|
+
// out of order (older seq) are dropped so a late packet can't rewind the
|
|
279
|
+
// live mirror. `null` until the first pose frame.
|
|
280
|
+
_lastPoseSeq = null;
|
|
281
|
+
// When the last pushed pose frame was applied, used to park the periodic
|
|
282
|
+
// `get_state` poll while the stream is live (see POSE_STREAM_FRESH_MS).
|
|
283
|
+
_lastPoseFrameAt = 0;
|
|
284
|
+
// Local refcount of pose-stream consumers (the 3D mirror, the wizard's
|
|
285
|
+
// move-end watcher, ...). The daemon's subscription is a per-peer boolean
|
|
286
|
+
// (not refcounted), so we only send `unsubscribe_pose` once the LAST local
|
|
287
|
+
// consumer releases - otherwise one consumer's cleanup would kill the
|
|
288
|
+
// stream for the others.
|
|
289
|
+
_poseSubRefs = 0;
|
|
277
290
|
_preselectedRobotId;
|
|
278
291
|
// ─── Auth ────────────────────────────────────────────────────────────
|
|
279
292
|
_token = null;
|
|
@@ -301,6 +314,8 @@ class K extends EventTarget {
|
|
|
301
314
|
_volumeResolve = null;
|
|
302
315
|
_micVolumeResolve = null;
|
|
303
316
|
_trackedFaceResolve = null;
|
|
317
|
+
_robotNameResolve = null;
|
|
318
|
+
_deleteHfTokenResolve = null;
|
|
304
319
|
// applyAudioConfig() / readAudioParameter() share the same single-slot
|
|
305
320
|
// pattern as the volume helpers. Separate slots so the two can be
|
|
306
321
|
// in-flight concurrently without collision.
|
|
@@ -309,6 +324,13 @@ class K extends EventTarget {
|
|
|
309
324
|
// ─── Log subscribers ─────────────────────────────────────────────────
|
|
310
325
|
_logSubscribers = /* @__PURE__ */ new Set();
|
|
311
326
|
_updateProgressSubscribers = /* @__PURE__ */ new Set();
|
|
327
|
+
// ─── JSON-RPC app control (over the same DataChannel) ────────────────
|
|
328
|
+
// rpcCall() sends {jsonrpc,id,method,params} and awaits the matching
|
|
329
|
+
// response; onNotification() subscribes to one-way events (no id) the
|
|
330
|
+
// robot/app pushes (conversation.phase/turn/transcript, ...).
|
|
331
|
+
_rpcCounter = 0;
|
|
332
|
+
_pendingRpc = /* @__PURE__ */ new Map();
|
|
333
|
+
_rpcListeners = /* @__PURE__ */ new Map();
|
|
312
334
|
// ─── Broadcast waiters (playMove / playUploadedAudio) ────────────────
|
|
313
335
|
_broadcastWaiters = [];
|
|
314
336
|
// ─── Active upload ids for no-arg cancels ────────────────────────────
|
|
@@ -340,7 +362,7 @@ class K extends EventTarget {
|
|
|
340
362
|
// ─── Video element ───────────────────────────────────────────────────
|
|
341
363
|
_videoElement = null;
|
|
342
364
|
constructor(e = {}) {
|
|
343
|
-
super(), this._signalingUrl = e.signalingUrl || "https://pollen-robotics-reachy-mini-central.hf.space", this._clientId = e.clientId || null, this._appName = e.appName || "unknown", this._videoJitterBufferTargetMs = e.videoJitterBufferTargetMs ?? 0, this._autoStartFromUrl = e.autoStartFromUrl === !0, this._autoStartAttempted = !1, this._preselectedRobotId =
|
|
365
|
+
super(), this._signalingUrl = e.signalingUrl || "https://pollen-robotics-reachy-mini-central.hf.space", this._clientId = e.clientId || null, this._appName = e.appName || "unknown", this._videoJitterBufferTargetMs = e.videoJitterBufferTargetMs ?? 0, this._autoStartFromUrl = e.autoStartFromUrl === !0, this._autoStartAttempted = !1, this._preselectedRobotId = W();
|
|
344
366
|
}
|
|
345
367
|
// ─── Read-only properties ────────────────────────────────────────────
|
|
346
368
|
get state() {
|
|
@@ -392,8 +414,8 @@ class K extends EventTarget {
|
|
|
392
414
|
// ─── Auth ────────────────────────────────────────────────────────────
|
|
393
415
|
async authenticate() {
|
|
394
416
|
try {
|
|
395
|
-
|
|
396
|
-
const e = await
|
|
417
|
+
q();
|
|
418
|
+
const e = await V();
|
|
397
419
|
if (e)
|
|
398
420
|
return this._username = e.userInfo.preferred_username || e.userInfo.name || null, this._token = e.accessToken, this._tokenExpires = e.accessTokenExpiresAt, sessionStorage.setItem("hf_token", this._token), sessionStorage.setItem("hf_username", this._username ?? ""), sessionStorage.setItem(
|
|
399
421
|
"hf_token_expires",
|
|
@@ -407,7 +429,7 @@ class K extends EventTarget {
|
|
|
407
429
|
}
|
|
408
430
|
async login() {
|
|
409
431
|
const e = {};
|
|
410
|
-
this._clientId && (e.clientId = this._clientId), window.location.href = await
|
|
432
|
+
this._clientId && (e.clientId = this._clientId), window.location.href = await B(e);
|
|
411
433
|
}
|
|
412
434
|
logout() {
|
|
413
435
|
sessionStorage.removeItem("hf_token"), sessionStorage.removeItem("hf_username"), sessionStorage.removeItem("hf_token_expires"), this._username = null, this._tokenExpires = null, this.disconnect();
|
|
@@ -434,16 +456,16 @@ class K extends EventTarget {
|
|
|
434
456
|
return new Promise((s, i) => {
|
|
435
457
|
let o = !1;
|
|
436
458
|
const n = t.body.getReader(), a = new TextDecoder();
|
|
437
|
-
let
|
|
459
|
+
let l = "";
|
|
438
460
|
(async () => {
|
|
439
461
|
try {
|
|
440
462
|
for (; ; ) {
|
|
441
463
|
const { done: h, value: d } = await n.read();
|
|
442
464
|
if (h) break;
|
|
443
|
-
|
|
444
|
-
const m =
|
|
465
|
+
l += a.decode(d, { stream: !0 });
|
|
466
|
+
const m = l.split(`
|
|
445
467
|
`);
|
|
446
|
-
|
|
468
|
+
l = m.pop() ?? "";
|
|
447
469
|
for (const f of m)
|
|
448
470
|
if (f.startsWith("data:"))
|
|
449
471
|
try {
|
|
@@ -475,10 +497,10 @@ class K extends EventTarget {
|
|
|
475
497
|
wakeOnConnect: n = !0
|
|
476
498
|
} = e;
|
|
477
499
|
if (this._state === "streaming") {
|
|
478
|
-
const
|
|
500
|
+
const l = this._robots?.find((c) => c.id === this._selectedRobotId);
|
|
479
501
|
return {
|
|
480
502
|
robotId: this._selectedRobotId,
|
|
481
|
-
robotName:
|
|
503
|
+
robotName: l?.meta?.name ?? null,
|
|
482
504
|
isEmbedded: this.isEmbedded,
|
|
483
505
|
alreadyStreaming: !0
|
|
484
506
|
};
|
|
@@ -491,36 +513,36 @@ class K extends EventTarget {
|
|
|
491
513
|
else if (!this._token && !await this.authenticate())
|
|
492
514
|
throw new Error("Not authenticated — call login() or pass a token");
|
|
493
515
|
this._state === "disconnected" && await this.connect();
|
|
494
|
-
let
|
|
516
|
+
let l, c = null;
|
|
495
517
|
if (this.isEmbedded) {
|
|
496
|
-
|
|
518
|
+
l = this._preselectedRobotId;
|
|
497
519
|
try {
|
|
498
|
-
await this._waitForRobotInList(
|
|
520
|
+
await this._waitForRobotInList(l, 5e3);
|
|
499
521
|
} catch {
|
|
500
522
|
}
|
|
501
|
-
|
|
523
|
+
c = this._robots?.find((d) => d.id === l)?.meta?.name ?? null;
|
|
502
524
|
} else {
|
|
503
525
|
const h = await this._fetchOwnedRobots({ filterBusy: o });
|
|
504
526
|
if (h.length === 0)
|
|
505
527
|
throw new Error("No reachable robots");
|
|
506
528
|
if (i && h.length === 1 && !h[0].busy)
|
|
507
|
-
|
|
529
|
+
l = h[0].id, c = h[0].name;
|
|
508
530
|
else if (s) {
|
|
509
531
|
const d = await s(h);
|
|
510
532
|
if (!d) throw new Error("Robot selection cancelled");
|
|
511
|
-
|
|
533
|
+
l = d, c = h.find((m) => m.id === d)?.name ?? null;
|
|
512
534
|
} else
|
|
513
535
|
throw new Error(
|
|
514
536
|
"Multiple robots available — pass a pickRobot callback to autoConnect()"
|
|
515
537
|
);
|
|
516
538
|
}
|
|
517
|
-
if (await this.startSession(
|
|
539
|
+
if (await this.startSession(l), n && typeof this.ensureAwake == "function")
|
|
518
540
|
try {
|
|
519
541
|
await this.ensureAwake();
|
|
520
542
|
} catch (h) {
|
|
521
543
|
console.warn("[reachy-mini] autoConnect: ensureAwake failed:", h);
|
|
522
544
|
}
|
|
523
|
-
return { robotId:
|
|
545
|
+
return { robotId: l, robotName: c, isEmbedded: this.isEmbedded };
|
|
524
546
|
} finally {
|
|
525
547
|
this._autoStartFromUrl = a;
|
|
526
548
|
}
|
|
@@ -576,10 +598,10 @@ class K extends EventTarget {
|
|
|
576
598
|
if (!s) throw new Error("AudioContext not supported");
|
|
577
599
|
const i = new s(), o = i.createMediaStreamDestination(), n = i.createOscillator(), a = i.createGain();
|
|
578
600
|
a.gain.value = 0, n.connect(a).connect(o), n.start();
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}), this._micStream =
|
|
601
|
+
const l = o.stream;
|
|
602
|
+
l.getAudioTracks().forEach((c) => {
|
|
603
|
+
c.enabled = !1;
|
|
604
|
+
}), this._micStream = l, this._micMuted = !0;
|
|
583
605
|
} catch (t) {
|
|
584
606
|
console.warn("Audio sender placeholder setup failed:", t), this._micStream = null;
|
|
585
607
|
}
|
|
@@ -621,14 +643,26 @@ class K extends EventTarget {
|
|
|
621
643
|
return;
|
|
622
644
|
}
|
|
623
645
|
if (i === "failed") {
|
|
624
|
-
this._scheduleIceGrace(
|
|
646
|
+
this._scheduleIceGrace(N, "failed");
|
|
625
647
|
return;
|
|
626
648
|
}
|
|
627
649
|
}
|
|
628
650
|
}, this._pc.ondatachannel = (i) => {
|
|
629
|
-
|
|
651
|
+
const o = i.channel;
|
|
652
|
+
if (o.label === "pose") {
|
|
653
|
+
this._lastPoseSeq = null, o.onmessage = (n) => {
|
|
654
|
+
const a = JSON.parse(n.data);
|
|
655
|
+
if (typeof a.seq == "number") {
|
|
656
|
+
if (this._lastPoseSeq !== null && a.seq <= this._lastPoseSeq) return;
|
|
657
|
+
this._lastPoseSeq = a.seq;
|
|
658
|
+
}
|
|
659
|
+
this._lastPoseFrameAt = Date.now(), this._handleRobotMessage(a, !0);
|
|
660
|
+
};
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
this._dc = o, this._dc.onopen = () => {
|
|
630
664
|
this._dcOpen = !0, this._checkSessionReady();
|
|
631
|
-
}, this._dc.onmessage = (
|
|
665
|
+
}, this._dc.onmessage = (n) => this._handleRobotMessage(JSON.parse(n.data));
|
|
632
666
|
}, this._sendToServer({ type: "startSession", peerId: e }).then((i) => {
|
|
633
667
|
if (i?.type === "sessionRejected") {
|
|
634
668
|
this._failSessionRejected(i);
|
|
@@ -648,10 +682,10 @@ class K extends EventTarget {
|
|
|
648
682
|
}
|
|
649
683
|
}
|
|
650
684
|
async stopSession() {
|
|
651
|
-
this._versionResolve && (this._versionResolve(null), this._versionResolve = null), this._hardwareIdResolve && (this._hardwareIdResolve(null), this._hardwareIdResolve = null), this._volumeResolve && (this._volumeResolve(null), this._volumeResolve = null), this._micVolumeResolve && (this._micVolumeResolve(null), this._micVolumeResolve = null), this._trackedFaceResolve && (this._trackedFaceResolve(null), this._trackedFaceResolve = null), this._applyAudioConfigResolve && (this._applyAudioConfigResolve(!1), this._applyAudioConfigResolve = null), this._readAudioParameterResolve && (this._readAudioParameterResolve(null), this._readAudioParameterResolve = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._rejectPendingMotionCompletions(new Error("Session stopped")), this._clearIceGrace(), this._uninstallNetworkListeners(), this._sessionReject && (this._sessionReject(new Error("Session stopped")), this._sessionResolve = null, this._sessionReject = null), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this._sessionId && await this._sendToServer({ type: "endSession", sessionId: this._sessionId }), this._micStream && (this._micStream.getTracks().forEach((t) => t.stop()), this._micStream = null), this._micMuted = !0, this._micSupported = !1, this._pc && (this._pc.close(), this._pc = null), this._dc && (this._dc.close(), this._dc = null), this._sessionId = null, this._iceConnected = !1, this._dcOpen = !1, this._state === "streaming" && (this._state = "connected", this._emit("sessionStopped", { reason: "user" }));
|
|
685
|
+
this._versionResolve && (this._versionResolve(null), this._versionResolve = null), this._hardwareIdResolve && (this._hardwareIdResolve(null), this._hardwareIdResolve = null), this._volumeResolve && (this._volumeResolve(null), this._volumeResolve = null), this._micVolumeResolve && (this._micVolumeResolve(null), this._micVolumeResolve = null), this._trackedFaceResolve && (this._trackedFaceResolve(null), this._trackedFaceResolve = null), this._applyAudioConfigResolve && (this._applyAudioConfigResolve(!1), this._applyAudioConfigResolve = null), this._readAudioParameterResolve && (this._readAudioParameterResolve(null), this._readAudioParameterResolve = null), this._robotNameResolve && (this._robotNameResolve(null), this._robotNameResolve = null), this._deleteHfTokenResolve && (this._deleteHfTokenResolve(null), this._deleteHfTokenResolve = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._rejectPendingMotionCompletions(new Error("Session stopped")), this._rejectPendingRpc(new Error("Session stopped")), this._clearIceGrace(), this._uninstallNetworkListeners(), this._sessionReject && (this._sessionReject(new Error("Session stopped")), this._sessionResolve = null, this._sessionReject = null), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this._sessionId && await this._sendToServer({ type: "endSession", sessionId: this._sessionId }), this._micStream && (this._micStream.getTracks().forEach((t) => t.stop()), this._micStream = null), this._micMuted = !0, this._micSupported = !1, this._pc && (this._pc.close(), this._pc = null), this._dc && (this._dc.close(), this._dc = null), this._sessionId = null, this._iceConnected = !1, this._dcOpen = !1, this._state === "streaming" && (this._state = "connected", this._emit("sessionStopped", { reason: "user" }));
|
|
652
686
|
}
|
|
653
687
|
disconnect() {
|
|
654
|
-
this._sseAbortController && (this._sseAbortController.abort(), this._sseAbortController = null), this._versionResolve && (this._versionResolve(null), this._versionResolve = null), this._hardwareIdResolve && (this._hardwareIdResolve(null), this._hardwareIdResolve = null), this._volumeResolve && (this._volumeResolve(null), this._volumeResolve = null), this._micVolumeResolve && (this._micVolumeResolve(null), this._micVolumeResolve = null), this._trackedFaceResolve && (this._trackedFaceResolve(null), this._trackedFaceResolve = null), this._applyAudioConfigResolve && (this._applyAudioConfigResolve(!1), this._applyAudioConfigResolve = null), this._readAudioParameterResolve && (this._readAudioParameterResolve(null), this._readAudioParameterResolve = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._rejectPendingMotionCompletions(new Error("Disconnected")), this._clearIceGrace(), this._uninstallNetworkListeners(), this._sessionReject && (this._sessionReject(new Error("Disconnected")), this._sessionResolve = null, this._sessionReject = null), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this._sessionId && this._token && this._sendToServer({ type: "endSession", sessionId: this._sessionId }), this._micStream && (this._micStream.getTracks().forEach((e) => e.stop()), this._micStream = null), this._pc && (this._pc.close(), this._pc = null), this._dc && (this._dc.close(), this._dc = null), this._sessionId = null, this._micMuted = !0, this._micSupported = !1, this._iceConnected = !1, this._dcOpen = !1, this._robots = [], this._state = "disconnected", this._emit("disconnected", { reason: "user" });
|
|
688
|
+
this._sseAbortController && (this._sseAbortController.abort(), this._sseAbortController = null), this._versionResolve && (this._versionResolve(null), this._versionResolve = null), this._hardwareIdResolve && (this._hardwareIdResolve(null), this._hardwareIdResolve = null), this._volumeResolve && (this._volumeResolve(null), this._volumeResolve = null), this._micVolumeResolve && (this._micVolumeResolve(null), this._micVolumeResolve = null), this._trackedFaceResolve && (this._trackedFaceResolve(null), this._trackedFaceResolve = null), this._applyAudioConfigResolve && (this._applyAudioConfigResolve(!1), this._applyAudioConfigResolve = null), this._readAudioParameterResolve && (this._readAudioParameterResolve(null), this._readAudioParameterResolve = null), this._robotNameResolve && (this._robotNameResolve(null), this._robotNameResolve = null), this._deleteHfTokenResolve && (this._deleteHfTokenResolve(null), this._deleteHfTokenResolve = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._rejectPendingMotionCompletions(new Error("Disconnected")), this._clearIceGrace(), this._uninstallNetworkListeners(), this._sessionReject && (this._sessionReject(new Error("Disconnected")), this._sessionResolve = null, this._sessionReject = null), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this._sessionId && this._token && this._sendToServer({ type: "endSession", sessionId: this._sessionId }), this._micStream && (this._micStream.getTracks().forEach((e) => e.stop()), this._micStream = null), this._pc && (this._pc.close(), this._pc = null), this._dc && (this._dc.close(), this._dc = null), this._sessionId = null, this._micMuted = !0, this._micSupported = !1, this._iceConnected = !1, this._dcOpen = !1, this._robots = [], this._state = "disconnected", this._emit("disconnected", { reason: "user" });
|
|
655
689
|
}
|
|
656
690
|
// ─── Resilience: ICE-blip debounce + network awareness ───────────────
|
|
657
691
|
//
|
|
@@ -716,7 +750,7 @@ class K extends EventTarget {
|
|
|
716
750
|
if (typeof document < "u" && document.hidden || (document.removeEventListener("visibilitychange", t), this._pendingVisibilityHandler = null, !this._pc)) return;
|
|
717
751
|
const s = this._pc.iceConnectionState;
|
|
718
752
|
if (!(s === "connected" || s === "completed")) {
|
|
719
|
-
if (Date.now() - e >
|
|
753
|
+
if (Date.now() - e > K) {
|
|
720
754
|
const i = new Error(
|
|
721
755
|
"Session expired while tab was backgrounded"
|
|
722
756
|
);
|
|
@@ -724,7 +758,7 @@ class K extends EventTarget {
|
|
|
724
758
|
return;
|
|
725
759
|
}
|
|
726
760
|
if (s === "failed") {
|
|
727
|
-
this._scheduleIceGrace(
|
|
761
|
+
this._scheduleIceGrace(N, "failed");
|
|
728
762
|
return;
|
|
729
763
|
}
|
|
730
764
|
this._scheduleIceGrace(j, "disconnected");
|
|
@@ -872,7 +906,7 @@ class K extends EventTarget {
|
|
|
872
906
|
return o.duration = i, this._sendCommand(o);
|
|
873
907
|
}
|
|
874
908
|
setHeadRpyDeg(e, t, s) {
|
|
875
|
-
return this.setTarget({ head:
|
|
909
|
+
return this.setTarget({ head: G(e, t, s).flat() });
|
|
876
910
|
}
|
|
877
911
|
setAntennasDeg(e, t) {
|
|
878
912
|
return this.setTarget({ antennas: [R(e), R(t)] });
|
|
@@ -1005,7 +1039,7 @@ class K extends EventTarget {
|
|
|
1005
1039
|
(t) => {
|
|
1006
1040
|
this._volumeResolve = t;
|
|
1007
1041
|
},
|
|
1008
|
-
{ type: "set_volume", volume:
|
|
1042
|
+
{ type: "set_volume", volume: P(e) }
|
|
1009
1043
|
);
|
|
1010
1044
|
}
|
|
1011
1045
|
getMicrophoneVolume() {
|
|
@@ -1023,7 +1057,62 @@ class K extends EventTarget {
|
|
|
1023
1057
|
(t) => {
|
|
1024
1058
|
this._micVolumeResolve = t;
|
|
1025
1059
|
},
|
|
1026
|
-
{ type: "set_microphone_volume", volume:
|
|
1060
|
+
{ type: "set_microphone_volume", volume: P(e) }
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Query the persisted robot display name. Resolves the stored name,
|
|
1065
|
+
* `null` when none is set / the channel isn't open / the daemon predates
|
|
1066
|
+
* the `get_robot_name` command.
|
|
1067
|
+
*/
|
|
1068
|
+
getRobotName() {
|
|
1069
|
+
return this._slotRoundtrip(
|
|
1070
|
+
() => this._robotNameResolve,
|
|
1071
|
+
(e) => {
|
|
1072
|
+
this._robotNameResolve = e;
|
|
1073
|
+
},
|
|
1074
|
+
{ type: "get_robot_name" }
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Set and persist the robot display name on the robot. Resolves with the
|
|
1079
|
+
* stored (trimmed) name, or `null` on error / channel-closed. Applied live
|
|
1080
|
+
* by the daemon (status + central relay + mDNS), so it takes effect right
|
|
1081
|
+
* away without a restart; the persisted name also overrides --robot-name
|
|
1082
|
+
* on the next start.
|
|
1083
|
+
*/
|
|
1084
|
+
setRobotName(e) {
|
|
1085
|
+
return this._slotRoundtrip(
|
|
1086
|
+
() => this._robotNameResolve,
|
|
1087
|
+
(t) => {
|
|
1088
|
+
this._robotNameResolve = t;
|
|
1089
|
+
},
|
|
1090
|
+
{ type: "set_robot_name", name: e }
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Sign this robot out of Hugging Face: asks the daemon to delete its
|
|
1095
|
+
* stored HF token, which de-registers the robot from the central
|
|
1096
|
+
* signaling relay (it disappears from its owner's robot list until it
|
|
1097
|
+
* is set up again). Works over the WebRTC data channel, so it reaches
|
|
1098
|
+
* the robot remotely (no LAN HTTP path required).
|
|
1099
|
+
*
|
|
1100
|
+
* Resolves `true` when the daemon acked success, `false` on a daemon
|
|
1101
|
+
* error, or `null` when no ack arrives before the timeout (e.g. a
|
|
1102
|
+
* daemon that predates the `delete_hf_token` command silently drops
|
|
1103
|
+
* it). Rejects if the data channel isn't open. Note the sign-out
|
|
1104
|
+
* drops the central relay, so the session may tear down right after
|
|
1105
|
+
* the ack - callers should treat a post-call session drop as expected,
|
|
1106
|
+
* and a successful sign-out may surface as `null` if teardown races
|
|
1107
|
+
* ahead of the ack.
|
|
1108
|
+
*/
|
|
1109
|
+
signOut() {
|
|
1110
|
+
return this._slotRoundtrip(
|
|
1111
|
+
() => this._deleteHfTokenResolve,
|
|
1112
|
+
(e) => {
|
|
1113
|
+
this._deleteHfTokenResolve = e;
|
|
1114
|
+
},
|
|
1115
|
+
{ type: "delete_hf_token" }
|
|
1027
1116
|
);
|
|
1028
1117
|
}
|
|
1029
1118
|
applyAudioConfig(e, { verify: t = !0 } = {}) {
|
|
@@ -1065,7 +1154,12 @@ class K extends EventTarget {
|
|
|
1065
1154
|
return;
|
|
1066
1155
|
}
|
|
1067
1156
|
const n = e();
|
|
1068
|
-
n && n(null)
|
|
1157
|
+
n && n(null);
|
|
1158
|
+
let a;
|
|
1159
|
+
const l = (c) => {
|
|
1160
|
+
a !== void 0 && (clearTimeout(a), a = void 0), e() === l && t(null), i(c);
|
|
1161
|
+
};
|
|
1162
|
+
t(l), a = setTimeout(() => l(null), Q), this._sendCommand(s);
|
|
1069
1163
|
});
|
|
1070
1164
|
}
|
|
1071
1165
|
sendRaw(e) {
|
|
@@ -1084,6 +1178,25 @@ class K extends EventTarget {
|
|
|
1084
1178
|
requestState() {
|
|
1085
1179
|
return this._sendCommand({ type: "get_state" });
|
|
1086
1180
|
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Ask the daemon to *push* the robot state (~30 Hz) over the dedicated
|
|
1183
|
+
* unreliable/unordered `pose` data channel instead of polling get_state.
|
|
1184
|
+
* Fires `state` events as frames arrive. No-op against an older daemon (no
|
|
1185
|
+
* pose channel) - fall back to `requestState()` polling there.
|
|
1186
|
+
*
|
|
1187
|
+
* Refcounted: pair every `subscribePose()` with exactly one
|
|
1188
|
+
* `unsubscribePose()`. Multiple consumers share a single daemon-side
|
|
1189
|
+
* subscription; the daemon only stops pushing once the last one releases.
|
|
1190
|
+
* If the channel isn't open yet (or the session later reconnects), the
|
|
1191
|
+
* subscription is (re-)asserted from `_checkSessionReady`.
|
|
1192
|
+
*/
|
|
1193
|
+
subscribePose() {
|
|
1194
|
+
return this._poseSubRefs++, this._sendCommand({ type: "subscribe_pose" });
|
|
1195
|
+
}
|
|
1196
|
+
/** Release one pose-stream consumer; sends `unsubscribe_pose` on the last. */
|
|
1197
|
+
unsubscribePose() {
|
|
1198
|
+
return this._poseSubRefs > 0 && this._poseSubRefs--, this._poseSubRefs > 0 ? !0 : this._sendCommand({ type: "unsubscribe_pose" });
|
|
1199
|
+
}
|
|
1087
1200
|
// ─── Audio ───────────────────────────────────────────────────────────
|
|
1088
1201
|
setAudioMuted(e) {
|
|
1089
1202
|
this._audioMuted = e, this._videoElement && (this._videoElement.muted = e);
|
|
@@ -1114,8 +1227,8 @@ class K extends EventTarget {
|
|
|
1114
1227
|
encoding: o = "gzip+base64",
|
|
1115
1228
|
playFrequency: n = 100,
|
|
1116
1229
|
initialGotoDuration: a = 0,
|
|
1117
|
-
startTimeoutMs:
|
|
1118
|
-
onProgress:
|
|
1230
|
+
startTimeoutMs: l = 8e3,
|
|
1231
|
+
onProgress: c = () => {
|
|
1119
1232
|
},
|
|
1120
1233
|
onStarted: h = () => {
|
|
1121
1234
|
}
|
|
@@ -1131,35 +1244,35 @@ class K extends EventTarget {
|
|
|
1131
1244
|
time: e.time,
|
|
1132
1245
|
set_target_data: e.set_target_data
|
|
1133
1246
|
}, f = JSON.stringify(m);
|
|
1134
|
-
let p,
|
|
1135
|
-
o === "gzip+base64" &&
|
|
1136
|
-
const g = Math.ceil(p.length /
|
|
1137
|
-
|
|
1247
|
+
let p, y;
|
|
1248
|
+
o === "gzip+base64" && X() ? (p = await Y(f), y = "gzip+base64") : (p = f, y = "json");
|
|
1249
|
+
const g = Math.ceil(p.length / v) || 1;
|
|
1250
|
+
c({
|
|
1138
1251
|
phase: "starting",
|
|
1139
1252
|
sent: 0,
|
|
1140
1253
|
total: g,
|
|
1141
1254
|
bytes: p.length,
|
|
1142
|
-
encoding:
|
|
1255
|
+
encoding: y
|
|
1143
1256
|
}), this._sendCommand({
|
|
1144
1257
|
type: "upload_move_start",
|
|
1145
1258
|
upload_id: d,
|
|
1146
1259
|
total_chunks: g,
|
|
1147
1260
|
description: i,
|
|
1148
|
-
encoding:
|
|
1261
|
+
encoding: y
|
|
1149
1262
|
});
|
|
1150
1263
|
for (let u = 0; u < g; u++) {
|
|
1151
1264
|
this._dc.bufferedAmount > A && await this._awaitDataChannelDrain();
|
|
1152
|
-
const _ = u *
|
|
1265
|
+
const _ = u * v;
|
|
1153
1266
|
this._sendCommand({
|
|
1154
1267
|
type: "upload_move_chunk",
|
|
1155
1268
|
upload_id: d,
|
|
1156
1269
|
chunk_index: u,
|
|
1157
|
-
chunk: p.slice(_, _ +
|
|
1158
|
-
}),
|
|
1270
|
+
chunk: p.slice(_, _ + v)
|
|
1271
|
+
}), c({ phase: "upload", sent: u + 1, total: g });
|
|
1159
1272
|
}
|
|
1160
|
-
if (this._sendCommand({ type: "upload_move_finish", upload_id: d }),
|
|
1161
|
-
const u = new Uint8Array(await t.arrayBuffer()), _ = E(u), b = Math.ceil(_.length /
|
|
1162
|
-
|
|
1273
|
+
if (this._sendCommand({ type: "upload_move_finish", upload_id: d }), c({ phase: "uploaded", sent: g, total: g }), t) {
|
|
1274
|
+
const u = new Uint8Array(await t.arrayBuffer()), _ = E(u), b = Math.ceil(_.length / v) || 1;
|
|
1275
|
+
c({
|
|
1163
1276
|
phase: "audio-starting",
|
|
1164
1277
|
sent: 0,
|
|
1165
1278
|
total: b,
|
|
@@ -1168,20 +1281,20 @@ class K extends EventTarget {
|
|
|
1168
1281
|
type: "upload_audio_start",
|
|
1169
1282
|
upload_id: d,
|
|
1170
1283
|
total_chunks: b,
|
|
1171
|
-
encoding:
|
|
1284
|
+
encoding: L(t),
|
|
1172
1285
|
description: i
|
|
1173
1286
|
});
|
|
1174
1287
|
for (let I = 0; I < b; I++) {
|
|
1175
1288
|
this._dc.bufferedAmount > A && await this._awaitDataChannelDrain();
|
|
1176
|
-
const T = I *
|
|
1289
|
+
const T = I * v;
|
|
1177
1290
|
this._sendCommand({
|
|
1178
1291
|
type: "upload_audio_chunk",
|
|
1179
1292
|
upload_id: d,
|
|
1180
1293
|
chunk_index: I,
|
|
1181
|
-
chunk: _.slice(T, T +
|
|
1182
|
-
}),
|
|
1294
|
+
chunk: _.slice(T, T + v)
|
|
1295
|
+
}), c({ phase: "audio-upload", sent: I + 1, total: b });
|
|
1183
1296
|
}
|
|
1184
|
-
this._sendCommand({ type: "upload_audio_finish", upload_id: d }),
|
|
1297
|
+
this._sendCommand({ type: "upload_audio_finish", upload_id: d }), c({ phase: "audio-uploaded", sent: b, total: b });
|
|
1185
1298
|
}
|
|
1186
1299
|
this._sendCommand({
|
|
1187
1300
|
type: "play_uploaded_move",
|
|
@@ -1194,7 +1307,7 @@ class K extends EventTarget {
|
|
|
1194
1307
|
try {
|
|
1195
1308
|
w = await this._waitForBroadcast(
|
|
1196
1309
|
(u) => u?.type === "play_uploaded_move" && u?.upload_id === d && (u.started === !0 || typeof u.error == "string"),
|
|
1197
|
-
{ timeoutMs:
|
|
1310
|
+
{ timeoutMs: l, debugLabel: "play_uploaded_move started" }
|
|
1198
1311
|
);
|
|
1199
1312
|
} catch (u) {
|
|
1200
1313
|
throw new Error(
|
|
@@ -1211,7 +1324,7 @@ class K extends EventTarget {
|
|
|
1211
1324
|
} catch (u) {
|
|
1212
1325
|
console.warn("playMove.onStarted threw:", u);
|
|
1213
1326
|
}
|
|
1214
|
-
|
|
1327
|
+
c({ phase: "playing", duration_s: w.duration_s });
|
|
1215
1328
|
const S = await this._waitForBroadcast(
|
|
1216
1329
|
(u) => u?.type === "play_uploaded_move" && u?.upload_id === d && (u.finished === !0 || u.cancelled === !0 || typeof u.error == "string"),
|
|
1217
1330
|
{
|
|
@@ -1231,23 +1344,23 @@ class K extends EventTarget {
|
|
|
1231
1344
|
throw new Error("data channel not open");
|
|
1232
1345
|
if (!(e instanceof Blob))
|
|
1233
1346
|
throw new TypeError("uploadAudio: expected a Blob");
|
|
1234
|
-
const i = U(), o = new Uint8Array(await e.arrayBuffer()), n = E(o), a = Math.ceil(n.length /
|
|
1347
|
+
const i = U(), o = new Uint8Array(await e.arrayBuffer()), n = E(o), a = Math.ceil(n.length / v) || 1;
|
|
1235
1348
|
s({ phase: "audio-starting", sent: 0, total: a, bytes: n.length }), this._sendCommand({
|
|
1236
1349
|
type: "upload_audio_start",
|
|
1237
1350
|
upload_id: i,
|
|
1238
1351
|
total_chunks: a,
|
|
1239
|
-
encoding:
|
|
1352
|
+
encoding: L(e),
|
|
1240
1353
|
description: t
|
|
1241
1354
|
});
|
|
1242
|
-
for (let
|
|
1355
|
+
for (let l = 0; l < a; l++) {
|
|
1243
1356
|
this._dc.bufferedAmount > A && await this._awaitDataChannelDrain();
|
|
1244
|
-
const
|
|
1357
|
+
const c = l * v;
|
|
1245
1358
|
this._sendCommand({
|
|
1246
1359
|
type: "upload_audio_chunk",
|
|
1247
1360
|
upload_id: i,
|
|
1248
|
-
chunk_index:
|
|
1249
|
-
chunk: n.slice(
|
|
1250
|
-
}), s({ phase: "audio-upload", sent:
|
|
1361
|
+
chunk_index: l,
|
|
1362
|
+
chunk: n.slice(c, c + v)
|
|
1363
|
+
}), s({ phase: "audio-upload", sent: l + 1, total: a });
|
|
1251
1364
|
}
|
|
1252
1365
|
return this._sendCommand({ type: "upload_audio_finish", upload_id: i }), s({ phase: "audio-uploaded", sent: a, total: a }), i;
|
|
1253
1366
|
}
|
|
@@ -1285,7 +1398,7 @@ class K extends EventTarget {
|
|
|
1285
1398
|
});
|
|
1286
1399
|
}
|
|
1287
1400
|
async _awaitDataChannelDrain() {
|
|
1288
|
-
for (; this._dc && this._dc.bufferedAmount >
|
|
1401
|
+
for (; this._dc && this._dc.bufferedAmount > J; )
|
|
1289
1402
|
if (await new Promise((e) => setTimeout(e, 30)), !this._dc || this._dc.readyState !== "open")
|
|
1290
1403
|
throw new Error("data channel closed mid-upload");
|
|
1291
1404
|
}
|
|
@@ -1318,8 +1431,66 @@ class K extends EventTarget {
|
|
|
1318
1431
|
_sendCommand(e) {
|
|
1319
1432
|
return !this._dc || this._dc.readyState !== "open" ? !1 : (this._dc.send(JSON.stringify(e)), !0);
|
|
1320
1433
|
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Call a JSON-RPC method on the robot/app over the DataChannel and await
|
|
1436
|
+
* its result. This is the one way to drive an on-robot app (start/stop it
|
|
1437
|
+
* via `apps.*`, or drive a running app via its own namespace, e.g.
|
|
1438
|
+
* `conversation.say`). Rejects on the JSON-RPC error, a closed channel, or
|
|
1439
|
+
* timeout.
|
|
1440
|
+
*/
|
|
1441
|
+
rpcCall(e, t = {}, s = {}) {
|
|
1442
|
+
const i = s.timeoutMs ?? 2e4, o = `rpc-${++this._rpcCounter}`;
|
|
1443
|
+
return this._sendCommand({ jsonrpc: "2.0", id: o, method: e, params: t }) ? new Promise((n, a) => {
|
|
1444
|
+
const l = setTimeout(() => {
|
|
1445
|
+
this._pendingRpc.delete(o), a(new Error(`rpcCall(${e}) timed out after ${i}ms`));
|
|
1446
|
+
}, i);
|
|
1447
|
+
this._pendingRpc.set(o, {
|
|
1448
|
+
resolve: (c) => n(c),
|
|
1449
|
+
reject: a,
|
|
1450
|
+
timer: l
|
|
1451
|
+
});
|
|
1452
|
+
}) : Promise.reject(new Error(`rpcCall(${e}): data channel not open`));
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Subscribe to a JSON-RPC notification (one-way event) pushed by the
|
|
1456
|
+
* robot/app, e.g. `conversation.turn`. Returns an unsubscribe function.
|
|
1457
|
+
*/
|
|
1458
|
+
onNotification(e, t) {
|
|
1459
|
+
let s = this._rpcListeners.get(e);
|
|
1460
|
+
return s || (s = /* @__PURE__ */ new Set(), this._rpcListeners.set(e, s)), s.add(t), () => {
|
|
1461
|
+
this._rpcListeners.get(e)?.delete(t);
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
_rejectPendingRpc(e) {
|
|
1465
|
+
for (const t of this._pendingRpc.values())
|
|
1466
|
+
clearTimeout(t.timer), t.reject(e);
|
|
1467
|
+
this._pendingRpc.clear();
|
|
1468
|
+
}
|
|
1469
|
+
_handleRpcMessage(e) {
|
|
1470
|
+
if ("id" in e && e.id != null && ("result" in e || "error" in e)) {
|
|
1471
|
+
const t = this._pendingRpc.get(e.id);
|
|
1472
|
+
if (!t) return;
|
|
1473
|
+
if (this._pendingRpc.delete(e.id), clearTimeout(t.timer), "error" in e && e.error) {
|
|
1474
|
+
const s = e.error, i = new Error(s.message ?? "rpc error");
|
|
1475
|
+
i.reason = s.data?.reason, t.reject(i);
|
|
1476
|
+
} else
|
|
1477
|
+
t.resolve(e.result);
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
if (typeof e.method == "string") {
|
|
1481
|
+
const t = e.params ?? {};
|
|
1482
|
+
for (const s of this._rpcListeners.get(e.method) ?? [])
|
|
1483
|
+
try {
|
|
1484
|
+
s(t);
|
|
1485
|
+
} catch (i) {
|
|
1486
|
+
console.error(`onNotification(${e.method}) threw:`, i);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1321
1490
|
_checkSessionReady() {
|
|
1322
|
-
this._iceConnected && this._dcOpen && this._sessionResolve && (this._state = "streaming", this.requestState(), this.
|
|
1491
|
+
this._iceConnected && this._dcOpen && this._sessionResolve && (this._state = "streaming", this.requestState(), this._poseSubRefs > 0 && this._sendCommand({ type: "subscribe_pose" }), this._lastPoseFrameAt = 0, this._stateRefreshInterval = setInterval(() => {
|
|
1492
|
+
Date.now() - this._lastPoseFrameAt < D || this.requestState();
|
|
1493
|
+
}, 500), this._emit("streaming", { sessionId: this._sessionId, robotId: this._selectedRobotId }), this._sessionResolve(), this._sessionResolve = null, this._sessionReject = null);
|
|
1323
1494
|
}
|
|
1324
1495
|
async _handleSignalingMessage(e) {
|
|
1325
1496
|
switch (e.type) {
|
|
@@ -1370,7 +1541,7 @@ class K extends EventTarget {
|
|
|
1370
1541
|
if (e.sdp) {
|
|
1371
1542
|
const t = e.sdp;
|
|
1372
1543
|
if (t.type === "offer") {
|
|
1373
|
-
const i =
|
|
1544
|
+
const i = z(t.sdp);
|
|
1374
1545
|
if (this._micSupported = i, this._emit("micSupported", { supported: i }), i && this._micStream)
|
|
1375
1546
|
for (const n of this._micStream.getAudioTracks())
|
|
1376
1547
|
this._pc.addTrack(n, this._micStream);
|
|
@@ -1402,7 +1573,16 @@ class K extends EventTarget {
|
|
|
1402
1573
|
console.error("WebRTC error:", t), this._emit("error", { source: "webrtc", error: t });
|
|
1403
1574
|
}
|
|
1404
1575
|
}
|
|
1405
|
-
|
|
1576
|
+
/**
|
|
1577
|
+
* @param fromPoseStream Frame came from the pushed `pose` channel rather
|
|
1578
|
+
* than the reliable control channel. Only those may refresh the state
|
|
1579
|
+
* mirror while the stream is live (see the `data.state` branch).
|
|
1580
|
+
*/
|
|
1581
|
+
_handleRobotMessage(e, t = !1) {
|
|
1582
|
+
if (e.jsonrpc === "2.0") {
|
|
1583
|
+
this._handleRpcMessage(e);
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1406
1586
|
if ("version" in e && this._versionResolve) {
|
|
1407
1587
|
this._versionResolve(e.version), this._versionResolve = null;
|
|
1408
1588
|
return;
|
|
@@ -1419,6 +1599,16 @@ class K extends EventTarget {
|
|
|
1419
1599
|
this._micVolumeResolve && (this._micVolumeResolve(e.status === "error" ? null : e.volume), this._micVolumeResolve = null);
|
|
1420
1600
|
return;
|
|
1421
1601
|
}
|
|
1602
|
+
if (e.command === "get_robot_name" || e.command === "set_robot_name") {
|
|
1603
|
+
this._robotNameResolve && (this._robotNameResolve(
|
|
1604
|
+
e.status === "error" ? null : e.name ?? null
|
|
1605
|
+
), this._robotNameResolve = null);
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
if (e.command === "delete_hf_token") {
|
|
1609
|
+
this._deleteHfTokenResolve && (this._deleteHfTokenResolve(e.status !== "error"), this._deleteHfTokenResolve = null);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1422
1612
|
if (e.command === "apply_audio_config") {
|
|
1423
1613
|
this._applyAudioConfigResolve && (this._applyAudioConfigResolve(e.error ? !1 : !!e.applied), this._applyAudioConfigResolve = null);
|
|
1424
1614
|
return;
|
|
@@ -1436,72 +1626,72 @@ class K extends EventTarget {
|
|
|
1436
1626
|
return;
|
|
1437
1627
|
}
|
|
1438
1628
|
if ((e.command === "wake_up" || e.command === "goto_sleep") && this._pendingMotionCompletions && this._pendingMotionCompletions[e.command]) {
|
|
1439
|
-
const
|
|
1440
|
-
if (e.completed === !0 &&
|
|
1441
|
-
const
|
|
1442
|
-
clearTimeout(
|
|
1629
|
+
const s = this._pendingMotionCompletions[e.command];
|
|
1630
|
+
if (e.completed === !0 && s.length > 0) {
|
|
1631
|
+
const i = s.shift();
|
|
1632
|
+
clearTimeout(i.timer), i.resolve();
|
|
1443
1633
|
return;
|
|
1444
1634
|
}
|
|
1445
|
-
if (e.error &&
|
|
1446
|
-
const
|
|
1447
|
-
clearTimeout(
|
|
1635
|
+
if (e.error && s.length > 0) {
|
|
1636
|
+
const i = s.shift();
|
|
1637
|
+
clearTimeout(i.timer), i.reject(new Error(`${e.command}: ${e.error}`));
|
|
1448
1638
|
return;
|
|
1449
1639
|
}
|
|
1450
1640
|
}
|
|
1451
1641
|
if (e.type === "log_line") {
|
|
1452
|
-
for (const
|
|
1642
|
+
for (const s of this._logSubscribers)
|
|
1453
1643
|
try {
|
|
1454
|
-
|
|
1455
|
-
} catch (
|
|
1456
|
-
console.error("subscribeLogs onLine threw:",
|
|
1644
|
+
s.onLine({ timestamp: e.timestamp, line: e.line });
|
|
1645
|
+
} catch (i) {
|
|
1646
|
+
console.error("subscribeLogs onLine threw:", i);
|
|
1457
1647
|
}
|
|
1458
1648
|
return;
|
|
1459
1649
|
}
|
|
1460
1650
|
if (e.type === "log_stream_error") {
|
|
1461
|
-
for (const
|
|
1462
|
-
if (typeof
|
|
1651
|
+
for (const s of this._logSubscribers)
|
|
1652
|
+
if (typeof s.onError == "function")
|
|
1463
1653
|
try {
|
|
1464
|
-
|
|
1465
|
-
} catch (
|
|
1466
|
-
console.error("subscribeLogs onError threw:",
|
|
1654
|
+
s.onError(e.error);
|
|
1655
|
+
} catch (i) {
|
|
1656
|
+
console.error("subscribeLogs onError threw:", i);
|
|
1467
1657
|
}
|
|
1468
1658
|
return;
|
|
1469
1659
|
}
|
|
1470
1660
|
if (e.command === "start_update") {
|
|
1471
1661
|
if (typeof e.error == "string") {
|
|
1472
|
-
const
|
|
1473
|
-
for (const
|
|
1662
|
+
const s = { status: "failed", error: e.error };
|
|
1663
|
+
for (const i of this._updateProgressSubscribers)
|
|
1474
1664
|
try {
|
|
1475
|
-
s
|
|
1476
|
-
} catch (
|
|
1477
|
-
console.error("startDaemonUpdate onProgress threw:",
|
|
1665
|
+
i(s);
|
|
1666
|
+
} catch (o) {
|
|
1667
|
+
console.error("startDaemonUpdate onProgress threw:", o);
|
|
1478
1668
|
}
|
|
1479
1669
|
}
|
|
1480
1670
|
return;
|
|
1481
1671
|
}
|
|
1482
1672
|
if (e.type === "update_progress") {
|
|
1483
|
-
const
|
|
1673
|
+
const s = {
|
|
1484
1674
|
status: e.status,
|
|
1485
1675
|
line: typeof e.line == "string" ? e.line : void 0,
|
|
1486
1676
|
error: typeof e.error == "string" ? e.error : void 0
|
|
1487
1677
|
};
|
|
1488
|
-
for (const
|
|
1678
|
+
for (const i of this._updateProgressSubscribers)
|
|
1489
1679
|
try {
|
|
1490
|
-
s
|
|
1491
|
-
} catch (
|
|
1492
|
-
console.error("startDaemonUpdate onProgress threw:",
|
|
1680
|
+
i(s);
|
|
1681
|
+
} catch (o) {
|
|
1682
|
+
console.error("startDaemonUpdate onProgress threw:", o);
|
|
1493
1683
|
}
|
|
1494
1684
|
return;
|
|
1495
1685
|
}
|
|
1496
|
-
if (e.state) {
|
|
1497
|
-
const
|
|
1498
|
-
|
|
1686
|
+
if (e.state && (t || Date.now() - this._lastPoseFrameAt >= D)) {
|
|
1687
|
+
const s = e.state;
|
|
1688
|
+
s.head_pose && (this._robotState.head = s.head_pose.flat()), s.antennas && (this._robotState.antennas = [s.antennas[0], s.antennas[1]]), typeof s.body_yaw == "number" && (this._robotState.body_yaw = s.body_yaw), s.motor_mode && (this._robotState.motor_mode = s.motor_mode), typeof s.is_move_running == "boolean" && (this._robotState.is_move_running = s.is_move_running), s.face_target && (this._robotState.face_target = s.face_target), this._emit("state", { ...this._robotState });
|
|
1499
1689
|
}
|
|
1500
1690
|
if (e.error && this._emit("error", { source: "robot", error: e.error }), this._broadcastWaiters.length > 0)
|
|
1501
|
-
for (let
|
|
1502
|
-
const
|
|
1503
|
-
if (
|
|
1504
|
-
this._broadcastWaiters.splice(
|
|
1691
|
+
for (let s = this._broadcastWaiters.length - 1; s >= 0; s--) {
|
|
1692
|
+
const i = this._broadcastWaiters[s];
|
|
1693
|
+
if (i.predicate(e)) {
|
|
1694
|
+
this._broadcastWaiters.splice(s, 1), clearTimeout(i.timer), i.resolve(e);
|
|
1505
1695
|
return;
|
|
1506
1696
|
}
|
|
1507
1697
|
}
|
|
@@ -1519,5 +1709,5 @@ class K extends EventTarget {
|
|
|
1519
1709
|
}
|
|
1520
1710
|
}
|
|
1521
1711
|
export {
|
|
1522
|
-
|
|
1712
|
+
Z as R
|
|
1523
1713
|
};
|