@busy-app/busy-lib 0.6.0 → 0.7.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/dist/index.cjs +1 -1
- package/dist/index.d.ts +369 -193
- package/dist/index.js +1112 -702
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,530 +1,618 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var U = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var u = (e, t, n) => U(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
import v from "openapi-fetch";
|
|
5
|
-
const
|
|
5
|
+
const k = "http://10.0.4.20", C = "https://proxy.busy.app", W = /^https?:\/\/proxy(?:\.(?:dev|test|stage))?\.busy\.app$/i, I = (e, t) => {
|
|
6
6
|
if (typeof FormData < "u" && e instanceof FormData || typeof Buffer < "u" && typeof Buffer.isBuffer == "function" && Buffer.isBuffer(e) || typeof File < "u" && e instanceof File || typeof Blob < "u" && e instanceof Blob || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer || typeof ArrayBuffer < "u" && ArrayBuffer.isView && ArrayBuffer.isView(e))
|
|
7
7
|
return e;
|
|
8
|
-
let
|
|
9
|
-
return t && (t instanceof Headers ?
|
|
8
|
+
let n;
|
|
9
|
+
return t && (t instanceof Headers ? n = t.get("Content-Type") ?? t.get("content-type") ?? void 0 : typeof t == "object" && (n = t["Content-Type"] ?? t["content-type"]), n === "application/x-www-form-urlencoded") ? e && typeof e == "object" && !(e instanceof URLSearchParams) ? new URLSearchParams(e).toString() : String(e) : JSON.stringify(e);
|
|
10
10
|
};
|
|
11
|
-
let y, w
|
|
12
|
-
async function
|
|
13
|
-
if (!
|
|
14
|
-
if (!
|
|
11
|
+
let m, y, w = null;
|
|
12
|
+
async function b() {
|
|
13
|
+
if (!y) {
|
|
14
|
+
if (!m)
|
|
15
15
|
throw new Error("getApiVersionFn is not set");
|
|
16
|
-
|
|
17
|
-
const e = await
|
|
16
|
+
w || (w = (async () => {
|
|
17
|
+
const e = await m();
|
|
18
18
|
if (!e.api_semver)
|
|
19
19
|
throw new Error("Empty API version");
|
|
20
|
-
|
|
20
|
+
y = e.api_semver;
|
|
21
21
|
})().finally(() => {
|
|
22
|
-
|
|
23
|
-
})), await
|
|
22
|
+
w = null;
|
|
23
|
+
})), await w;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
async function
|
|
27
|
-
const
|
|
26
|
+
async function S(e) {
|
|
27
|
+
const r = (e.headers.get("content-type") || "").includes("application/json") ? await e.clone().json() : await e.clone().text(), i = typeof r == "object" && r !== null ? r.error || r.message : typeof r == "string" ? r : void 0;
|
|
28
28
|
return Object.assign(
|
|
29
|
-
new Error(
|
|
29
|
+
new Error(i || `HTTP ${e.status} ${e.statusText}`),
|
|
30
30
|
{
|
|
31
31
|
status: e.status,
|
|
32
32
|
statusText: e.statusText,
|
|
33
|
-
body:
|
|
33
|
+
body: r
|
|
34
34
|
}
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
|
-
let
|
|
38
|
-
function
|
|
39
|
-
|
|
37
|
+
let T;
|
|
38
|
+
function R(e) {
|
|
39
|
+
T = e;
|
|
40
40
|
}
|
|
41
|
-
let
|
|
42
|
-
const
|
|
41
|
+
let f;
|
|
42
|
+
const $ = {
|
|
43
43
|
async onRequest({ request: e, schemaPath: t }) {
|
|
44
|
-
return
|
|
44
|
+
return f && e.headers.set("Authorization", `Bearer ${f}`), t !== "/version" && (await b(), y && e.headers.set("X-API-Sem-Ver", y), T && e.headers.set("X-API-Token", T)), e;
|
|
45
45
|
},
|
|
46
|
-
async onResponse({ request: e, response: t, options:
|
|
46
|
+
async onResponse({ request: e, response: t, options: n, schemaPath: r }) {
|
|
47
47
|
if (t.ok)
|
|
48
48
|
return t;
|
|
49
|
-
if (
|
|
50
|
-
throw await
|
|
49
|
+
if (r === "/version")
|
|
50
|
+
throw await S(t);
|
|
51
51
|
if (t.status !== 405)
|
|
52
|
-
throw await
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
57
|
-
throw await
|
|
52
|
+
throw await S(t);
|
|
53
|
+
y = void 0, await b(), y && e.headers.set("X-API-Sem-Ver", y), f && e.headers.set("Authorization", `Bearer ${f}`);
|
|
54
|
+
const i = await (n.fetch ?? fetch)(e);
|
|
55
|
+
if (i.ok)
|
|
56
|
+
return i;
|
|
57
|
+
throw await S(i);
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
let
|
|
61
|
-
function
|
|
62
|
-
|
|
60
|
+
let p = null;
|
|
61
|
+
function N(e, t, n) {
|
|
62
|
+
m = t, f = n ?? void 0, p = v({
|
|
63
63
|
baseUrl: e,
|
|
64
|
-
bodySerializer:
|
|
65
|
-
}),
|
|
64
|
+
bodySerializer: I
|
|
65
|
+
}), p.use($);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
if (!
|
|
67
|
+
function o() {
|
|
68
|
+
if (!p)
|
|
69
69
|
throw new Error("API client is not initialized");
|
|
70
|
-
|
|
71
|
-
if (t)
|
|
72
|
-
throw t;
|
|
73
|
-
return e;
|
|
70
|
+
return p;
|
|
74
71
|
}
|
|
75
|
-
async function
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
async function a(e, t = 3e3) {
|
|
73
|
+
if (t <= 0)
|
|
74
|
+
return await e();
|
|
75
|
+
const n = new AbortController(), r = setTimeout(() => n.abort(), t);
|
|
76
|
+
try {
|
|
77
|
+
return await e(n.signal);
|
|
78
|
+
} catch (i) {
|
|
79
|
+
throw i instanceof DOMException && i.name === "AbortError" ? new Error(`Request timed out after ${t}ms`) : i;
|
|
80
|
+
} finally {
|
|
81
|
+
clearTimeout(r);
|
|
82
|
+
}
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
function g(e) {
|
|
85
|
+
const t = e.split(".");
|
|
86
|
+
if (t.length !== 4)
|
|
87
|
+
return !1;
|
|
88
|
+
for (const n of t) {
|
|
89
|
+
if (n.length === 0 || n.length > 1 && n[0] === "0" || !/^\d+$/.test(n))
|
|
90
|
+
return !1;
|
|
91
|
+
const r = Number(n);
|
|
92
|
+
if (r < 0 || r > 255)
|
|
93
|
+
return !1;
|
|
94
|
+
}
|
|
95
|
+
return !0;
|
|
90
96
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!r)
|
|
94
|
-
throw new Error("API client is not initialized");
|
|
95
|
-
const { data: s, error: a } = await r.POST("/assets/upload", {
|
|
96
|
-
params: {
|
|
97
|
-
query: {
|
|
98
|
-
app_id: t,
|
|
99
|
-
file: i
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
headers: {
|
|
103
|
-
"Content-Type": "application/octet-stream"
|
|
104
|
-
},
|
|
105
|
-
body: n
|
|
106
|
-
});
|
|
107
|
-
if (a)
|
|
108
|
-
throw a;
|
|
109
|
-
return s;
|
|
97
|
+
function A(e) {
|
|
98
|
+
return /\.local$/i.test(e);
|
|
110
99
|
}
|
|
111
|
-
async function
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
app_id: t
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
if (n)
|
|
123
|
-
throw n;
|
|
124
|
-
return i;
|
|
125
|
-
}
|
|
126
|
-
async function R(e) {
|
|
127
|
-
if (!r)
|
|
128
|
-
throw new Error("API client is not initialized");
|
|
129
|
-
const { appId: t, elements: i } = e, { data: n, error: s } = await r.POST("/display/draw", {
|
|
130
|
-
body: {
|
|
131
|
-
app_id: t,
|
|
132
|
-
elements: i
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (s)
|
|
136
|
-
throw s;
|
|
100
|
+
async function K(e) {
|
|
101
|
+
const t = o(), { data: n, error: r } = await a(
|
|
102
|
+
(i) => t.GET("/account", { signal: i }),
|
|
103
|
+
e == null ? void 0 : e.timeout
|
|
104
|
+
);
|
|
105
|
+
if (r)
|
|
106
|
+
throw r;
|
|
137
107
|
return n;
|
|
138
108
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
async function K(e) {
|
|
148
|
-
const { appId: t, path: i } = e;
|
|
149
|
-
if (!r)
|
|
150
|
-
throw new Error("API client is not initialized");
|
|
151
|
-
const { data: n, error: s } = await r.POST("/audio/play", {
|
|
152
|
-
params: {
|
|
153
|
-
query: {
|
|
154
|
-
app_id: t,
|
|
155
|
-
path: i
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
if (s)
|
|
160
|
-
throw s;
|
|
109
|
+
async function V(e) {
|
|
110
|
+
const t = o(), { data: n, error: r } = await a(
|
|
111
|
+
(i) => t.DELETE("/account", { signal: i }),
|
|
112
|
+
e == null ? void 0 : e.timeout
|
|
113
|
+
);
|
|
114
|
+
if (r)
|
|
115
|
+
throw r;
|
|
161
116
|
return n;
|
|
162
117
|
}
|
|
163
|
-
async function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
118
|
+
async function G(e) {
|
|
119
|
+
const t = o(), { data: n, error: r } = await a(
|
|
120
|
+
(i) => t.POST("/account/link", { signal: i }),
|
|
121
|
+
e == null ? void 0 : e.timeout
|
|
122
|
+
);
|
|
123
|
+
if (r)
|
|
124
|
+
throw r;
|
|
125
|
+
return n;
|
|
170
126
|
}
|
|
171
|
-
async function _() {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
127
|
+
async function _(e) {
|
|
128
|
+
const { appId: t, fileName: n, file: r } = e, i = o(), { data: s, error: c } = await a(
|
|
129
|
+
(h) => i.POST("/assets/upload", {
|
|
130
|
+
params: {
|
|
131
|
+
query: {
|
|
132
|
+
app_id: t,
|
|
133
|
+
file: n
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
headers: {
|
|
137
|
+
"Content-Type": "application/octet-stream"
|
|
138
|
+
},
|
|
139
|
+
body: r,
|
|
140
|
+
signal: h
|
|
141
|
+
}),
|
|
142
|
+
e.timeout
|
|
143
|
+
);
|
|
144
|
+
if (c)
|
|
145
|
+
throw c;
|
|
146
|
+
return s;
|
|
178
147
|
}
|
|
179
148
|
async function F(e) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
gateway: e.ipConfig.gateway
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
149
|
+
const { appId: t } = e, n = o(), { data: r, error: i } = await a(
|
|
150
|
+
(s) => n.DELETE("/assets/upload", {
|
|
151
|
+
params: {
|
|
152
|
+
query: {
|
|
153
|
+
app_id: t
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
signal: s
|
|
157
|
+
}),
|
|
158
|
+
e.timeout
|
|
159
|
+
);
|
|
195
160
|
if (i)
|
|
196
161
|
throw i;
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
async function G() {
|
|
200
|
-
if (!r)
|
|
201
|
-
throw new Error("API client is not initialized");
|
|
202
|
-
const { data: e, error: t } = await r.POST("/wifi/disconnect");
|
|
203
|
-
if (t)
|
|
204
|
-
throw t;
|
|
205
|
-
return e;
|
|
206
|
-
}
|
|
207
|
-
async function N() {
|
|
208
|
-
if (!r)
|
|
209
|
-
throw new Error("API client is not initialized");
|
|
210
|
-
const { data: e, error: t } = await r.GET("/wifi/networks");
|
|
211
|
-
if (t)
|
|
212
|
-
throw t;
|
|
213
|
-
return e;
|
|
162
|
+
return r;
|
|
214
163
|
}
|
|
215
|
-
async function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
body: i
|
|
228
|
-
});
|
|
164
|
+
async function x(e) {
|
|
165
|
+
const t = o(), { appId: n, elements: r } = e, { data: i, error: s } = await a(
|
|
166
|
+
(c) => t.POST("/display/draw", {
|
|
167
|
+
body: {
|
|
168
|
+
app_id: n,
|
|
169
|
+
elements: r
|
|
170
|
+
},
|
|
171
|
+
signal: c
|
|
172
|
+
}),
|
|
173
|
+
e.timeout
|
|
174
|
+
);
|
|
229
175
|
if (s)
|
|
230
176
|
throw s;
|
|
231
|
-
return
|
|
177
|
+
return i;
|
|
232
178
|
}
|
|
233
179
|
async function q(e) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
parseAs: i ? "arrayBuffer" : "blob"
|
|
243
|
-
});
|
|
244
|
-
if (s)
|
|
245
|
-
throw s;
|
|
180
|
+
const t = o(), { data: n, error: r } = await a(
|
|
181
|
+
(i) => t.DELETE("/display/draw", { signal: i }),
|
|
182
|
+
e == null ? void 0 : e.timeout
|
|
183
|
+
);
|
|
184
|
+
if (r)
|
|
185
|
+
throw r;
|
|
246
186
|
return n;
|
|
247
187
|
}
|
|
248
|
-
async function x(e) {
|
|
249
|
-
if (!r)
|
|
250
|
-
throw new Error("API client is not initialized");
|
|
251
|
-
const { path: t } = e, { data: i, error: n } = await r.GET("/storage/list", {
|
|
252
|
-
params: {
|
|
253
|
-
query: {
|
|
254
|
-
path: t
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
if (n)
|
|
259
|
-
throw n;
|
|
260
|
-
return i;
|
|
261
|
-
}
|
|
262
188
|
async function j(e) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
189
|
+
const t = o(), { appId: n, path: r } = e, { data: i, error: s } = await a(
|
|
190
|
+
(c) => t.POST("/audio/play", {
|
|
191
|
+
params: {
|
|
192
|
+
query: {
|
|
193
|
+
app_id: n,
|
|
194
|
+
path: r
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
signal: c
|
|
198
|
+
}),
|
|
199
|
+
e.timeout
|
|
200
|
+
);
|
|
201
|
+
if (s)
|
|
202
|
+
throw s;
|
|
274
203
|
return i;
|
|
275
204
|
}
|
|
276
205
|
async function H(e) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
if (n)
|
|
287
|
-
throw n;
|
|
288
|
-
return i;
|
|
206
|
+
const t = o(), { data: n, error: r } = await a(
|
|
207
|
+
(i) => t.DELETE("/audio/play", { signal: i }),
|
|
208
|
+
e == null ? void 0 : e.timeout
|
|
209
|
+
);
|
|
210
|
+
if (r)
|
|
211
|
+
throw r;
|
|
212
|
+
return n;
|
|
289
213
|
}
|
|
290
|
-
async function
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
214
|
+
async function z(e) {
|
|
215
|
+
const t = o(), { data: n, error: r } = await a(
|
|
216
|
+
(i) => t.GET("/wifi/status", { signal: i }),
|
|
217
|
+
e == null ? void 0 : e.timeout
|
|
218
|
+
);
|
|
219
|
+
if (r)
|
|
220
|
+
throw r;
|
|
221
|
+
return n;
|
|
297
222
|
}
|
|
298
|
-
async function
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
223
|
+
async function J(e) {
|
|
224
|
+
const t = o(), { data: n, error: r } = await a(
|
|
225
|
+
(i) => t.POST("/wifi/connect", {
|
|
226
|
+
body: {
|
|
227
|
+
ssid: e.ssid,
|
|
228
|
+
password: e.password,
|
|
229
|
+
security: e.security,
|
|
230
|
+
ip_config: {
|
|
231
|
+
ip_method: e.ipConfig.ipMethod,
|
|
232
|
+
address: e.ipConfig.address,
|
|
233
|
+
mask: e.ipConfig.mask,
|
|
234
|
+
gateway: e.ipConfig.gateway
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
signal: i
|
|
238
|
+
}),
|
|
239
|
+
e.timeout
|
|
240
|
+
);
|
|
241
|
+
if (r)
|
|
242
|
+
throw r;
|
|
243
|
+
return n;
|
|
305
244
|
}
|
|
306
245
|
async function M(e) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
headers: {
|
|
316
|
-
"Content-Type": "application/octet-stream"
|
|
317
|
-
},
|
|
318
|
-
body: i
|
|
319
|
-
});
|
|
320
|
-
if (s)
|
|
321
|
-
throw s;
|
|
246
|
+
const t = o(), { data: n, error: r } = await a(
|
|
247
|
+
(i) => t.POST("/wifi/disconnect", { signal: i }),
|
|
248
|
+
e == null ? void 0 : e.timeout
|
|
249
|
+
);
|
|
250
|
+
if (r)
|
|
251
|
+
throw r;
|
|
322
252
|
return n;
|
|
323
253
|
}
|
|
324
|
-
async function
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
async function Y() {
|
|
333
|
-
if (!r)
|
|
334
|
-
throw new Error("API client is not initialized");
|
|
335
|
-
const { data: e, error: t } = await r.GET("/status/system");
|
|
336
|
-
if (t)
|
|
337
|
-
throw t;
|
|
338
|
-
return e;
|
|
254
|
+
async function X(e) {
|
|
255
|
+
const t = o(), { data: n, error: r } = await a(
|
|
256
|
+
(i) => t.GET("/wifi/networks", { signal: i }),
|
|
257
|
+
e == null ? void 0 : e.timeout
|
|
258
|
+
);
|
|
259
|
+
if (r)
|
|
260
|
+
throw r;
|
|
261
|
+
return n;
|
|
339
262
|
}
|
|
340
|
-
async function
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
263
|
+
async function Q(e) {
|
|
264
|
+
const t = o(), { path: n, file: r } = e, { data: i, error: s } = await a(
|
|
265
|
+
(c) => t.POST("/storage/write", {
|
|
266
|
+
params: {
|
|
267
|
+
query: {
|
|
268
|
+
path: n
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
headers: {
|
|
272
|
+
"Content-Type": "application/octet-stream"
|
|
273
|
+
},
|
|
274
|
+
body: r,
|
|
275
|
+
signal: c
|
|
276
|
+
}),
|
|
277
|
+
e.timeout
|
|
278
|
+
);
|
|
279
|
+
if (s)
|
|
280
|
+
throw s;
|
|
281
|
+
return i;
|
|
347
282
|
}
|
|
348
|
-
async function
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
283
|
+
async function Y(e) {
|
|
284
|
+
const t = o(), { path: n, asArrayBuffer: r } = e, { data: i, error: s } = await a(
|
|
285
|
+
(c) => t.GET("/storage/read", {
|
|
286
|
+
params: {
|
|
287
|
+
query: {
|
|
288
|
+
path: n
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
parseAs: r ? "arrayBuffer" : "blob",
|
|
292
|
+
signal: c
|
|
293
|
+
}),
|
|
294
|
+
e.timeout
|
|
295
|
+
);
|
|
296
|
+
if (s)
|
|
297
|
+
throw s;
|
|
298
|
+
return i;
|
|
355
299
|
}
|
|
356
|
-
async function
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
300
|
+
async function Z(e) {
|
|
301
|
+
const t = o(), { path: n } = e, { data: r, error: i } = await a(
|
|
302
|
+
(s) => t.GET("/storage/list", {
|
|
303
|
+
params: {
|
|
304
|
+
query: {
|
|
305
|
+
path: n
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
signal: s
|
|
309
|
+
}),
|
|
310
|
+
e.timeout
|
|
311
|
+
);
|
|
364
312
|
if (i)
|
|
365
313
|
throw i;
|
|
366
|
-
return
|
|
314
|
+
return r;
|
|
367
315
|
}
|
|
368
|
-
async function
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
316
|
+
async function tt(e) {
|
|
317
|
+
const t = o(), { path: n } = e, { data: r, error: i } = await a(
|
|
318
|
+
(s) => t.DELETE("/storage/remove", {
|
|
319
|
+
params: {
|
|
320
|
+
query: {
|
|
321
|
+
path: n
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
signal: s
|
|
325
|
+
}),
|
|
326
|
+
e.timeout
|
|
327
|
+
);
|
|
376
328
|
if (i)
|
|
377
329
|
throw i;
|
|
378
|
-
return
|
|
330
|
+
return r;
|
|
379
331
|
}
|
|
380
|
-
async function
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
332
|
+
async function et(e) {
|
|
333
|
+
const t = o(), { path: n } = e, { data: r, error: i } = await a(
|
|
334
|
+
(s) => t.POST("/storage/mkdir", {
|
|
335
|
+
params: {
|
|
336
|
+
query: {
|
|
337
|
+
path: n
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
signal: s
|
|
341
|
+
}),
|
|
342
|
+
e.timeout
|
|
343
|
+
);
|
|
344
|
+
if (i)
|
|
345
|
+
throw i;
|
|
346
|
+
return r;
|
|
387
347
|
}
|
|
388
348
|
async function nt(e) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
349
|
+
const t = o(), { data: n, error: r } = await a(
|
|
350
|
+
(i) => t.GET("/storage/status", { signal: i }),
|
|
351
|
+
e == null ? void 0 : e.timeout
|
|
352
|
+
);
|
|
353
|
+
if (r)
|
|
354
|
+
throw r;
|
|
355
|
+
return n;
|
|
356
|
+
}
|
|
357
|
+
async function rt(e) {
|
|
358
|
+
const t = o(), { data: n, error: r } = await a(
|
|
359
|
+
(i) => t.GET("/version", { signal: i }),
|
|
360
|
+
e == null ? void 0 : e.timeout
|
|
361
|
+
);
|
|
362
|
+
if (r)
|
|
363
|
+
throw r;
|
|
364
|
+
return n;
|
|
365
|
+
}
|
|
366
|
+
async function it(e) {
|
|
367
|
+
const t = o(), { name: n, file: r } = e, { data: i, error: s } = await a(
|
|
368
|
+
(c) => t.POST("/update", {
|
|
369
|
+
params: {
|
|
370
|
+
query: {
|
|
371
|
+
name: n
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
headers: {
|
|
375
|
+
"Content-Type": "application/octet-stream"
|
|
376
|
+
},
|
|
377
|
+
body: r,
|
|
378
|
+
signal: c
|
|
379
|
+
}),
|
|
380
|
+
e.timeout
|
|
381
|
+
);
|
|
382
|
+
if (s)
|
|
383
|
+
throw s;
|
|
384
|
+
return i;
|
|
385
|
+
}
|
|
386
|
+
async function st(e) {
|
|
387
|
+
const t = o(), { data: n, error: r } = await a(
|
|
388
|
+
(i) => t.GET("/status", { signal: i }),
|
|
389
|
+
e == null ? void 0 : e.timeout
|
|
390
|
+
);
|
|
391
|
+
if (r)
|
|
392
|
+
throw r;
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
395
|
+
async function ot(e) {
|
|
396
|
+
const t = o(), { data: n, error: r } = await a(
|
|
397
|
+
(i) => t.GET("/status/system", { signal: i }),
|
|
398
|
+
e == null ? void 0 : e.timeout
|
|
399
|
+
);
|
|
400
|
+
if (r)
|
|
401
|
+
throw r;
|
|
402
|
+
return n;
|
|
403
|
+
}
|
|
404
|
+
async function at(e) {
|
|
405
|
+
const t = o(), { data: n, error: r } = await a(
|
|
406
|
+
(i) => t.GET("/status/power", { signal: i }),
|
|
407
|
+
e == null ? void 0 : e.timeout
|
|
408
|
+
);
|
|
409
|
+
if (r)
|
|
410
|
+
throw r;
|
|
411
|
+
return n;
|
|
412
|
+
}
|
|
413
|
+
async function ct(e) {
|
|
414
|
+
const t = o(), { data: n, error: r } = await a(
|
|
415
|
+
(i) => t.GET("/time", { signal: i }),
|
|
416
|
+
e == null ? void 0 : e.timeout
|
|
417
|
+
);
|
|
418
|
+
if (r)
|
|
419
|
+
throw r;
|
|
420
|
+
return n;
|
|
421
|
+
}
|
|
422
|
+
async function ut(e) {
|
|
423
|
+
const t = o(), { data: n, error: r } = await a(
|
|
424
|
+
(i) => t.POST("/time/timestamp", {
|
|
425
|
+
params: {
|
|
426
|
+
query: { ...e, timeout: void 0 }
|
|
427
|
+
},
|
|
428
|
+
signal: i
|
|
429
|
+
}),
|
|
430
|
+
e.timeout
|
|
431
|
+
);
|
|
432
|
+
if (r)
|
|
433
|
+
throw r;
|
|
434
|
+
return n;
|
|
435
|
+
}
|
|
436
|
+
async function dt(e) {
|
|
437
|
+
const t = o(), { data: n, error: r } = await a(
|
|
438
|
+
(i) => t.POST("/time/timezone", {
|
|
439
|
+
params: {
|
|
440
|
+
query: { ...e, timeout: void 0 }
|
|
441
|
+
},
|
|
442
|
+
signal: i
|
|
443
|
+
}),
|
|
444
|
+
e.timeout
|
|
445
|
+
);
|
|
446
|
+
if (r)
|
|
447
|
+
throw r;
|
|
448
|
+
return n;
|
|
449
|
+
}
|
|
450
|
+
async function ht(e) {
|
|
451
|
+
const t = o(), { data: n, error: r } = await a(
|
|
452
|
+
(i) => t.GET("/display/brightness", { signal: i }),
|
|
453
|
+
e == null ? void 0 : e.timeout
|
|
454
|
+
);
|
|
455
|
+
if (r)
|
|
456
|
+
throw r;
|
|
457
|
+
return n;
|
|
458
|
+
}
|
|
459
|
+
async function yt(e) {
|
|
460
|
+
const t = o(), { front: n, back: r } = e, i = (d) => {
|
|
461
|
+
if (typeof d == "number") {
|
|
462
|
+
if (d < 0 || d > 100)
|
|
394
463
|
throw new Error("Brightness value must be between 0 and 100 or 'auto'");
|
|
395
|
-
return String(
|
|
464
|
+
return String(d);
|
|
396
465
|
}
|
|
397
|
-
if (
|
|
466
|
+
if (d === "auto")
|
|
398
467
|
return "auto";
|
|
399
|
-
}, s = n
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
468
|
+
}, s = i(n), c = i(r), { data: h, error: l } = await a(
|
|
469
|
+
(d) => t.POST("/display/brightness", {
|
|
470
|
+
params: {
|
|
471
|
+
query: {
|
|
472
|
+
front: s,
|
|
473
|
+
back: c
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
signal: d
|
|
477
|
+
}),
|
|
478
|
+
e.timeout
|
|
479
|
+
);
|
|
480
|
+
if (l)
|
|
481
|
+
throw l;
|
|
482
|
+
return h;
|
|
410
483
|
}
|
|
411
|
-
async function
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
484
|
+
async function lt(e) {
|
|
485
|
+
const t = o(), { data: n, error: r } = await a(
|
|
486
|
+
(i) => t.GET("/audio/volume", { signal: i }),
|
|
487
|
+
e == null ? void 0 : e.timeout
|
|
488
|
+
);
|
|
489
|
+
if (r)
|
|
490
|
+
throw r;
|
|
491
|
+
return n;
|
|
418
492
|
}
|
|
419
|
-
async function
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const { volume: t } = e;
|
|
423
|
-
if (typeof t != "number" || t < 0 || t > 100)
|
|
493
|
+
async function ft(e) {
|
|
494
|
+
const t = o(), { volume: n } = e;
|
|
495
|
+
if (typeof n != "number" || n < 0 || n > 100)
|
|
424
496
|
throw new Error("Volume must be a number between 0 and 100");
|
|
425
|
-
const { data:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
497
|
+
const { data: r, error: i } = await a(
|
|
498
|
+
(s) => t.POST("/audio/volume", {
|
|
499
|
+
params: {
|
|
500
|
+
query: {
|
|
501
|
+
volume: n
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
signal: s
|
|
505
|
+
}),
|
|
506
|
+
e.timeout
|
|
507
|
+
);
|
|
508
|
+
if (i)
|
|
509
|
+
throw i;
|
|
510
|
+
return r;
|
|
435
511
|
}
|
|
436
|
-
async function
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
512
|
+
async function wt(e) {
|
|
513
|
+
const t = o(), { data: n, error: r } = await a(
|
|
514
|
+
(i) => t.GET("/access", { signal: i }),
|
|
515
|
+
e == null ? void 0 : e.timeout
|
|
516
|
+
);
|
|
517
|
+
if (r)
|
|
518
|
+
throw r;
|
|
519
|
+
return n;
|
|
443
520
|
}
|
|
444
|
-
async function
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (!/^\d{4,10}$/.test(String(i)))
|
|
521
|
+
async function pt(e) {
|
|
522
|
+
const t = o();
|
|
523
|
+
let { mode: n, key: r } = e;
|
|
524
|
+
if (r = r ?? "", String(r).trim() && !/^\d{4,10}$/.test(String(r)))
|
|
449
525
|
throw new Error("Key must be a string of 4 to 10 digits");
|
|
450
|
-
const { data:
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
526
|
+
const { data: i, error: s } = await a(
|
|
527
|
+
(c) => t.POST("/access", {
|
|
528
|
+
params: {
|
|
529
|
+
query: {
|
|
530
|
+
mode: n,
|
|
531
|
+
key: r
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
signal: c
|
|
535
|
+
}),
|
|
536
|
+
e.timeout
|
|
537
|
+
);
|
|
458
538
|
if (s)
|
|
459
539
|
throw s;
|
|
460
|
-
return
|
|
540
|
+
return i;
|
|
461
541
|
}
|
|
462
|
-
async function
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
542
|
+
async function St(e) {
|
|
543
|
+
const t = o(), { data: n, error: r } = await a(
|
|
544
|
+
(i) => t.GET("/name", { signal: i }),
|
|
545
|
+
e == null ? void 0 : e.timeout
|
|
546
|
+
);
|
|
547
|
+
if (r)
|
|
548
|
+
throw r;
|
|
549
|
+
return n;
|
|
469
550
|
}
|
|
470
|
-
async function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
551
|
+
async function mt(e) {
|
|
552
|
+
const t = o(), { data: n, error: r } = await a(
|
|
553
|
+
(i) => t.POST("/name", {
|
|
554
|
+
body: e,
|
|
555
|
+
signal: i
|
|
556
|
+
}),
|
|
557
|
+
e.timeout
|
|
558
|
+
);
|
|
559
|
+
if (r)
|
|
560
|
+
throw r;
|
|
561
|
+
return n;
|
|
479
562
|
}
|
|
480
|
-
async function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
563
|
+
async function Tt(e) {
|
|
564
|
+
const t = o(), { data: n, error: r } = await a(
|
|
565
|
+
(i) => t.POST("/ble/enable", { signal: i }),
|
|
566
|
+
e == null ? void 0 : e.timeout
|
|
567
|
+
);
|
|
568
|
+
if (r)
|
|
569
|
+
throw r;
|
|
570
|
+
return n;
|
|
487
571
|
}
|
|
488
|
-
async function
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
572
|
+
async function Et(e) {
|
|
573
|
+
const t = o(), { data: n, error: r } = await a(
|
|
574
|
+
(i) => t.POST("/ble/disable", { signal: i }),
|
|
575
|
+
e == null ? void 0 : e.timeout
|
|
576
|
+
);
|
|
577
|
+
if (r)
|
|
578
|
+
throw r;
|
|
579
|
+
return n;
|
|
495
580
|
}
|
|
496
|
-
async function
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
581
|
+
async function kt(e) {
|
|
582
|
+
const t = o(), { data: n, error: r } = await a(
|
|
583
|
+
(i) => t.DELETE("/ble/pairing", { signal: i }),
|
|
584
|
+
e == null ? void 0 : e.timeout
|
|
585
|
+
);
|
|
586
|
+
if (r)
|
|
587
|
+
throw r;
|
|
588
|
+
return n;
|
|
503
589
|
}
|
|
504
|
-
async function
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
590
|
+
async function gt(e) {
|
|
591
|
+
const t = o(), { data: n, error: r } = await a(
|
|
592
|
+
(i) => t.GET("/ble/status", { signal: i }),
|
|
593
|
+
e == null ? void 0 : e.timeout
|
|
594
|
+
);
|
|
595
|
+
if (r)
|
|
596
|
+
throw r;
|
|
597
|
+
return n;
|
|
511
598
|
}
|
|
512
|
-
async function
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
599
|
+
async function At(e) {
|
|
600
|
+
const t = o(), { keyName: n } = e, { data: r, error: i } = await a(
|
|
601
|
+
(s) => t.POST("/input", {
|
|
602
|
+
params: {
|
|
603
|
+
query: {
|
|
604
|
+
key: n
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
signal: s
|
|
608
|
+
}),
|
|
609
|
+
e.timeout
|
|
610
|
+
);
|
|
611
|
+
if (i)
|
|
612
|
+
throw i;
|
|
613
|
+
return r;
|
|
525
614
|
}
|
|
526
|
-
|
|
527
|
-
class Tt {
|
|
615
|
+
class Lt {
|
|
528
616
|
/**
|
|
529
617
|
* Creates an instance of BUSY Bar.
|
|
530
618
|
* Initializes the API client with the provided host address.
|
|
@@ -553,222 +641,367 @@ class Tt {
|
|
|
553
641
|
* @type {BusyBarConfig['host']}
|
|
554
642
|
* @readonly
|
|
555
643
|
*/
|
|
556
|
-
|
|
644
|
+
u(this, "addr");
|
|
557
645
|
/**
|
|
558
646
|
* Current API semantic version.
|
|
559
647
|
* @type {ApiSemver}
|
|
560
648
|
*/
|
|
561
|
-
|
|
649
|
+
u(this, "apiSemver");
|
|
650
|
+
/**
|
|
651
|
+
* Detected connection type based on auth requirements.
|
|
652
|
+
* - "wifi": Device requires authentication (returned 401/403).
|
|
653
|
+
* - "usb": Device allows access without token (returned 200).
|
|
654
|
+
* - "unknown": Detection failed or not yet completed.
|
|
655
|
+
*/
|
|
656
|
+
u(this, "connectionType", "unknown");
|
|
562
657
|
if (!t || !t.addr && !t.token)
|
|
563
|
-
this.addr =
|
|
658
|
+
this.addr = k;
|
|
564
659
|
else if (!t.addr)
|
|
565
|
-
this.addr =
|
|
660
|
+
this.addr = C;
|
|
566
661
|
else {
|
|
567
|
-
let
|
|
568
|
-
if (/^https?:\/\//i.test(
|
|
662
|
+
let n = t.addr.trim();
|
|
663
|
+
if (/^https?:\/\//i.test(n) || (n = `http://${n}`), W.test(n) && !t.token)
|
|
569
664
|
throw new Error("Token is required. Please provide it.");
|
|
570
|
-
this.addr =
|
|
665
|
+
this.addr = n;
|
|
571
666
|
}
|
|
572
|
-
this.apiSemver = "",
|
|
667
|
+
this.apiSemver = "", N(
|
|
573
668
|
`${this.addr}/api/`,
|
|
574
|
-
this.
|
|
669
|
+
this.SystemVersion.bind(this),
|
|
575
670
|
t == null ? void 0 : t.token
|
|
576
|
-
);
|
|
671
|
+
), this.detectConnectionType();
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Probes the device to determine connection type.
|
|
675
|
+
* Sends a request without authentication credentials.
|
|
676
|
+
*/
|
|
677
|
+
async detectConnectionType() {
|
|
678
|
+
const t = new URL(this.addr).hostname;
|
|
679
|
+
if (!g(t) && !A(t)) {
|
|
680
|
+
this.connectionType = "wifi";
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const n = v({
|
|
684
|
+
baseUrl: `${this.addr}/api/`
|
|
685
|
+
});
|
|
686
|
+
try {
|
|
687
|
+
const { response: r } = await n.GET("/name");
|
|
688
|
+
if (r.status === 401 || r.status === 403)
|
|
689
|
+
this.connectionType = "wifi";
|
|
690
|
+
else if (r.ok)
|
|
691
|
+
this.connectionType = "usb";
|
|
692
|
+
else
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Failed to detect connection type. Status: ${r.status}`
|
|
695
|
+
);
|
|
696
|
+
} catch (r) {
|
|
697
|
+
throw r;
|
|
698
|
+
}
|
|
577
699
|
}
|
|
578
700
|
/**
|
|
579
|
-
*
|
|
701
|
+
* Get API version information.
|
|
580
702
|
*
|
|
703
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
704
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
581
705
|
* @returns {Promise<VersionInfo>} A promise that resolves to an object containing the `api_semver` string.
|
|
582
706
|
*/
|
|
583
|
-
async
|
|
584
|
-
const
|
|
585
|
-
return this.apiSemver =
|
|
707
|
+
async SystemVersion(t) {
|
|
708
|
+
const n = await rt(t);
|
|
709
|
+
return this.apiSemver = n.api_semver, n;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* @deprecated Use `SystemVersion` instead. will be removed in the next release.
|
|
713
|
+
*/
|
|
714
|
+
async getApiVersion(t) {
|
|
715
|
+
return this.SystemVersion(t);
|
|
586
716
|
}
|
|
587
717
|
/**
|
|
588
|
-
*
|
|
718
|
+
* Update firmware. Uploads a firmware update package (TAR file) and initiates the update process.
|
|
589
719
|
*
|
|
590
720
|
* @param {UpdateParams} params - Parameters for the firmware update.
|
|
591
|
-
*
|
|
592
|
-
*
|
|
721
|
+
* @param {UpdateParams['name']} params.name - Name for the update package.
|
|
722
|
+
* @param {UpdateParams['file']} params.file - File data to upload.
|
|
723
|
+
* @param {UpdateParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
593
724
|
* @returns {Promise<SuccessResponse>} Result of the update operation.
|
|
594
725
|
*/
|
|
726
|
+
async SystemUpdate(t) {
|
|
727
|
+
return await it(t);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* @deprecated Use `SystemUpdate` instead. will be removed in the next release.
|
|
731
|
+
*/
|
|
595
732
|
async updateFirmware(t) {
|
|
596
|
-
return
|
|
733
|
+
return this.SystemUpdate(t);
|
|
597
734
|
}
|
|
598
735
|
/**
|
|
599
|
-
*
|
|
736
|
+
* Get device status.
|
|
600
737
|
*
|
|
738
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
739
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
601
740
|
* @returns {Promise<Status>} Current status of the device.
|
|
602
741
|
*/
|
|
603
|
-
async
|
|
604
|
-
return await
|
|
742
|
+
async SystemStatus(t) {
|
|
743
|
+
return await st(t);
|
|
605
744
|
}
|
|
606
745
|
/**
|
|
607
|
-
*
|
|
746
|
+
* @deprecated Use `SystemStatus` instead. will be removed in the next release.
|
|
747
|
+
*/
|
|
748
|
+
async deviceStatus(t) {
|
|
749
|
+
return this.SystemStatus(t);
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Get system status.
|
|
608
753
|
*
|
|
754
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
755
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
609
756
|
* @returns {Promise<StatusSystem>} Current system status.
|
|
610
757
|
*/
|
|
611
|
-
async
|
|
612
|
-
return await
|
|
758
|
+
async SystemInfo(t) {
|
|
759
|
+
return await ot(t);
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* @deprecated Use `SystemInfo` instead. will be removed in the next release.
|
|
763
|
+
*/
|
|
764
|
+
async systemStatus(t) {
|
|
765
|
+
return this.SystemInfo(t);
|
|
613
766
|
}
|
|
614
767
|
/**
|
|
615
|
-
*
|
|
768
|
+
* Get power status.
|
|
616
769
|
*
|
|
770
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
771
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
617
772
|
* @returns {Promise<StatusPower>} Current power status.
|
|
618
773
|
*/
|
|
619
|
-
async
|
|
620
|
-
return await
|
|
774
|
+
async SystemStatusPower(t) {
|
|
775
|
+
return await at(t);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* @deprecated Use `SystemStatusPower` instead. will be removed in the next release.
|
|
779
|
+
*/
|
|
780
|
+
async powerStatus(t) {
|
|
781
|
+
return this.SystemStatusPower(t);
|
|
621
782
|
}
|
|
622
783
|
/**
|
|
623
|
-
*
|
|
784
|
+
* Get current timestamp with timezone. Retrieves the current timestamp from RTC with timezone in ISO 8601 format.
|
|
624
785
|
*
|
|
786
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
787
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
625
788
|
* @returns {Promise<TimestampInfo>} Current device timestamp as an ISO 8601 string.
|
|
626
789
|
*/
|
|
627
|
-
async
|
|
628
|
-
return await
|
|
790
|
+
async SystemTime(t) {
|
|
791
|
+
return await ct(t);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* @deprecated Use `SystemTime` instead. will be removed in the next release.
|
|
795
|
+
*/
|
|
796
|
+
async getTime(t) {
|
|
797
|
+
return this.SystemTime(t);
|
|
629
798
|
}
|
|
630
799
|
/**
|
|
631
|
-
* Sets the
|
|
800
|
+
* Set current timestamp. Sets the RTC timestamp in ISO 8601 format.
|
|
801
|
+
* * - Without 'Z': treated as local time
|
|
802
|
+
* * - With 'Z': treated as UTC and converted to local time using current timezone offset
|
|
632
803
|
*
|
|
633
804
|
* @param {SetTimestampParams} params - The parameters for setting the timestamp.
|
|
634
|
-
*
|
|
805
|
+
* @param {SetTimestampParams['timestamp']} params.timestamp - The new timestamp (ISO 8601 string).
|
|
806
|
+
* @param {SetTimestampParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
635
807
|
* @returns {Promise<SuccessResponse>} A success response if the timestamp was set.
|
|
636
808
|
*/
|
|
809
|
+
async SystemTimeTimestamp(t) {
|
|
810
|
+
return await ut(t);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* @deprecated Use `SystemTimeTimestamp` instead. will be removed in the next release.
|
|
814
|
+
*/
|
|
637
815
|
async setTimestamp(t) {
|
|
638
|
-
return
|
|
816
|
+
return this.SystemTimeTimestamp(t);
|
|
639
817
|
}
|
|
640
818
|
/**
|
|
641
|
-
* Sets the
|
|
819
|
+
* Set timezone offset. Sets the timezone offset in ±HH:MM format.
|
|
642
820
|
*
|
|
643
821
|
* @param {SetTimezoneParams} params - The parameters for setting the timezone.
|
|
644
|
-
*
|
|
822
|
+
* @param {SetTimezoneParams['timezone']} params.timezone - The new timezone identifier (IANA TZ string).
|
|
823
|
+
* @param {SetTimezoneParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
645
824
|
* @returns {Promise<SuccessResponse>} A success response if the timezone was set.
|
|
646
825
|
*/
|
|
826
|
+
async SystemTimeTimezone(t) {
|
|
827
|
+
return await dt(t);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* @deprecated Use `SystemTimeTimezone` instead. will be removed in the next release.
|
|
831
|
+
*/
|
|
647
832
|
async setTimezone(t) {
|
|
648
|
-
return
|
|
833
|
+
return this.SystemTimeTimezone(t);
|
|
649
834
|
}
|
|
650
835
|
/**
|
|
651
|
-
*
|
|
836
|
+
* Get MQTT status info.
|
|
652
837
|
*
|
|
838
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
839
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
653
840
|
* @returns {Promise<AccountInfo>} Information about the current MQTT account status.
|
|
654
841
|
*/
|
|
655
|
-
async
|
|
656
|
-
return await
|
|
842
|
+
async Account(t) {
|
|
843
|
+
return await K(t);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* @deprecated Use `Account` instead. will be removed in the next release.
|
|
847
|
+
*/
|
|
848
|
+
async getMqttStatus(t) {
|
|
849
|
+
return this.Account(t);
|
|
657
850
|
}
|
|
658
851
|
/**
|
|
659
|
-
*
|
|
852
|
+
* Unlink device from account. Removes account linking data.
|
|
660
853
|
*
|
|
854
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
855
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
661
856
|
* @returns {Promise<SuccessResponse>} Result of the account unlink operation.
|
|
662
857
|
*/
|
|
663
|
-
async
|
|
664
|
-
return await
|
|
858
|
+
async AccountUnlink(t) {
|
|
859
|
+
return await V(t);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* @deprecated Use `AccountUnlink` instead. will be removed in the next release.
|
|
863
|
+
*/
|
|
864
|
+
async unlinkAccount(t) {
|
|
865
|
+
return this.AccountUnlink(t);
|
|
665
866
|
}
|
|
666
867
|
/**
|
|
667
|
-
*
|
|
868
|
+
* Link device to account. Requests account link PIN. Works only if device is connected to MQTT and is not linked to account.
|
|
668
869
|
*
|
|
870
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
871
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
669
872
|
* @returns {Promise<AccountLink>} Information about the account link operation.
|
|
670
873
|
*/
|
|
671
|
-
async
|
|
672
|
-
return await
|
|
874
|
+
async AccountLink(t) {
|
|
875
|
+
return await G(t);
|
|
673
876
|
}
|
|
674
877
|
/**
|
|
675
|
-
*
|
|
878
|
+
* @deprecated Use `AccountLink` instead. will be removed in the next release.
|
|
879
|
+
*/
|
|
880
|
+
async linkAccount(t) {
|
|
881
|
+
return this.AccountLink(t);
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Upload asset file with app ID. Uploads a file to a specific app's assets directory.
|
|
676
885
|
*
|
|
677
886
|
* @param {UploadParams} params - Parameters for the upload.
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
887
|
+
* @param {UploadParams['appId']} params.appId - Application ID for organizing assets.
|
|
888
|
+
* @param {UploadParams['fileName']} params.fileName - Filename for the uploaded asset.
|
|
889
|
+
* @param {UploadParams['file']} params.file - File data to upload.
|
|
890
|
+
* @param {UploadParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
681
891
|
* @returns {Promise<SuccessResponse>} Result of the upload operation.
|
|
682
892
|
*/
|
|
893
|
+
async AssetsUpload(t) {
|
|
894
|
+
return await _(t);
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* @deprecated Use `AssetsUpload` instead. will be removed in the next release.
|
|
898
|
+
*/
|
|
683
899
|
async uploadAsset(t) {
|
|
684
|
-
return
|
|
900
|
+
return this.AssetsUpload(t);
|
|
685
901
|
}
|
|
686
902
|
/**
|
|
687
|
-
* Deletes all assets for a specific
|
|
903
|
+
* Delete app assets. Deletes all assets for a specific app ID.
|
|
688
904
|
*
|
|
689
905
|
* @param {DeleteParams} params - Parameters for the delete.
|
|
690
|
-
*
|
|
906
|
+
* @param {DeleteParams['appId']} params.appId - Application ID whose assets should be deleted.
|
|
907
|
+
* @param {DeleteParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
691
908
|
* @returns {Promise<SuccessResponse>} Result of the delete operation.
|
|
692
909
|
*/
|
|
910
|
+
async AssetsDelete(t) {
|
|
911
|
+
return await F(t);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* @deprecated Use `AssetsDelete` instead. will be removed in the next release.
|
|
915
|
+
*/
|
|
693
916
|
async deleteAssets(t) {
|
|
694
|
-
return
|
|
917
|
+
return this.AssetsDelete(t);
|
|
695
918
|
}
|
|
696
919
|
/**
|
|
697
|
-
*
|
|
920
|
+
* Draw on display. Sends drawing data to the display. Supports JSON-defined display elements.
|
|
698
921
|
*
|
|
699
922
|
* @param {DrawParams} params - Parameters for the draw operation.
|
|
700
|
-
*
|
|
701
|
-
*
|
|
923
|
+
* @param {DrawParams['appId']} params.appId - Application ID for organizing display elements.
|
|
924
|
+
* @param {DrawParams['elements'][]} params.elements - Array of display elements (text or image).
|
|
925
|
+
* @param {DrawParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
702
926
|
* @returns {Promise<SuccessResponse>} Result of the draw operation.
|
|
703
927
|
*/
|
|
928
|
+
async DisplayDraw(t) {
|
|
929
|
+
return await x(t);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* @deprecated Use `DisplayDraw` instead. will be removed in the next release.
|
|
933
|
+
*/
|
|
704
934
|
async drawDisplay(t) {
|
|
705
|
-
return
|
|
935
|
+
return this.DisplayDraw(t);
|
|
706
936
|
}
|
|
707
937
|
/**
|
|
708
|
-
* Clears the
|
|
938
|
+
* Clear display. Clears the display and stops the Canvas application if running.
|
|
709
939
|
*
|
|
940
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
941
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
710
942
|
* @returns {Promise<SuccessResponse>} Result of the clear operation.
|
|
711
943
|
*/
|
|
712
|
-
async
|
|
713
|
-
return await
|
|
944
|
+
async DisplayClear(t) {
|
|
945
|
+
return await q(t);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* @deprecated Use `DisplayClear` instead. will be removed in the next release.
|
|
949
|
+
*/
|
|
950
|
+
async clearDisplay(t) {
|
|
951
|
+
return this.DisplayClear(t);
|
|
714
952
|
}
|
|
715
953
|
/**
|
|
716
|
-
* Plays an audio file from the assets directory.
|
|
954
|
+
* Play audio file. Plays an audio file from the assets directory. Supported formats include .snd files.
|
|
717
955
|
*
|
|
718
956
|
* @param {AudioPlayParams} params - Parameters for the audio playback.
|
|
719
|
-
*
|
|
720
|
-
*
|
|
957
|
+
* @param {AudioPlayParams['appId']} params.appId - Application ID for organizing assets.
|
|
958
|
+
* @param {AudioPlayParams['path']} params.path - Path to the audio file within the app's assets directory.
|
|
959
|
+
* @param {AudioPlayParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
721
960
|
* @returns {Promise<SuccessResponse>} Result of the play operation.
|
|
722
961
|
*/
|
|
962
|
+
async AudioPlay(t) {
|
|
963
|
+
return await j(t);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @deprecated Use `AudioPlay` instead. will be removed in the next release.
|
|
967
|
+
*/
|
|
723
968
|
async playSound(t) {
|
|
724
|
-
return
|
|
969
|
+
return this.AudioPlay(t);
|
|
725
970
|
}
|
|
726
971
|
/**
|
|
727
|
-
* Stops any currently playing audio
|
|
972
|
+
* Stop audio playback. Stops any currently playing audio.
|
|
728
973
|
*
|
|
974
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
975
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
729
976
|
* @returns {Promise<SuccessResponse>} Result of the stop operation.
|
|
730
977
|
*/
|
|
731
|
-
async
|
|
732
|
-
return await
|
|
978
|
+
async AudioStop(t) {
|
|
979
|
+
return await H(t);
|
|
733
980
|
}
|
|
734
981
|
/**
|
|
735
|
-
* @deprecated
|
|
736
|
-
*
|
|
737
|
-
* This method is no longer supported and does nothing.
|
|
738
|
-
*
|
|
739
|
-
* Works only with BusyLib v0.5.0 and device firmware v0.3.0.
|
|
740
|
-
*
|
|
741
|
-
* Always throws an error.
|
|
982
|
+
* @deprecated Use `AudioStop` instead. will be removed in the next release.
|
|
742
983
|
*/
|
|
743
|
-
async
|
|
744
|
-
|
|
745
|
-
"[DEPRECATED] BusyBar.enableWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
|
|
746
|
-
);
|
|
984
|
+
async stopSound(t) {
|
|
985
|
+
return this.AudioStop(t);
|
|
747
986
|
}
|
|
748
987
|
/**
|
|
749
|
-
*
|
|
988
|
+
* Returns current Wi-Fi status.
|
|
750
989
|
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
* Always throws an error.
|
|
990
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
991
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
992
|
+
* @returns {Promise<WifiStatusResponse>} Current Wi-Fi status.
|
|
756
993
|
*/
|
|
757
|
-
async
|
|
758
|
-
|
|
759
|
-
"[DEPRECATED] BusyBar.disableWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
|
|
760
|
-
);
|
|
994
|
+
async WifiStatus(t) {
|
|
995
|
+
return await z(t);
|
|
761
996
|
}
|
|
762
997
|
/**
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
* @returns {Promise<WifiStatusResponse>} Current Wi-Fi status.
|
|
998
|
+
* @deprecated Use `WifiStatus` instead. will be removed in the next release.
|
|
766
999
|
*/
|
|
767
|
-
async statusWifi() {
|
|
768
|
-
return
|
|
1000
|
+
async statusWifi(t) {
|
|
1001
|
+
return this.WifiStatus(t);
|
|
769
1002
|
}
|
|
770
1003
|
/**
|
|
771
|
-
*
|
|
1004
|
+
* Attempts to connect to Wi-Fi using config.
|
|
772
1005
|
*
|
|
773
1006
|
* @param {ConnectParams} params - Connection parameters:
|
|
774
1007
|
* @param {ConnectParams['ssid']} params.ssid - SSID (network name) to connect to.
|
|
@@ -780,283 +1013,452 @@ class Tt {
|
|
|
780
1013
|
* @param {ConnectParams['ipConfig']['address']} [params.ipConfig.address] - Static IP address (if using "static" method).
|
|
781
1014
|
* @param {ConnectParams['ipConfig']['mask']} [params.ipConfig.mask] - Subnet mask (if using "static" method).
|
|
782
1015
|
* @param {ConnectParams['ipConfig']['gateway']} [params.ipConfig.gateway] - Gateway address (if using "static" method).
|
|
1016
|
+
* @param {ConnectParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
783
1017
|
* @returns {Promise<SuccessResponse>} Result of the connect operation.
|
|
784
1018
|
*/
|
|
1019
|
+
async WifiConnect(t) {
|
|
1020
|
+
return await J(t);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* @deprecated Use `WifiConnect` instead. will be removed in the next release.
|
|
1024
|
+
*/
|
|
785
1025
|
async connectWifi(t) {
|
|
786
|
-
return
|
|
1026
|
+
return this.WifiConnect(t);
|
|
787
1027
|
}
|
|
788
1028
|
/**
|
|
789
|
-
* Disconnects
|
|
1029
|
+
* Disconnects from Wi-Fi.
|
|
790
1030
|
*
|
|
1031
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1032
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
791
1033
|
* @returns {Promise<SuccessResponse>} Result of the disconnect operation.
|
|
792
1034
|
*/
|
|
793
|
-
async
|
|
794
|
-
return await
|
|
1035
|
+
async WifiDisconnect(t) {
|
|
1036
|
+
return await M(t);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* @deprecated Use `WifiDisconnect` instead. will be removed in the next release.
|
|
1040
|
+
*/
|
|
1041
|
+
async disconnectWifi(t) {
|
|
1042
|
+
return this.WifiDisconnect(t);
|
|
795
1043
|
}
|
|
796
1044
|
/**
|
|
797
|
-
* Scans for available Wi-Fi networks
|
|
1045
|
+
* Scans environment for available Wi-Fi networks.
|
|
798
1046
|
*
|
|
1047
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1048
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
799
1049
|
* @returns {Promise<WifiNetworkResponse>} List of discovered networks.
|
|
800
1050
|
*/
|
|
801
|
-
async
|
|
802
|
-
return await
|
|
1051
|
+
async WifiNetworks(t) {
|
|
1052
|
+
return await X(t);
|
|
803
1053
|
}
|
|
804
1054
|
/**
|
|
805
|
-
* @deprecated
|
|
806
|
-
*
|
|
807
|
-
* This method is no longer supported and does nothing.
|
|
808
|
-
*
|
|
809
|
-
* Works only with BusyLib v0.5.0 and device firmware v0.3.0.
|
|
810
|
-
*
|
|
811
|
-
* Always throws an error.
|
|
1055
|
+
* @deprecated Use `WifiNetworks` instead. will be removed in the next release.
|
|
812
1056
|
*/
|
|
813
|
-
async
|
|
814
|
-
|
|
815
|
-
"[DEPRECATED] BusyBar.forgetWifi: This method is deprecated since v0.5.0 and will be removed in v0.7.0. It is no longer supported and does nothing. Works only with BusyLib v0.5.0 and device firmware v0.3.0."
|
|
816
|
-
);
|
|
1057
|
+
async networksWifi(t) {
|
|
1058
|
+
return this.WifiNetworks(t);
|
|
817
1059
|
}
|
|
818
1060
|
/**
|
|
819
|
-
* Uploads a file to
|
|
1061
|
+
* Upload file to internal storage. Uploads a file to a specified path.
|
|
820
1062
|
*
|
|
821
1063
|
* @param {UploadFileParams} params - Upload parameters:
|
|
822
1064
|
* @param {UploadFileParams['path']} params.path - Path where the file will be saved (e.g., "/ext/test.png").
|
|
823
1065
|
* @param {UploadFileParams['file']} params.file - File data to upload.
|
|
1066
|
+
* @param {UploadFileParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
824
1067
|
* @returns {Promise<SuccessResponse>} Result of the upload operation.
|
|
825
1068
|
*/
|
|
1069
|
+
async StorageWrite(t) {
|
|
1070
|
+
return await Q(t);
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* @deprecated Use `StorageWrite` instead. will be removed in the next release.
|
|
1074
|
+
*/
|
|
826
1075
|
async uploadFile(t) {
|
|
827
|
-
return
|
|
1076
|
+
return this.StorageWrite(t);
|
|
828
1077
|
}
|
|
829
1078
|
/**
|
|
830
|
-
* Downloads a file from
|
|
1079
|
+
* Download file from internal storage. Downloads a file from a specified path.
|
|
831
1080
|
*
|
|
832
1081
|
* @param {DownloadFileParams} params - Download parameters:
|
|
833
1082
|
* @param {DownloadFileParams['path']} params.path - Path to the file to download (e.g., "/ext/test.png").
|
|
834
1083
|
* @param {DownloadFileParams['asArrayBuffer']} [params.asArrayBuffer] - If true, returns data as ArrayBuffer; otherwise, as Blob.
|
|
1084
|
+
* @param {DownloadFileParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
835
1085
|
* @returns {Promise<StorageReadResponse>} The file data.
|
|
836
1086
|
*/
|
|
1087
|
+
async StorageRead(t) {
|
|
1088
|
+
return await Y(t);
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* @deprecated Use `StorageRead` instead. will be removed in the next release.
|
|
1092
|
+
*/
|
|
837
1093
|
async downloadFile(t) {
|
|
838
|
-
return
|
|
1094
|
+
return this.StorageRead(t);
|
|
839
1095
|
}
|
|
840
1096
|
/**
|
|
841
|
-
*
|
|
1097
|
+
* List files on internal storage.
|
|
842
1098
|
*
|
|
843
1099
|
* @param {ReadDirectoryParams} params - List parameters:
|
|
844
1100
|
* @param {ReadDirectoryParams['path']} params.path - Path to the directory to list (e.g., "/ext").
|
|
1101
|
+
* @param {ReadDirectoryParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
845
1102
|
* @returns {Promise<StorageList>} List of files and directories.
|
|
846
1103
|
*/
|
|
1104
|
+
async StorageList(t) {
|
|
1105
|
+
return await Z(t);
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* @deprecated Use `StorageList` instead. will be removed in the next release.
|
|
1109
|
+
*/
|
|
847
1110
|
async readDirectory(t) {
|
|
848
|
-
return
|
|
1111
|
+
return this.StorageList(t);
|
|
849
1112
|
}
|
|
850
1113
|
/**
|
|
851
|
-
*
|
|
1114
|
+
* Remove a file on internal storage. Removes a file with a specified path.
|
|
852
1115
|
*
|
|
853
1116
|
* @param {RemoveParams} params - Remove parameters:
|
|
854
1117
|
* @param {RemoveParams['path']} params.path - Path of the file to remove (e.g., "/ext/test.png").
|
|
1118
|
+
* @param {RemoveParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
855
1119
|
* @returns {Promise<SuccessResponse>} Result of the remove operation.
|
|
856
1120
|
*/
|
|
1121
|
+
async StorageRemove(t) {
|
|
1122
|
+
return await tt(t);
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* @deprecated Use `StorageRemove` instead. will be removed in the next release.
|
|
1126
|
+
*/
|
|
857
1127
|
async removeResource(t) {
|
|
858
|
-
return
|
|
1128
|
+
return this.StorageRemove(t);
|
|
859
1129
|
}
|
|
860
1130
|
/**
|
|
861
|
-
* Creates a new directory
|
|
1131
|
+
* Create a directory on internal storage. Creates a new directory with a specified path.
|
|
862
1132
|
*
|
|
863
1133
|
* @param {CreateDirectoryParams} params - Directory creation parameters:
|
|
864
1134
|
* @param {CreateDirectoryParams['path']} params.path - Path to the new directory (e.g., "/ext/newdir").
|
|
1135
|
+
* @param {CreateDirectoryParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
865
1136
|
* @returns {Promise<SuccessResponse>} Result of the create operation.
|
|
866
1137
|
*/
|
|
1138
|
+
async StorageMkdir(t) {
|
|
1139
|
+
return await et(t);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* @deprecated Use `StorageMkdir` instead. will be removed in the next release.
|
|
1143
|
+
*/
|
|
867
1144
|
async createDirectory(t) {
|
|
868
|
-
return
|
|
1145
|
+
return this.StorageMkdir(t);
|
|
869
1146
|
}
|
|
870
1147
|
/**
|
|
871
|
-
*
|
|
1148
|
+
* Show storage usage.
|
|
872
1149
|
*
|
|
1150
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1151
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
873
1152
|
* @returns {Promise<StorageStatus>} Current storage status information.
|
|
874
1153
|
*/
|
|
875
|
-
async
|
|
876
|
-
return await
|
|
1154
|
+
async StorageStatus(t) {
|
|
1155
|
+
return await nt(t);
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* @deprecated Use `StorageStatus` instead. will be removed in the next release.
|
|
1159
|
+
*/
|
|
1160
|
+
async statusStorage(t) {
|
|
1161
|
+
return this.StorageStatus(t);
|
|
877
1162
|
}
|
|
878
1163
|
/**
|
|
879
|
-
*
|
|
1164
|
+
* Get brightness value for displays.
|
|
880
1165
|
*
|
|
1166
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1167
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
881
1168
|
* @returns {Promise<DisplayBrightnessInfo>} Current brightness information for front and back panels.
|
|
882
1169
|
*/
|
|
883
|
-
async
|
|
884
|
-
return await
|
|
1170
|
+
async DisplayBrightness(t) {
|
|
1171
|
+
return await ht(t);
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* @deprecated Use `DisplayBrightness` instead. will be removed in the next release.
|
|
1175
|
+
*/
|
|
1176
|
+
async getDisplayBrightness(t) {
|
|
1177
|
+
return this.DisplayBrightness(t);
|
|
885
1178
|
}
|
|
886
1179
|
/**
|
|
887
|
-
*
|
|
1180
|
+
* Set display brightness. Set brightness for one or both displays.
|
|
888
1181
|
*
|
|
889
1182
|
* @param {BrightnessParams} params - Brightness parameters:
|
|
890
1183
|
* @param {BrightnessParams['front']} [params.front] - Brightness for the front panel (0-100 or "auto").
|
|
891
1184
|
* @param {BrightnessParams['back']} [params.back] - Brightness for the back panel (0-100 or "auto").
|
|
1185
|
+
* @param {BrightnessParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
892
1186
|
* @returns {Promise<SuccessResponse>} Result of the brightness update operation.
|
|
893
1187
|
* @throws {Error} If brightness value is outside the range 0-100 or not "auto".
|
|
894
1188
|
*/
|
|
1189
|
+
async DisplayBrightnessSet(t) {
|
|
1190
|
+
return await yt(t);
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* @deprecated Use `DisplayBrightnessSet` instead. will be removed in the next release.
|
|
1194
|
+
*/
|
|
895
1195
|
async setDisplayBrightness(t) {
|
|
896
|
-
return
|
|
1196
|
+
return this.DisplayBrightnessSet(t);
|
|
897
1197
|
}
|
|
898
1198
|
/**
|
|
899
|
-
*
|
|
1199
|
+
* Get audio volume.
|
|
900
1200
|
*
|
|
1201
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1202
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
901
1203
|
* @returns {Promise<AudioVolumeInfo>} Current audio volume (0-100).
|
|
902
1204
|
*/
|
|
903
|
-
async
|
|
904
|
-
return await
|
|
1205
|
+
async AudioVolume(t) {
|
|
1206
|
+
return await lt(t);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* @deprecated Use `AudioVolume` instead. will be removed in the next release.
|
|
1210
|
+
*/
|
|
1211
|
+
async getAudioVolume(t) {
|
|
1212
|
+
return this.AudioVolume(t);
|
|
905
1213
|
}
|
|
906
1214
|
/**
|
|
907
|
-
*
|
|
1215
|
+
* Set audio volume.
|
|
908
1216
|
*
|
|
909
1217
|
* @param {AudioVolumeParams} params - Audio volume parameters:
|
|
910
1218
|
* @param {AudioVolumeParams['volume']} params.volume - Audio volume (number from 0 to 100).
|
|
1219
|
+
* @param {AudioVolumeParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
911
1220
|
* @returns {Promise<SuccessResponse>} Result of the volume update operation.
|
|
912
1221
|
* @throws {Error} If volume is outside the range 0-100 or request fails.
|
|
913
1222
|
*/
|
|
1223
|
+
async AudioVolumeSet(t) {
|
|
1224
|
+
return await ft(t);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* @deprecated Use `AudioVolumeSet` instead. will be removed in the next release.
|
|
1228
|
+
*/
|
|
914
1229
|
async setAudioVolume(t) {
|
|
915
|
-
return
|
|
1230
|
+
return this.AudioVolumeSet(t);
|
|
916
1231
|
}
|
|
917
1232
|
/**
|
|
918
|
-
*
|
|
1233
|
+
* Get HTTP API access over Wi-Fi configuration.
|
|
919
1234
|
*
|
|
1235
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1236
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
920
1237
|
* @returns {Promise<HttpAccessInfo>} Current HTTP access info.
|
|
921
1238
|
*/
|
|
922
|
-
async
|
|
923
|
-
return await
|
|
1239
|
+
async SettingsAccess(t) {
|
|
1240
|
+
return await wt(t);
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* @deprecated Use `SettingsAccess` instead. will be removed in the next release.
|
|
1244
|
+
*/
|
|
1245
|
+
async getHttpAccess(t) {
|
|
1246
|
+
return this.SettingsAccess(t);
|
|
924
1247
|
}
|
|
925
1248
|
/**
|
|
926
|
-
*
|
|
1249
|
+
* Set HTTP API access over Wi-Fi configuration.
|
|
927
1250
|
*
|
|
928
1251
|
* @param {HttpAccessParams} params - Access parameters:
|
|
929
1252
|
* @param {HttpAccessParams['mode']} params.mode - Access mode ("disabled", "enabled", "key").
|
|
930
1253
|
* @param {HttpAccessParams['key']} params.key - Access key (4-10 digits).
|
|
1254
|
+
* @param {HttpAccessParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
931
1255
|
* @returns {Promise<SuccessResponse>} Result of the set operation.
|
|
932
1256
|
*/
|
|
1257
|
+
async SettingsAccessSet(t) {
|
|
1258
|
+
const n = await pt(t);
|
|
1259
|
+
return t.mode === "key" && t.key && this.setApiKey(t.key), n;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* @deprecated Use `SettingsAccessSet` instead. will be removed in the next release.
|
|
1263
|
+
*/
|
|
933
1264
|
async setHttpAccess(t) {
|
|
934
|
-
|
|
935
|
-
return t.mode === "key" && t.key && this.setApiKey(t.key), i;
|
|
1265
|
+
return this.SettingsAccessSet(t);
|
|
936
1266
|
}
|
|
937
1267
|
/**
|
|
938
|
-
*
|
|
1268
|
+
* Get current device name.
|
|
939
1269
|
*
|
|
1270
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1271
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
940
1272
|
* @returns {Promise<NameInfo>} The current device name information.
|
|
941
1273
|
*/
|
|
942
|
-
async
|
|
943
|
-
return await
|
|
1274
|
+
async SettingsName(t) {
|
|
1275
|
+
return await St(t);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* @deprecated Use `SettingsName` instead. will be removed in the next release.
|
|
1279
|
+
*/
|
|
1280
|
+
async getName(t) {
|
|
1281
|
+
return this.SettingsName(t);
|
|
944
1282
|
}
|
|
945
1283
|
/**
|
|
946
|
-
*
|
|
1284
|
+
* Set new device name.
|
|
947
1285
|
*
|
|
948
1286
|
* @param {NameParams} params - The parameters for setting the device name.
|
|
949
|
-
*
|
|
1287
|
+
* @param {NameParams['name']} params.name - The new device name.
|
|
1288
|
+
* @param {NameParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
950
1289
|
* @returns {Promise<SuccessResponse>} Result of setting the device name.
|
|
951
1290
|
*/
|
|
1291
|
+
async SettingsNameSet(t) {
|
|
1292
|
+
return await mt(t);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* @deprecated Use `SettingsNameSet` instead. will be removed in the next release.
|
|
1296
|
+
*/
|
|
952
1297
|
async setName(t) {
|
|
953
|
-
return
|
|
1298
|
+
return this.SettingsNameSet(t);
|
|
954
1299
|
}
|
|
955
1300
|
/**
|
|
956
1301
|
* Sets API key for all subsequent requests.
|
|
957
1302
|
* @param {string} key - API key to use in "X-API-Token" header.
|
|
958
1303
|
*/
|
|
959
1304
|
setApiKey(t) {
|
|
960
|
-
|
|
1305
|
+
R(t);
|
|
961
1306
|
}
|
|
962
1307
|
/**
|
|
963
|
-
* Enables BLE module.
|
|
1308
|
+
* Enable BLE. Enables BLE module and starts advertising.
|
|
1309
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1310
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
964
1311
|
* @returns {Promise<SuccessResponse>} Result of the enable operation.
|
|
965
1312
|
*/
|
|
966
|
-
async
|
|
967
|
-
return await
|
|
1313
|
+
async BleEnable(t) {
|
|
1314
|
+
return await Tt(t);
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* @deprecated Use `BleEnable` instead. will be removed in the next release.
|
|
1318
|
+
*/
|
|
1319
|
+
async enableBle(t) {
|
|
1320
|
+
return this.BleEnable(t);
|
|
968
1321
|
}
|
|
969
1322
|
/**
|
|
970
|
-
*
|
|
1323
|
+
* Disable BLE. Stops advertising.
|
|
1324
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1325
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
971
1326
|
* @returns {Promise<SuccessResponse>} Result of the disable operation.
|
|
972
1327
|
*/
|
|
973
|
-
async
|
|
974
|
-
return await
|
|
1328
|
+
async BleDisable(t) {
|
|
1329
|
+
return await Et(t);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* @deprecated Use `BleDisable` instead. will be removed in the next release.
|
|
1333
|
+
*/
|
|
1334
|
+
async disableBle(t) {
|
|
1335
|
+
return this.BleDisable(t);
|
|
975
1336
|
}
|
|
976
1337
|
/**
|
|
977
|
-
*
|
|
1338
|
+
* Remove pairing. Remove pairing with previous device.
|
|
978
1339
|
*
|
|
1340
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1341
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
979
1342
|
* @returns {Promise<SuccessResponse>} Result of the BLE pairing removal operation.
|
|
980
1343
|
*/
|
|
981
|
-
async
|
|
982
|
-
return await
|
|
1344
|
+
async BleUnpair(t) {
|
|
1345
|
+
return await kt(t);
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* @deprecated Use `BleUnpair` instead. will be removed in the next release.
|
|
1349
|
+
*/
|
|
1350
|
+
async pairingBle(t) {
|
|
1351
|
+
return this.BleUnpair(t);
|
|
983
1352
|
}
|
|
984
1353
|
/**
|
|
985
|
-
*
|
|
1354
|
+
* Returns current BLE status.
|
|
986
1355
|
*
|
|
1356
|
+
* @param {TimeoutOptions} [params] - Optional parameters.
|
|
1357
|
+
* @param {TimeoutOptions['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
987
1358
|
* @returns {Promise<BleStatusResponse>} Current BLE status information.
|
|
988
1359
|
*/
|
|
989
|
-
async
|
|
990
|
-
return await
|
|
1360
|
+
async BleStatus(t) {
|
|
1361
|
+
return await gt(t);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* @deprecated Use `BleStatus` instead. will be removed in the next release.
|
|
1365
|
+
*/
|
|
1366
|
+
async statusBle(t) {
|
|
1367
|
+
return this.BleStatus(t);
|
|
991
1368
|
}
|
|
992
1369
|
/**
|
|
993
|
-
*
|
|
1370
|
+
* Send input event. Send single key press event.
|
|
994
1371
|
*
|
|
995
1372
|
* @param params - Button press parameters:
|
|
996
1373
|
* @param {InputKeyParams['keyName']} params.keyName - Button key.
|
|
1374
|
+
* @param {InputKeyParams['timeout']} [params.timeout] - Request timeout in milliseconds.
|
|
997
1375
|
* @example
|
|
998
1376
|
* {
|
|
999
|
-
* keyName: "ok"
|
|
1377
|
+
* keyName: "ok",
|
|
1378
|
+
* timeout: 1000
|
|
1000
1379
|
* }
|
|
1001
1380
|
* @returns {Promise<SuccessResponse>} Result of pressing the button.
|
|
1002
1381
|
*/
|
|
1382
|
+
async InputSend(t) {
|
|
1383
|
+
return await At(t);
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* @deprecated Use `InputSend` instead. will be removed in the next release.
|
|
1387
|
+
*/
|
|
1003
1388
|
async pressButton(t) {
|
|
1004
|
-
return
|
|
1389
|
+
return this.InputSend(t);
|
|
1005
1390
|
}
|
|
1006
1391
|
}
|
|
1007
1392
|
var E = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(E || {});
|
|
1008
|
-
const
|
|
1009
|
-
function
|
|
1393
|
+
const D = 3e3, B = /* @__PURE__ */ new Set([1001, 1006, 1012, 1013, 1014, 3008]);
|
|
1394
|
+
function L(e, t) {
|
|
1010
1395
|
if (t < 0 || t >= e.length)
|
|
1011
1396
|
throw new Error(`Index ${t} is out of bounds (0…${e.length - 1})`);
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1397
|
+
const n = e[t];
|
|
1398
|
+
if (n === void 0)
|
|
1014
1399
|
throw new Error(`Unexpected undefined at index ${t}`);
|
|
1015
|
-
return
|
|
1400
|
+
return n;
|
|
1016
1401
|
}
|
|
1017
|
-
function
|
|
1018
|
-
let
|
|
1019
|
-
const
|
|
1020
|
-
for (;
|
|
1021
|
-
const
|
|
1022
|
-
if (
|
|
1023
|
-
const c =
|
|
1024
|
-
for (let
|
|
1025
|
-
|
|
1026
|
-
|
|
1402
|
+
function bt(e, t) {
|
|
1403
|
+
let n = 0;
|
|
1404
|
+
const r = e.length, i = [];
|
|
1405
|
+
for (; n < r; ) {
|
|
1406
|
+
const s = L(e, n);
|
|
1407
|
+
if (n += 1, (s & 128) !== 0) {
|
|
1408
|
+
const c = s & 127;
|
|
1409
|
+
for (let h = 0; h < c * t; h++)
|
|
1410
|
+
i.push(e[n + h]);
|
|
1411
|
+
n += c * t;
|
|
1027
1412
|
} else {
|
|
1028
|
-
const c =
|
|
1029
|
-
for (let
|
|
1030
|
-
for (let
|
|
1031
|
-
|
|
1032
|
-
|
|
1413
|
+
const c = s, h = e.slice(n, n + t);
|
|
1414
|
+
for (let l = 0; l < c; l++)
|
|
1415
|
+
for (let d = 0; d < t; d++)
|
|
1416
|
+
i.push(h[d]);
|
|
1417
|
+
n += t;
|
|
1033
1418
|
}
|
|
1034
1419
|
}
|
|
1035
|
-
return new Uint8Array(
|
|
1420
|
+
return new Uint8Array(i);
|
|
1036
1421
|
}
|
|
1037
|
-
function
|
|
1422
|
+
function vt(e) {
|
|
1038
1423
|
const t = new Uint8Array(e.length * 2);
|
|
1039
|
-
let
|
|
1040
|
-
for (;
|
|
1041
|
-
const
|
|
1042
|
-
t[
|
|
1424
|
+
let n = 0, r = 0;
|
|
1425
|
+
for (; n < e.length; ) {
|
|
1426
|
+
const i = L(e, n), s = i & 15, c = i >> 4 & 15;
|
|
1427
|
+
t[r] = s, t[r + 1] = c, n += 1, r += 2;
|
|
1043
1428
|
}
|
|
1044
1429
|
return t;
|
|
1045
1430
|
}
|
|
1431
|
+
const P = () => typeof window < "u" && typeof window.document < "u";
|
|
1046
1432
|
class Pt {
|
|
1047
1433
|
constructor(t) {
|
|
1048
|
-
|
|
1434
|
+
u(this, "addr");
|
|
1435
|
+
u(this, "connected", !1);
|
|
1049
1436
|
// @ts-ignore
|
|
1050
|
-
|
|
1437
|
+
u(this, "apiKey");
|
|
1051
1438
|
// @ts-ignore
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
if (this.config = t, !(
|
|
1439
|
+
u(this, "apiSemver");
|
|
1440
|
+
u(this, "dataListeners", []);
|
|
1441
|
+
u(this, "stopListeners", []);
|
|
1442
|
+
u(this, "errorListeners", []);
|
|
1443
|
+
u(this, "socket", null);
|
|
1444
|
+
if (this.config = t, !P())
|
|
1058
1445
|
throw new Error("not browser");
|
|
1059
|
-
t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver)
|
|
1446
|
+
if (t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver), !t || !t.addr)
|
|
1447
|
+
this.addr = k;
|
|
1448
|
+
else {
|
|
1449
|
+
let n = t.addr.trim();
|
|
1450
|
+
/^https?:\/\//i.test(n) || (n = `http://${n}`);
|
|
1451
|
+
try {
|
|
1452
|
+
const i = new URL(n).hostname;
|
|
1453
|
+
if (!g(i) && !A(i))
|
|
1454
|
+
throw new Error(
|
|
1455
|
+
`Invalid address: "${t.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`
|
|
1456
|
+
);
|
|
1457
|
+
} catch (r) {
|
|
1458
|
+
throw r instanceof Error && r.message.startsWith("Invalid address") ? r : new Error(`Invalid URL format: "${t.addr}"`);
|
|
1459
|
+
}
|
|
1460
|
+
this.addr = n;
|
|
1461
|
+
}
|
|
1060
1462
|
}
|
|
1061
1463
|
onData(t) {
|
|
1062
1464
|
this.dataListeners.push(t);
|
|
@@ -1068,62 +1470,53 @@ class Pt {
|
|
|
1068
1470
|
this.errorListeners.push(t);
|
|
1069
1471
|
}
|
|
1070
1472
|
emitData(t) {
|
|
1071
|
-
for (const
|
|
1072
|
-
|
|
1473
|
+
for (const n of this.dataListeners)
|
|
1474
|
+
n(t);
|
|
1073
1475
|
}
|
|
1074
1476
|
emitStop() {
|
|
1075
1477
|
for (const t of this.stopListeners)
|
|
1076
1478
|
t();
|
|
1077
1479
|
}
|
|
1078
1480
|
emitError(t) {
|
|
1079
|
-
for (const
|
|
1080
|
-
|
|
1481
|
+
for (const n of this.errorListeners)
|
|
1482
|
+
n(t);
|
|
1081
1483
|
}
|
|
1082
1484
|
async openWebsocket() {
|
|
1083
1485
|
this.socket && await this.closeWebsocket();
|
|
1084
|
-
|
|
1085
|
-
if (this.
|
|
1486
|
+
const t = new URL(`${this.addr}/api/screen/ws`);
|
|
1487
|
+
if (this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver), !t)
|
|
1086
1488
|
throw new Error("The WebSocket URL is not specified");
|
|
1087
1489
|
this.socket = new WebSocket(t), this.socket.onopen = () => {
|
|
1088
|
-
this.socket && (this.
|
|
1089
|
-
|
|
1090
|
-
token: this.config.token,
|
|
1091
|
-
display: this.config.deviceScreen
|
|
1092
|
-
})
|
|
1093
|
-
) : this.config.mode === "local" && this.socket.send(JSON.stringify({ display: this.config.deviceScreen })), this.connected = !0);
|
|
1094
|
-
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (i) => {
|
|
1490
|
+
this.socket && (this.socket.send(JSON.stringify({ display: this.config.deviceScreen })), this.connected = !0);
|
|
1491
|
+
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (n) => {
|
|
1095
1492
|
try {
|
|
1096
|
-
if (typeof
|
|
1493
|
+
if (typeof n.data == "string")
|
|
1097
1494
|
return;
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
this.config.deviceScreen === E.BACK ? s = gt(c) : s = c, this.emitData(s);
|
|
1107
|
-
} catch {
|
|
1108
|
-
this.emitData(n);
|
|
1109
|
-
}
|
|
1495
|
+
const r = new Uint8Array(n.data);
|
|
1496
|
+
let i;
|
|
1497
|
+
const s = this.config.deviceScreen === E.FRONT ? 3 : 2;
|
|
1498
|
+
try {
|
|
1499
|
+
const c = bt(r, s);
|
|
1500
|
+
this.config.deviceScreen === E.BACK ? i = vt(c) : i = c, this.emitData(i);
|
|
1501
|
+
} catch {
|
|
1502
|
+
this.emitData(r);
|
|
1110
1503
|
}
|
|
1111
1504
|
} catch {
|
|
1112
1505
|
this.connected = !1, this.emitStop();
|
|
1113
1506
|
}
|
|
1114
|
-
}, this.socket.onerror = (
|
|
1507
|
+
}, this.socket.onerror = (n) => {
|
|
1115
1508
|
this.connected = !1, this.emitError({
|
|
1116
1509
|
code: 1006,
|
|
1117
1510
|
// Standard «abnormal closure» code per RFC-6455
|
|
1118
1511
|
message: "WebSocket error occurred",
|
|
1119
|
-
raw:
|
|
1512
|
+
raw: n
|
|
1120
1513
|
}), this.emitStop();
|
|
1121
|
-
}, this.socket.onclose = async (
|
|
1122
|
-
if (this.socket = null, this.connected = !1,
|
|
1514
|
+
}, this.socket.onclose = async (n) => {
|
|
1515
|
+
if (this.socket = null, this.connected = !1, n.code === D || B.has(n.code)) {
|
|
1123
1516
|
this.emitError({
|
|
1124
|
-
code:
|
|
1125
|
-
message:
|
|
1126
|
-
raw:
|
|
1517
|
+
code: n.code,
|
|
1518
|
+
message: n.reason,
|
|
1519
|
+
raw: n
|
|
1127
1520
|
});
|
|
1128
1521
|
return;
|
|
1129
1522
|
}
|
|
@@ -1138,21 +1531,38 @@ class Pt {
|
|
|
1138
1531
|
});
|
|
1139
1532
|
}
|
|
1140
1533
|
}
|
|
1141
|
-
class
|
|
1534
|
+
class Ot {
|
|
1142
1535
|
constructor(t) {
|
|
1143
|
-
|
|
1536
|
+
u(this, "addr");
|
|
1537
|
+
u(this, "connected", !1);
|
|
1144
1538
|
// @ts-ignore
|
|
1145
|
-
|
|
1539
|
+
u(this, "apiKey");
|
|
1146
1540
|
// @ts-ignore
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
if (
|
|
1541
|
+
u(this, "apiSemver");
|
|
1542
|
+
u(this, "inputEvent");
|
|
1543
|
+
u(this, "dataListeners", []);
|
|
1544
|
+
u(this, "stopListeners", []);
|
|
1545
|
+
u(this, "errorListeners", []);
|
|
1546
|
+
u(this, "socket", null);
|
|
1547
|
+
if (!P())
|
|
1154
1548
|
throw new Error("not browser");
|
|
1155
|
-
t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver),
|
|
1549
|
+
if (t != null && t.apiKey && (this.apiKey = t.apiKey), t != null && t.apiSemver && (this.apiSemver = t.apiSemver), !t || !t.addr)
|
|
1550
|
+
this.addr = k;
|
|
1551
|
+
else {
|
|
1552
|
+
let n = t.addr.trim();
|
|
1553
|
+
/^https?:\/\//i.test(n) || (n = `http://${n}`);
|
|
1554
|
+
try {
|
|
1555
|
+
const i = new URL(n).hostname;
|
|
1556
|
+
if (!g(i) && !A(i))
|
|
1557
|
+
throw new Error(
|
|
1558
|
+
`Invalid address: "${t.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`
|
|
1559
|
+
);
|
|
1560
|
+
} catch (r) {
|
|
1561
|
+
throw r instanceof Error && r.message.startsWith("Invalid address") ? r : new Error(`Invalid URL format: "${t.addr}"`);
|
|
1562
|
+
}
|
|
1563
|
+
this.addr = n;
|
|
1564
|
+
}
|
|
1565
|
+
this.inputEvent = {};
|
|
1156
1566
|
}
|
|
1157
1567
|
onData(t) {
|
|
1158
1568
|
this.dataListeners.push(t);
|
|
@@ -1164,56 +1574,56 @@ class vt {
|
|
|
1164
1574
|
this.errorListeners.push(t);
|
|
1165
1575
|
}
|
|
1166
1576
|
emitData(t) {
|
|
1167
|
-
for (const
|
|
1168
|
-
|
|
1577
|
+
for (const n of this.dataListeners)
|
|
1578
|
+
n(t);
|
|
1169
1579
|
}
|
|
1170
1580
|
emitStop() {
|
|
1171
1581
|
for (const t of this.stopListeners)
|
|
1172
1582
|
t();
|
|
1173
1583
|
}
|
|
1174
1584
|
emitError(t) {
|
|
1175
|
-
for (const
|
|
1176
|
-
|
|
1585
|
+
for (const n of this.errorListeners)
|
|
1586
|
+
n(t);
|
|
1177
1587
|
}
|
|
1178
1588
|
async openWebsocket() {
|
|
1179
1589
|
this.socket && await this.closeWebsocket();
|
|
1180
|
-
|
|
1181
|
-
if (this.
|
|
1590
|
+
const t = new URL(`${this.addr}/api/input`);
|
|
1591
|
+
if (this.apiKey && t.searchParams.append("x-api-token", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver), !t)
|
|
1182
1592
|
throw new Error("The WebSocket URL is not specified");
|
|
1183
1593
|
this.socket = new WebSocket(t), this.socket.onopen = () => {
|
|
1184
1594
|
this.socket && (this.connected = !0);
|
|
1185
|
-
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (
|
|
1595
|
+
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (n) => {
|
|
1186
1596
|
try {
|
|
1187
|
-
if (typeof
|
|
1597
|
+
if (typeof n.data == "string")
|
|
1188
1598
|
return;
|
|
1189
|
-
const
|
|
1190
|
-
this.emitData(
|
|
1599
|
+
const r = new Uint8Array(n.data);
|
|
1600
|
+
this.emitData(r);
|
|
1191
1601
|
} catch {
|
|
1192
1602
|
this.connected = !1, this.emitStop();
|
|
1193
1603
|
}
|
|
1194
|
-
}, this.socket.onerror = (
|
|
1604
|
+
}, this.socket.onerror = (n) => {
|
|
1195
1605
|
this.connected = !1, this.emitError({
|
|
1196
1606
|
code: 1006,
|
|
1197
1607
|
// Standard «abnormal closure» code per RFC-6455
|
|
1198
1608
|
message: "WebSocket error occurred",
|
|
1199
|
-
raw:
|
|
1609
|
+
raw: n
|
|
1200
1610
|
}), this.emitStop();
|
|
1201
|
-
}, this.socket.onclose = async (
|
|
1202
|
-
if (this.socket = null, this.connected = !1,
|
|
1611
|
+
}, this.socket.onclose = async (n) => {
|
|
1612
|
+
if (this.socket = null, this.connected = !1, n.code === D || B.has(n.code)) {
|
|
1203
1613
|
this.emitError({
|
|
1204
|
-
code:
|
|
1205
|
-
message:
|
|
1206
|
-
raw:
|
|
1614
|
+
code: n.code,
|
|
1615
|
+
message: n.reason,
|
|
1616
|
+
raw: n
|
|
1207
1617
|
});
|
|
1208
1618
|
return;
|
|
1209
1619
|
}
|
|
1210
1620
|
this.emitStop();
|
|
1211
1621
|
};
|
|
1212
1622
|
}
|
|
1213
|
-
sendInput({ keyName: t, value:
|
|
1623
|
+
sendInput({ keyName: t, value: n }) {
|
|
1214
1624
|
if (!this.socket || !this.connected)
|
|
1215
1625
|
throw new Error("WebSocket: Not connected");
|
|
1216
|
-
this.inputEvent[t] =
|
|
1626
|
+
this.inputEvent[t] = n, this.socket.send(JSON.stringify(this.inputEvent)), n === 0 && delete this.inputEvent[t];
|
|
1217
1627
|
}
|
|
1218
1628
|
closeWebsocket() {
|
|
1219
1629
|
return this.connected = !1, new Promise((t) => {
|
|
@@ -1224,8 +1634,8 @@ class vt {
|
|
|
1224
1634
|
}
|
|
1225
1635
|
}
|
|
1226
1636
|
export {
|
|
1227
|
-
|
|
1637
|
+
Lt as BusyBar,
|
|
1228
1638
|
E as DeviceScreen,
|
|
1229
|
-
|
|
1639
|
+
Ot as Input,
|
|
1230
1640
|
Pt as ScreenStream
|
|
1231
1641
|
};
|