@pollen-robotics/reachy-mini-sdk 1.13.0-dev.0.main.e4f3403 → 1.13.0
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/APP_CREATION_GUIDE.md +1 -1
- package/dist/animation/safe-return.d.ts +6 -4
- package/dist/animation/safe-return.d.ts.map +1 -1
- package/dist/animation/safe-return.js +12 -4
- package/dist/animation/safe-return.js.map +1 -1
- package/dist/lib/app-dx.test.d.ts +2 -0
- package/dist/lib/app-dx.test.d.ts.map +1 -0
- package/dist/lib/app-dx.test.js +100 -0
- package/dist/lib/app-dx.test.js.map +1 -0
- package/dist/lib/central-timeouts.test.d.ts +2 -0
- package/dist/lib/central-timeouts.test.d.ts.map +1 -0
- package/dist/lib/central-timeouts.test.js +101 -0
- package/dist/lib/central-timeouts.test.js.map +1 -0
- package/dist/lib/dial-races.test.d.ts +2 -0
- package/dist/lib/dial-races.test.d.ts.map +1 -0
- package/dist/lib/dial-races.test.js +215 -0
- package/dist/lib/dial-races.test.js.map +1 -0
- package/dist/lib/end-session-id.test.d.ts +2 -0
- package/dist/lib/end-session-id.test.d.ts.map +1 -0
- package/dist/lib/end-session-id.test.js +113 -0
- package/dist/lib/end-session-id.test.js.map +1 -0
- package/dist/lib/ice-grace.test.js +1 -0
- package/dist/lib/ice-grace.test.js.map +1 -1
- package/dist/lib/math.d.ts +3 -2
- package/dist/lib/math.d.ts.map +1 -1
- package/dist/lib/math.js +6 -2
- package/dist/lib/math.js.map +1 -1
- package/dist/lib/peer-link-liveness.test.d.ts +2 -0
- package/dist/lib/peer-link-liveness.test.d.ts.map +1 -0
- package/dist/lib/peer-link-liveness.test.js +97 -0
- package/dist/lib/peer-link-liveness.test.js.map +1 -0
- package/dist/lib/pending-replies.d.ts +3 -1
- package/dist/lib/pending-replies.d.ts.map +1 -1
- package/dist/lib/pending-replies.js.map +1 -1
- package/dist/lib/reachy-mini.d.ts +99 -1
- package/dist/lib/reachy-mini.d.ts.map +1 -1
- package/dist/lib/reachy-mini.js +491 -26
- package/dist/lib/reachy-mini.js.map +1 -1
- package/dist/lib/redial.test.js +59 -0
- package/dist/lib/redial.test.js.map +1 -1
- package/dist/lib/session-supervisor.d.ts +10 -0
- package/dist/lib/session-supervisor.d.ts.map +1 -1
- package/dist/lib/session-supervisor.js +12 -1
- package/dist/lib/session-supervisor.js.map +1 -1
- package/dist/lib/signaling-stall.test.d.ts +2 -0
- package/dist/lib/signaling-stall.test.d.ts.map +1 -0
- package/dist/lib/signaling-stall.test.js +64 -0
- package/dist/lib/signaling-stall.test.js.map +1 -0
- package/dist/lib/types.d.ts +50 -3
- 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/dist/reachy-mini-sdk.d.ts +1 -1
- package/dist/reachy-mini-sdk.d.ts.map +1 -1
- package/dist/reachy-mini-sdk.js.map +1 -1
- package/host/dist/chunks/{centralRest-K3a9U_Sk.js → centralRest-DR0Wx46x.js} +752 -508
- package/host/dist/chunks/{index-B79tSfbK.js → index-B14lPGN5.js} +1 -1
- package/host/dist/chunks/{mountHost-CMP4uYnZ.js → mountHost-CEY42tfj.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,24 +1,24 @@
|
|
|
1
|
-
var re = Object.defineProperty,
|
|
1
|
+
var re = Object.defineProperty, oe = (s, e, t) => e in s ? re(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, C = (s, e, t) => (oe(s, typeof e != "symbol" ? e + "" : e, t), t), te = "https://huggingface.co";
|
|
2
2
|
async function D(s, e) {
|
|
3
3
|
var t, n;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
4
|
+
const i = new ae(s.url, s.status, (t = s.headers.get("X-Request-Id")) != null ? t : void 0);
|
|
5
|
+
i.message = `Api error with status ${i.statusCode}`;
|
|
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")) {
|
|
8
8
|
const o = await s.json();
|
|
9
|
-
|
|
9
|
+
i.message = o.error || o.message || i.message, i.data = o;
|
|
10
10
|
} else
|
|
11
|
-
|
|
12
|
-
throw
|
|
11
|
+
i.data = { message: await s.text() };
|
|
12
|
+
throw i.message += `. ${r}`, i;
|
|
13
13
|
}
|
|
14
|
-
var
|
|
14
|
+
var ae = class extends Error {
|
|
15
15
|
constructor(s, e, t, n) {
|
|
16
|
-
super(n),
|
|
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 ce(s) {
|
|
22
22
|
if (globalThis.Buffer)
|
|
23
23
|
return globalThis.Buffer.from(s).toString("base64");
|
|
24
24
|
{
|
|
@@ -28,13 +28,13 @@ function oe(s) {
|
|
|
28
28
|
}), globalThis.btoa(e.join(""));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
31
|
+
async function G(s) {
|
|
32
32
|
var e, t;
|
|
33
33
|
if (typeof window > "u")
|
|
34
34
|
throw new Error("oauthHandleRedirect is only available in the browser");
|
|
35
|
-
const n = new URLSearchParams(window.location.search), [
|
|
36
|
-
if (
|
|
37
|
-
throw new Error(`${
|
|
35
|
+
const n = new URLSearchParams(window.location.search), [i, r] = [n.get("error"), n.get("error_description")];
|
|
36
|
+
if (i)
|
|
37
|
+
throw new Error(`${i}: ${r}`);
|
|
38
38
|
const o = n.get("code"), a = localStorage.getItem("huggingface.co:oauth:nonce");
|
|
39
39
|
if (!o)
|
|
40
40
|
throw new Error("Missing oauth code from query parameters in redirected URL");
|
|
@@ -43,25 +43,25 @@ async function B(s) {
|
|
|
43
43
|
const c = localStorage.getItem("huggingface.co:oauth:code_verifier");
|
|
44
44
|
if (!c)
|
|
45
45
|
throw new Error("Missing oauth code_verifier from localStorage");
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
46
|
+
const l = n.get("state");
|
|
47
|
+
if (!l)
|
|
48
48
|
throw new Error("Missing oauth state from query parameters in redirected URL");
|
|
49
|
-
let
|
|
49
|
+
let d;
|
|
50
50
|
try {
|
|
51
|
-
|
|
51
|
+
d = JSON.parse(l);
|
|
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: " + l);
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
55
|
+
if (d.nonce !== a)
|
|
56
56
|
throw new Error("Invalid oauth state in redirected URL");
|
|
57
|
-
const
|
|
57
|
+
const u = te, b = `${new URL(u).origin}/.well-known/openid-configuration`, S = await fetch(b, {
|
|
58
58
|
headers: {
|
|
59
59
|
Accept: "application/json"
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
if (!
|
|
63
|
-
throw await D(
|
|
64
|
-
const
|
|
62
|
+
if (!S.ok)
|
|
63
|
+
throw await D(S);
|
|
64
|
+
const m = await S.json(), g = await fetch(m.token_endpoint, {
|
|
65
65
|
method: "POST",
|
|
66
66
|
headers: {
|
|
67
67
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -69,23 +69,23 @@ async function B(s) {
|
|
|
69
69
|
body: new URLSearchParams({
|
|
70
70
|
grant_type: "authorization_code",
|
|
71
71
|
code: o,
|
|
72
|
-
redirect_uri:
|
|
72
|
+
redirect_uri: d.redirectUri,
|
|
73
73
|
code_verifier: c
|
|
74
74
|
}).toString()
|
|
75
75
|
});
|
|
76
|
-
if (localStorage.removeItem("huggingface.co:oauth:code_verifier"), localStorage.removeItem("huggingface.co:oauth:nonce"), !
|
|
77
|
-
throw await D(
|
|
78
|
-
const w = await
|
|
76
|
+
if (localStorage.removeItem("huggingface.co:oauth:code_verifier"), localStorage.removeItem("huggingface.co:oauth:nonce"), !g.ok)
|
|
77
|
+
throw await D(g);
|
|
78
|
+
const w = await g.json(), p = new Date(Date.now() + w.expires_in * 1e3), v = await fetch(m.userinfo_endpoint, {
|
|
79
79
|
headers: {
|
|
80
80
|
Authorization: `Bearer ${w.access_token}`
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
if (!
|
|
84
|
-
throw await D(
|
|
85
|
-
const h = await
|
|
83
|
+
if (!v.ok)
|
|
84
|
+
throw await D(v);
|
|
85
|
+
const h = await v.json();
|
|
86
86
|
return {
|
|
87
87
|
accessToken: w.access_token,
|
|
88
|
-
accessTokenExpiresAt:
|
|
88
|
+
accessTokenExpiresAt: p,
|
|
89
89
|
userInfo: {
|
|
90
90
|
id: h.sub,
|
|
91
91
|
name: h.name,
|
|
@@ -95,108 +95,108 @@ async function B(s) {
|
|
|
95
95
|
avatarUrl: h.picture,
|
|
96
96
|
websiteUrl: h.website,
|
|
97
97
|
isPro: h.isPro,
|
|
98
|
-
orgs: (t = (e = h.orgs) == null ? void 0 : e.map((
|
|
99
|
-
id:
|
|
100
|
-
name:
|
|
101
|
-
fullname:
|
|
102
|
-
isEnterprise:
|
|
103
|
-
canPay:
|
|
104
|
-
avatarUrl:
|
|
105
|
-
roleInOrg:
|
|
98
|
+
orgs: (t = (e = h.orgs) == null ? void 0 : e.map((f) => ({
|
|
99
|
+
id: f.sub,
|
|
100
|
+
name: f.name,
|
|
101
|
+
fullname: f.name,
|
|
102
|
+
isEnterprise: f.isEnterprise,
|
|
103
|
+
canPay: f.canPay,
|
|
104
|
+
avatarUrl: f.picture,
|
|
105
|
+
roleInOrg: f.roleInOrg
|
|
106
106
|
}))) != null ? t : []
|
|
107
107
|
},
|
|
108
|
-
state:
|
|
108
|
+
state: d.state,
|
|
109
109
|
scope: w.scope
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
112
|
+
async function le(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") ? G() : e.has("code") ? localStorage.getItem("huggingface.co:oauth:nonce") ? G() : (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 de(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 || te, i = `${new URL(n).origin}/.well-known/openid-configuration`, r = await fetch(i, {
|
|
125
125
|
headers: {
|
|
126
126
|
Accept: "application/json"
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
|
-
if (!
|
|
130
|
-
throw await D(
|
|
131
|
-
const o = await
|
|
129
|
+
if (!r.ok)
|
|
130
|
+
throw await D(r);
|
|
131
|
+
const o = await r.json(), a = globalThis.crypto.randomUUID(), c = globalThis.crypto.randomUUID() + globalThis.crypto.randomUUID();
|
|
132
132
|
localStorage.setItem("huggingface.co:oauth:nonce", a), localStorage.setItem("huggingface.co:oauth:code_verifier", c);
|
|
133
|
-
const
|
|
133
|
+
const l = s?.redirectUrl || window.location.href, d = JSON.stringify({
|
|
134
134
|
nonce: a,
|
|
135
|
-
redirectUri:
|
|
135
|
+
redirectUri: l,
|
|
136
136
|
state: s?.state
|
|
137
|
-
}),
|
|
138
|
-
if (!
|
|
139
|
-
throw
|
|
140
|
-
const
|
|
137
|
+
}), u = (t = (e = window?.huggingface) == null ? void 0 : e.variables) != null ? t : null, b = s?.clientId || u?.OAUTH_CLIENT_ID;
|
|
138
|
+
if (!b)
|
|
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 = ce(
|
|
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({
|
|
144
|
-
client_id:
|
|
145
|
-
scope: s?.scopes ||
|
|
144
|
+
client_id: b,
|
|
145
|
+
scope: s?.scopes || u?.OAUTH_SCOPES || "openid profile",
|
|
146
146
|
response_type: "code",
|
|
147
|
-
redirect_uri:
|
|
148
|
-
state:
|
|
149
|
-
code_challenge:
|
|
147
|
+
redirect_uri: l,
|
|
148
|
+
state: d,
|
|
149
|
+
code_challenge: S,
|
|
150
150
|
code_challenge_method: "S256"
|
|
151
151
|
}).toString()}`;
|
|
152
152
|
}
|
|
153
|
-
const
|
|
153
|
+
const I = {
|
|
154
154
|
debug: 0,
|
|
155
155
|
info: 1,
|
|
156
156
|
warn: 2,
|
|
157
157
|
error: 3,
|
|
158
158
|
silent: 4
|
|
159
|
-
},
|
|
160
|
-
function
|
|
159
|
+
}, ue = "reachy-log";
|
|
160
|
+
function he() {
|
|
161
161
|
try {
|
|
162
|
-
const s = globalThis.localStorage?.getItem(
|
|
163
|
-
if (s && s in
|
|
162
|
+
const s = globalThis.localStorage?.getItem(ue);
|
|
163
|
+
if (s && s in I) return s;
|
|
164
164
|
} catch {
|
|
165
165
|
}
|
|
166
166
|
return "info";
|
|
167
167
|
}
|
|
168
|
-
let
|
|
169
|
-
function
|
|
168
|
+
let M = he();
|
|
169
|
+
function j(s) {
|
|
170
170
|
const e = `[reachy:${s}]`;
|
|
171
171
|
return {
|
|
172
172
|
debug: (...t) => {
|
|
173
|
-
|
|
173
|
+
I[M] <= I.debug && console.debug(e, ...t);
|
|
174
174
|
},
|
|
175
175
|
info: (...t) => {
|
|
176
|
-
|
|
176
|
+
I[M] <= I.info && console.info(e, ...t);
|
|
177
177
|
},
|
|
178
178
|
warn: (...t) => {
|
|
179
|
-
|
|
179
|
+
I[M] <= I.warn && console.warn(e, ...t);
|
|
180
180
|
},
|
|
181
181
|
error: (...t) => {
|
|
182
|
-
|
|
182
|
+
I[M] <= I.error && console.error(e, ...t);
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function k(s) {
|
|
187
187
|
return s * Math.PI / 180;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
const n =
|
|
189
|
+
function _e(s, e, t) {
|
|
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
|
-
[o * c, o *
|
|
193
|
-
[a * c, a *
|
|
194
|
-
[-
|
|
192
|
+
[o * c, o * l * u - a * d, o * l * d + a * u, 0],
|
|
193
|
+
[a * c, a * l * u + o * d, a * l * d - o * u, 0],
|
|
194
|
+
[-l, c * u, c * d, 0],
|
|
195
195
|
[0, 0, 0, 1]
|
|
196
196
|
];
|
|
197
197
|
}
|
|
198
|
-
const
|
|
199
|
-
class
|
|
198
|
+
const pe = 4096;
|
|
199
|
+
class fe {
|
|
200
200
|
_partials = /* @__PURE__ */ new Map();
|
|
201
201
|
/**
|
|
202
202
|
* Feed one parsed frame. Returns the message to handle: the frame itself
|
|
@@ -205,17 +205,17 @@ class _e {
|
|
|
205
205
|
*/
|
|
206
206
|
accept(e) {
|
|
207
207
|
if (e.type !== "message_chunk") return e;
|
|
208
|
-
const { id: t, index: n, count:
|
|
209
|
-
if (typeof t != "string" || typeof n != "number" || typeof
|
|
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 > pe)
|
|
210
210
|
return null;
|
|
211
211
|
let o = this._partials.get(t);
|
|
212
|
-
return n === 0 && (o = [], this._partials.set(t, o)), !o || n !== o.length ? (this._partials.delete(t), null) : (o.push(
|
|
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
|
|
215
|
+
const ne = 4e3;
|
|
216
216
|
class P extends Error {
|
|
217
217
|
}
|
|
218
|
-
class
|
|
218
|
+
class me {
|
|
219
219
|
_replySlots = /* @__PURE__ */ new Map();
|
|
220
220
|
_rpcCounter = 0;
|
|
221
221
|
_pendingRpc = /* @__PURE__ */ new Map();
|
|
@@ -233,13 +233,13 @@ class pe {
|
|
|
233
233
|
*/
|
|
234
234
|
slotRoundtrip(e, t) {
|
|
235
235
|
return new Promise((n) => {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
let
|
|
236
|
+
const i = this._replySlots.get(e);
|
|
237
|
+
i && i(null);
|
|
238
|
+
let r;
|
|
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),
|
|
242
|
+
this._replySlots.set(e, o), r = setTimeout(() => o(null), ne), t();
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
@@ -259,12 +259,12 @@ class pe {
|
|
|
259
259
|
* response; rejects on timeout. Same shape as `slotRoundtrip`.
|
|
260
260
|
*/
|
|
261
261
|
rpcRoundtrip(e, t, n) {
|
|
262
|
-
const
|
|
263
|
-
return n(
|
|
262
|
+
const i = `rpc-${++this._rpcCounter}`;
|
|
263
|
+
return n(i) ? new Promise((r, o) => {
|
|
264
264
|
const a = setTimeout(() => {
|
|
265
|
-
this._pendingRpc.delete(
|
|
265
|
+
this._pendingRpc.delete(i), o(new Error(`rpcCall(${e}) timed out after ${t}ms`));
|
|
266
266
|
}, t);
|
|
267
|
-
this._pendingRpc.set(
|
|
267
|
+
this._pendingRpc.set(i, { resolve: r, reject: o, timer: a });
|
|
268
268
|
}) : Promise.reject(new Error(`rpcCall(${e}): data channel not open`));
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
@@ -279,8 +279,8 @@ class pe {
|
|
|
279
279
|
const t = this._pendingRpc.get(e.id);
|
|
280
280
|
if (!t) return !0;
|
|
281
281
|
if (this._pendingRpc.delete(e.id), clearTimeout(t.timer), "error" in e && e.error) {
|
|
282
|
-
const n = e.error,
|
|
283
|
-
|
|
282
|
+
const n = e.error, i = new Error(n.message ?? "rpc error");
|
|
283
|
+
i.reason = n.data?.reason, t.reject(i);
|
|
284
284
|
} else
|
|
285
285
|
t.resolve(e.result);
|
|
286
286
|
return !0;
|
|
@@ -288,16 +288,16 @@ class pe {
|
|
|
288
288
|
/* ─── Motion completions (wake_up / goto_sleep) ──────────────────── */
|
|
289
289
|
/** FIFO waiter for one `wake_up` / `goto_sleep` ack; rejects on timeout. */
|
|
290
290
|
awaitMotion(e, t) {
|
|
291
|
-
return new Promise((n,
|
|
292
|
-
const
|
|
291
|
+
return new Promise((n, i) => {
|
|
292
|
+
const r = {
|
|
293
293
|
resolve: n,
|
|
294
|
-
reject:
|
|
294
|
+
reject: i,
|
|
295
295
|
timer: setTimeout(() => {
|
|
296
|
-
const o = this._pendingMotion[e], a = o.indexOf(
|
|
297
|
-
a !== -1 && o.splice(a, 1),
|
|
296
|
+
const o = this._pendingMotion[e], a = o.indexOf(r);
|
|
297
|
+
a !== -1 && o.splice(a, 1), i(new Error(`${e} timed out after ${t}ms`));
|
|
298
298
|
}, t)
|
|
299
299
|
};
|
|
300
|
-
this._pendingMotion[e].push(
|
|
300
|
+
this._pendingMotion[e].push(r);
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
@@ -309,26 +309,26 @@ class pe {
|
|
|
309
309
|
settleMotion(e, t) {
|
|
310
310
|
const n = this._pendingMotion[e];
|
|
311
311
|
if (t.completed === !0 && n.length > 0) {
|
|
312
|
-
const
|
|
313
|
-
return clearTimeout(
|
|
312
|
+
const i = n.shift();
|
|
313
|
+
return clearTimeout(i.timer), i.resolve(), !0;
|
|
314
314
|
}
|
|
315
315
|
if (t.error && n.length > 0) {
|
|
316
|
-
const
|
|
317
|
-
return clearTimeout(
|
|
316
|
+
const i = n.shift();
|
|
317
|
+
return clearTimeout(i.timer), i.reject(new Error(`${e}: ${t.error}`)), !0;
|
|
318
318
|
}
|
|
319
319
|
return !1;
|
|
320
320
|
}
|
|
321
321
|
/* ─── Broadcast waiters ──────────────────────────────────────────── */
|
|
322
322
|
/** Await the first broadcast matching `predicate`; rejects on timeout. */
|
|
323
323
|
awaitBroadcast(e, { timeoutMs: t = 5e3, debugLabel: n = "" } = {}) {
|
|
324
|
-
return new Promise((
|
|
324
|
+
return new Promise((i, r) => {
|
|
325
325
|
const o = {
|
|
326
326
|
predicate: e,
|
|
327
|
-
resolve:
|
|
328
|
-
reject:
|
|
327
|
+
resolve: i,
|
|
328
|
+
reject: r,
|
|
329
329
|
timer: setTimeout(() => {
|
|
330
330
|
const a = this._broadcastWaiters.indexOf(o);
|
|
331
|
-
a !== -1 && this._broadcastWaiters.splice(a, 1),
|
|
331
|
+
a !== -1 && this._broadcastWaiters.splice(a, 1), r(new P(`broadcast timeout (${t} ms): ${n}`));
|
|
332
332
|
}, t)
|
|
333
333
|
};
|
|
334
334
|
this._broadcastWaiters.push(o);
|
|
@@ -364,8 +364,8 @@ class pe {
|
|
|
364
364
|
for (const t of Object.keys(this._pendingMotion)) {
|
|
365
365
|
const n = this._pendingMotion[t];
|
|
366
366
|
for (; n.length; ) {
|
|
367
|
-
const
|
|
368
|
-
clearTimeout(
|
|
367
|
+
const i = n.shift();
|
|
368
|
+
clearTimeout(i.timer), i.reject(e);
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
for (const t of this._broadcastWaiters)
|
|
@@ -373,8 +373,8 @@ class pe {
|
|
|
373
373
|
this._broadcastWaiters = [];
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
const
|
|
377
|
-
class
|
|
376
|
+
const A = j("session"), q = 3e3, V = 1e3, ge = 6e4, J = [0, 2e3, 4e3, 8e3, 8e3], we = 15e3, K = 1e3, ye = 2500, be = 8e3;
|
|
377
|
+
class Se {
|
|
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
|
|
@@ -401,6 +401,10 @@ class be {
|
|
|
401
401
|
this._deps = e, this._autoReconnect = t.autoReconnect;
|
|
402
402
|
}
|
|
403
403
|
/** True while the re-dial loop is running. */
|
|
404
|
+
/** Milliseconds since the last inbound data-channel message. */
|
|
405
|
+
get dcInboundAgeMs() {
|
|
406
|
+
return Date.now() - this._lastDcInboundAt;
|
|
407
|
+
}
|
|
404
408
|
get redialing() {
|
|
405
409
|
return this._redialing;
|
|
406
410
|
}
|
|
@@ -442,7 +446,7 @@ class be {
|
|
|
442
446
|
* the session.
|
|
443
447
|
*/
|
|
444
448
|
onIceFailed() {
|
|
445
|
-
this._scheduleIceGrace(
|
|
449
|
+
this._scheduleIceGrace(V, "failed");
|
|
446
450
|
}
|
|
447
451
|
/**
|
|
448
452
|
* Cancel any pending ICE grace timer and visibility handler. Called
|
|
@@ -472,21 +476,21 @@ class be {
|
|
|
472
476
|
this._iceGraceTimer = null;
|
|
473
477
|
const n = this._iceGraceReason;
|
|
474
478
|
this._iceGraceReason = null;
|
|
475
|
-
const
|
|
476
|
-
if (!(
|
|
477
|
-
if (n === "disconnected" &&
|
|
479
|
+
const i = this._deps.iceState();
|
|
480
|
+
if (!(i === "connected" || i === "completed")) {
|
|
481
|
+
if (n === "disconnected" && i === "disconnected") {
|
|
478
482
|
if (this.maybeBeginRedial(`ICE stuck in 'disconnected' for > ${e}ms`)) return;
|
|
479
483
|
this._emitError(new Error(`ICE stuck in 'disconnected' for > ${e}ms`));
|
|
480
484
|
return;
|
|
481
485
|
}
|
|
482
|
-
if (n === "failed" ||
|
|
483
|
-
const
|
|
484
|
-
if (this._deps.rejectPendingSession(
|
|
485
|
-
this._redialing || this._emitError(
|
|
486
|
+
if (n === "failed" || i === "failed") {
|
|
487
|
+
const r = new Error("ICE connection failed");
|
|
488
|
+
if (this._deps.rejectPendingSession(r)) {
|
|
489
|
+
this._redialing || this._emitError(r);
|
|
486
490
|
return;
|
|
487
491
|
}
|
|
488
492
|
if (this.maybeBeginRedial("ICE connection failed")) return;
|
|
489
|
-
this._emitError(
|
|
493
|
+
this._emitError(r);
|
|
490
494
|
}
|
|
491
495
|
}
|
|
492
496
|
}, e);
|
|
@@ -504,18 +508,18 @@ class be {
|
|
|
504
508
|
if (typeof document < "u" && document.hidden || (document.removeEventListener("visibilitychange", t), this._pendingVisibilityHandler = null, !this._deps.hasPc())) return;
|
|
505
509
|
const n = this._deps.iceState();
|
|
506
510
|
if (!(n === "connected" || n === "completed")) {
|
|
507
|
-
if (Date.now() - e >
|
|
508
|
-
const
|
|
509
|
-
if (this._deps.rejectPendingSession(
|
|
510
|
-
this._redialing || this._emitError(
|
|
511
|
+
if (Date.now() - e > ge) {
|
|
512
|
+
const i = new Error("Session expired while tab was backgrounded");
|
|
513
|
+
if (this._deps.rejectPendingSession(i)) {
|
|
514
|
+
this._redialing || this._emitError(i);
|
|
511
515
|
return;
|
|
512
516
|
}
|
|
513
517
|
if (this.maybeBeginRedial("Session expired while tab was backgrounded")) return;
|
|
514
|
-
this._emitError(
|
|
518
|
+
this._emitError(i);
|
|
515
519
|
return;
|
|
516
520
|
}
|
|
517
521
|
if (n === "failed") {
|
|
518
|
-
this._scheduleIceGrace(
|
|
522
|
+
this._scheduleIceGrace(V, "failed");
|
|
519
523
|
return;
|
|
520
524
|
}
|
|
521
525
|
this._scheduleIceGrace(q, "disconnected");
|
|
@@ -549,13 +553,13 @@ class be {
|
|
|
549
553
|
window.addEventListener("online", e), window.addEventListener("offline", t), this._onlineHandler = e, this._offlineHandler = t;
|
|
550
554
|
const n = navigator.connection;
|
|
551
555
|
if (n && typeof n.addEventListener == "function") {
|
|
552
|
-
const
|
|
556
|
+
const i = () => this._deps.emit("networkChange", {
|
|
553
557
|
effectiveType: n.effectiveType,
|
|
554
558
|
downlink: n.downlink,
|
|
555
559
|
rtt: n.rtt,
|
|
556
560
|
saveData: n.saveData
|
|
557
561
|
});
|
|
558
|
-
n.addEventListener("change",
|
|
562
|
+
n.addEventListener("change", i), this._connectionChangeHandler = i;
|
|
559
563
|
}
|
|
560
564
|
}
|
|
561
565
|
/** Counterpart to `installNetworkListeners`. */
|
|
@@ -577,7 +581,7 @@ class be {
|
|
|
577
581
|
if (this._redialing) return !0;
|
|
578
582
|
if (this._deps.isMidSetup()) return !1;
|
|
579
583
|
const t = this._deps.selectedRobotId();
|
|
580
|
-
return !t || !this._deps.hasPc() ? !1 : (this._redialing = !0,
|
|
584
|
+
return !t || !this._deps.hasPc() ? !1 : (this._redialing = !0, A.info(`auto-reconnect: ${e} - re-dialing ${t}`), this._runRedialLoop(t, e), !0);
|
|
581
585
|
}
|
|
582
586
|
/**
|
|
583
587
|
* The re-dial loop. One teardown, then up to REDIAL_BACKOFF_MS.length
|
|
@@ -592,29 +596,31 @@ class be {
|
|
|
592
596
|
* which flip `_redialing` off via `cancelRedial`.
|
|
593
597
|
*/
|
|
594
598
|
async _runRedialLoop(e, t) {
|
|
595
|
-
const n =
|
|
599
|
+
const n = J.length, i = this._deps.redialTargetResolver(e);
|
|
596
600
|
this._deps.teardownForRedial();
|
|
597
|
-
for (let
|
|
598
|
-
if (!this._redialing || (this._deps.emit("sessionReconnecting", { attempt:
|
|
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(J[o - 1]), !this._redialing)) return;
|
|
599
603
|
try {
|
|
600
|
-
if (this._deps.isSignalingDown() && await this._deps.reconnectSignaling(), !this._redialing
|
|
601
|
-
|
|
602
|
-
|
|
604
|
+
if (this._deps.isSignalingDown() && await this._deps.reconnectSignaling(), !this._redialing) return;
|
|
605
|
+
const a = i();
|
|
606
|
+
if (a !== e && A.info(`auto-reconnect: robot re-registered as ${a} (was ${e})`), await ve(
|
|
607
|
+
this._deps.dial(a),
|
|
608
|
+
we,
|
|
603
609
|
"auto-reconnect dial timed out"
|
|
604
|
-
), !this._redialing)
|
|
605
|
-
this._redialing = !1,
|
|
610
|
+
), !this._redialing) return;
|
|
611
|
+
this._redialing = !1, A.info(`auto-reconnect: recovered on attempt ${o}`), this._deps.emit("sessionReconnected", { attempt: o });
|
|
606
612
|
return;
|
|
607
|
-
} catch (
|
|
608
|
-
|
|
609
|
-
`auto-reconnect attempt ${
|
|
610
|
-
|
|
613
|
+
} catch (a) {
|
|
614
|
+
A.warn(
|
|
615
|
+
`auto-reconnect attempt ${o}/${n} failed:`,
|
|
616
|
+
a
|
|
611
617
|
), this._redialing && this._deps.teardownForRedial();
|
|
612
618
|
}
|
|
613
619
|
}
|
|
614
620
|
if (!this._redialing) return;
|
|
615
621
|
this._redialing = !1;
|
|
616
622
|
const r = `Auto-reconnect gave up after ${n} attempts (${t})`;
|
|
617
|
-
|
|
623
|
+
A.warn(r), this._deps.emit("sessionStopped", { reason: "reconnect_failed", message: r }), this._emitError(new Error(r));
|
|
618
624
|
}
|
|
619
625
|
/**
|
|
620
626
|
* Cancellable backoff sleep — `cancelRedial` wakes it immediately.
|
|
@@ -644,7 +650,7 @@ class be {
|
|
|
644
650
|
startDcWatchdog() {
|
|
645
651
|
this.stopDcWatchdog();
|
|
646
652
|
const e = Date.now();
|
|
647
|
-
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(), K);
|
|
648
654
|
}
|
|
649
655
|
stopDcWatchdog() {
|
|
650
656
|
this._dcWatchdogId !== null && (clearInterval(this._dcWatchdogId), this._dcWatchdogId = null);
|
|
@@ -659,7 +665,7 @@ class be {
|
|
|
659
665
|
_dcWatchdogTick() {
|
|
660
666
|
const e = Date.now(), t = e - this._dcWatchdogLastTickAt;
|
|
661
667
|
if (this._dcWatchdogLastTickAt = e, !this._deps.isStreaming()) return;
|
|
662
|
-
if (t >
|
|
668
|
+
if (t > K * 3) {
|
|
663
669
|
this._lastDcInboundAt = e, this._dcSilenceNudged = !1;
|
|
664
670
|
return;
|
|
665
671
|
}
|
|
@@ -668,25 +674,25 @@ class be {
|
|
|
668
674
|
return;
|
|
669
675
|
}
|
|
670
676
|
const n = e - this._lastDcInboundAt;
|
|
671
|
-
if (n <
|
|
677
|
+
if (n < ye) return;
|
|
672
678
|
if (!this._dcSilenceNudged) {
|
|
673
679
|
this._dcSilenceNudged = !0, this._deps.nudgeState();
|
|
674
680
|
return;
|
|
675
681
|
}
|
|
676
|
-
if (n <
|
|
682
|
+
if (n < be) return;
|
|
677
683
|
this._dcSilenceNudged = !1;
|
|
678
|
-
const
|
|
679
|
-
this.maybeBeginRedial(
|
|
684
|
+
const i = `No data-channel traffic for ${n}ms`;
|
|
685
|
+
this.maybeBeginRedial(i) || (this.stopDcWatchdog(), this._emitError(new Error(i)));
|
|
680
686
|
}
|
|
681
687
|
}
|
|
682
|
-
function
|
|
688
|
+
function ve(s, e, t) {
|
|
683
689
|
return Promise.race([
|
|
684
690
|
s,
|
|
685
|
-
new Promise((n,
|
|
691
|
+
new Promise((n, i) => setTimeout(() => i(new Error(t)), e))
|
|
686
692
|
]);
|
|
687
693
|
}
|
|
688
|
-
const z = "0.0.0-managed-by-ci",
|
|
689
|
-
function
|
|
694
|
+
const z = "0.0.0-managed-by-ci", Re = j("sdk");
|
|
695
|
+
function Ie() {
|
|
690
696
|
if (typeof window > "u" || !window.location.hash) return;
|
|
691
697
|
const s = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
692
698
|
let e;
|
|
@@ -697,11 +703,11 @@ function ve() {
|
|
|
697
703
|
}
|
|
698
704
|
const t = e.get("hf_token");
|
|
699
705
|
if (!t) return;
|
|
700
|
-
const n = e.get("hf_username") || "user",
|
|
706
|
+
const n = e.get("hf_username") || "user", i = e.get("hf_token_expires"), r = i && !Number.isNaN(new Date(i).getTime()) ? i : new Date(Date.now() + 365 * 24 * 60 * 60 * 1e3).toISOString();
|
|
701
707
|
try {
|
|
702
|
-
sessionStorage.setItem("hf_token", t), sessionStorage.setItem("hf_username", n), sessionStorage.setItem("hf_token_expires",
|
|
708
|
+
sessionStorage.setItem("hf_token", t), sessionStorage.setItem("hf_username", n), sessionStorage.setItem("hf_token_expires", r);
|
|
703
709
|
} catch (c) {
|
|
704
|
-
|
|
710
|
+
Re.warn("could not persist pre-seeded HF credentials:", c);
|
|
705
711
|
}
|
|
706
712
|
e.delete("hf_token"), e.delete("hf_username"), e.delete("hf_token_expires");
|
|
707
713
|
const o = e.toString(), a = window.location.pathname + window.location.search + (o ? "#" + o : "");
|
|
@@ -710,7 +716,7 @@ function ve() {
|
|
|
710
716
|
} catch {
|
|
711
717
|
}
|
|
712
718
|
}
|
|
713
|
-
function
|
|
719
|
+
function Te() {
|
|
714
720
|
if (typeof window > "u") return null;
|
|
715
721
|
if (window.location.hash) {
|
|
716
722
|
const s = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
@@ -728,7 +734,7 @@ function Re() {
|
|
|
728
734
|
}
|
|
729
735
|
return null;
|
|
730
736
|
}
|
|
731
|
-
function
|
|
737
|
+
function ke(s) {
|
|
732
738
|
const e = s.split(`\r
|
|
733
739
|
`);
|
|
734
740
|
let t = !1;
|
|
@@ -736,55 +742,55 @@ function Ie(s) {
|
|
|
736
742
|
if (n.startsWith("m=audio") ? t = !0 : n.startsWith("m=") && (t = !1), t && n === "a=sendrecv") return !0;
|
|
737
743
|
return !1;
|
|
738
744
|
}
|
|
739
|
-
const
|
|
740
|
-
function
|
|
745
|
+
const x = "hf_token", F = "hf_username", H = "hf_token_expires", L = "hf_token_last_seen", Ee = 1440 * 60 * 1e3;
|
|
746
|
+
function Ae(s) {
|
|
741
747
|
try {
|
|
742
|
-
sessionStorage.setItem(
|
|
748
|
+
sessionStorage.setItem(x, s.token), sessionStorage.setItem(F, s.username), sessionStorage.setItem(H, s.expires), sessionStorage.setItem(L, (/* @__PURE__ */ new Date()).toISOString());
|
|
743
749
|
} catch {
|
|
744
750
|
}
|
|
745
751
|
}
|
|
746
|
-
function
|
|
752
|
+
function Ce(s = Date.now()) {
|
|
747
753
|
try {
|
|
748
|
-
const e = sessionStorage.getItem(
|
|
754
|
+
const e = sessionStorage.getItem(x), t = sessionStorage.getItem(F), n = sessionStorage.getItem(H);
|
|
749
755
|
if (!e || !n) return null;
|
|
750
756
|
if (new Date(n).getTime() <= s)
|
|
751
757
|
return N(), null;
|
|
752
|
-
const
|
|
753
|
-
if (
|
|
754
|
-
const
|
|
755
|
-
if (!Number.isFinite(
|
|
758
|
+
const i = sessionStorage.getItem(L);
|
|
759
|
+
if (i !== null) {
|
|
760
|
+
const r = new Date(i).getTime();
|
|
761
|
+
if (!Number.isFinite(r) || s - r > Ee)
|
|
756
762
|
return N(), null;
|
|
757
763
|
}
|
|
758
|
-
return sessionStorage.setItem(
|
|
764
|
+
return sessionStorage.setItem(L, new Date(s).toISOString()), { token: e, username: t ?? "", expires: n };
|
|
759
765
|
} catch {
|
|
760
766
|
return null;
|
|
761
767
|
}
|
|
762
768
|
}
|
|
763
769
|
function N() {
|
|
764
770
|
try {
|
|
765
|
-
sessionStorage.removeItem(
|
|
771
|
+
sessionStorage.removeItem(x), sessionStorage.removeItem(F), sessionStorage.removeItem(H), sessionStorage.removeItem(L);
|
|
766
772
|
} catch {
|
|
767
773
|
}
|
|
768
774
|
}
|
|
769
|
-
const
|
|
775
|
+
const Me = /* @__PURE__ */ new Set([
|
|
770
776
|
"login_required",
|
|
771
777
|
"consent_required",
|
|
772
778
|
"interaction_required",
|
|
773
779
|
"access_denied"
|
|
774
780
|
]);
|
|
775
|
-
function
|
|
781
|
+
function De() {
|
|
776
782
|
try {
|
|
777
783
|
const s = new URL(window.location.href), e = s.searchParams.get("error");
|
|
778
|
-
return e === null || !
|
|
784
|
+
return e === null || !Me.has(e) ? null : (s.searchParams.delete("error"), s.searchParams.delete("error_description"), s.searchParams.delete("state"), window.history.replaceState(null, "", s.toString()), e);
|
|
779
785
|
} catch {
|
|
780
786
|
return null;
|
|
781
787
|
}
|
|
782
788
|
}
|
|
783
|
-
const
|
|
784
|
-
function
|
|
789
|
+
const R = 12 * 1024, U = 1 * 1024 * 1024, Le = 512 * 1024;
|
|
790
|
+
function Ue() {
|
|
785
791
|
return typeof CompressionStream < "u";
|
|
786
792
|
}
|
|
787
|
-
function
|
|
793
|
+
function Y() {
|
|
788
794
|
return "u" + Math.random().toString(36).slice(2, 11) + Date.now().toString(36);
|
|
789
795
|
}
|
|
790
796
|
function $(s) {
|
|
@@ -796,17 +802,17 @@ function $(s) {
|
|
|
796
802
|
);
|
|
797
803
|
return btoa(e);
|
|
798
804
|
}
|
|
799
|
-
async function
|
|
805
|
+
async function Oe(s) {
|
|
800
806
|
const e = new TextEncoder().encode(s), t = await new Response(
|
|
801
807
|
new Blob([e]).stream().pipeThrough(new CompressionStream("gzip"))
|
|
802
808
|
).arrayBuffer();
|
|
803
809
|
return $(new Uint8Array(t));
|
|
804
810
|
}
|
|
805
|
-
function
|
|
811
|
+
function X(s) {
|
|
806
812
|
const e = Math.round(Number(s) || 0);
|
|
807
813
|
return Math.max(0, Math.min(100, e));
|
|
808
814
|
}
|
|
809
|
-
function
|
|
815
|
+
function Q(s) {
|
|
810
816
|
switch ((s.type || "").toLowerCase().split(";")[0]?.trim() ?? "") {
|
|
811
817
|
case "audio/ogg":
|
|
812
818
|
case "application/ogg":
|
|
@@ -829,8 +835,13 @@ function X(s) {
|
|
|
829
835
|
return "wav-base64";
|
|
830
836
|
}
|
|
831
837
|
}
|
|
832
|
-
const _ =
|
|
833
|
-
|
|
838
|
+
const _ = j("sdk"), Z = 750, Pe = 2500, Ne = 8, $e = 75e3, je = 15e3, xe = 5e3, ee = 1e4, Fe = 15e3, He = 15e3;
|
|
839
|
+
function O(s) {
|
|
840
|
+
const e = s?.meta;
|
|
841
|
+
return e?.install_id ?? e?.hardware_id ?? null;
|
|
842
|
+
}
|
|
843
|
+
const We = 5e3;
|
|
844
|
+
class Qe extends EventTarget {
|
|
834
845
|
// ─── Config ──────────────────────────────────────────────────────────
|
|
835
846
|
_signalingUrl;
|
|
836
847
|
_clientId;
|
|
@@ -862,14 +873,32 @@ class Be extends EventTarget {
|
|
|
862
873
|
_tokenExpires = null;
|
|
863
874
|
// ─── Signaling ───────────────────────────────────────────────────────
|
|
864
875
|
_sseAbortController = null;
|
|
876
|
+
/** The open in flight (fetch → welcome): a second open joins it. */
|
|
877
|
+
_signalingOpening = null;
|
|
878
|
+
_signalingOpeningController = null;
|
|
865
879
|
// ─── WebRTC ──────────────────────────────────────────────────────────
|
|
866
880
|
_pc = null;
|
|
867
881
|
_dc = null;
|
|
868
882
|
_sessionId = null;
|
|
883
|
+
/** Our session after central dropped it while the peer link lived on. */
|
|
884
|
+
_staleSessionId = null;
|
|
885
|
+
/** Sessions we closed: a late endSession for one must not end the next. */
|
|
886
|
+
_retiredSessionIds = /* @__PURE__ */ new Set();
|
|
869
887
|
_selectedRobotId = null;
|
|
870
888
|
_pendingRemoteIce = [];
|
|
871
889
|
// ─── Audio ───────────────────────────────────────────────────────────
|
|
872
890
|
_micStream = null;
|
|
891
|
+
_robotAudioTrack = null;
|
|
892
|
+
_outgoingAudioTrack = null;
|
|
893
|
+
/** Context driving the silent placeholder track; closed with it. */
|
|
894
|
+
_micCtx = null;
|
|
895
|
+
/** Robot dialed last and its stable identity (see `_redialTargetResolver`). */
|
|
896
|
+
_dialedRobotId = null;
|
|
897
|
+
_dialedRobotIdentity = null;
|
|
898
|
+
/** Signaling (SSE) dropped while streaming; reconnecting in the background. */
|
|
899
|
+
_signalingDown = !1;
|
|
900
|
+
_signalingRetryTimer = null;
|
|
901
|
+
_signalingRetryAttempt = 0;
|
|
873
902
|
_micMuted = !0;
|
|
874
903
|
_audioMuted = !0;
|
|
875
904
|
_micSupported = !1;
|
|
@@ -879,7 +908,7 @@ class Be extends EventTarget {
|
|
|
879
908
|
// ─── Pending replies (reply slots / JSON-RPC / motion / broadcast) ───
|
|
880
909
|
// All request/response waiters on the data channel live in one
|
|
881
910
|
// ledger so every teardown path settles them in a single call.
|
|
882
|
-
_pending = new
|
|
911
|
+
_pending = new me();
|
|
883
912
|
// ─── Log subscribers ─────────────────────────────────────────────────
|
|
884
913
|
_logSubscribers = /* @__PURE__ */ new Set();
|
|
885
914
|
_updateProgressSubscribers = /* @__PURE__ */ new Set();
|
|
@@ -904,12 +933,12 @@ class Be extends EventTarget {
|
|
|
904
933
|
// ─── Video element ───────────────────────────────────────────────────
|
|
905
934
|
_videoElement = null;
|
|
906
935
|
constructor(e = {}) {
|
|
907
|
-
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 =
|
|
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 = Te(), this._supervisor = new Se({
|
|
908
937
|
iceState: () => this._pc?.iceConnectionState ?? null,
|
|
909
938
|
hasPc: () => !!this._pc,
|
|
910
939
|
isStreaming: () => this._state === "streaming",
|
|
911
940
|
isMidSetup: () => !!(this._sessionResolve || this._sessionReject),
|
|
912
|
-
isSignalingDown: () => this._state === "disconnected",
|
|
941
|
+
isSignalingDown: () => this._state === "disconnected" || this._signalingDown,
|
|
913
942
|
selectedRobotId: () => this._selectedRobotId,
|
|
914
943
|
rejectPendingSession: (t) => {
|
|
915
944
|
if (!this._sessionReject) return !1;
|
|
@@ -920,6 +949,7 @@ class Be extends EventTarget {
|
|
|
920
949
|
// The private dial skips the public startSession()'s
|
|
921
950
|
// cancelRedial, so the loop's own attempts don't cancel it.
|
|
922
951
|
dial: (t) => this._startSessionInternal(t),
|
|
952
|
+
redialTargetResolver: (t) => this._redialTargetResolver(t),
|
|
923
953
|
teardownForRedial: () => this._teardownForRedial(),
|
|
924
954
|
nudgeState: () => {
|
|
925
955
|
this.requestState();
|
|
@@ -967,6 +997,14 @@ class Be extends EventTarget {
|
|
|
967
997
|
get peerConnection() {
|
|
968
998
|
return this._pc;
|
|
969
999
|
}
|
|
1000
|
+
/**
|
|
1001
|
+
* The robot's microphone as a live audio track, or `null` until the
|
|
1002
|
+
* session's audio arrives (see the `audioTrack` event). Feed it to Web
|
|
1003
|
+
* Audio, `MediaRecorder` or `SpeechRecognition.start(track)`.
|
|
1004
|
+
*/
|
|
1005
|
+
get robotAudioTrack() {
|
|
1006
|
+
return this._robotAudioTrack;
|
|
1007
|
+
}
|
|
970
1008
|
/**
|
|
971
1009
|
* Build version of this SDK (npm package `version`), injected from
|
|
972
1010
|
* package.json at build time. This is the JS SDK's OWN version and is
|
|
@@ -1001,17 +1039,17 @@ class Be extends EventTarget {
|
|
|
1001
1039
|
// ─── Auth ────────────────────────────────────────────────────────────
|
|
1002
1040
|
async authenticate() {
|
|
1003
1041
|
try {
|
|
1004
|
-
|
|
1005
|
-
const e =
|
|
1042
|
+
Ie();
|
|
1043
|
+
const e = De();
|
|
1006
1044
|
e && _.info("silent sign-in declined:", e);
|
|
1007
|
-
const t = await
|
|
1045
|
+
const t = await le();
|
|
1008
1046
|
if (t)
|
|
1009
|
-
return this._username = t.userInfo.preferred_username || t.userInfo.name || null, this._token = t.accessToken, this._tokenExpires = t.accessTokenExpiresAt,
|
|
1047
|
+
return this._username = t.userInfo.preferred_username || t.userInfo.name || null, this._token = t.accessToken, this._tokenExpires = t.accessTokenExpiresAt, Ae({
|
|
1010
1048
|
token: this._token,
|
|
1011
1049
|
username: this._username ?? "",
|
|
1012
1050
|
expires: typeof this._tokenExpires == "string" ? this._tokenExpires : this._tokenExpires.toISOString()
|
|
1013
1051
|
}), !0;
|
|
1014
|
-
const n =
|
|
1052
|
+
const n = Ce();
|
|
1015
1053
|
return n && n.username ? (this._token = n.token, this._username = n.username, this._tokenExpires = n.expires, !0) : !1;
|
|
1016
1054
|
} catch (e) {
|
|
1017
1055
|
return _.error("authenticate failed:", e), !1;
|
|
@@ -1020,10 +1058,10 @@ class Be extends EventTarget {
|
|
|
1020
1058
|
async login(e) {
|
|
1021
1059
|
const t = {};
|
|
1022
1060
|
this._clientId && (t.clientId = this._clientId);
|
|
1023
|
-
let n = await
|
|
1061
|
+
let n = await de(t);
|
|
1024
1062
|
if (e?.prompt) {
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1063
|
+
const i = new URL(n);
|
|
1064
|
+
i.searchParams.set("prompt", e.prompt), n = i.toString();
|
|
1027
1065
|
}
|
|
1028
1066
|
window.location.href = n;
|
|
1029
1067
|
}
|
|
@@ -1034,53 +1072,100 @@ class Be extends EventTarget {
|
|
|
1034
1072
|
async connect(e) {
|
|
1035
1073
|
if (this._state !== "disconnected") throw new Error("Already connected");
|
|
1036
1074
|
if (e && (this._token = e), !this._token) throw new Error("No token — call authenticate() first or pass a token");
|
|
1037
|
-
this.
|
|
1038
|
-
|
|
1075
|
+
return this._openSignaling();
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Open the signaling SSE stream and resolve on central's `welcome`.
|
|
1079
|
+
* Shared by `connect()` and the background reconnect that runs while a
|
|
1080
|
+
* session keeps streaming without signaling (see `signalingLost`).
|
|
1081
|
+
*/
|
|
1082
|
+
_openSignaling() {
|
|
1083
|
+
if (this._signalingOpening && !this._signalingOpeningController?.signal.aborted)
|
|
1084
|
+
return this._signalingOpening;
|
|
1085
|
+
const e = this._openSignalingOnce().finally(() => {
|
|
1086
|
+
this._signalingOpening === e && (this._signalingOpening = null, this._signalingOpeningController = null);
|
|
1087
|
+
});
|
|
1088
|
+
return this._signalingOpening = e, e;
|
|
1089
|
+
}
|
|
1090
|
+
async _openSignalingOnce() {
|
|
1091
|
+
this._sseAbortController = new AbortController(), this._signalingOpeningController = this._sseAbortController;
|
|
1092
|
+
const e = this._sseAbortController;
|
|
1093
|
+
let t = !1;
|
|
1094
|
+
const n = setTimeout(() => {
|
|
1095
|
+
t = !0, e.abort();
|
|
1096
|
+
}, Fe);
|
|
1097
|
+
let i;
|
|
1039
1098
|
try {
|
|
1040
|
-
|
|
1099
|
+
i = await fetch(
|
|
1041
1100
|
`${this._signalingUrl}/events`,
|
|
1042
1101
|
{
|
|
1043
|
-
signal:
|
|
1102
|
+
signal: e.signal,
|
|
1044
1103
|
headers: { Authorization: `Bearer ${this._token}` }
|
|
1045
1104
|
}
|
|
1046
1105
|
);
|
|
1047
|
-
} catch (
|
|
1048
|
-
throw this._sseAbortController = null,
|
|
1106
|
+
} catch (r) {
|
|
1107
|
+
throw this._sseAbortController === e && (this._sseAbortController = null), t ? new Error("signaling: no answer from central") : r;
|
|
1108
|
+
} finally {
|
|
1109
|
+
clearTimeout(n);
|
|
1049
1110
|
}
|
|
1050
|
-
if (!
|
|
1051
|
-
throw this._sseAbortController = null, new Error(`HTTP ${
|
|
1052
|
-
return new Promise((
|
|
1053
|
-
let
|
|
1054
|
-
const
|
|
1055
|
-
let
|
|
1111
|
+
if (!i.ok)
|
|
1112
|
+
throw this._sseAbortController === e && (this._sseAbortController = null), new Error(`HTTP ${i.status}`);
|
|
1113
|
+
return new Promise((r, o) => {
|
|
1114
|
+
let a = !1;
|
|
1115
|
+
const c = i.body.getReader(), l = new TextDecoder();
|
|
1116
|
+
let d = "";
|
|
1117
|
+
const u = e;
|
|
1118
|
+
let b = !1;
|
|
1119
|
+
const S = setTimeout(() => {
|
|
1120
|
+
a || (b = !0, _.warn("signaling: no welcome from central; aborting the stream"), u?.abort());
|
|
1121
|
+
}, He);
|
|
1122
|
+
let m = null;
|
|
1123
|
+
const g = (p = $e) => {
|
|
1124
|
+
m !== null && clearTimeout(m);
|
|
1125
|
+
const v = Date.now();
|
|
1126
|
+
m = setTimeout(() => {
|
|
1127
|
+
if (Date.now() - v > p + je) {
|
|
1128
|
+
g(xe);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
_.warn("signaling stream silent for too long; reconnecting"), u?.abort();
|
|
1132
|
+
}, p);
|
|
1133
|
+
};
|
|
1056
1134
|
(async () => {
|
|
1057
1135
|
try {
|
|
1058
|
-
for (; ; ) {
|
|
1059
|
-
const { done:
|
|
1060
|
-
if (
|
|
1061
|
-
|
|
1062
|
-
const
|
|
1136
|
+
for (g(); ; ) {
|
|
1137
|
+
const { done: p, value: v } = await c.read();
|
|
1138
|
+
if (p) break;
|
|
1139
|
+
g(), d += l.decode(v, { stream: !0 });
|
|
1140
|
+
const h = d.split(`
|
|
1063
1141
|
`);
|
|
1064
|
-
|
|
1065
|
-
for (const
|
|
1066
|
-
if (
|
|
1142
|
+
d = h.pop() ?? "";
|
|
1143
|
+
for (const f of h)
|
|
1144
|
+
if (f.startsWith("data:"))
|
|
1067
1145
|
try {
|
|
1068
|
-
const
|
|
1069
|
-
!
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1146
|
+
const y = JSON.parse(f.slice(5).trim());
|
|
1147
|
+
if (!a && y.type === "welcome" && y.peerId) {
|
|
1148
|
+
a = !0, clearTimeout(S);
|
|
1149
|
+
const T = this._state !== "disconnected";
|
|
1150
|
+
T || (this._state = "connected"), this._signalingDown = !1, this._signalingRetryAttempt = 0, await this._sendToServer({
|
|
1151
|
+
type: "setPeerStatus",
|
|
1152
|
+
roles: ["listener"],
|
|
1153
|
+
meta: { name: this._appName }
|
|
1154
|
+
}), T ? (_.info("signaling restored while streaming"), this._emit("signalingRestored", { peerId: y.peerId })) : this._emit("connected", { peerId: y.peerId }), r();
|
|
1155
|
+
}
|
|
1156
|
+
this._handleSignalingMessage(y);
|
|
1074
1157
|
} catch {
|
|
1075
1158
|
}
|
|
1076
1159
|
}
|
|
1077
|
-
} catch (
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1160
|
+
} catch (p) {
|
|
1161
|
+
if (p.name !== "AbortError" && this._emit("error", { source: "signaling", error: p }), !a) {
|
|
1162
|
+
o(b ? new Error("signaling: no welcome from central") : p);
|
|
1080
1163
|
return;
|
|
1081
1164
|
}
|
|
1165
|
+
} finally {
|
|
1166
|
+
clearTimeout(S), m !== null && clearTimeout(m);
|
|
1082
1167
|
}
|
|
1083
|
-
this._state !== "disconnected" && (this._state = "disconnected", this._emit("disconnected", { reason: "SSE closed" })),
|
|
1168
|
+
this._state === "streaming" ? (this._sseAbortController = null, this._signalingDown || (this._signalingDown = !0, _.warn("signaling lost while streaming; keeping the session"), this._emit("signalingLost", { reason: "SSE closed" })), this._scheduleSignalingRetry()) : this._state !== "disconnected" && (this._state = "disconnected", this._emit("disconnected", { reason: "SSE closed" })), a || o(new Error("Connection closed before welcome"));
|
|
1084
1169
|
})();
|
|
1085
1170
|
});
|
|
1086
1171
|
}
|
|
@@ -1088,12 +1173,12 @@ class Be extends EventTarget {
|
|
|
1088
1173
|
const {
|
|
1089
1174
|
token: t,
|
|
1090
1175
|
pickRobot: n,
|
|
1091
|
-
autoPickIfSingle:
|
|
1092
|
-
filterBusy:
|
|
1176
|
+
autoPickIfSingle: i = !0,
|
|
1177
|
+
filterBusy: r = !0,
|
|
1093
1178
|
wakeOnConnect: o = !0
|
|
1094
1179
|
} = e;
|
|
1095
1180
|
if (this._state === "streaming") {
|
|
1096
|
-
const c = this._robots?.find((
|
|
1181
|
+
const c = this._robots?.find((l) => l.id === this._selectedRobotId);
|
|
1097
1182
|
return {
|
|
1098
1183
|
robotId: this._selectedRobotId,
|
|
1099
1184
|
robotName: c?.meta?.name ?? null,
|
|
@@ -1109,24 +1194,24 @@ class Be extends EventTarget {
|
|
|
1109
1194
|
else if (!this._token && !await this.authenticate())
|
|
1110
1195
|
throw new Error("Not authenticated — call login() or pass a token");
|
|
1111
1196
|
this._state === "disconnected" && await this.connect();
|
|
1112
|
-
let c,
|
|
1197
|
+
let c, l = null;
|
|
1113
1198
|
if (this.isEmbedded) {
|
|
1114
1199
|
c = this._preselectedRobotId;
|
|
1115
1200
|
try {
|
|
1116
1201
|
await this._waitForRobotInList(c, 5e3);
|
|
1117
1202
|
} catch {
|
|
1118
1203
|
}
|
|
1119
|
-
|
|
1204
|
+
l = this._robots?.find((u) => u.id === c)?.meta?.name ?? null;
|
|
1120
1205
|
} else {
|
|
1121
|
-
const
|
|
1122
|
-
if (
|
|
1206
|
+
const d = await this._fetchOwnedRobots({ filterBusy: r });
|
|
1207
|
+
if (d.length === 0)
|
|
1123
1208
|
throw new Error("No reachable robots");
|
|
1124
|
-
if (
|
|
1125
|
-
c =
|
|
1209
|
+
if (i && d.length === 1 && !d[0].busy)
|
|
1210
|
+
c = d[0].id, l = d[0].name;
|
|
1126
1211
|
else if (n) {
|
|
1127
|
-
const
|
|
1128
|
-
if (!
|
|
1129
|
-
c =
|
|
1212
|
+
const u = await n(d);
|
|
1213
|
+
if (!u) throw new Error("Robot selection cancelled");
|
|
1214
|
+
c = u, l = d.find((b) => b.id === u)?.name ?? null;
|
|
1130
1215
|
} else
|
|
1131
1216
|
throw new Error(
|
|
1132
1217
|
"Multiple robots available — pass a pickRobot callback to autoConnect()"
|
|
@@ -1135,55 +1220,59 @@ class Be extends EventTarget {
|
|
|
1135
1220
|
if (await this.startSession(c), o && typeof this.ensureAwake == "function")
|
|
1136
1221
|
try {
|
|
1137
1222
|
await this.ensureAwake();
|
|
1138
|
-
} catch (
|
|
1139
|
-
_.warn("autoConnect: ensureAwake failed:",
|
|
1223
|
+
} catch (d) {
|
|
1224
|
+
_.warn("autoConnect: ensureAwake failed:", d);
|
|
1140
1225
|
}
|
|
1141
|
-
return { robotId: c, robotName:
|
|
1226
|
+
return { robotId: c, robotName: l, isEmbedded: this.isEmbedded };
|
|
1142
1227
|
} finally {
|
|
1143
1228
|
this._autoStartFromUrl = a;
|
|
1144
1229
|
}
|
|
1145
1230
|
}
|
|
1146
1231
|
async _fetchOwnedRobots({ filterBusy: e = !0 } = {}) {
|
|
1232
|
+
const t = new AbortController(), n = setTimeout(() => t.abort(), ee);
|
|
1147
1233
|
try {
|
|
1148
|
-
const
|
|
1149
|
-
headers: { Authorization: `Bearer ${this._token}` }
|
|
1234
|
+
const i = await fetch(`${this._signalingUrl}/api/robot-status`, {
|
|
1235
|
+
headers: { Authorization: `Bearer ${this._token}` },
|
|
1236
|
+
signal: t.signal
|
|
1150
1237
|
});
|
|
1151
|
-
if (!
|
|
1152
|
-
const
|
|
1153
|
-
for (const
|
|
1154
|
-
if (e &&
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
id:
|
|
1158
|
-
name:
|
|
1159
|
-
busy: !!
|
|
1160
|
-
activeApp:
|
|
1161
|
-
meta:
|
|
1162
|
-
lastSeenAgeSeconds:
|
|
1238
|
+
if (!i.ok) throw new Error(`HTTP ${i.status}`);
|
|
1239
|
+
const r = await i.json(), o = /* @__PURE__ */ new Map();
|
|
1240
|
+
for (const a of r.robots || []) {
|
|
1241
|
+
if (e && a.busy) continue;
|
|
1242
|
+
const c = a.meta?.install_id ?? a.meta?.hardware_id ?? a.peerId;
|
|
1243
|
+
o.set(c, {
|
|
1244
|
+
id: a.peerId,
|
|
1245
|
+
name: a.robotName ?? a.meta?.name ?? null,
|
|
1246
|
+
busy: !!a.busy,
|
|
1247
|
+
activeApp: a.activeApp ?? null,
|
|
1248
|
+
meta: a.meta ?? {},
|
|
1249
|
+
lastSeenAgeSeconds: a.last_seen_age_seconds ?? null
|
|
1163
1250
|
});
|
|
1164
1251
|
}
|
|
1165
|
-
return Array.from(
|
|
1166
|
-
(
|
|
1252
|
+
return Array.from(o.values()).sort(
|
|
1253
|
+
(a, c) => (a.lastSeenAgeSeconds ?? 1 / 0) - (c.lastSeenAgeSeconds ?? 1 / 0)
|
|
1167
1254
|
);
|
|
1168
|
-
} catch (
|
|
1169
|
-
return _.warn("/api/robot-status unavailable, using SSE list:",
|
|
1170
|
-
id:
|
|
1171
|
-
name:
|
|
1255
|
+
} catch (i) {
|
|
1256
|
+
return _.warn("/api/robot-status unavailable, using SSE list:", i), (this._robots || []).map((r) => ({
|
|
1257
|
+
id: r.id,
|
|
1258
|
+
name: r.meta?.name ?? null,
|
|
1172
1259
|
busy: !1,
|
|
1173
1260
|
activeApp: null,
|
|
1174
|
-
meta:
|
|
1261
|
+
meta: r.meta ?? {},
|
|
1175
1262
|
lastSeenAgeSeconds: null
|
|
1176
1263
|
}));
|
|
1264
|
+
} finally {
|
|
1265
|
+
clearTimeout(n);
|
|
1177
1266
|
}
|
|
1178
1267
|
}
|
|
1179
1268
|
_waitForRobotInList(e, t) {
|
|
1180
|
-
return this._robots?.find((n) => n.id === e) ? Promise.resolve() : new Promise((n,
|
|
1181
|
-
const
|
|
1182
|
-
this._robots?.find((a) => a.id === e) && (this.removeEventListener("robotsChanged",
|
|
1269
|
+
return this._robots?.find((n) => n.id === e) ? Promise.resolve() : new Promise((n, i) => {
|
|
1270
|
+
const r = () => {
|
|
1271
|
+
this._robots?.find((a) => a.id === e) && (this.removeEventListener("robotsChanged", r), clearTimeout(o), n());
|
|
1183
1272
|
}, o = setTimeout(() => {
|
|
1184
|
-
this.removeEventListener("robotsChanged",
|
|
1273
|
+
this.removeEventListener("robotsChanged", r), i(new Error(`Timeout waiting for robot ${e} in list`));
|
|
1185
1274
|
}, t);
|
|
1186
|
-
this.addEventListener("robotsChanged",
|
|
1275
|
+
this.addEventListener("robotsChanged", r);
|
|
1187
1276
|
});
|
|
1188
1277
|
}
|
|
1189
1278
|
async startSession(e) {
|
|
@@ -1191,88 +1280,110 @@ class Be extends EventTarget {
|
|
|
1191
1280
|
}
|
|
1192
1281
|
async _startSessionInternal(e) {
|
|
1193
1282
|
if (this._state !== "connected") throw new Error("Not connected");
|
|
1194
|
-
this._selectedRobotId = e
|
|
1283
|
+
this._selectedRobotId = e;
|
|
1284
|
+
const t = O(this._robots.find((n) => n.id === e));
|
|
1285
|
+
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 = [];
|
|
1195
1286
|
try {
|
|
1196
|
-
const
|
|
1197
|
-
if (!
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1287
|
+
const n = window, i = n.AudioContext ?? n.webkitAudioContext;
|
|
1288
|
+
if (!i) throw new Error("AudioContext not supported");
|
|
1289
|
+
this._releaseMicPlaceholder();
|
|
1290
|
+
const r = new i();
|
|
1291
|
+
this._micCtx = r;
|
|
1292
|
+
const o = r.createMediaStreamDestination(), a = r.createOscillator(), c = r.createGain();
|
|
1293
|
+
c.gain.value = 0, a.connect(c).connect(o), a.start();
|
|
1294
|
+
const l = o.stream;
|
|
1295
|
+
l.getAudioTracks().forEach((d) => {
|
|
1202
1296
|
d.enabled = !1;
|
|
1203
|
-
}), this._micStream =
|
|
1204
|
-
} catch (
|
|
1205
|
-
_.warn("audio sender placeholder setup failed:",
|
|
1297
|
+
}), this._micStream = l, this._micMuted = !0;
|
|
1298
|
+
} catch (n) {
|
|
1299
|
+
_.warn("audio sender placeholder setup failed:", n), this._micStream = null;
|
|
1206
1300
|
}
|
|
1207
1301
|
return this._pc = new RTCPeerConnection({
|
|
1208
1302
|
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
|
1209
|
-
}), this._supervisor.installNetworkListeners(), new Promise((
|
|
1210
|
-
this._sessionResolve =
|
|
1211
|
-
if (
|
|
1212
|
-
const
|
|
1303
|
+
}), this._supervisor.installNetworkListeners(), new Promise((n, i) => {
|
|
1304
|
+
this._sessionResolve = n, this._sessionReject = i, this._pc.ontrack = (o) => {
|
|
1305
|
+
if (o.track.kind === "video") {
|
|
1306
|
+
const a = this._videoJitterBufferTargetMs;
|
|
1213
1307
|
try {
|
|
1214
|
-
|
|
1308
|
+
o.receiver.jitterBufferTarget = a;
|
|
1215
1309
|
} catch {
|
|
1216
1310
|
}
|
|
1217
1311
|
try {
|
|
1218
|
-
|
|
1312
|
+
o.receiver.playoutDelayHint = a / 1e3;
|
|
1219
1313
|
} catch {
|
|
1220
1314
|
}
|
|
1221
|
-
this._emit("videoTrack", { track:
|
|
1222
|
-
}
|
|
1223
|
-
}, this._pc.onicecandidate = async (
|
|
1224
|
-
|
|
1315
|
+
this._emit("videoTrack", { track: o.track, stream: o.streams[0] });
|
|
1316
|
+
} else o.track.kind === "audio" && (this._robotAudioTrack = o.track, this._emit("audioTrack", { track: o.track, stream: o.streams[0] }));
|
|
1317
|
+
}, this._pc.onicecandidate = async (o) => {
|
|
1318
|
+
o.candidate && this._sessionId && await this._sendToServer({
|
|
1225
1319
|
type: "peer",
|
|
1226
1320
|
sessionId: this._sessionId,
|
|
1227
1321
|
ice: {
|
|
1228
|
-
candidate:
|
|
1229
|
-
sdpMLineIndex:
|
|
1230
|
-
sdpMid:
|
|
1322
|
+
candidate: o.candidate.candidate,
|
|
1323
|
+
sdpMLineIndex: o.candidate.sdpMLineIndex,
|
|
1324
|
+
sdpMid: o.candidate.sdpMid
|
|
1231
1325
|
}
|
|
1232
1326
|
});
|
|
1233
1327
|
}, this._pc.oniceconnectionstatechange = () => {
|
|
1234
|
-
const
|
|
1235
|
-
if (
|
|
1236
|
-
if (this._emit("iceStateChange", { state:
|
|
1328
|
+
const o = this._pc?.iceConnectionState;
|
|
1329
|
+
if (o) {
|
|
1330
|
+
if (this._emit("iceStateChange", { state: o }), o === "connected" || o === "completed") {
|
|
1237
1331
|
this._supervisor.onIceHealed(), this._iceConnected = !0, this._checkSessionReady();
|
|
1238
1332
|
return;
|
|
1239
1333
|
}
|
|
1240
|
-
if (
|
|
1334
|
+
if (o === "disconnected") {
|
|
1241
1335
|
this._supervisor.onIceDisconnected();
|
|
1242
1336
|
return;
|
|
1243
1337
|
}
|
|
1244
|
-
if (
|
|
1338
|
+
if (o === "failed") {
|
|
1245
1339
|
this._supervisor.onIceFailed();
|
|
1246
1340
|
return;
|
|
1247
1341
|
}
|
|
1248
1342
|
}
|
|
1249
|
-
}, this._pc.ondatachannel = (
|
|
1250
|
-
const
|
|
1251
|
-
if (
|
|
1252
|
-
this._lastPoseSeq = null,
|
|
1253
|
-
const
|
|
1254
|
-
if (typeof
|
|
1255
|
-
if (this._lastPoseSeq !== null &&
|
|
1256
|
-
this._lastPoseSeq =
|
|
1343
|
+
}, this._pc.ondatachannel = (o) => {
|
|
1344
|
+
const a = o.channel;
|
|
1345
|
+
if (a.label === "pose") {
|
|
1346
|
+
this._lastPoseSeq = null, a.onmessage = (l) => {
|
|
1347
|
+
const d = JSON.parse(l.data);
|
|
1348
|
+
if (typeof d.seq == "number") {
|
|
1349
|
+
if (this._lastPoseSeq !== null && d.seq <= this._lastPoseSeq) return;
|
|
1350
|
+
this._lastPoseSeq = d.seq;
|
|
1257
1351
|
}
|
|
1258
|
-
this._lastPoseFrameAt = Date.now(), this._handleRobotMessage(
|
|
1352
|
+
this._lastPoseFrameAt = Date.now(), this._handleRobotMessage(d, !0);
|
|
1259
1353
|
};
|
|
1260
1354
|
return;
|
|
1261
1355
|
}
|
|
1262
|
-
this._dc =
|
|
1356
|
+
this._dc = a, this._dc.onopen = () => {
|
|
1263
1357
|
this._dcOpen = !0, this._checkSessionReady();
|
|
1264
1358
|
};
|
|
1265
|
-
const
|
|
1266
|
-
this._dc.onmessage = (
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1359
|
+
const c = new fe();
|
|
1360
|
+
this._dc.onmessage = (l) => {
|
|
1361
|
+
const d = c.accept(JSON.parse(l.data));
|
|
1362
|
+
d && this._handleRobotMessage(d);
|
|
1363
|
+
}, a.onclose = () => {
|
|
1364
|
+
if (this._dc !== a || this._state !== "streaming") return;
|
|
1365
|
+
const l = this._pc?.iceConnectionState;
|
|
1366
|
+
l !== "connected" && l !== "completed" || (_.info("robot closed the session"), this._endedByRobot("remote_end", null));
|
|
1269
1367
|
};
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1368
|
+
};
|
|
1369
|
+
const r = this._pc;
|
|
1370
|
+
this._sendToServer({ type: "startSession", peerId: e }).then((o) => {
|
|
1371
|
+
if (this._pc !== r) {
|
|
1372
|
+
o?.sessionId && (this._sessionId === o.sessionId && (this._sessionId = null), this._retireSession(o.sessionId), this._sendToServer({ type: "endSession", sessionId: o.sessionId, reason: "client_stop" }));
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
if (o?.type === "sessionRejected") {
|
|
1376
|
+
this._failSessionRejected(o);
|
|
1273
1377
|
return;
|
|
1274
1378
|
}
|
|
1275
|
-
|
|
1379
|
+
if (o?.sessionId) {
|
|
1380
|
+
this._sessionId = o.sessionId;
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
if (o === null && this._sessionReject) {
|
|
1384
|
+
const a = this._closeTransport(new Error("Could not reach central to start the session"));
|
|
1385
|
+
a && this._sendToServer({ type: "endSession", sessionId: a, reason: "client_stop" });
|
|
1386
|
+
} else o?.type === "error" && this._sessionReject && this._closeTransport(new Error(`Central refused the session: ${o.message ?? "error"}`));
|
|
1276
1387
|
});
|
|
1277
1388
|
});
|
|
1278
1389
|
}
|
|
@@ -1292,9 +1403,27 @@ class Be extends EventTarget {
|
|
|
1292
1403
|
const n = this._sessionReject;
|
|
1293
1404
|
this._sessionResolve = null, this._sessionReject = null, n(e);
|
|
1294
1405
|
}
|
|
1295
|
-
this._sessionResolve = null, this._supervisor.clearIceGrace(), this._supervisor.uninstallNetworkListeners(), this._supervisor.stopDcWatchdog(), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this.
|
|
1406
|
+
this._sessionResolve = null, this._supervisor.clearIceGrace(), this._supervisor.uninstallNetworkListeners(), this._supervisor.stopDcWatchdog(), this._stateRefreshInterval && (clearInterval(this._stateRefreshInterval), this._stateRefreshInterval = null), this._latencyMonitorId && (clearInterval(this._latencyMonitorId), this._latencyMonitorId = null), this._releaseMicPlaceholder(), this._robotAudioTrack = null, this._micMuted = !0, this._micSupported = !1, this._pc && (this._pc.close(), this._pc = null), this._dc && (this._dc.close(), this._dc = null), this._iceConnected = !1, this._dcOpen = !1;
|
|
1296
1407
|
const t = this._sessionId;
|
|
1297
|
-
return this._sessionId = null, t;
|
|
1408
|
+
return this._sessionId = null, this._retireSession(t), this._retireSession(this._staleSessionId), this._staleSessionId = null, t;
|
|
1409
|
+
}
|
|
1410
|
+
_retireSession(e) {
|
|
1411
|
+
if (e && (this._retiredSessionIds.add(e), this._retiredSessionIds.size > Ne)) {
|
|
1412
|
+
const t = this._retiredSessionIds.values().next().value;
|
|
1413
|
+
t !== void 0 && this._retiredSessionIds.delete(t);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether an endSession is about another session than ours: one we
|
|
1418
|
+
* already closed (a re-dial's old session, ended late by the robot as
|
|
1419
|
+
* superseded), or any id but the current one. With no id known yet
|
|
1420
|
+
* (startSession in flight) it is ours: rejections arrive that way.
|
|
1421
|
+
*/
|
|
1422
|
+
_isOtherSession(e) {
|
|
1423
|
+
if (!e) return !1;
|
|
1424
|
+
if (this._retiredSessionIds.has(e)) return !0;
|
|
1425
|
+
const t = this._sessionId ?? this._staleSessionId;
|
|
1426
|
+
return t !== null && e !== t;
|
|
1298
1427
|
}
|
|
1299
1428
|
_failSessionRejected(e) {
|
|
1300
1429
|
const t = new Error(
|
|
@@ -1303,14 +1432,14 @@ class Be extends EventTarget {
|
|
|
1303
1432
|
t.reason = e.reason ?? null, t.activeApp = e.activeApp ?? null, this._closeTransport(t), this._supervisor.redialing || this._emit("sessionRejected", { reason: e.reason, activeApp: e.activeApp });
|
|
1304
1433
|
}
|
|
1305
1434
|
async stopSession() {
|
|
1306
|
-
this._supervisor.cancelRedial(), this._logSubscribers.clear(), this._updateProgressSubscribers.clear();
|
|
1435
|
+
this._supervisor.cancelRedial(), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._outgoingAudioTrack = null;
|
|
1307
1436
|
const e = this._closeTransport(new Error("Session stopped"));
|
|
1308
|
-
e && await this._sendToServer({ type: "endSession", sessionId: e }), this._state === "streaming" && (this._state = "connected", this._emit("sessionStopped", { reason: "user" }));
|
|
1437
|
+
e && await this._sendToServer({ type: "endSession", sessionId: e, reason: "client_stop" }), this._state === "streaming" && (this._state = "connected", this._emit("sessionStopped", { reason: "user" })), this._dropToDisconnectedIfSignalingDown();
|
|
1309
1438
|
}
|
|
1310
1439
|
disconnect() {
|
|
1311
|
-
this._supervisor.cancelRedial(), this._sseAbortController && (this._sseAbortController.abort(), this._sseAbortController = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear();
|
|
1440
|
+
this._supervisor.cancelRedial(), this._sseAbortController && (this._sseAbortController.abort(), this._sseAbortController = null), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._outgoingAudioTrack = null, this._clearSignalingRetry(), this._signalingDown = !1;
|
|
1312
1441
|
const e = this._closeTransport(new Error("Disconnected"));
|
|
1313
|
-
e && this._token && this._sendToServer({ type: "endSession", sessionId: e }), this._robots = [], this._state = "disconnected", this._emit("disconnected", { reason: "user" });
|
|
1442
|
+
e && this._token && this._sendToServer({ type: "endSession", sessionId: e, reason: "client_disconnect" }), this._robots = [], this._state = "disconnected", this._emit("disconnected", { reason: "user" });
|
|
1314
1443
|
}
|
|
1315
1444
|
// ─── Resilience: supervisor delegation ───────────────────────────────
|
|
1316
1445
|
// The policy lives in `session-supervisor.ts`; only the transport
|
|
@@ -1343,9 +1472,67 @@ class Be extends EventTarget {
|
|
|
1343
1472
|
* armed, and a late signaling reply could otherwise settle them
|
|
1344
1473
|
* against a closed pc).
|
|
1345
1474
|
*/
|
|
1475
|
+
/**
|
|
1476
|
+
* Resolver for the redial loop. Matches on the robot's stable
|
|
1477
|
+
* identity (`install_id`, else `hardware_id`; never the name, which
|
|
1478
|
+
* users often leave at the default and share across robots). A
|
|
1479
|
+
* listed robot with that identity under a NEW id is the same robot,
|
|
1480
|
+
* re-registered; otherwise keep dialing the original id.
|
|
1481
|
+
*/
|
|
1482
|
+
_redialTargetResolver(e) {
|
|
1483
|
+
const t = (this._dialedRobotId === e ? this._dialedRobotIdentity : null) ?? O(this._robots.find((n) => n.id === e));
|
|
1484
|
+
return t ? () => this._robots.find((n) => n.id !== e && O(n) === t)?.id ?? e : () => e;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Stop the placeholder sender track AND close its AudioContext.
|
|
1488
|
+
* Stopping the track alone left the context (and its oscillator)
|
|
1489
|
+
* running: one leaked context per dial, and browsers cap open audio
|
|
1490
|
+
* outputs (Chromium: 10 per page), so after a few re-dials every
|
|
1491
|
+
* new AudioContext in the host app fails silently.
|
|
1492
|
+
*/
|
|
1493
|
+
_releaseMicPlaceholder() {
|
|
1494
|
+
this._micStream && (this._micStream.getTracks().forEach((t) => t.stop()), this._micStream = null);
|
|
1495
|
+
const e = this._micCtx;
|
|
1496
|
+
this._micCtx = null, e && e.state !== "closed" && e.close().catch(() => {
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1346
1499
|
_teardownForRedial() {
|
|
1347
1500
|
const e = this._closeTransport(new Error("Session reconnecting"));
|
|
1348
|
-
e && this._token && this._sendToServer({ type: "endSession", sessionId: e }), this._state === "streaming" && (this._state = "connected");
|
|
1501
|
+
e && this._token && this._sendToServer({ type: "endSession", sessionId: e, reason: "client_redial" }), this._state === "streaming" && (this._state = "connected"), this._signalingDown && (this._clearSignalingRetry(), this._signalingDown = !1, this._state = "disconnected");
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* The robot (or central on its behalf) ended a streaming session:
|
|
1505
|
+
* tear our side down and emit ONE `sessionStopped` carrying the
|
|
1506
|
+
* robot's reason (`stopSession()` would add a second, `user`, one).
|
|
1507
|
+
* No endSession goes back: the other side already ended it.
|
|
1508
|
+
*/
|
|
1509
|
+
_endedByRobot(e, t) {
|
|
1510
|
+
this._supervisor.cancelRedial(), this._logSubscribers.clear(), this._updateProgressSubscribers.clear(), this._outgoingAudioTrack = null, this._closeTransport(new Error("Session ended by the robot")), this._state === "streaming" && (this._state = "connected"), this._emit("sessionStopped", { reason: e, message: t }), this._dropToDisconnectedIfSignalingDown();
|
|
1511
|
+
}
|
|
1512
|
+
/** Session over while signaling is down: surface the real state. */
|
|
1513
|
+
_dropToDisconnectedIfSignalingDown() {
|
|
1514
|
+
this._signalingDown && (this._clearSignalingRetry(), this._signalingDown = !1, this._state !== "disconnected" && (this._state = "disconnected", this._emit("disconnected", { reason: "SSE closed" })));
|
|
1515
|
+
}
|
|
1516
|
+
_clearSignalingRetry() {
|
|
1517
|
+
this._signalingRetryTimer !== null && (clearTimeout(this._signalingRetryTimer), this._signalingRetryTimer = null), this._signalingDown && this._sseAbortController && (this._sseAbortController.abort(), this._sseAbortController = null), this._signalingRetryAttempt = 0;
|
|
1518
|
+
}
|
|
1519
|
+
/** Background signaling reconnect while a session keeps streaming. */
|
|
1520
|
+
_scheduleSignalingRetry() {
|
|
1521
|
+
if (this._signalingRetryTimer !== null) return;
|
|
1522
|
+
const e = [1e3, 2e3, 4e3, 8e3, 15e3], t = e[Math.min(this._signalingRetryAttempt, e.length - 1)];
|
|
1523
|
+
this._signalingRetryAttempt += 1, this._signalingRetryTimer = setTimeout(() => {
|
|
1524
|
+
this._signalingRetryTimer = null, !(!this._signalingDown || this._state !== "streaming") && this._openSignaling().catch(() => {
|
|
1525
|
+
this._signalingDown && this._state === "streaming" && this._scheduleSignalingRetry();
|
|
1526
|
+
});
|
|
1527
|
+
}, t);
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Liveness of the peer link itself: data channel open, ICE up, and the
|
|
1531
|
+
* robot heard from recently (it answers the ~500 ms state poll).
|
|
1532
|
+
*/
|
|
1533
|
+
_peerLinkLive() {
|
|
1534
|
+
const e = this._pc?.iceConnectionState;
|
|
1535
|
+
return this._dcOpen && this._dc?.readyState === "open" && (e === "connected" || e === "completed") && this._supervisor.dcInboundAgeMs < Pe;
|
|
1349
1536
|
}
|
|
1350
1537
|
// ─── Commands ────────────────────────────────────────────────────────
|
|
1351
1538
|
/**
|
|
@@ -1392,67 +1579,67 @@ class Be extends EventTarget {
|
|
|
1392
1579
|
* `false` if the channel is not open.
|
|
1393
1580
|
*/
|
|
1394
1581
|
setTarget({ head: e, antennas: t, body_yaw: n } = {}) {
|
|
1395
|
-
const
|
|
1582
|
+
const i = { type: "set_full_target" };
|
|
1396
1583
|
if (e !== void 0) {
|
|
1397
|
-
if (!Array.isArray(e) || e.length !== 16 || !e.every((
|
|
1584
|
+
if (!Array.isArray(e) || e.length !== 16 || !e.every((r) => Number.isFinite(r)))
|
|
1398
1585
|
throw new TypeError(
|
|
1399
1586
|
`setTarget: head must be a 16-element flat row-major 4×4 matrix of finite numbers; got ${Array.isArray(e) ? `Array(${e.length})` : typeof e}`
|
|
1400
1587
|
);
|
|
1401
|
-
|
|
1588
|
+
i.head = e;
|
|
1402
1589
|
}
|
|
1403
1590
|
if (t !== void 0) {
|
|
1404
|
-
if (!Array.isArray(t) || t.length !== 2 || !t.every((
|
|
1591
|
+
if (!Array.isArray(t) || t.length !== 2 || !t.every((r) => Number.isFinite(r)))
|
|
1405
1592
|
throw new TypeError(
|
|
1406
1593
|
`setTarget: antennas must be [rightRad, leftRad] (2 finite numbers); got ${Array.isArray(t) ? `Array(${t.length})` : typeof t}`
|
|
1407
1594
|
);
|
|
1408
|
-
|
|
1595
|
+
i.antennas = t;
|
|
1409
1596
|
}
|
|
1410
1597
|
if (n !== void 0) {
|
|
1411
1598
|
if (!Number.isFinite(n))
|
|
1412
1599
|
throw new TypeError(
|
|
1413
1600
|
`setTarget: body_yaw must be a finite number (radians); got ${n}`
|
|
1414
1601
|
);
|
|
1415
|
-
|
|
1602
|
+
i.body_yaw = n;
|
|
1416
1603
|
}
|
|
1417
|
-
return this._sendCommand(
|
|
1604
|
+
return this._sendCommand(i);
|
|
1418
1605
|
}
|
|
1419
|
-
gotoTarget({ head: e, antennas: t, body_yaw: n, duration:
|
|
1420
|
-
const
|
|
1606
|
+
gotoTarget({ head: e, antennas: t, body_yaw: n, duration: i }) {
|
|
1607
|
+
const r = { type: "goto_target" };
|
|
1421
1608
|
if (e !== void 0) {
|
|
1422
1609
|
if (!Array.isArray(e) || e.length !== 16 || !e.every((o) => Number.isFinite(o)))
|
|
1423
1610
|
throw new TypeError(
|
|
1424
1611
|
`gotoTarget: head must be a 16-element flat row-major 4×4 matrix of finite numbers; got ${Array.isArray(e) ? `Array(${e.length})` : typeof e}`
|
|
1425
1612
|
);
|
|
1426
|
-
|
|
1613
|
+
r.head = e;
|
|
1427
1614
|
}
|
|
1428
1615
|
if (t !== void 0) {
|
|
1429
1616
|
if (!Array.isArray(t) || t.length !== 2 || !t.every((o) => Number.isFinite(o)))
|
|
1430
1617
|
throw new TypeError(
|
|
1431
1618
|
`gotoTarget: antennas must be [rightRad, leftRad] (2 finite numbers); got ${Array.isArray(t) ? `Array(${t.length})` : typeof t}`
|
|
1432
1619
|
);
|
|
1433
|
-
|
|
1620
|
+
r.antennas = t;
|
|
1434
1621
|
}
|
|
1435
1622
|
if (n !== void 0) {
|
|
1436
1623
|
if (!Number.isFinite(n))
|
|
1437
1624
|
throw new TypeError(
|
|
1438
1625
|
`gotoTarget: body_yaw must be a finite number (radians); got ${n}`
|
|
1439
1626
|
);
|
|
1440
|
-
|
|
1627
|
+
r.body_yaw = n;
|
|
1441
1628
|
}
|
|
1442
|
-
if (!Number.isFinite(
|
|
1629
|
+
if (!Number.isFinite(i) || i <= 0)
|
|
1443
1630
|
throw new TypeError(
|
|
1444
|
-
`gotoTarget: duration must be a positive finite number (seconds); got ${
|
|
1631
|
+
`gotoTarget: duration must be a positive finite number (seconds); got ${i}`
|
|
1445
1632
|
);
|
|
1446
|
-
return
|
|
1633
|
+
return r.duration = i, this._sendCommand(r);
|
|
1447
1634
|
}
|
|
1448
1635
|
setHeadRpyDeg(e, t, n) {
|
|
1449
|
-
return this.setTarget({ head:
|
|
1636
|
+
return this.setTarget({ head: _e(e, t, n).flat() });
|
|
1450
1637
|
}
|
|
1451
1638
|
setAntennasDeg(e, t) {
|
|
1452
|
-
return this.setTarget({ antennas: [
|
|
1639
|
+
return this.setTarget({ antennas: [k(e), k(t)] });
|
|
1453
1640
|
}
|
|
1454
1641
|
setBodyYawDeg(e) {
|
|
1455
|
-
return this.setTarget({ body_yaw:
|
|
1642
|
+
return this.setTarget({ body_yaw: k(e) });
|
|
1456
1643
|
}
|
|
1457
1644
|
playSound(e) {
|
|
1458
1645
|
return this._sendCommand({ type: "play_sound", file: e });
|
|
@@ -1556,10 +1743,10 @@ class Be extends EventTarget {
|
|
|
1556
1743
|
}
|
|
1557
1744
|
async ensureAwake(e = 1e3) {
|
|
1558
1745
|
if (this._robotState?.motor_mode === void 0 && await new Promise((n) => {
|
|
1559
|
-
const
|
|
1560
|
-
this.removeEventListener("state",
|
|
1561
|
-
},
|
|
1562
|
-
this.addEventListener("state",
|
|
1746
|
+
const i = () => {
|
|
1747
|
+
this.removeEventListener("state", i), clearTimeout(r), n();
|
|
1748
|
+
}, r = setTimeout(i, e);
|
|
1749
|
+
this.addEventListener("state", i), this.requestState();
|
|
1563
1750
|
}), this._robotState?.motor_mode === "gravity_compensation")
|
|
1564
1751
|
return _.info("ensureAwake: gravity compensation inherited, flipping to enabled (no emote)"), this.setMotorMode("enabled"), this.requestState(), !0;
|
|
1565
1752
|
if (this.isAwake())
|
|
@@ -1567,7 +1754,7 @@ class Be extends EventTarget {
|
|
|
1567
1754
|
_.info(`ensureAwake: robot asleep (motor_mode=${this._robotState?.motor_mode ?? "unknown"}), playing wake-up`);
|
|
1568
1755
|
const t = Date.now();
|
|
1569
1756
|
try {
|
|
1570
|
-
await this.wakeUp({ timeoutMs:
|
|
1757
|
+
await this.wakeUp({ timeoutMs: We }), _.info(`ensureAwake: wake-up trajectory done in ${Date.now() - t}ms`);
|
|
1571
1758
|
} catch (n) {
|
|
1572
1759
|
_.warn(`ensureAwake: wake-up not confirmed after ${Date.now() - t}ms (continuing):`, n);
|
|
1573
1760
|
}
|
|
@@ -1596,13 +1783,13 @@ class Be extends EventTarget {
|
|
|
1596
1783
|
return this._slotRoundtrip("volume", { type: "get_volume" });
|
|
1597
1784
|
}
|
|
1598
1785
|
setVolume(e) {
|
|
1599
|
-
return this._slotRoundtrip("volume", { type: "set_volume", volume:
|
|
1786
|
+
return this._slotRoundtrip("volume", { type: "set_volume", volume: X(e) });
|
|
1600
1787
|
}
|
|
1601
1788
|
getMicrophoneVolume() {
|
|
1602
1789
|
return this._slotRoundtrip("mic_volume", { type: "get_microphone_volume" });
|
|
1603
1790
|
}
|
|
1604
1791
|
setMicrophoneVolume(e) {
|
|
1605
|
-
return this._slotRoundtrip("mic_volume", { type: "set_microphone_volume", volume:
|
|
1792
|
+
return this._slotRoundtrip("mic_volume", { type: "set_microphone_volume", volume: X(e) });
|
|
1606
1793
|
}
|
|
1607
1794
|
/**
|
|
1608
1795
|
* Query whether the first wake-up setup wizard has been completed.
|
|
@@ -1639,6 +1826,20 @@ class Be extends EventTarget {
|
|
|
1639
1826
|
setRobotName(e) {
|
|
1640
1827
|
return this._slotRoundtrip("robot_name", { type: "set_robot_name", name: e });
|
|
1641
1828
|
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Read the robot's anonymous telemetry choice. Resolves `null` when the
|
|
1831
|
+
* channel isn't open or the daemon predates the `get_telemetry` command.
|
|
1832
|
+
*/
|
|
1833
|
+
getTelemetry() {
|
|
1834
|
+
return this._slotRoundtrip("telemetry", { type: "get_telemetry" });
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Enable or disable telemetry on the robot, applied live. Disabling also
|
|
1838
|
+
* forgets the robot id. Resolves the stored choice, or `null` on error.
|
|
1839
|
+
*/
|
|
1840
|
+
setTelemetry(e) {
|
|
1841
|
+
return this._slotRoundtrip("set_telemetry", { type: "set_telemetry", enabled: e });
|
|
1842
|
+
}
|
|
1642
1843
|
/**
|
|
1643
1844
|
* Sign this robot out of Hugging Face: asks the daemon to delete its
|
|
1644
1845
|
* stored HF token, which de-registers the robot from the central
|
|
@@ -1695,23 +1896,23 @@ class Be extends EventTarget {
|
|
|
1695
1896
|
* reach this matcher - use the typed wrappers for those. Pass `match`
|
|
1696
1897
|
* for replies that don't follow the `command` echo convention.
|
|
1697
1898
|
*/
|
|
1698
|
-
request(e, { timeoutMs: t =
|
|
1899
|
+
request(e, { timeoutMs: t = ne, match: n } = {}) {
|
|
1699
1900
|
if (!this._sendCommand(e))
|
|
1700
1901
|
return Promise.reject(new Error("Data channel not open"));
|
|
1701
|
-
const
|
|
1702
|
-
return this._pending.awaitBroadcast(
|
|
1703
|
-
if (
|
|
1704
|
-
throw
|
|
1902
|
+
const i = n ?? ((r) => r.command === e.type);
|
|
1903
|
+
return this._pending.awaitBroadcast(i, { timeoutMs: t, debugLabel: `request(${e.type})` }).catch((r) => {
|
|
1904
|
+
if (r instanceof P) return null;
|
|
1905
|
+
throw r;
|
|
1705
1906
|
});
|
|
1706
1907
|
}
|
|
1707
1908
|
subscribeLogs({ onLine: e, onError: t }) {
|
|
1708
1909
|
if (typeof e != "function")
|
|
1709
1910
|
throw new TypeError("subscribeLogs: onLine callback is required");
|
|
1710
|
-
const n = { onLine: e, onError: t },
|
|
1711
|
-
this._logSubscribers.add(n),
|
|
1712
|
-
let
|
|
1911
|
+
const n = { onLine: e, onError: t }, i = this._logSubscribers.size === 0;
|
|
1912
|
+
this._logSubscribers.add(n), i && this._sendCommand({ type: "subscribe_logs" });
|
|
1913
|
+
let r = !1;
|
|
1713
1914
|
return () => {
|
|
1714
|
-
|
|
1915
|
+
r || (r = !0, this._logSubscribers.delete(n), this._logSubscribers.size === 0 && this._sendCommand({ type: "unsubscribe_logs" }));
|
|
1715
1916
|
};
|
|
1716
1917
|
}
|
|
1717
1918
|
requestState() {
|
|
@@ -1745,12 +1946,37 @@ class Be extends EventTarget {
|
|
|
1745
1946
|
t.enabled = !e;
|
|
1746
1947
|
});
|
|
1747
1948
|
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Stream an audio track to the robot's speaker in real time (TTS output,
|
|
1951
|
+
* a WebAudio graph, the user's own mic for teleop…). Pass `null` to go
|
|
1952
|
+
* back to silence. The track survives auto-reconnects; the app keeps
|
|
1953
|
+
* ownership of it (the SDK never stops it).
|
|
1954
|
+
*
|
|
1955
|
+
* Resolves `true` once the track is on the wire, `false` when there is
|
|
1956
|
+
* no live session yet (it is then applied as soon as one starts) or when
|
|
1957
|
+
* the robot didn't offer two-way audio. Cleared by `stopSession()` /
|
|
1958
|
+
* `disconnect()`. `setMicMuted()` only mutes the SDK's placeholder, not
|
|
1959
|
+
* this track — stop or disable the track itself to go quiet.
|
|
1960
|
+
* For clips that must stay in sync with motion, prefer
|
|
1961
|
+
* `playMove(motion, { audioBlob })` or `uploadAudio` + `playUploadedAudio`.
|
|
1962
|
+
*/
|
|
1963
|
+
async setOutgoingAudioTrack(e) {
|
|
1964
|
+
if (e && e.kind !== "audio")
|
|
1965
|
+
throw new TypeError(`setOutgoingAudioTrack: expected an audio track, got "${e.kind}"`);
|
|
1966
|
+
return this._outgoingAudioTrack = e, this._applyOutgoingAudioTrack();
|
|
1967
|
+
}
|
|
1968
|
+
async _applyOutgoingAudioTrack() {
|
|
1969
|
+
const e = this._pc?.getTransceivers().find((n) => n.receiver.track.kind === "audio")?.sender;
|
|
1970
|
+
if (!e || !this._micSupported) return !1;
|
|
1971
|
+
const t = this._micStream?.getAudioTracks()[0] ?? null;
|
|
1972
|
+
return await e.replaceTrack(this._outgoingAudioTrack ?? t), !0;
|
|
1973
|
+
}
|
|
1748
1974
|
// ─── Video helper ────────────────────────────────────────────────────
|
|
1749
1975
|
attachVideo(e) {
|
|
1750
1976
|
this._videoElement = e, e.muted = this._audioMuted;
|
|
1751
|
-
const t = (
|
|
1752
|
-
const
|
|
1753
|
-
e.srcObject =
|
|
1977
|
+
const t = (i) => {
|
|
1978
|
+
const r = i;
|
|
1979
|
+
e.srcObject = r.detail.stream, e.playsInline = !0, "requestVideoFrameCallback" in e && this._startLatencyMonitor(e);
|
|
1754
1980
|
}, n = () => {
|
|
1755
1981
|
e.srcObject = null;
|
|
1756
1982
|
};
|
|
@@ -1762,90 +1988,90 @@ class Be extends EventTarget {
|
|
|
1762
1988
|
async playMove(e, {
|
|
1763
1989
|
audioBlob: t = null,
|
|
1764
1990
|
audioLeadMs: n = -100,
|
|
1765
|
-
description:
|
|
1766
|
-
encoding:
|
|
1991
|
+
description: i = "move",
|
|
1992
|
+
encoding: r = "gzip+base64",
|
|
1767
1993
|
playFrequency: o = 100,
|
|
1768
1994
|
initialGotoDuration: a = 0,
|
|
1769
1995
|
startTimeoutMs: c = 8e3,
|
|
1770
|
-
onProgress:
|
|
1996
|
+
onProgress: l = () => {
|
|
1771
1997
|
},
|
|
1772
|
-
onStarted:
|
|
1998
|
+
onStarted: d = () => {
|
|
1773
1999
|
}
|
|
1774
2000
|
} = {}) {
|
|
1775
2001
|
if (!this._dc || this._dc.readyState !== "open")
|
|
1776
2002
|
throw new Error("data channel not open");
|
|
1777
2003
|
if (!e?.time?.length || !e?.set_target_data?.length)
|
|
1778
2004
|
throw new Error("playMove: motion must have time + set_target_data");
|
|
1779
|
-
const
|
|
1780
|
-
this._activeMoveUploadId =
|
|
1781
|
-
const
|
|
1782
|
-
description:
|
|
2005
|
+
const u = Y();
|
|
2006
|
+
this._activeMoveUploadId = u;
|
|
2007
|
+
const b = {
|
|
2008
|
+
description: i,
|
|
1783
2009
|
time: e.time,
|
|
1784
2010
|
set_target_data: e.set_target_data
|
|
1785
|
-
},
|
|
1786
|
-
let
|
|
1787
|
-
|
|
1788
|
-
const w = Math.ceil(
|
|
1789
|
-
|
|
2011
|
+
}, S = JSON.stringify(b);
|
|
2012
|
+
let m, g;
|
|
2013
|
+
r === "gzip+base64" && Ue() ? (m = await Oe(S), g = "gzip+base64") : (m = S, g = "json");
|
|
2014
|
+
const w = Math.ceil(m.length / R) || 1;
|
|
2015
|
+
l({
|
|
1790
2016
|
phase: "starting",
|
|
1791
2017
|
sent: 0,
|
|
1792
2018
|
total: w,
|
|
1793
|
-
bytes:
|
|
1794
|
-
encoding:
|
|
2019
|
+
bytes: m.length,
|
|
2020
|
+
encoding: g
|
|
1795
2021
|
}), this._sendCommand({
|
|
1796
2022
|
type: "upload_move_start",
|
|
1797
|
-
upload_id:
|
|
2023
|
+
upload_id: u,
|
|
1798
2024
|
total_chunks: w,
|
|
1799
|
-
description:
|
|
1800
|
-
encoding:
|
|
2025
|
+
description: i,
|
|
2026
|
+
encoding: g
|
|
1801
2027
|
});
|
|
1802
2028
|
for (let h = 0; h < w; h++) {
|
|
1803
|
-
this._dc.bufferedAmount >
|
|
1804
|
-
const
|
|
2029
|
+
this._dc.bufferedAmount > U && await this._awaitDataChannelDrain();
|
|
2030
|
+
const f = h * R;
|
|
1805
2031
|
this._sendCommand({
|
|
1806
2032
|
type: "upload_move_chunk",
|
|
1807
|
-
upload_id:
|
|
2033
|
+
upload_id: u,
|
|
1808
2034
|
chunk_index: h,
|
|
1809
|
-
chunk:
|
|
1810
|
-
}),
|
|
2035
|
+
chunk: m.slice(f, f + R)
|
|
2036
|
+
}), l({ phase: "upload", sent: h + 1, total: w });
|
|
1811
2037
|
}
|
|
1812
|
-
if (this._sendCommand({ type: "upload_move_finish", upload_id:
|
|
1813
|
-
const h = new Uint8Array(await t.arrayBuffer()),
|
|
1814
|
-
|
|
2038
|
+
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 = $(h), y = Math.ceil(f.length / R) || 1;
|
|
2040
|
+
l({
|
|
1815
2041
|
phase: "audio-starting",
|
|
1816
2042
|
sent: 0,
|
|
1817
|
-
total:
|
|
1818
|
-
bytes:
|
|
2043
|
+
total: y,
|
|
2044
|
+
bytes: f.length
|
|
1819
2045
|
}), this._sendCommand({
|
|
1820
2046
|
type: "upload_audio_start",
|
|
1821
|
-
upload_id:
|
|
1822
|
-
total_chunks:
|
|
1823
|
-
encoding:
|
|
1824
|
-
description:
|
|
2047
|
+
upload_id: u,
|
|
2048
|
+
total_chunks: y,
|
|
2049
|
+
encoding: Q(t),
|
|
2050
|
+
description: i
|
|
1825
2051
|
});
|
|
1826
|
-
for (let T = 0; T <
|
|
1827
|
-
this._dc.bufferedAmount >
|
|
1828
|
-
const
|
|
2052
|
+
for (let T = 0; T < y; T++) {
|
|
2053
|
+
this._dc.bufferedAmount > U && await this._awaitDataChannelDrain();
|
|
2054
|
+
const B = T * R;
|
|
1829
2055
|
this._sendCommand({
|
|
1830
2056
|
type: "upload_audio_chunk",
|
|
1831
|
-
upload_id:
|
|
2057
|
+
upload_id: u,
|
|
1832
2058
|
chunk_index: T,
|
|
1833
|
-
chunk:
|
|
1834
|
-
}),
|
|
2059
|
+
chunk: f.slice(B, B + R)
|
|
2060
|
+
}), l({ phase: "audio-upload", sent: T + 1, total: y });
|
|
1835
2061
|
}
|
|
1836
|
-
this._sendCommand({ type: "upload_audio_finish", upload_id:
|
|
2062
|
+
this._sendCommand({ type: "upload_audio_finish", upload_id: u }), l({ phase: "audio-uploaded", sent: y, total: y });
|
|
1837
2063
|
}
|
|
1838
2064
|
this._sendCommand({
|
|
1839
2065
|
type: "play_uploaded_move",
|
|
1840
|
-
upload_id:
|
|
2066
|
+
upload_id: u,
|
|
1841
2067
|
play_frequency: o,
|
|
1842
2068
|
initial_goto_duration: a,
|
|
1843
2069
|
audio_lead_ms: n
|
|
1844
2070
|
});
|
|
1845
|
-
let
|
|
2071
|
+
let p;
|
|
1846
2072
|
try {
|
|
1847
|
-
|
|
1848
|
-
(h) => h?.type === "play_uploaded_move" && h?.upload_id ===
|
|
2073
|
+
p = await this._waitForBroadcast(
|
|
2074
|
+
(h) => h?.type === "play_uploaded_move" && h?.upload_id === u && (h.started === !0 || typeof h.error == "string"),
|
|
1849
2075
|
{ timeoutMs: c, debugLabel: "play_uploaded_move started" }
|
|
1850
2076
|
);
|
|
1851
2077
|
} catch (h) {
|
|
@@ -1853,25 +2079,25 @@ class Be extends EventTarget {
|
|
|
1853
2079
|
`Daemon did not respond to play_uploaded_move (requires the reachy_mini daemon with feature/daemon-side-move-upload). Underlying: ${h.message}`
|
|
1854
2080
|
);
|
|
1855
2081
|
}
|
|
1856
|
-
if (typeof
|
|
1857
|
-
throw new Error(`play_uploaded_move: ${
|
|
2082
|
+
if (typeof p.error == "string")
|
|
2083
|
+
throw new Error(`play_uploaded_move: ${p.error}`);
|
|
1858
2084
|
try {
|
|
1859
|
-
|
|
1860
|
-
duration_s:
|
|
1861
|
-
has_audio:
|
|
2085
|
+
d({
|
|
2086
|
+
duration_s: p.duration_s,
|
|
2087
|
+
has_audio: p.has_audio === !0
|
|
1862
2088
|
});
|
|
1863
2089
|
} catch (h) {
|
|
1864
2090
|
_.warn("playMove.onStarted threw:", h);
|
|
1865
2091
|
}
|
|
1866
|
-
|
|
1867
|
-
const
|
|
1868
|
-
(h) => h?.type === "play_uploaded_move" && h?.upload_id ===
|
|
2092
|
+
l({ phase: "playing", duration_s: p.duration_s });
|
|
2093
|
+
const v = await this._waitForBroadcast(
|
|
2094
|
+
(h) => h?.type === "play_uploaded_move" && h?.upload_id === u && (h.finished === !0 || h.cancelled === !0 || typeof h.error == "string"),
|
|
1869
2095
|
{
|
|
1870
|
-
timeoutMs: (
|
|
2096
|
+
timeoutMs: (p.duration_s + 30) * 1e3,
|
|
1871
2097
|
debugLabel: "play_uploaded_move final"
|
|
1872
2098
|
}
|
|
1873
2099
|
);
|
|
1874
|
-
return this._activeMoveUploadId ===
|
|
2100
|
+
return this._activeMoveUploadId === u && (this._activeMoveUploadId = null), v;
|
|
1875
2101
|
}
|
|
1876
2102
|
cancelMove(e = null) {
|
|
1877
2103
|
const t = e ?? this._activeMoveUploadId;
|
|
@@ -1883,37 +2109,37 @@ class Be extends EventTarget {
|
|
|
1883
2109
|
throw new Error("data channel not open");
|
|
1884
2110
|
if (!(e instanceof Blob))
|
|
1885
2111
|
throw new TypeError("uploadAudio: expected a Blob");
|
|
1886
|
-
const
|
|
2112
|
+
const i = Y(), r = new Uint8Array(await e.arrayBuffer()), o = $(r), a = Math.ceil(o.length / R) || 1;
|
|
1887
2113
|
n({ phase: "audio-starting", sent: 0, total: a, bytes: o.length }), this._sendCommand({
|
|
1888
2114
|
type: "upload_audio_start",
|
|
1889
|
-
upload_id:
|
|
2115
|
+
upload_id: i,
|
|
1890
2116
|
total_chunks: a,
|
|
1891
|
-
encoding:
|
|
2117
|
+
encoding: Q(e),
|
|
1892
2118
|
description: t
|
|
1893
2119
|
});
|
|
1894
2120
|
for (let c = 0; c < a; c++) {
|
|
1895
|
-
this._dc.bufferedAmount >
|
|
1896
|
-
const
|
|
2121
|
+
this._dc.bufferedAmount > U && await this._awaitDataChannelDrain();
|
|
2122
|
+
const l = c * R;
|
|
1897
2123
|
this._sendCommand({
|
|
1898
2124
|
type: "upload_audio_chunk",
|
|
1899
|
-
upload_id:
|
|
2125
|
+
upload_id: i,
|
|
1900
2126
|
chunk_index: c,
|
|
1901
|
-
chunk: o.slice(
|
|
2127
|
+
chunk: o.slice(l, l + R)
|
|
1902
2128
|
}), n({ phase: "audio-upload", sent: c + 1, total: a });
|
|
1903
2129
|
}
|
|
1904
|
-
return this._sendCommand({ type: "upload_audio_finish", upload_id:
|
|
2130
|
+
return this._sendCommand({ type: "upload_audio_finish", upload_id: i }), n({ phase: "audio-uploaded", sent: a, total: a }), i;
|
|
1905
2131
|
}
|
|
1906
2132
|
async playUploadedAudio(e, { timeoutMs: t = 8e3 } = {}) {
|
|
1907
2133
|
if (!this._dc || this._dc.readyState !== "open")
|
|
1908
2134
|
throw new Error("data channel not open");
|
|
1909
2135
|
const n = this._waitForBroadcast(
|
|
1910
|
-
(
|
|
2136
|
+
(r) => r?.type === "play_uploaded_audio" && r?.upload_id === e && (r.started === !0 || typeof r.error == "string"),
|
|
1911
2137
|
{ timeoutMs: t, debugLabel: "play_uploaded_audio started" }
|
|
1912
2138
|
);
|
|
1913
2139
|
this._sendCommand({ type: "play_uploaded_audio", upload_id: e });
|
|
1914
|
-
const
|
|
1915
|
-
if (typeof
|
|
1916
|
-
return this._activeAudioUploadId = e,
|
|
2140
|
+
const i = await n;
|
|
2141
|
+
if (typeof i.error == "string") throw new Error(i.error);
|
|
2142
|
+
return this._activeAudioUploadId = e, i;
|
|
1917
2143
|
}
|
|
1918
2144
|
cancelAudio(e = null) {
|
|
1919
2145
|
const t = e ?? this._activeAudioUploadId;
|
|
@@ -1927,34 +2153,38 @@ class Be extends EventTarget {
|
|
|
1927
2153
|
return this._pending.awaitBroadcast(e, t);
|
|
1928
2154
|
}
|
|
1929
2155
|
async _awaitDataChannelDrain() {
|
|
1930
|
-
for (; this._dc && this._dc.bufferedAmount >
|
|
2156
|
+
for (; this._dc && this._dc.bufferedAmount > Le; )
|
|
1931
2157
|
if (await new Promise((e) => setTimeout(e, 30)), !this._dc || this._dc.readyState !== "open")
|
|
1932
2158
|
throw new Error("data channel closed mid-upload");
|
|
1933
2159
|
}
|
|
1934
2160
|
async _sendToServer(e) {
|
|
1935
2161
|
if (!this._token) throw new Error("No token — authenticate() first");
|
|
2162
|
+
const t = new AbortController(), n = setTimeout(() => t.abort(), ee);
|
|
1936
2163
|
try {
|
|
1937
|
-
const
|
|
2164
|
+
const i = await fetch(`${this._signalingUrl}/send`, {
|
|
1938
2165
|
method: "POST",
|
|
1939
2166
|
headers: {
|
|
1940
2167
|
"Content-Type": "application/json",
|
|
1941
2168
|
Authorization: `Bearer ${this._token}`
|
|
1942
2169
|
},
|
|
1943
|
-
body: JSON.stringify(e)
|
|
2170
|
+
body: JSON.stringify(e),
|
|
2171
|
+
signal: t.signal
|
|
1944
2172
|
});
|
|
1945
|
-
if (!
|
|
1946
|
-
let
|
|
2173
|
+
if (!i.ok) {
|
|
2174
|
+
let r = "";
|
|
1947
2175
|
try {
|
|
1948
|
-
|
|
2176
|
+
r = await i.text();
|
|
1949
2177
|
} catch {
|
|
1950
2178
|
}
|
|
1951
2179
|
return _.warn(
|
|
1952
|
-
`/send rejected (${
|
|
2180
|
+
`/send rejected (${i.status}) for type=${e?.type}; body=${r || "<empty>"}`
|
|
1953
2181
|
), null;
|
|
1954
2182
|
}
|
|
1955
|
-
return await
|
|
1956
|
-
} catch (
|
|
1957
|
-
return _.error("signaling /send failed:",
|
|
2183
|
+
return await i.json();
|
|
2184
|
+
} catch (i) {
|
|
2185
|
+
return _.error("signaling /send failed:", i), null;
|
|
2186
|
+
} finally {
|
|
2187
|
+
clearTimeout(n);
|
|
1958
2188
|
}
|
|
1959
2189
|
}
|
|
1960
2190
|
_sendCommand(e) {
|
|
@@ -1968,11 +2198,11 @@ class Be extends EventTarget {
|
|
|
1968
2198
|
* timeout.
|
|
1969
2199
|
*/
|
|
1970
2200
|
rpcCall(e, t = {}, n = {}) {
|
|
1971
|
-
const
|
|
2201
|
+
const i = n.timeoutMs ?? 2e4;
|
|
1972
2202
|
return this._pending.rpcRoundtrip(
|
|
1973
2203
|
e,
|
|
1974
|
-
|
|
1975
|
-
(
|
|
2204
|
+
i,
|
|
2205
|
+
(r) => this._sendCommand({ jsonrpc: "2.0", id: r, method: e, params: t })
|
|
1976
2206
|
);
|
|
1977
2207
|
}
|
|
1978
2208
|
/**
|
|
@@ -1991,14 +2221,14 @@ class Be extends EventTarget {
|
|
|
1991
2221
|
for (const n of this._rpcListeners.get(e.method) ?? [])
|
|
1992
2222
|
try {
|
|
1993
2223
|
n(t);
|
|
1994
|
-
} catch (
|
|
1995
|
-
_.error(`onNotification(${e.method}) threw:`,
|
|
2224
|
+
} catch (i) {
|
|
2225
|
+
_.error(`onNotification(${e.method}) threw:`, i);
|
|
1996
2226
|
}
|
|
1997
2227
|
}
|
|
1998
2228
|
}
|
|
1999
2229
|
_checkSessionReady() {
|
|
2000
2230
|
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(() => {
|
|
2001
|
-
Date.now() - this._lastPoseFrameAt <
|
|
2231
|
+
Date.now() - this._lastPoseFrameAt < Z || this.requestState();
|
|
2002
2232
|
}, 500), this._supervisor.startDcWatchdog(), this._emit("streaming", { sessionId: this._sessionId, robotId: this._selectedRobotId }), this._sessionResolve(), this._sessionResolve = null, this._sessionReject = null);
|
|
2003
2233
|
}
|
|
2004
2234
|
async _handleSignalingMessage(e) {
|
|
@@ -2014,6 +2244,7 @@ class Be extends EventTarget {
|
|
|
2014
2244
|
break;
|
|
2015
2245
|
}
|
|
2016
2246
|
case "sessionStarted":
|
|
2247
|
+
if (e.sessionId && this._retiredSessionIds.has(e.sessionId)) break;
|
|
2017
2248
|
this._sessionId = e.sessionId ?? null;
|
|
2018
2249
|
break;
|
|
2019
2250
|
case "sessionRejected":
|
|
@@ -2028,49 +2259,55 @@ class Be extends EventTarget {
|
|
|
2028
2259
|
}
|
|
2029
2260
|
}
|
|
2030
2261
|
_handleEndSession(e) {
|
|
2262
|
+
if (this._isOtherSession(e.sessionId)) {
|
|
2263
|
+
_.info(`ignoring endSession for session ${e.sessionId}: not the current one`);
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2031
2266
|
const t = e.reason, n = t === "robot_busy_local_app" ? "Robot is busy: a local Python app is running" : t === "local_app_started" ? "Disconnected: a local Python app started on the robot" : t === "robot_busy_local" ? "Robot is busy: another session is already active" : null;
|
|
2032
2267
|
if (this._sessionReject) {
|
|
2033
|
-
const
|
|
2268
|
+
const i = new Error(
|
|
2034
2269
|
n || `Session ended before it could start: ${t || "unknown reason"}`
|
|
2035
2270
|
);
|
|
2036
|
-
|
|
2037
|
-
const
|
|
2038
|
-
this._sessionResolve = null, this._sessionReject = null, i
|
|
2271
|
+
i.reason = t ?? null, this._supervisor.redialing || this._emit("sessionRejected", { reason: t, activeApp: null }), this._supervisor.clearIceGrace(), this._supervisor.uninstallNetworkListeners(), this._pc && (this._pc.close(), this._pc = null), this._releaseMicPlaceholder(), this._robotAudioTrack = null, this._iceConnected = !1, this._dcOpen = !1, this._micMuted = !0, this._micSupported = !1, this._retireSession(this._sessionId), this._sessionId = null;
|
|
2272
|
+
const r = this._sessionReject;
|
|
2273
|
+
this._sessionResolve = null, this._sessionReject = null, r(i);
|
|
2039
2274
|
return;
|
|
2040
2275
|
}
|
|
2041
|
-
this._state === "streaming"
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2276
|
+
if (this._state === "streaming") {
|
|
2277
|
+
if (!t && this._peerLinkLive()) {
|
|
2278
|
+
_.info("central ended the session but the peer link is live; keeping it"), this._staleSessionId = this._sessionId, this._sessionId = null, this._emit("signalingSessionEnded", { reason: null });
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
this._endedByRobot(t || "remote_end", n);
|
|
2282
|
+
}
|
|
2046
2283
|
}
|
|
2047
2284
|
async _handlePeerMessage(e) {
|
|
2048
|
-
if (this._pc)
|
|
2285
|
+
if (this._pc && !(e.sessionId && this._retiredSessionIds.has(e.sessionId)))
|
|
2049
2286
|
try {
|
|
2050
2287
|
if (e.sdp) {
|
|
2051
2288
|
const t = e.sdp;
|
|
2052
2289
|
if (t.type === "offer") {
|
|
2053
|
-
const
|
|
2054
|
-
if (this._micSupported =
|
|
2290
|
+
const i = ke(t.sdp);
|
|
2291
|
+
if (this._micSupported = i, this._emit("micSupported", { supported: i }), i && this._micStream)
|
|
2055
2292
|
for (const o of this._micStream.getAudioTracks())
|
|
2056
2293
|
this._pc.addTrack(o, this._micStream);
|
|
2057
2294
|
await this._pc.setRemoteDescription(new RTCSessionDescription(t));
|
|
2058
|
-
const
|
|
2059
|
-
await this._pc.setLocalDescription(
|
|
2295
|
+
const r = await this._pc.createAnswer();
|
|
2296
|
+
await this._pc.setLocalDescription(r), this._outgoingAudioTrack && await this._applyOutgoingAudioTrack().catch((o) => _.warn("re-applying outgoing audio failed:", o)), await this._sendToServer({
|
|
2060
2297
|
type: "peer",
|
|
2061
2298
|
sessionId: this._sessionId,
|
|
2062
|
-
sdp: { type: "answer", sdp:
|
|
2299
|
+
sdp: { type: "answer", sdp: r.sdp }
|
|
2063
2300
|
});
|
|
2064
2301
|
} else
|
|
2065
2302
|
await this._pc.setRemoteDescription(new RTCSessionDescription(t));
|
|
2066
2303
|
const n = this._pendingRemoteIce;
|
|
2067
2304
|
if (n && n.length) {
|
|
2068
2305
|
this._pendingRemoteIce = [];
|
|
2069
|
-
for (const
|
|
2306
|
+
for (const i of n)
|
|
2070
2307
|
try {
|
|
2071
|
-
await this._pc.addIceCandidate(new RTCIceCandidate(
|
|
2072
|
-
} catch (
|
|
2073
|
-
_.warn("buffered ICE candidate rejected:",
|
|
2308
|
+
await this._pc.addIceCandidate(new RTCIceCandidate(i));
|
|
2309
|
+
} catch (r) {
|
|
2310
|
+
_.warn("buffered ICE candidate rejected:", r);
|
|
2074
2311
|
}
|
|
2075
2312
|
}
|
|
2076
2313
|
}
|
|
@@ -2115,6 +2352,13 @@ class Be extends EventTarget {
|
|
|
2115
2352
|
);
|
|
2116
2353
|
return;
|
|
2117
2354
|
}
|
|
2355
|
+
if (e.command === "get_telemetry" || e.command === "set_telemetry") {
|
|
2356
|
+
this._pending.settleReplySlot(
|
|
2357
|
+
e.command === "get_telemetry" ? "telemetry" : "set_telemetry",
|
|
2358
|
+
e.status === "error" ? null : { enabled: !!e.enabled, disabled_by_env: !!e.disabled_by_env }
|
|
2359
|
+
);
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2118
2362
|
if (e.command === "delete_hf_token") {
|
|
2119
2363
|
this._pending.settleReplySlot("delete_hf_token", e.status !== "error");
|
|
2120
2364
|
return;
|
|
@@ -2143,8 +2387,8 @@ class Be extends EventTarget {
|
|
|
2143
2387
|
for (const n of this._logSubscribers)
|
|
2144
2388
|
try {
|
|
2145
2389
|
n.onLine({ timestamp: e.timestamp, line: e.line });
|
|
2146
|
-
} catch (
|
|
2147
|
-
_.error("subscribeLogs onLine threw:",
|
|
2390
|
+
} catch (i) {
|
|
2391
|
+
_.error("subscribeLogs onLine threw:", i);
|
|
2148
2392
|
}
|
|
2149
2393
|
return;
|
|
2150
2394
|
}
|
|
@@ -2153,19 +2397,19 @@ class Be extends EventTarget {
|
|
|
2153
2397
|
if (typeof n.onError == "function")
|
|
2154
2398
|
try {
|
|
2155
2399
|
n.onError(e.error);
|
|
2156
|
-
} catch (
|
|
2157
|
-
_.error("subscribeLogs onError threw:",
|
|
2400
|
+
} catch (i) {
|
|
2401
|
+
_.error("subscribeLogs onError threw:", i);
|
|
2158
2402
|
}
|
|
2159
2403
|
return;
|
|
2160
2404
|
}
|
|
2161
2405
|
if (e.command === "start_update") {
|
|
2162
2406
|
if (typeof e.error == "string") {
|
|
2163
2407
|
const n = { status: "failed", error: e.error };
|
|
2164
|
-
for (const
|
|
2408
|
+
for (const i of this._updateProgressSubscribers)
|
|
2165
2409
|
try {
|
|
2166
|
-
|
|
2167
|
-
} catch (
|
|
2168
|
-
_.error("startDaemonUpdate onProgress threw:",
|
|
2410
|
+
i(n);
|
|
2411
|
+
} catch (r) {
|
|
2412
|
+
_.error("startDaemonUpdate onProgress threw:", r);
|
|
2169
2413
|
}
|
|
2170
2414
|
}
|
|
2171
2415
|
return;
|
|
@@ -2176,15 +2420,15 @@ class Be extends EventTarget {
|
|
|
2176
2420
|
line: typeof e.line == "string" ? e.line : void 0,
|
|
2177
2421
|
error: typeof e.error == "string" ? e.error : void 0
|
|
2178
2422
|
};
|
|
2179
|
-
for (const
|
|
2423
|
+
for (const i of this._updateProgressSubscribers)
|
|
2180
2424
|
try {
|
|
2181
|
-
|
|
2182
|
-
} catch (
|
|
2183
|
-
_.error("startDaemonUpdate onProgress threw:",
|
|
2425
|
+
i(n);
|
|
2426
|
+
} catch (r) {
|
|
2427
|
+
_.error("startDaemonUpdate onProgress threw:", r);
|
|
2184
2428
|
}
|
|
2185
2429
|
return;
|
|
2186
2430
|
}
|
|
2187
|
-
if (e.state && (t || Date.now() - this._lastPoseFrameAt >=
|
|
2431
|
+
if (e.state && (t || Date.now() - this._lastPoseFrameAt >= Z)) {
|
|
2188
2432
|
const n = e.state;
|
|
2189
2433
|
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 });
|
|
2190
2434
|
}
|
|
@@ -2198,14 +2442,14 @@ class Be extends EventTarget {
|
|
|
2198
2442
|
if (!e.srcObject || e.paused) return;
|
|
2199
2443
|
const t = e.buffered;
|
|
2200
2444
|
if (t.length > 0) {
|
|
2201
|
-
const n = t.end(t.length - 1),
|
|
2202
|
-
|
|
2445
|
+
const n = t.end(t.length - 1), i = n - e.currentTime;
|
|
2446
|
+
i > 0.5 && (_.debug(`video latency correction: was ${i.toFixed(2)}s behind`), e.currentTime = n - 0.1);
|
|
2203
2447
|
}
|
|
2204
2448
|
}, 2e3);
|
|
2205
2449
|
}
|
|
2206
2450
|
}
|
|
2207
|
-
const
|
|
2208
|
-
function
|
|
2451
|
+
const Be = "pollen-robotics/reachy_mini", Ge = `https://api.github.com/repos/${Be}/releases/latest`, ie = "reachy.daemonLatestRelease.v1", qe = 360 * 60 * 1e3, se = "1.8.2";
|
|
2452
|
+
function E(s) {
|
|
2209
2453
|
if (typeof s != "string") return null;
|
|
2210
2454
|
const e = s.trim().replace(/^v/i, "").match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
2211
2455
|
return e ? {
|
|
@@ -2214,26 +2458,26 @@ function k(s) {
|
|
|
2214
2458
|
patch: Number(e[3])
|
|
2215
2459
|
} : null;
|
|
2216
2460
|
}
|
|
2217
|
-
function
|
|
2461
|
+
function W(s, e) {
|
|
2218
2462
|
return s.major - e.major || s.minor - e.minor || s.patch - e.patch;
|
|
2219
2463
|
}
|
|
2220
|
-
function
|
|
2221
|
-
const t =
|
|
2222
|
-
return !t || !n ? !1 :
|
|
2464
|
+
function Ve(s, e) {
|
|
2465
|
+
const t = E(s), n = E(e);
|
|
2466
|
+
return !t || !n ? !1 : W(t, n) < 0;
|
|
2223
2467
|
}
|
|
2224
|
-
function
|
|
2225
|
-
const t =
|
|
2468
|
+
function Ze(s, e) {
|
|
2469
|
+
const t = E(s);
|
|
2226
2470
|
if (!t) return null;
|
|
2227
|
-
const n =
|
|
2228
|
-
return n &&
|
|
2471
|
+
const n = E(se);
|
|
2472
|
+
return n && W(t, n) < 0 ? "block" : Ve(s, e) ? "notice" : null;
|
|
2229
2473
|
}
|
|
2230
|
-
function
|
|
2231
|
-
const e =
|
|
2232
|
-
return !!e && !!t &&
|
|
2474
|
+
function et(s) {
|
|
2475
|
+
const e = E(s), t = E(se);
|
|
2476
|
+
return !!e && !!t && W(e, t) >= 0;
|
|
2233
2477
|
}
|
|
2234
|
-
function
|
|
2478
|
+
function Je() {
|
|
2235
2479
|
try {
|
|
2236
|
-
const s = localStorage.getItem(
|
|
2480
|
+
const s = localStorage.getItem(ie);
|
|
2237
2481
|
if (!s) return null;
|
|
2238
2482
|
const e = JSON.parse(s);
|
|
2239
2483
|
return typeof e.at != "number" ? null : {
|
|
@@ -2244,50 +2488,50 @@ function je() {
|
|
|
2244
2488
|
return null;
|
|
2245
2489
|
}
|
|
2246
2490
|
}
|
|
2247
|
-
async function
|
|
2248
|
-
const s =
|
|
2249
|
-
if (s && Date.now() - s.at <
|
|
2491
|
+
async function tt() {
|
|
2492
|
+
const s = Je();
|
|
2493
|
+
if (s && Date.now() - s.at < qe) return s.value;
|
|
2250
2494
|
try {
|
|
2251
|
-
const e = await fetch(
|
|
2495
|
+
const e = await fetch(Ge, {
|
|
2252
2496
|
headers: { Accept: "application/vnd.github+json" }
|
|
2253
2497
|
});
|
|
2254
2498
|
if (!e.ok)
|
|
2255
2499
|
return s?.value ?? null;
|
|
2256
|
-
const t = await e.json(), n = typeof t.tag_name == "string" ? t.tag_name : null,
|
|
2500
|
+
const t = await e.json(), n = typeof t.tag_name == "string" ? t.tag_name : null, i = n ? n.replace(/^v/i, "") : null;
|
|
2257
2501
|
try {
|
|
2258
|
-
localStorage.setItem(
|
|
2502
|
+
localStorage.setItem(ie, JSON.stringify({ value: i, at: Date.now() }));
|
|
2259
2503
|
} catch {
|
|
2260
2504
|
}
|
|
2261
|
-
return
|
|
2505
|
+
return i;
|
|
2262
2506
|
} catch {
|
|
2263
2507
|
return s?.value ?? null;
|
|
2264
2508
|
}
|
|
2265
2509
|
}
|
|
2266
|
-
const
|
|
2267
|
-
function
|
|
2510
|
+
const Ke = 8e3;
|
|
2511
|
+
function ze(s) {
|
|
2268
2512
|
if (!s) return null;
|
|
2269
2513
|
const e = s.id ?? s.peerId ?? s.peer_id;
|
|
2270
2514
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2271
2515
|
}
|
|
2272
|
-
function
|
|
2273
|
-
const e =
|
|
2516
|
+
function Ye(s) {
|
|
2517
|
+
const e = ze(s);
|
|
2274
2518
|
if (!e) return null;
|
|
2275
|
-
const t = s.meta?.name ?? s.name, n = typeof s.meta?.transport == "string" && s.meta.transport.length > 0 ? s.meta.transport : null,
|
|
2519
|
+
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;
|
|
2276
2520
|
return {
|
|
2277
2521
|
id: e,
|
|
2278
2522
|
meta: t ? { name: t } : void 0,
|
|
2279
2523
|
busy: s.busy === !0,
|
|
2280
2524
|
activeApp: typeof s.activeApp == "string" && s.activeApp.trim().length > 0 ? s.activeApp : null,
|
|
2281
2525
|
transport: n,
|
|
2282
|
-
hardwareId:
|
|
2526
|
+
hardwareId: i
|
|
2283
2527
|
};
|
|
2284
2528
|
}
|
|
2285
|
-
async function
|
|
2529
|
+
async function nt(s) {
|
|
2286
2530
|
const { signalingUrl: e, hfToken: t } = s;
|
|
2287
2531
|
if (!t) return { ok: !1, robots: [], reason: "No HF token" };
|
|
2288
2532
|
if (!e)
|
|
2289
2533
|
return { ok: !1, robots: [], reason: "No signaling URL" };
|
|
2290
|
-
const n = `${e.replace(/\/$/, "")}/api/robot-status`,
|
|
2534
|
+
const n = `${e.replace(/\/$/, "")}/api/robot-status`, i = new AbortController(), r = setTimeout(() => i.abort(), Ke), o = s.signal ? Xe([i.signal, s.signal]) : i.signal;
|
|
2291
2535
|
try {
|
|
2292
2536
|
const a = await fetch(n, {
|
|
2293
2537
|
method: "GET",
|
|
@@ -2306,17 +2550,17 @@ async function Je(s) {
|
|
|
2306
2550
|
reason: `Central returned HTTP ${a.status}`
|
|
2307
2551
|
};
|
|
2308
2552
|
const c = await a.json();
|
|
2309
|
-
return { ok: !0, robots: (Array.isArray(c.robots) ? c.robots : []).map(
|
|
2553
|
+
return { ok: !0, robots: (Array.isArray(c.robots) ? c.robots : []).map(Ye).filter((u) => u != null) };
|
|
2310
2554
|
} catch (a) {
|
|
2311
2555
|
if (a instanceof DOMException && a.name === "AbortError")
|
|
2312
2556
|
return { ok: !1, robots: [], reason: "Central request timed out" };
|
|
2313
2557
|
const c = a instanceof Error ? a.message : String(a);
|
|
2314
2558
|
return { ok: !1, robots: [], reason: `Network error: ${c}` };
|
|
2315
2559
|
} finally {
|
|
2316
|
-
clearTimeout(
|
|
2560
|
+
clearTimeout(r);
|
|
2317
2561
|
}
|
|
2318
2562
|
}
|
|
2319
|
-
function
|
|
2563
|
+
function Xe(s) {
|
|
2320
2564
|
const e = new AbortController();
|
|
2321
2565
|
for (const t of s) {
|
|
2322
2566
|
if (t.aborted)
|
|
@@ -2326,12 +2570,12 @@ function We(s) {
|
|
|
2326
2570
|
return e.signal;
|
|
2327
2571
|
}
|
|
2328
2572
|
export {
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2573
|
+
se as M,
|
|
2574
|
+
Qe as R,
|
|
2575
|
+
nt as a,
|
|
2576
|
+
j as c,
|
|
2577
|
+
Ze as d,
|
|
2578
|
+
tt as f,
|
|
2579
|
+
E as p,
|
|
2580
|
+
et as s
|
|
2337
2581
|
};
|