@pollen-robotics/reachy-mini-sdk 1.13.0-rc.1 → 1.14.0-dev.0.main.6891cbc
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/client-hello-gate.test.d.ts +2 -0
- package/dist/lib/client-hello-gate.test.d.ts.map +1 -0
- package/dist/lib/client-hello-gate.test.js +59 -0
- package/dist/lib/client-hello-gate.test.js.map +1 -0
- package/dist/lib/client-hello.d.ts +16 -0
- package/dist/lib/client-hello.d.ts.map +1 -0
- package/dist/lib/client-hello.js +47 -0
- package/dist/lib/client-hello.js.map +1 -0
- package/dist/lib/client-hello.test.d.ts +2 -0
- package/dist/lib/client-hello.test.d.ts.map +1 -0
- package/dist/lib/client-hello.test.js +40 -0
- package/dist/lib/client-hello.test.js.map +1 -0
- package/dist/lib/reachy-mini.d.ts +5 -0
- package/dist/lib/reachy-mini.d.ts.map +1 -1
- package/dist/lib/reachy-mini.js +23 -0
- package/dist/lib/reachy-mini.js.map +1 -1
- package/dist/lib/types.d.ts +5 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/lib/version.js.map +1 -1
- package/host/dist/chunks/{centralRest-DR0Wx46x.js → centralRest-IY-5999m.js} +185 -151
- package/host/dist/chunks/{index-B14lPGN5.js → index-BnNoQlWU.js} +1 -1
- package/host/dist/chunks/{mountHost-CEY42tfj.js → mountHost-CoNoHgg_.js} +1 -1
- package/host/dist/entry/auto.js +2 -2
- package/host/dist/entry/embed.js +2 -2
- package/host/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
1
|
+
var oe = Object.defineProperty, ae = (s, e, t) => e in s ? oe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, C = (s, e, t) => (ae(s, typeof e != "symbol" ? e + "" : e, t), t), ne = "https://huggingface.co";
|
|
2
2
|
async function D(s, e) {
|
|
3
3
|
var t, n;
|
|
4
|
-
const i = new
|
|
4
|
+
const i = new ce(s.url, s.status, (t = s.headers.get("X-Request-Id")) != null ? t : void 0);
|
|
5
5
|
i.message = `Api error with status ${i.statusCode}`;
|
|
6
6
|
const r = [`URL: ${i.url}`, i.requestId ? `Request ID: ${i.requestId}` : void 0].filter(Boolean).join(". ");
|
|
7
7
|
if ((n = s.headers.get("Content-Type")) != null && n.startsWith("application/json")) {
|
|
@@ -11,14 +11,14 @@ async function D(s, e) {
|
|
|
11
11
|
i.data = { message: await s.text() };
|
|
12
12
|
throw i.message += `. ${r}`, i;
|
|
13
13
|
}
|
|
14
|
-
var
|
|
14
|
+
var ce = class extends Error {
|
|
15
15
|
constructor(s, e, t, n) {
|
|
16
16
|
super(n), C(this, "statusCode"), C(this, "url"), C(this, "requestId"), C(this, "data"), this.statusCode = e, this.requestId = t, this.url = s;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
new Promise((s) => {
|
|
20
20
|
});
|
|
21
|
-
function
|
|
21
|
+
function le(s) {
|
|
22
22
|
if (globalThis.Buffer)
|
|
23
23
|
return globalThis.Buffer.from(s).toString("base64");
|
|
24
24
|
{
|
|
@@ -28,7 +28,7 @@ function ce(s) {
|
|
|
28
28
|
}), globalThis.btoa(e.join(""));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
31
|
+
async function V(s) {
|
|
32
32
|
var e, t;
|
|
33
33
|
if (typeof window > "u")
|
|
34
34
|
throw new Error("oauthHandleRedirect is only available in the browser");
|
|
@@ -54,7 +54,7 @@ async function G(s) {
|
|
|
54
54
|
}
|
|
55
55
|
if (d.nonce !== a)
|
|
56
56
|
throw new Error("Invalid oauth state in redirected URL");
|
|
57
|
-
const u =
|
|
57
|
+
const u = ne, b = `${new URL(u).origin}/.well-known/openid-configuration`, S = await fetch(b, {
|
|
58
58
|
headers: {
|
|
59
59
|
Accept: "application/json"
|
|
60
60
|
}
|
|
@@ -109,19 +109,19 @@ async function G(s) {
|
|
|
109
109
|
scope: w.scope
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
112
|
+
async function de(s) {
|
|
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);
|
|
116
|
-
return e.has("error") ?
|
|
116
|
+
return e.has("error") ? V() : e.has("code") ? localStorage.getItem("huggingface.co:oauth:nonce") ? V() : (console.warn(
|
|
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 ue(s) {
|
|
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 n = s?.hubUrl ||
|
|
124
|
+
const n = s?.hubUrl || ne, i = `${new URL(n).origin}/.well-known/openid-configuration`, r = await fetch(i, {
|
|
125
125
|
headers: {
|
|
126
126
|
Accept: "application/json"
|
|
127
127
|
}
|
|
@@ -137,7 +137,7 @@ async function de(s) {
|
|
|
137
137
|
}), u = (t = (e = window?.huggingface) == null ? void 0 : e.variables) != null ? t : null, b = s?.clientId || u?.OAUTH_CLIENT_ID;
|
|
138
138
|
if (!b)
|
|
139
139
|
throw u ? 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 S =
|
|
140
|
+
const S = le(
|
|
141
141
|
new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(c)))
|
|
142
142
|
).replace(/[+]/g, "-").replace(/[/]/g, "_").replace(/=/g, "");
|
|
143
143
|
return `${o.authorization_endpoint}?${new URLSearchParams({
|
|
@@ -156,17 +156,17 @@ const I = {
|
|
|
156
156
|
warn: 2,
|
|
157
157
|
error: 3,
|
|
158
158
|
silent: 4
|
|
159
|
-
},
|
|
160
|
-
function
|
|
159
|
+
}, he = "reachy-log";
|
|
160
|
+
function _e() {
|
|
161
161
|
try {
|
|
162
|
-
const s = globalThis.localStorage?.getItem(
|
|
162
|
+
const s = globalThis.localStorage?.getItem(he);
|
|
163
163
|
if (s && s in I) return s;
|
|
164
164
|
} catch {
|
|
165
165
|
}
|
|
166
166
|
return "info";
|
|
167
167
|
}
|
|
168
|
-
let M =
|
|
169
|
-
function
|
|
168
|
+
let M = _e();
|
|
169
|
+
function F(s) {
|
|
170
170
|
const e = `[reachy:${s}]`;
|
|
171
171
|
return {
|
|
172
172
|
debug: (...t) => {
|
|
@@ -186,7 +186,7 @@ function j(s) {
|
|
|
186
186
|
function k(s) {
|
|
187
187
|
return s * Math.PI / 180;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function pe(s, e, t) {
|
|
190
190
|
const n = k(s), i = k(e), r = k(t), o = Math.cos(r), a = Math.sin(r), c = Math.cos(i), l = Math.sin(i), d = Math.cos(n), u = Math.sin(n);
|
|
191
191
|
return [
|
|
192
192
|
[o * c, o * l * u - a * d, o * l * d + a * u, 0],
|
|
@@ -195,8 +195,8 @@ function _e(s, e, t) {
|
|
|
195
195
|
[0, 0, 0, 1]
|
|
196
196
|
];
|
|
197
197
|
}
|
|
198
|
-
const
|
|
199
|
-
class
|
|
198
|
+
const fe = 4096;
|
|
199
|
+
class me {
|
|
200
200
|
_partials = /* @__PURE__ */ new Map();
|
|
201
201
|
/**
|
|
202
202
|
* Feed one parsed frame. Returns the message to handle: the frame itself
|
|
@@ -206,16 +206,16 @@ class fe {
|
|
|
206
206
|
accept(e) {
|
|
207
207
|
if (e.type !== "message_chunk") return e;
|
|
208
208
|
const { id: t, index: n, count: i, data: r } = e;
|
|
209
|
-
if (typeof t != "string" || typeof n != "number" || typeof i != "number" || typeof r != "string" || i < 1 || i >
|
|
209
|
+
if (typeof t != "string" || typeof n != "number" || typeof i != "number" || typeof r != "string" || i < 1 || i > fe)
|
|
210
210
|
return null;
|
|
211
211
|
let o = this._partials.get(t);
|
|
212
212
|
return n === 0 && (o = [], this._partials.set(t, o)), !o || n !== o.length ? (this._partials.delete(t), null) : (o.push(r), o.length < i ? null : (this._partials.delete(t), JSON.parse(o.join(""))));
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
class
|
|
215
|
+
const ie = 4e3;
|
|
216
|
+
class $ extends Error {
|
|
217
217
|
}
|
|
218
|
-
class
|
|
218
|
+
class ge {
|
|
219
219
|
_replySlots = /* @__PURE__ */ new Map();
|
|
220
220
|
_rpcCounter = 0;
|
|
221
221
|
_pendingRpc = /* @__PURE__ */ new Map();
|
|
@@ -239,7 +239,7 @@ class me {
|
|
|
239
239
|
const o = (a) => {
|
|
240
240
|
r !== void 0 && (clearTimeout(r), r = void 0), this._replySlots.get(e) === o && this._replySlots.delete(e), n(a);
|
|
241
241
|
};
|
|
242
|
-
this._replySlots.set(e, o), r = setTimeout(() => o(null),
|
|
242
|
+
this._replySlots.set(e, o), r = setTimeout(() => o(null), ie), t();
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
@@ -328,7 +328,7 @@ class me {
|
|
|
328
328
|
reject: r,
|
|
329
329
|
timer: setTimeout(() => {
|
|
330
330
|
const a = this._broadcastWaiters.indexOf(o);
|
|
331
|
-
a !== -1 && this._broadcastWaiters.splice(a, 1), r(new
|
|
331
|
+
a !== -1 && this._broadcastWaiters.splice(a, 1), r(new $(`broadcast timeout (${t} ms): ${n}`));
|
|
332
332
|
}, t)
|
|
333
333
|
};
|
|
334
334
|
this._broadcastWaiters.push(o);
|
|
@@ -373,8 +373,8 @@ class me {
|
|
|
373
373
|
this._broadcastWaiters = [];
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
const A =
|
|
377
|
-
class
|
|
376
|
+
const A = F("session"), J = 3e3, K = 1e3, we = 6e4, z = [0, 2e3, 4e3, 8e3, 8e3], ye = 15e3, Y = 1e3, be = 2500, Se = 8e3;
|
|
377
|
+
class ve {
|
|
378
378
|
_deps;
|
|
379
379
|
// ICE-blip debounce. All handler slots are scoped to the lifetime
|
|
380
380
|
// of a live session (armed from the pc's state handler, cleared by
|
|
@@ -437,7 +437,7 @@ class Se {
|
|
|
437
437
|
* next foreground frame.
|
|
438
438
|
*/
|
|
439
439
|
onIceDisconnected() {
|
|
440
|
-
typeof document < "u" && document.hidden ? this._armIceGraceOnVisibility() : this._scheduleIceGrace(
|
|
440
|
+
typeof document < "u" && document.hidden ? this._armIceGraceOnVisibility() : this._scheduleIceGrace(J, "disconnected");
|
|
441
441
|
}
|
|
442
442
|
/**
|
|
443
443
|
* ICE hit `failed` — terminal per spec, but in practice we've seen
|
|
@@ -446,7 +446,7 @@ class Se {
|
|
|
446
446
|
* the session.
|
|
447
447
|
*/
|
|
448
448
|
onIceFailed() {
|
|
449
|
-
this._scheduleIceGrace(
|
|
449
|
+
this._scheduleIceGrace(K, "failed");
|
|
450
450
|
}
|
|
451
451
|
/**
|
|
452
452
|
* Cancel any pending ICE grace timer and visibility handler. Called
|
|
@@ -508,7 +508,7 @@ class Se {
|
|
|
508
508
|
if (typeof document < "u" && document.hidden || (document.removeEventListener("visibilitychange", t), this._pendingVisibilityHandler = null, !this._deps.hasPc())) return;
|
|
509
509
|
const n = this._deps.iceState();
|
|
510
510
|
if (!(n === "connected" || n === "completed")) {
|
|
511
|
-
if (Date.now() - e >
|
|
511
|
+
if (Date.now() - e > we) {
|
|
512
512
|
const i = new Error("Session expired while tab was backgrounded");
|
|
513
513
|
if (this._deps.rejectPendingSession(i)) {
|
|
514
514
|
this._redialing || this._emitError(i);
|
|
@@ -519,10 +519,10 @@ class Se {
|
|
|
519
519
|
return;
|
|
520
520
|
}
|
|
521
521
|
if (n === "failed") {
|
|
522
|
-
this._scheduleIceGrace(
|
|
522
|
+
this._scheduleIceGrace(K, "failed");
|
|
523
523
|
return;
|
|
524
524
|
}
|
|
525
|
-
this._scheduleIceGrace(
|
|
525
|
+
this._scheduleIceGrace(J, "disconnected");
|
|
526
526
|
}
|
|
527
527
|
};
|
|
528
528
|
document.addEventListener("visibilitychange", t), this._pendingVisibilityHandler = t;
|
|
@@ -596,16 +596,16 @@ class Se {
|
|
|
596
596
|
* which flip `_redialing` off via `cancelRedial`.
|
|
597
597
|
*/
|
|
598
598
|
async _runRedialLoop(e, t) {
|
|
599
|
-
const n =
|
|
599
|
+
const n = z.length, i = this._deps.redialTargetResolver(e);
|
|
600
600
|
this._deps.teardownForRedial();
|
|
601
601
|
for (let o = 1; o <= n; o++) {
|
|
602
|
-
if (!this._redialing || (this._deps.emit("sessionReconnecting", { attempt: o, maxAttempts: n, cause: t }), await this._redialSleep(
|
|
602
|
+
if (!this._redialing || (this._deps.emit("sessionReconnecting", { attempt: o, maxAttempts: n, cause: t }), await this._redialSleep(z[o - 1]), !this._redialing)) return;
|
|
603
603
|
try {
|
|
604
604
|
if (this._deps.isSignalingDown() && await this._deps.reconnectSignaling(), !this._redialing) return;
|
|
605
605
|
const a = i();
|
|
606
|
-
if (a !== e && A.info(`auto-reconnect: robot re-registered as ${a} (was ${e})`), await
|
|
606
|
+
if (a !== e && A.info(`auto-reconnect: robot re-registered as ${a} (was ${e})`), await Re(
|
|
607
607
|
this._deps.dial(a),
|
|
608
|
-
|
|
608
|
+
ye,
|
|
609
609
|
"auto-reconnect dial timed out"
|
|
610
610
|
), !this._redialing) return;
|
|
611
611
|
this._redialing = !1, A.info(`auto-reconnect: recovered on attempt ${o}`), this._deps.emit("sessionReconnected", { attempt: o });
|
|
@@ -650,7 +650,7 @@ class Se {
|
|
|
650
650
|
startDcWatchdog() {
|
|
651
651
|
this.stopDcWatchdog();
|
|
652
652
|
const e = Date.now();
|
|
653
|
-
this._lastDcInboundAt = e, this._dcWatchdogLastTickAt = e, this._dcSilenceNudged = !1, this._dcWatchdogId = setInterval(() => this._dcWatchdogTick(),
|
|
653
|
+
this._lastDcInboundAt = e, this._dcWatchdogLastTickAt = e, this._dcSilenceNudged = !1, this._dcWatchdogId = setInterval(() => this._dcWatchdogTick(), Y);
|
|
654
654
|
}
|
|
655
655
|
stopDcWatchdog() {
|
|
656
656
|
this._dcWatchdogId !== null && (clearInterval(this._dcWatchdogId), this._dcWatchdogId = null);
|
|
@@ -665,7 +665,7 @@ class Se {
|
|
|
665
665
|
_dcWatchdogTick() {
|
|
666
666
|
const e = Date.now(), t = e - this._dcWatchdogLastTickAt;
|
|
667
667
|
if (this._dcWatchdogLastTickAt = e, !this._deps.isStreaming()) return;
|
|
668
|
-
if (t >
|
|
668
|
+
if (t > Y * 3) {
|
|
669
669
|
this._lastDcInboundAt = e, this._dcSilenceNudged = !1;
|
|
670
670
|
return;
|
|
671
671
|
}
|
|
@@ -674,25 +674,49 @@ class Se {
|
|
|
674
674
|
return;
|
|
675
675
|
}
|
|
676
676
|
const n = e - this._lastDcInboundAt;
|
|
677
|
-
if (n <
|
|
677
|
+
if (n < be) return;
|
|
678
678
|
if (!this._dcSilenceNudged) {
|
|
679
679
|
this._dcSilenceNudged = !0, this._deps.nudgeState();
|
|
680
680
|
return;
|
|
681
681
|
}
|
|
682
|
-
if (n <
|
|
682
|
+
if (n < Se) return;
|
|
683
683
|
this._dcSilenceNudged = !1;
|
|
684
684
|
const i = `No data-channel traffic for ${n}ms`;
|
|
685
685
|
this.maybeBeginRedial(i) || (this.stopDcWatchdog(), this._emitError(new Error(i)));
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function Re(s, e, t) {
|
|
689
689
|
return Promise.race([
|
|
690
690
|
s,
|
|
691
691
|
new Promise((n, i) => setTimeout(() => i(new Error(t)), e))
|
|
692
692
|
]);
|
|
693
693
|
}
|
|
694
|
-
const
|
|
695
|
-
|
|
694
|
+
const U = "0.0.0-managed-by-ci", Ie = 5e3;
|
|
695
|
+
let O = null;
|
|
696
|
+
function Te() {
|
|
697
|
+
const s = globalThis.huggingface?.variables?.SPACE_ID;
|
|
698
|
+
return typeof s == "string" && s.includes("/") ? s : void 0;
|
|
699
|
+
}
|
|
700
|
+
async function ke(s) {
|
|
701
|
+
try {
|
|
702
|
+
const e = s.split("/").map(encodeURIComponent).join("/"), t = await fetch(`https://huggingface.co/api/spaces/${e}`, {
|
|
703
|
+
credentials: "omit",
|
|
704
|
+
signal: AbortSignal.timeout(Ie)
|
|
705
|
+
});
|
|
706
|
+
return t.ok && (await t.json()).private === !1 ? s : "private";
|
|
707
|
+
} catch {
|
|
708
|
+
return "private";
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function Ee() {
|
|
712
|
+
if (!O) {
|
|
713
|
+
const s = Te();
|
|
714
|
+
O = s ? ke(s) : Promise.resolve(void 0);
|
|
715
|
+
}
|
|
716
|
+
return O;
|
|
717
|
+
}
|
|
718
|
+
const Ae = F("sdk");
|
|
719
|
+
function Ce() {
|
|
696
720
|
if (typeof window > "u" || !window.location.hash) return;
|
|
697
721
|
const s = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
698
722
|
let e;
|
|
@@ -707,7 +731,7 @@ function Ie() {
|
|
|
707
731
|
try {
|
|
708
732
|
sessionStorage.setItem("hf_token", t), sessionStorage.setItem("hf_username", n), sessionStorage.setItem("hf_token_expires", r);
|
|
709
733
|
} catch (c) {
|
|
710
|
-
|
|
734
|
+
Ae.warn("could not persist pre-seeded HF credentials:", c);
|
|
711
735
|
}
|
|
712
736
|
e.delete("hf_token"), e.delete("hf_username"), e.delete("hf_token_expires");
|
|
713
737
|
const o = e.toString(), a = window.location.pathname + window.location.search + (o ? "#" + o : "");
|
|
@@ -716,7 +740,7 @@ function Ie() {
|
|
|
716
740
|
} catch {
|
|
717
741
|
}
|
|
718
742
|
}
|
|
719
|
-
function
|
|
743
|
+
function Me() {
|
|
720
744
|
if (typeof window > "u") return null;
|
|
721
745
|
if (window.location.hash) {
|
|
722
746
|
const s = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
@@ -734,7 +758,7 @@ function Te() {
|
|
|
734
758
|
}
|
|
735
759
|
return null;
|
|
736
760
|
}
|
|
737
|
-
function
|
|
761
|
+
function De(s) {
|
|
738
762
|
const e = s.split(`\r
|
|
739
763
|
`);
|
|
740
764
|
let t = !1;
|
|
@@ -742,58 +766,58 @@ function ke(s) {
|
|
|
742
766
|
if (n.startsWith("m=audio") ? t = !0 : n.startsWith("m=") && (t = !1), t && n === "a=sendrecv") return !0;
|
|
743
767
|
return !1;
|
|
744
768
|
}
|
|
745
|
-
const
|
|
746
|
-
function
|
|
769
|
+
const H = "hf_token", B = "hf_username", W = "hf_token_expires", L = "hf_token_last_seen", Le = 1440 * 60 * 1e3;
|
|
770
|
+
function Ue(s) {
|
|
747
771
|
try {
|
|
748
|
-
sessionStorage.setItem(
|
|
772
|
+
sessionStorage.setItem(H, s.token), sessionStorage.setItem(B, s.username), sessionStorage.setItem(W, s.expires), sessionStorage.setItem(L, (/* @__PURE__ */ new Date()).toISOString());
|
|
749
773
|
} catch {
|
|
750
774
|
}
|
|
751
775
|
}
|
|
752
|
-
function
|
|
776
|
+
function Oe(s = Date.now()) {
|
|
753
777
|
try {
|
|
754
|
-
const e = sessionStorage.getItem(
|
|
778
|
+
const e = sessionStorage.getItem(H), t = sessionStorage.getItem(B), n = sessionStorage.getItem(W);
|
|
755
779
|
if (!e || !n) return null;
|
|
756
780
|
if (new Date(n).getTime() <= s)
|
|
757
|
-
return
|
|
781
|
+
return j(), null;
|
|
758
782
|
const i = sessionStorage.getItem(L);
|
|
759
783
|
if (i !== null) {
|
|
760
784
|
const r = new Date(i).getTime();
|
|
761
|
-
if (!Number.isFinite(r) || s - r >
|
|
762
|
-
return
|
|
785
|
+
if (!Number.isFinite(r) || s - r > Le)
|
|
786
|
+
return j(), null;
|
|
763
787
|
}
|
|
764
788
|
return sessionStorage.setItem(L, new Date(s).toISOString()), { token: e, username: t ?? "", expires: n };
|
|
765
789
|
} catch {
|
|
766
790
|
return null;
|
|
767
791
|
}
|
|
768
792
|
}
|
|
769
|
-
function
|
|
793
|
+
function j() {
|
|
770
794
|
try {
|
|
771
|
-
sessionStorage.removeItem(
|
|
795
|
+
sessionStorage.removeItem(H), sessionStorage.removeItem(B), sessionStorage.removeItem(W), sessionStorage.removeItem(L);
|
|
772
796
|
} catch {
|
|
773
797
|
}
|
|
774
798
|
}
|
|
775
|
-
const
|
|
799
|
+
const Pe = /* @__PURE__ */ new Set([
|
|
776
800
|
"login_required",
|
|
777
801
|
"consent_required",
|
|
778
802
|
"interaction_required",
|
|
779
803
|
"access_denied"
|
|
780
804
|
]);
|
|
781
|
-
function
|
|
805
|
+
function Ne() {
|
|
782
806
|
try {
|
|
783
807
|
const s = new URL(window.location.href), e = s.searchParams.get("error");
|
|
784
|
-
return e === null || !
|
|
808
|
+
return e === null || !Pe.has(e) ? null : (s.searchParams.delete("error"), s.searchParams.delete("error_description"), s.searchParams.delete("state"), window.history.replaceState(null, "", s.toString()), e);
|
|
785
809
|
} catch {
|
|
786
810
|
return null;
|
|
787
811
|
}
|
|
788
812
|
}
|
|
789
|
-
const R = 12 * 1024,
|
|
790
|
-
function
|
|
813
|
+
const R = 12 * 1024, P = 1 * 1024 * 1024, $e = 512 * 1024;
|
|
814
|
+
function je() {
|
|
791
815
|
return typeof CompressionStream < "u";
|
|
792
816
|
}
|
|
793
|
-
function
|
|
817
|
+
function X() {
|
|
794
818
|
return "u" + Math.random().toString(36).slice(2, 11) + Date.now().toString(36);
|
|
795
819
|
}
|
|
796
|
-
function
|
|
820
|
+
function x(s) {
|
|
797
821
|
let e = "";
|
|
798
822
|
for (let n = 0; n < s.length; n += 32768)
|
|
799
823
|
e += String.fromCharCode.apply(
|
|
@@ -802,17 +826,17 @@ function $(s) {
|
|
|
802
826
|
);
|
|
803
827
|
return btoa(e);
|
|
804
828
|
}
|
|
805
|
-
async function
|
|
829
|
+
async function xe(s) {
|
|
806
830
|
const e = new TextEncoder().encode(s), t = await new Response(
|
|
807
831
|
new Blob([e]).stream().pipeThrough(new CompressionStream("gzip"))
|
|
808
832
|
).arrayBuffer();
|
|
809
|
-
return
|
|
833
|
+
return x(new Uint8Array(t));
|
|
810
834
|
}
|
|
811
|
-
function
|
|
835
|
+
function Q(s) {
|
|
812
836
|
const e = Math.round(Number(s) || 0);
|
|
813
837
|
return Math.max(0, Math.min(100, e));
|
|
814
838
|
}
|
|
815
|
-
function
|
|
839
|
+
function Z(s) {
|
|
816
840
|
switch ((s.type || "").toLowerCase().split(";")[0]?.trim() ?? "") {
|
|
817
841
|
case "audio/ogg":
|
|
818
842
|
case "application/ogg":
|
|
@@ -835,17 +859,20 @@ function Q(s) {
|
|
|
835
859
|
return "wav-base64";
|
|
836
860
|
}
|
|
837
861
|
}
|
|
838
|
-
const _ =
|
|
839
|
-
function
|
|
862
|
+
const _ = F("sdk"), ee = 750, Fe = 2500, He = 8, Be = 75e3, We = 15e3, Ge = 5e3, te = 1e4, qe = 15e3, Ve = 15e3;
|
|
863
|
+
function N(s) {
|
|
840
864
|
const e = s?.meta;
|
|
841
865
|
return e?.install_id ?? e?.hardware_id ?? null;
|
|
842
866
|
}
|
|
843
|
-
const
|
|
844
|
-
class
|
|
867
|
+
const Je = 5e3;
|
|
868
|
+
class it extends EventTarget {
|
|
845
869
|
// ─── Config ──────────────────────────────────────────────────────────
|
|
846
870
|
_signalingUrl;
|
|
847
871
|
_clientId;
|
|
848
872
|
_appName;
|
|
873
|
+
_client;
|
|
874
|
+
/** Hello already sent on the current control channel. */
|
|
875
|
+
_helloSent = !1;
|
|
849
876
|
_videoJitterBufferTargetMs;
|
|
850
877
|
_autoStartFromUrl;
|
|
851
878
|
_autoStartAttempted;
|
|
@@ -908,7 +935,7 @@ class Qe extends EventTarget {
|
|
|
908
935
|
// ─── Pending replies (reply slots / JSON-RPC / motion / broadcast) ───
|
|
909
936
|
// All request/response waiters on the data channel live in one
|
|
910
937
|
// ledger so every teardown path settles them in a single call.
|
|
911
|
-
_pending = new
|
|
938
|
+
_pending = new ge();
|
|
912
939
|
// ─── Log subscribers ─────────────────────────────────────────────────
|
|
913
940
|
_logSubscribers = /* @__PURE__ */ new Set();
|
|
914
941
|
_updateProgressSubscribers = /* @__PURE__ */ new Set();
|
|
@@ -933,7 +960,7 @@ class Qe extends EventTarget {
|
|
|
933
960
|
// ─── Video element ───────────────────────────────────────────────────
|
|
934
961
|
_videoElement = null;
|
|
935
962
|
constructor(e = {}) {
|
|
936
|
-
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 =
|
|
963
|
+
super(), this._signalingUrl = e.signalingUrl || "https://pollen-robotics-reachy-mini-central.hf.space", this._clientId = e.clientId || null, this._appName = e.appName || "unknown", this._client = e.client || `web/${U}`, this._videoJitterBufferTargetMs = e.videoJitterBufferTargetMs ?? 0, this._autoStartFromUrl = e.autoStartFromUrl === !0, this._autoStartAttempted = !1, this._preselectedRobotId = Me(), this._supervisor = new ve({
|
|
937
964
|
iceState: () => this._pc?.iceConnectionState ?? null,
|
|
938
965
|
hasPc: () => !!this._pc,
|
|
939
966
|
isStreaming: () => this._state === "streaming",
|
|
@@ -1013,12 +1040,12 @@ class Qe extends EventTarget {
|
|
|
1013
1040
|
* build (npm releases carry a real semver).
|
|
1014
1041
|
*/
|
|
1015
1042
|
get sdkVersion() {
|
|
1016
|
-
return
|
|
1043
|
+
return U;
|
|
1017
1044
|
}
|
|
1018
1045
|
/** Same value as the instance `sdkVersion`, reachable without an
|
|
1019
1046
|
* instance: `ReachyMini.version`. */
|
|
1020
1047
|
static get version() {
|
|
1021
|
-
return
|
|
1048
|
+
return U;
|
|
1022
1049
|
}
|
|
1023
1050
|
/**
|
|
1024
1051
|
* Internal: try to honour the `autoStartFromUrl` constructor
|
|
@@ -1039,17 +1066,17 @@ class Qe extends EventTarget {
|
|
|
1039
1066
|
// ─── Auth ────────────────────────────────────────────────────────────
|
|
1040
1067
|
async authenticate() {
|
|
1041
1068
|
try {
|
|
1042
|
-
|
|
1043
|
-
const e =
|
|
1069
|
+
Ce();
|
|
1070
|
+
const e = Ne();
|
|
1044
1071
|
e && _.info("silent sign-in declined:", e);
|
|
1045
|
-
const t = await
|
|
1072
|
+
const t = await de();
|
|
1046
1073
|
if (t)
|
|
1047
|
-
return this._username = t.userInfo.preferred_username || t.userInfo.name || null, this._token = t.accessToken, this._tokenExpires = t.accessTokenExpiresAt,
|
|
1074
|
+
return this._username = t.userInfo.preferred_username || t.userInfo.name || null, this._token = t.accessToken, this._tokenExpires = t.accessTokenExpiresAt, Ue({
|
|
1048
1075
|
token: this._token,
|
|
1049
1076
|
username: this._username ?? "",
|
|
1050
1077
|
expires: typeof this._tokenExpires == "string" ? this._tokenExpires : this._tokenExpires.toISOString()
|
|
1051
1078
|
}), !0;
|
|
1052
|
-
const n =
|
|
1079
|
+
const n = Oe();
|
|
1053
1080
|
return n && n.username ? (this._token = n.token, this._username = n.username, this._tokenExpires = n.expires, !0) : !1;
|
|
1054
1081
|
} catch (e) {
|
|
1055
1082
|
return _.error("authenticate failed:", e), !1;
|
|
@@ -1058,7 +1085,7 @@ class Qe extends EventTarget {
|
|
|
1058
1085
|
async login(e) {
|
|
1059
1086
|
const t = {};
|
|
1060
1087
|
this._clientId && (t.clientId = this._clientId);
|
|
1061
|
-
let n = await
|
|
1088
|
+
let n = await ue(t);
|
|
1062
1089
|
if (e?.prompt) {
|
|
1063
1090
|
const i = new URL(n);
|
|
1064
1091
|
i.searchParams.set("prompt", e.prompt), n = i.toString();
|
|
@@ -1066,7 +1093,7 @@ class Qe extends EventTarget {
|
|
|
1066
1093
|
window.location.href = n;
|
|
1067
1094
|
}
|
|
1068
1095
|
logout() {
|
|
1069
|
-
|
|
1096
|
+
j(), this._username = null, this._tokenExpires = null, this.disconnect();
|
|
1070
1097
|
}
|
|
1071
1098
|
// ─── Lifecycle ───────────────────────────────────────────────────────
|
|
1072
1099
|
async connect(e) {
|
|
@@ -1093,7 +1120,7 @@ class Qe extends EventTarget {
|
|
|
1093
1120
|
let t = !1;
|
|
1094
1121
|
const n = setTimeout(() => {
|
|
1095
1122
|
t = !0, e.abort();
|
|
1096
|
-
},
|
|
1123
|
+
}, qe);
|
|
1097
1124
|
let i;
|
|
1098
1125
|
try {
|
|
1099
1126
|
i = await fetch(
|
|
@@ -1118,14 +1145,14 @@ class Qe extends EventTarget {
|
|
|
1118
1145
|
let b = !1;
|
|
1119
1146
|
const S = setTimeout(() => {
|
|
1120
1147
|
a || (b = !0, _.warn("signaling: no welcome from central; aborting the stream"), u?.abort());
|
|
1121
|
-
},
|
|
1148
|
+
}, Ve);
|
|
1122
1149
|
let m = null;
|
|
1123
|
-
const g = (p =
|
|
1150
|
+
const g = (p = Be) => {
|
|
1124
1151
|
m !== null && clearTimeout(m);
|
|
1125
1152
|
const v = Date.now();
|
|
1126
1153
|
m = setTimeout(() => {
|
|
1127
|
-
if (Date.now() - v > p +
|
|
1128
|
-
g(
|
|
1154
|
+
if (Date.now() - v > p + We) {
|
|
1155
|
+
g(Ge);
|
|
1129
1156
|
return;
|
|
1130
1157
|
}
|
|
1131
1158
|
_.warn("signaling stream silent for too long; reconnecting"), u?.abort();
|
|
@@ -1229,7 +1256,7 @@ class Qe extends EventTarget {
|
|
|
1229
1256
|
}
|
|
1230
1257
|
}
|
|
1231
1258
|
async _fetchOwnedRobots({ filterBusy: e = !0 } = {}) {
|
|
1232
|
-
const t = new AbortController(), n = setTimeout(() => t.abort(),
|
|
1259
|
+
const t = new AbortController(), n = setTimeout(() => t.abort(), te);
|
|
1233
1260
|
try {
|
|
1234
1261
|
const i = await fetch(`${this._signalingUrl}/api/robot-status`, {
|
|
1235
1262
|
headers: { Authorization: `Bearer ${this._token}` },
|
|
@@ -1281,7 +1308,7 @@ class Qe extends EventTarget {
|
|
|
1281
1308
|
async _startSessionInternal(e) {
|
|
1282
1309
|
if (this._state !== "connected") throw new Error("Not connected");
|
|
1283
1310
|
this._selectedRobotId = e;
|
|
1284
|
-
const t =
|
|
1311
|
+
const t = N(this._robots.find((n) => n.id === e));
|
|
1285
1312
|
t ? this._dialedRobotIdentity = t : this._dialedRobotId !== e && (this._dialedRobotIdentity = null), this._dialedRobotId = e, this._retireSession(this._sessionId), this._sessionId = null, this._retireSession(this._staleSessionId), this._staleSessionId = null, this._iceConnected = !1, this._dcOpen = !1, this._micSupported = !1, this._pendingRemoteIce = [];
|
|
1286
1313
|
try {
|
|
1287
1314
|
const n = window, i = n.AudioContext ?? n.webkitAudioContext;
|
|
@@ -1354,9 +1381,9 @@ class Qe extends EventTarget {
|
|
|
1354
1381
|
return;
|
|
1355
1382
|
}
|
|
1356
1383
|
this._dc = a, this._dc.onopen = () => {
|
|
1357
|
-
this._dcOpen = !0, this._checkSessionReady();
|
|
1384
|
+
this._dcOpen = !0, this._checkSessionReady(), this._helloSent = !1, this._sendCommand({ type: "get_version" });
|
|
1358
1385
|
};
|
|
1359
|
-
const c = new
|
|
1386
|
+
const c = new me();
|
|
1360
1387
|
this._dc.onmessage = (l) => {
|
|
1361
1388
|
const d = c.accept(JSON.parse(l.data));
|
|
1362
1389
|
d && this._handleRobotMessage(d);
|
|
@@ -1408,7 +1435,7 @@ class Qe extends EventTarget {
|
|
|
1408
1435
|
return this._sessionId = null, this._retireSession(t), this._retireSession(this._staleSessionId), this._staleSessionId = null, t;
|
|
1409
1436
|
}
|
|
1410
1437
|
_retireSession(e) {
|
|
1411
|
-
if (e && (this._retiredSessionIds.add(e), this._retiredSessionIds.size >
|
|
1438
|
+
if (e && (this._retiredSessionIds.add(e), this._retiredSessionIds.size > He)) {
|
|
1412
1439
|
const t = this._retiredSessionIds.values().next().value;
|
|
1413
1440
|
t !== void 0 && this._retiredSessionIds.delete(t);
|
|
1414
1441
|
}
|
|
@@ -1480,8 +1507,8 @@ class Qe extends EventTarget {
|
|
|
1480
1507
|
* re-registered; otherwise keep dialing the original id.
|
|
1481
1508
|
*/
|
|
1482
1509
|
_redialTargetResolver(e) {
|
|
1483
|
-
const t = (this._dialedRobotId === e ? this._dialedRobotIdentity : null) ??
|
|
1484
|
-
return t ? () => this._robots.find((n) => n.id !== e &&
|
|
1510
|
+
const t = (this._dialedRobotId === e ? this._dialedRobotIdentity : null) ?? N(this._robots.find((n) => n.id === e));
|
|
1511
|
+
return t ? () => this._robots.find((n) => n.id !== e && N(n) === t)?.id ?? e : () => e;
|
|
1485
1512
|
}
|
|
1486
1513
|
/**
|
|
1487
1514
|
* Stop the placeholder sender track AND close its AudioContext.
|
|
@@ -1532,7 +1559,7 @@ class Qe extends EventTarget {
|
|
|
1532
1559
|
*/
|
|
1533
1560
|
_peerLinkLive() {
|
|
1534
1561
|
const e = this._pc?.iceConnectionState;
|
|
1535
|
-
return this._dcOpen && this._dc?.readyState === "open" && (e === "connected" || e === "completed") && this._supervisor.dcInboundAgeMs <
|
|
1562
|
+
return this._dcOpen && this._dc?.readyState === "open" && (e === "connected" || e === "completed") && this._supervisor.dcInboundAgeMs < Fe;
|
|
1536
1563
|
}
|
|
1537
1564
|
// ─── Commands ────────────────────────────────────────────────────────
|
|
1538
1565
|
/**
|
|
@@ -1633,7 +1660,7 @@ class Qe extends EventTarget {
|
|
|
1633
1660
|
return r.duration = i, this._sendCommand(r);
|
|
1634
1661
|
}
|
|
1635
1662
|
setHeadRpyDeg(e, t, n) {
|
|
1636
|
-
return this.setTarget({ head:
|
|
1663
|
+
return this.setTarget({ head: pe(e, t, n).flat() });
|
|
1637
1664
|
}
|
|
1638
1665
|
setAntennasDeg(e, t) {
|
|
1639
1666
|
return this.setTarget({ antennas: [k(e), k(t)] });
|
|
@@ -1682,7 +1709,7 @@ class Qe extends EventTarget {
|
|
|
1682
1709
|
(n) => n.command === "preload_dataset" && n.dataset_name === e,
|
|
1683
1710
|
{ timeoutMs: t, debugLabel: `preload_dataset(${e})` }
|
|
1684
1711
|
).then((n) => n.status === "ok").catch((n) => {
|
|
1685
|
-
if (n instanceof
|
|
1712
|
+
if (n instanceof $) return null;
|
|
1686
1713
|
throw n;
|
|
1687
1714
|
}) : Promise.reject(new Error("Data channel not open"));
|
|
1688
1715
|
}
|
|
@@ -1754,7 +1781,7 @@ class Qe extends EventTarget {
|
|
|
1754
1781
|
_.info(`ensureAwake: robot asleep (motor_mode=${this._robotState?.motor_mode ?? "unknown"}), playing wake-up`);
|
|
1755
1782
|
const t = Date.now();
|
|
1756
1783
|
try {
|
|
1757
|
-
await this.wakeUp({ timeoutMs:
|
|
1784
|
+
await this.wakeUp({ timeoutMs: Je }), _.info(`ensureAwake: wake-up trajectory done in ${Date.now() - t}ms`);
|
|
1758
1785
|
} catch (n) {
|
|
1759
1786
|
_.warn(`ensureAwake: wake-up not confirmed after ${Date.now() - t}ms (continuing):`, n);
|
|
1760
1787
|
}
|
|
@@ -1783,13 +1810,13 @@ class Qe extends EventTarget {
|
|
|
1783
1810
|
return this._slotRoundtrip("volume", { type: "get_volume" });
|
|
1784
1811
|
}
|
|
1785
1812
|
setVolume(e) {
|
|
1786
|
-
return this._slotRoundtrip("volume", { type: "set_volume", volume:
|
|
1813
|
+
return this._slotRoundtrip("volume", { type: "set_volume", volume: Q(e) });
|
|
1787
1814
|
}
|
|
1788
1815
|
getMicrophoneVolume() {
|
|
1789
1816
|
return this._slotRoundtrip("mic_volume", { type: "get_microphone_volume" });
|
|
1790
1817
|
}
|
|
1791
1818
|
setMicrophoneVolume(e) {
|
|
1792
|
-
return this._slotRoundtrip("mic_volume", { type: "set_microphone_volume", volume:
|
|
1819
|
+
return this._slotRoundtrip("mic_volume", { type: "set_microphone_volume", volume: Q(e) });
|
|
1793
1820
|
}
|
|
1794
1821
|
/**
|
|
1795
1822
|
* Query whether the first wake-up setup wizard has been completed.
|
|
@@ -1896,12 +1923,12 @@ class Qe extends EventTarget {
|
|
|
1896
1923
|
* reach this matcher - use the typed wrappers for those. Pass `match`
|
|
1897
1924
|
* for replies that don't follow the `command` echo convention.
|
|
1898
1925
|
*/
|
|
1899
|
-
request(e, { timeoutMs: t =
|
|
1926
|
+
request(e, { timeoutMs: t = ie, match: n } = {}) {
|
|
1900
1927
|
if (!this._sendCommand(e))
|
|
1901
1928
|
return Promise.reject(new Error("Data channel not open"));
|
|
1902
1929
|
const i = n ?? ((r) => r.command === e.type);
|
|
1903
1930
|
return this._pending.awaitBroadcast(i, { timeoutMs: t, debugLabel: `request(${e.type})` }).catch((r) => {
|
|
1904
|
-
if (r instanceof
|
|
1931
|
+
if (r instanceof $) return null;
|
|
1905
1932
|
throw r;
|
|
1906
1933
|
});
|
|
1907
1934
|
}
|
|
@@ -2002,7 +2029,7 @@ class Qe extends EventTarget {
|
|
|
2002
2029
|
throw new Error("data channel not open");
|
|
2003
2030
|
if (!e?.time?.length || !e?.set_target_data?.length)
|
|
2004
2031
|
throw new Error("playMove: motion must have time + set_target_data");
|
|
2005
|
-
const u =
|
|
2032
|
+
const u = X();
|
|
2006
2033
|
this._activeMoveUploadId = u;
|
|
2007
2034
|
const b = {
|
|
2008
2035
|
description: i,
|
|
@@ -2010,7 +2037,7 @@ class Qe extends EventTarget {
|
|
|
2010
2037
|
set_target_data: e.set_target_data
|
|
2011
2038
|
}, S = JSON.stringify(b);
|
|
2012
2039
|
let m, g;
|
|
2013
|
-
r === "gzip+base64" &&
|
|
2040
|
+
r === "gzip+base64" && je() ? (m = await xe(S), g = "gzip+base64") : (m = S, g = "json");
|
|
2014
2041
|
const w = Math.ceil(m.length / R) || 1;
|
|
2015
2042
|
l({
|
|
2016
2043
|
phase: "starting",
|
|
@@ -2026,7 +2053,7 @@ class Qe extends EventTarget {
|
|
|
2026
2053
|
encoding: g
|
|
2027
2054
|
});
|
|
2028
2055
|
for (let h = 0; h < w; h++) {
|
|
2029
|
-
this._dc.bufferedAmount >
|
|
2056
|
+
this._dc.bufferedAmount > P && await this._awaitDataChannelDrain();
|
|
2030
2057
|
const f = h * R;
|
|
2031
2058
|
this._sendCommand({
|
|
2032
2059
|
type: "upload_move_chunk",
|
|
@@ -2036,7 +2063,7 @@ class Qe extends EventTarget {
|
|
|
2036
2063
|
}), l({ phase: "upload", sent: h + 1, total: w });
|
|
2037
2064
|
}
|
|
2038
2065
|
if (this._sendCommand({ type: "upload_move_finish", upload_id: u }), l({ phase: "uploaded", sent: w, total: w }), t) {
|
|
2039
|
-
const h = new Uint8Array(await t.arrayBuffer()), f =
|
|
2066
|
+
const h = new Uint8Array(await t.arrayBuffer()), f = x(h), y = Math.ceil(f.length / R) || 1;
|
|
2040
2067
|
l({
|
|
2041
2068
|
phase: "audio-starting",
|
|
2042
2069
|
sent: 0,
|
|
@@ -2046,17 +2073,17 @@ class Qe extends EventTarget {
|
|
|
2046
2073
|
type: "upload_audio_start",
|
|
2047
2074
|
upload_id: u,
|
|
2048
2075
|
total_chunks: y,
|
|
2049
|
-
encoding:
|
|
2076
|
+
encoding: Z(t),
|
|
2050
2077
|
description: i
|
|
2051
2078
|
});
|
|
2052
2079
|
for (let T = 0; T < y; T++) {
|
|
2053
|
-
this._dc.bufferedAmount >
|
|
2054
|
-
const
|
|
2080
|
+
this._dc.bufferedAmount > P && await this._awaitDataChannelDrain();
|
|
2081
|
+
const q = T * R;
|
|
2055
2082
|
this._sendCommand({
|
|
2056
2083
|
type: "upload_audio_chunk",
|
|
2057
2084
|
upload_id: u,
|
|
2058
2085
|
chunk_index: T,
|
|
2059
|
-
chunk: f.slice(
|
|
2086
|
+
chunk: f.slice(q, q + R)
|
|
2060
2087
|
}), l({ phase: "audio-upload", sent: T + 1, total: y });
|
|
2061
2088
|
}
|
|
2062
2089
|
this._sendCommand({ type: "upload_audio_finish", upload_id: u }), l({ phase: "audio-uploaded", sent: y, total: y });
|
|
@@ -2109,16 +2136,16 @@ class Qe extends EventTarget {
|
|
|
2109
2136
|
throw new Error("data channel not open");
|
|
2110
2137
|
if (!(e instanceof Blob))
|
|
2111
2138
|
throw new TypeError("uploadAudio: expected a Blob");
|
|
2112
|
-
const i =
|
|
2139
|
+
const i = X(), r = new Uint8Array(await e.arrayBuffer()), o = x(r), a = Math.ceil(o.length / R) || 1;
|
|
2113
2140
|
n({ phase: "audio-starting", sent: 0, total: a, bytes: o.length }), this._sendCommand({
|
|
2114
2141
|
type: "upload_audio_start",
|
|
2115
2142
|
upload_id: i,
|
|
2116
2143
|
total_chunks: a,
|
|
2117
|
-
encoding:
|
|
2144
|
+
encoding: Z(e),
|
|
2118
2145
|
description: t
|
|
2119
2146
|
});
|
|
2120
2147
|
for (let c = 0; c < a; c++) {
|
|
2121
|
-
this._dc.bufferedAmount >
|
|
2148
|
+
this._dc.bufferedAmount > P && await this._awaitDataChannelDrain();
|
|
2122
2149
|
const l = c * R;
|
|
2123
2150
|
this._sendCommand({
|
|
2124
2151
|
type: "upload_audio_chunk",
|
|
@@ -2153,13 +2180,13 @@ class Qe extends EventTarget {
|
|
|
2153
2180
|
return this._pending.awaitBroadcast(e, t);
|
|
2154
2181
|
}
|
|
2155
2182
|
async _awaitDataChannelDrain() {
|
|
2156
|
-
for (; this._dc && this._dc.bufferedAmount >
|
|
2183
|
+
for (; this._dc && this._dc.bufferedAmount > $e; )
|
|
2157
2184
|
if (await new Promise((e) => setTimeout(e, 30)), !this._dc || this._dc.readyState !== "open")
|
|
2158
2185
|
throw new Error("data channel closed mid-upload");
|
|
2159
2186
|
}
|
|
2160
2187
|
async _sendToServer(e) {
|
|
2161
2188
|
if (!this._token) throw new Error("No token — authenticate() first");
|
|
2162
|
-
const t = new AbortController(), n = setTimeout(() => t.abort(),
|
|
2189
|
+
const t = new AbortController(), n = setTimeout(() => t.abort(), te);
|
|
2163
2190
|
try {
|
|
2164
2191
|
const i = await fetch(`${this._signalingUrl}/send`, {
|
|
2165
2192
|
method: "POST",
|
|
@@ -2228,7 +2255,7 @@ class Qe extends EventTarget {
|
|
|
2228
2255
|
}
|
|
2229
2256
|
_checkSessionReady() {
|
|
2230
2257
|
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(() => {
|
|
2231
|
-
Date.now() - this._lastPoseFrameAt <
|
|
2258
|
+
Date.now() - this._lastPoseFrameAt < ee || this.requestState();
|
|
2232
2259
|
}, 500), this._supervisor.startDcWatchdog(), this._emit("streaming", { sessionId: this._sessionId, robotId: this._selectedRobotId }), this._sessionResolve(), this._sessionResolve = null, this._sessionReject = null);
|
|
2233
2260
|
}
|
|
2234
2261
|
async _handleSignalingMessage(e) {
|
|
@@ -2287,7 +2314,7 @@ class Qe extends EventTarget {
|
|
|
2287
2314
|
if (e.sdp) {
|
|
2288
2315
|
const t = e.sdp;
|
|
2289
2316
|
if (t.type === "offer") {
|
|
2290
|
-
const i =
|
|
2317
|
+
const i = De(t.sdp);
|
|
2291
2318
|
if (this._micSupported = i, this._emit("micSupported", { supported: i }), i && this._micStream)
|
|
2292
2319
|
for (const o of this._micStream.getAudioTracks())
|
|
2293
2320
|
this._pc.addTrack(o, this._micStream);
|
|
@@ -2329,7 +2356,7 @@ class Qe extends EventTarget {
|
|
|
2329
2356
|
this._handleRpcMessage(e);
|
|
2330
2357
|
return;
|
|
2331
2358
|
}
|
|
2332
|
-
if (!("version" in e && this._pending.settleReplySlot("version", e.version ?? null)) && !("hardware_id" in e && this._pending.settleReplySlot("hardware_id", e.hardware_id ?? null))) {
|
|
2359
|
+
if (e.client_hello === !0 && this._sendClientHello(), !("version" in e && this._pending.settleReplySlot("version", e.version ?? null)) && !("hardware_id" in e && this._pending.settleReplySlot("hardware_id", e.hardware_id ?? null))) {
|
|
2333
2360
|
if (e.command === "get_volume" || e.command === "set_volume") {
|
|
2334
2361
|
this._pending.settleReplySlot("volume", e.status === "error" ? null : e.volume);
|
|
2335
2362
|
return;
|
|
@@ -2428,7 +2455,7 @@ class Qe extends EventTarget {
|
|
|
2428
2455
|
}
|
|
2429
2456
|
return;
|
|
2430
2457
|
}
|
|
2431
|
-
if (e.state && (t || Date.now() - this._lastPoseFrameAt >=
|
|
2458
|
+
if (e.state && (t || Date.now() - this._lastPoseFrameAt >= ee)) {
|
|
2432
2459
|
const n = e.state;
|
|
2433
2460
|
n.head_pose && (this._robotState.head = n.head_pose.flat()), n.antennas && (this._robotState.antennas = [n.antennas[0], n.antennas[1]]), n.head_joint_positions && (this._robotState.head_joint_positions = n.head_joint_positions), typeof n.body_yaw == "number" && (this._robotState.body_yaw = n.body_yaw), n.motor_mode && (this._robotState.motor_mode = n.motor_mode), typeof n.is_move_running == "boolean" && (this._robotState.is_move_running = n.is_move_running), n.face_target && (this._robotState.face_target = n.face_target), "doa" in n && (this._robotState.doa = n.doa ?? void 0), "imu" in n && (this._robotState.imu = n.imu ?? void 0), this._emit("state", { ...this._robotState });
|
|
2434
2461
|
}
|
|
@@ -2436,6 +2463,13 @@ class Qe extends EventTarget {
|
|
|
2436
2463
|
}
|
|
2437
2464
|
}
|
|
2438
2465
|
}
|
|
2466
|
+
/** Identify this client (and its public Space, if any) once per channel. */
|
|
2467
|
+
_sendClientHello() {
|
|
2468
|
+
const e = this._dc;
|
|
2469
|
+
this._helloSent || !e || e.readyState !== "open" || (this._helloSent = !0, Ee().then((t) => {
|
|
2470
|
+
this._dc !== e || e.readyState !== "open" || this._sendCommand({ type: "client_hello", client: this._client, ...t && { app: t } });
|
|
2471
|
+
}));
|
|
2472
|
+
}
|
|
2439
2473
|
/** Snap video playback to live edge if buffered lag exceeds 0.5 s. */
|
|
2440
2474
|
_startLatencyMonitor(e) {
|
|
2441
2475
|
this._latencyMonitorId && clearInterval(this._latencyMonitorId), this._latencyMonitorId = setInterval(() => {
|
|
@@ -2448,7 +2482,7 @@ class Qe extends EventTarget {
|
|
|
2448
2482
|
}, 2e3);
|
|
2449
2483
|
}
|
|
2450
2484
|
}
|
|
2451
|
-
const
|
|
2485
|
+
const Ke = "pollen-robotics/reachy_mini", ze = `https://api.github.com/repos/${Ke}/releases/latest`, se = "reachy.daemonLatestRelease.v1", Ye = 360 * 60 * 1e3, re = "1.8.2";
|
|
2452
2486
|
function E(s) {
|
|
2453
2487
|
if (typeof s != "string") return null;
|
|
2454
2488
|
const e = s.trim().replace(/^v/i, "").match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
@@ -2458,26 +2492,26 @@ function E(s) {
|
|
|
2458
2492
|
patch: Number(e[3])
|
|
2459
2493
|
} : null;
|
|
2460
2494
|
}
|
|
2461
|
-
function
|
|
2495
|
+
function G(s, e) {
|
|
2462
2496
|
return s.major - e.major || s.minor - e.minor || s.patch - e.patch;
|
|
2463
2497
|
}
|
|
2464
|
-
function
|
|
2498
|
+
function Xe(s, e) {
|
|
2465
2499
|
const t = E(s), n = E(e);
|
|
2466
|
-
return !t || !n ? !1 :
|
|
2500
|
+
return !t || !n ? !1 : G(t, n) < 0;
|
|
2467
2501
|
}
|
|
2468
|
-
function
|
|
2502
|
+
function st(s, e) {
|
|
2469
2503
|
const t = E(s);
|
|
2470
2504
|
if (!t) return null;
|
|
2471
|
-
const n = E(
|
|
2472
|
-
return n &&
|
|
2505
|
+
const n = E(re);
|
|
2506
|
+
return n && G(t, n) < 0 ? "block" : Xe(s, e) ? "notice" : null;
|
|
2473
2507
|
}
|
|
2474
|
-
function
|
|
2475
|
-
const e = E(s), t = E(
|
|
2476
|
-
return !!e && !!t &&
|
|
2508
|
+
function rt(s) {
|
|
2509
|
+
const e = E(s), t = E(re);
|
|
2510
|
+
return !!e && !!t && G(e, t) >= 0;
|
|
2477
2511
|
}
|
|
2478
|
-
function
|
|
2512
|
+
function Qe() {
|
|
2479
2513
|
try {
|
|
2480
|
-
const s = localStorage.getItem(
|
|
2514
|
+
const s = localStorage.getItem(se);
|
|
2481
2515
|
if (!s) return null;
|
|
2482
2516
|
const e = JSON.parse(s);
|
|
2483
2517
|
return typeof e.at != "number" ? null : {
|
|
@@ -2488,18 +2522,18 @@ function Je() {
|
|
|
2488
2522
|
return null;
|
|
2489
2523
|
}
|
|
2490
2524
|
}
|
|
2491
|
-
async function
|
|
2492
|
-
const s =
|
|
2493
|
-
if (s && Date.now() - s.at <
|
|
2525
|
+
async function ot() {
|
|
2526
|
+
const s = Qe();
|
|
2527
|
+
if (s && Date.now() - s.at < Ye) return s.value;
|
|
2494
2528
|
try {
|
|
2495
|
-
const e = await fetch(
|
|
2529
|
+
const e = await fetch(ze, {
|
|
2496
2530
|
headers: { Accept: "application/vnd.github+json" }
|
|
2497
2531
|
});
|
|
2498
2532
|
if (!e.ok)
|
|
2499
2533
|
return s?.value ?? null;
|
|
2500
2534
|
const t = await e.json(), n = typeof t.tag_name == "string" ? t.tag_name : null, i = n ? n.replace(/^v/i, "") : null;
|
|
2501
2535
|
try {
|
|
2502
|
-
localStorage.setItem(
|
|
2536
|
+
localStorage.setItem(se, JSON.stringify({ value: i, at: Date.now() }));
|
|
2503
2537
|
} catch {
|
|
2504
2538
|
}
|
|
2505
2539
|
return i;
|
|
@@ -2507,14 +2541,14 @@ async function tt() {
|
|
|
2507
2541
|
return s?.value ?? null;
|
|
2508
2542
|
}
|
|
2509
2543
|
}
|
|
2510
|
-
const
|
|
2511
|
-
function
|
|
2544
|
+
const Ze = 8e3;
|
|
2545
|
+
function et(s) {
|
|
2512
2546
|
if (!s) return null;
|
|
2513
2547
|
const e = s.id ?? s.peerId ?? s.peer_id;
|
|
2514
2548
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2515
2549
|
}
|
|
2516
|
-
function
|
|
2517
|
-
const e =
|
|
2550
|
+
function tt(s) {
|
|
2551
|
+
const e = et(s);
|
|
2518
2552
|
if (!e) return null;
|
|
2519
2553
|
const t = s.meta?.name ?? s.name, n = typeof s.meta?.transport == "string" && s.meta.transport.length > 0 ? s.meta.transport : null, i = typeof s.meta?.hardware_id == "string" && s.meta.hardware_id.length > 0 ? s.meta.hardware_id : null;
|
|
2520
2554
|
return {
|
|
@@ -2526,12 +2560,12 @@ function Ye(s) {
|
|
|
2526
2560
|
hardwareId: i
|
|
2527
2561
|
};
|
|
2528
2562
|
}
|
|
2529
|
-
async function
|
|
2563
|
+
async function at(s) {
|
|
2530
2564
|
const { signalingUrl: e, hfToken: t } = s;
|
|
2531
2565
|
if (!t) return { ok: !1, robots: [], reason: "No HF token" };
|
|
2532
2566
|
if (!e)
|
|
2533
2567
|
return { ok: !1, robots: [], reason: "No signaling URL" };
|
|
2534
|
-
const n = `${e.replace(/\/$/, "")}/api/robot-status`, i = new AbortController(), r = setTimeout(() => i.abort(),
|
|
2568
|
+
const n = `${e.replace(/\/$/, "")}/api/robot-status`, i = new AbortController(), r = setTimeout(() => i.abort(), Ze), o = s.signal ? nt([i.signal, s.signal]) : i.signal;
|
|
2535
2569
|
try {
|
|
2536
2570
|
const a = await fetch(n, {
|
|
2537
2571
|
method: "GET",
|
|
@@ -2550,7 +2584,7 @@ async function nt(s) {
|
|
|
2550
2584
|
reason: `Central returned HTTP ${a.status}`
|
|
2551
2585
|
};
|
|
2552
2586
|
const c = await a.json();
|
|
2553
|
-
return { ok: !0, robots: (Array.isArray(c.robots) ? c.robots : []).map(
|
|
2587
|
+
return { ok: !0, robots: (Array.isArray(c.robots) ? c.robots : []).map(tt).filter((u) => u != null) };
|
|
2554
2588
|
} catch (a) {
|
|
2555
2589
|
if (a instanceof DOMException && a.name === "AbortError")
|
|
2556
2590
|
return { ok: !1, robots: [], reason: "Central request timed out" };
|
|
@@ -2560,7 +2594,7 @@ async function nt(s) {
|
|
|
2560
2594
|
clearTimeout(r);
|
|
2561
2595
|
}
|
|
2562
2596
|
}
|
|
2563
|
-
function
|
|
2597
|
+
function nt(s) {
|
|
2564
2598
|
const e = new AbortController();
|
|
2565
2599
|
for (const t of s) {
|
|
2566
2600
|
if (t.aborted)
|
|
@@ -2570,12 +2604,12 @@ function Xe(s) {
|
|
|
2570
2604
|
return e.signal;
|
|
2571
2605
|
}
|
|
2572
2606
|
export {
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2607
|
+
re as M,
|
|
2608
|
+
it as R,
|
|
2609
|
+
at as a,
|
|
2610
|
+
F as c,
|
|
2611
|
+
st as d,
|
|
2612
|
+
ot as f,
|
|
2579
2613
|
E as p,
|
|
2580
|
-
|
|
2614
|
+
rt as s
|
|
2581
2615
|
};
|