@aixnn/aixautots 0.6.12 → 0.6.17
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/{automation-queue-CvrWEOw2.d.ts → automation-queue-DO8fOG6l.d.ts} +2 -2
- package/dist/{chunk-PUEKOYSH.js → chunk-2KPZSPV6.js} +131 -3
- package/dist/{chunk-D7J4EQTA.js → chunk-3OBCSW2J.js} +1 -1
- package/dist/{chunk-UH5OYPXE.js → chunk-7BJPVSEZ.js} +205 -18
- package/dist/{chunk-SKTL6ACT.js → chunk-7RQTSTR6.js} +3 -3
- package/dist/{chunk-LO3XD4T5.js → chunk-FJPIY4YI.js} +124 -8
- package/dist/{chunk-SL6M6CC6.js → chunk-KASSYUGM.js} +3 -3
- package/dist/chunk-LOKPZ677.js +422 -0
- package/dist/{chunk-E7WMHM63.js → chunk-MBBVYSPD.js} +7 -0
- package/dist/{chunk-ROOOAG3E.js → chunk-NIEGPH3E.js} +51 -418
- package/dist/{chunk-7IXBWJHB.js → chunk-QEK25NUA.js} +5 -5
- package/dist/{chunk-QZLUQSLA.js → chunk-TJ2QIP5M.js} +352 -423
- package/dist/{chunk-LR5LJJNM.js → chunk-WOPEKCVC.js} +4 -4
- package/dist/chunk-ZCTAYVPK.js +1 -0
- package/dist/{chunk-XCYGBYFC.js → chunk-ZDCTHR7D.js} +215 -126
- package/dist/{config-BUH2EYHO.d.ts → config-CBUhr4Gl.d.ts} +173 -2
- package/dist/core/index.d.ts +29 -11
- package/dist/core/index.js +2 -2
- package/dist/{device-normalize-DzuVemCy.d.ts → device-normalize-Vl5JYbAI.d.ts} +7 -4
- package/dist/device-session-3XK2SZDF.js +1 -0
- package/dist/i18n/index.js +1 -1
- package/dist/{mirror-session-D2YY9mKf.d.ts → mirror-session-Y1InpkUY.d.ts} +14 -4
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +3 -3
- package/dist/{script-debugger-Csm4CrfY.d.ts → script-debugger-DoT02din.d.ts} +1 -1
- package/dist/{task-agent-runner-C4WfT77g.d.ts → task-agent-runner-Cl2ickJ1.d.ts} +3 -3
- package/dist/{types-BfIeUpsU.d.ts → types-Cp1ohbTb.d.ts} +35 -3
- package/dist/ui/billing.d.ts +2 -2
- package/dist/ui/billing.js +14 -8
- package/dist/ui/device-create.d.ts +5 -2
- package/dist/ui/device-create.js +8 -7
- package/dist/ui/device-mirror.js +7 -7
- package/dist/ui/devices.d.ts +5 -5
- package/dist/ui/devices.js +12 -11
- package/dist/ui/editor.d.ts +2 -2
- package/dist/ui/editor.js +7 -7
- package/dist/ui/index.d.ts +5 -4
- package/dist/ui/index.js +9 -7
- package/dist/ui/inspector.js +5 -5
- package/dist/ui/ip-commerce.d.ts +28 -0
- package/dist/ui/ip-commerce.js +8 -0
- package/dist/ui/market.js +4 -4
- package/dist/ui/mirror.d.ts +5 -4
- package/dist/ui/mirror.js +1 -1
- package/dist/ui/primitives/index.js +1 -1
- package/dist/ui/script-studio.js +6 -6
- package/dist/ui/scripts.d.ts +1 -1
- package/dist/ui/scripts.js +5 -5
- package/dist/ui/tasks.js +12 -11
- package/package.json +6 -2
- package/dist/device-session-7MKEJTIA.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-
|
|
2
|
-
import { S as Script } from './types-
|
|
1
|
+
import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-CBUhr4Gl.js';
|
|
2
|
+
import { S as Script } from './types-Cp1ohbTb.js';
|
|
3
3
|
|
|
4
4
|
interface FlowSubmit {
|
|
5
5
|
/** Inline flow JSON (XOR scriptId). */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var DICT = {
|
|
3
3
|
en: {
|
|
4
4
|
auth: "Authentication error",
|
|
5
|
+
network: "Server connection failed",
|
|
5
6
|
timeout: "Operation timed out",
|
|
6
7
|
offline: "Device offline",
|
|
7
8
|
locked: "Device locked",
|
|
@@ -10,6 +11,7 @@ var DICT = {
|
|
|
10
11
|
},
|
|
11
12
|
zh: {
|
|
12
13
|
auth: "\u8BA4\u8BC1\u9519\u8BEF",
|
|
14
|
+
network: "\u670D\u52A1\u5668\u8FDE\u63A5\u5931\u8D25",
|
|
13
15
|
timeout: "\u64CD\u4F5C\u8D85\u65F6",
|
|
14
16
|
offline: "\u8BBE\u5907\u79BB\u7EBF",
|
|
15
17
|
locked: "\u8BBE\u5907\u5DF2\u9501\u5B9A",
|
|
@@ -260,6 +262,23 @@ var ReconnectingSocket = class {
|
|
|
260
262
|
});
|
|
261
263
|
}, exp + jitter);
|
|
262
264
|
}
|
|
265
|
+
/** Re-admit with a fresh token. Retire the old socket before close callbacks
|
|
266
|
+
* can run; queued messages/close events must never affect its replacement. */
|
|
267
|
+
reconnect() {
|
|
268
|
+
if (this.closed) return;
|
|
269
|
+
if (this.reconnectTimer !== null) {
|
|
270
|
+
clearTimeout(this.reconnectTimer);
|
|
271
|
+
this.reconnectTimer = null;
|
|
272
|
+
}
|
|
273
|
+
const previous = this.ws;
|
|
274
|
+
this.ws = null;
|
|
275
|
+
try {
|
|
276
|
+
previous?.close();
|
|
277
|
+
} catch {
|
|
278
|
+
}
|
|
279
|
+
this.o.onClose?.();
|
|
280
|
+
this.scheduleReconnect();
|
|
281
|
+
}
|
|
263
282
|
send(text) {
|
|
264
283
|
if (!this.ws) throw new Error("socket not connected");
|
|
265
284
|
this.ws.send(text);
|
|
@@ -299,6 +318,39 @@ async function mintViewerToken(cfg, session) {
|
|
|
299
318
|
}
|
|
300
319
|
return (await resp.json()).token;
|
|
301
320
|
}
|
|
321
|
+
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
322
|
+
function validUuid(value) {
|
|
323
|
+
return typeof value === "string" && uuid.test(value) && value !== "00000000-0000-0000-0000-000000000000";
|
|
324
|
+
}
|
|
325
|
+
function validSession(session) {
|
|
326
|
+
return !!session && new TextEncoder().encode(session).length <= 512 && !session.startsWith("dc:") && !/[\x00-\x1f\x7f-\x9f]/.test(session);
|
|
327
|
+
}
|
|
328
|
+
function validateViewerGrant(value, session) {
|
|
329
|
+
const v = value;
|
|
330
|
+
if (!validSession(session) || !v || typeof v.token !== "string" || v.token.length < 16 || v.token.length > 16384 || /[^\x21-\x7e]/.test(v.token) || !validUuid(v.grant_id) || v.session !== session || v.permission !== "video_only" || v.protocol_version !== 2 || !Number.isSafeInteger(v.expires_at_ms) || v.expires_at_ms <= Date.now() || v.expires_at_ms > Date.now() + 305e3 || !v.node_connection || !validUuid(v.node_connection.node_id) || !validUuid(v.node_connection.session_id) || !Number.isSafeInteger(v.node_connection.generation) || v.node_connection.generation < 0) throw new AixError("Invalid video-only viewer proof");
|
|
331
|
+
return {
|
|
332
|
+
token: v.token,
|
|
333
|
+
grant_id: v.grant_id,
|
|
334
|
+
session,
|
|
335
|
+
permission: "video_only",
|
|
336
|
+
protocol_version: 2,
|
|
337
|
+
expires_at_ms: v.expires_at_ms,
|
|
338
|
+
node_connection: { node_id: v.node_connection.node_id, generation: v.node_connection.generation, session_id: v.node_connection.session_id }
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
async function mintViewerGrant(cfg, session) {
|
|
342
|
+
if (!validSession(session)) throw new AixError("Invalid video-only session");
|
|
343
|
+
const resp = await cfg.fetchFn(joinUrl(cfg.baseUrl, "/api/signal/tokens"), {
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: { ...await cfg.auth.headers("caller"), "content-type": "application/json" },
|
|
346
|
+
body: JSON.stringify({ session, permission: "video_only", protocol_version: 2 })
|
|
347
|
+
});
|
|
348
|
+
if (!resp.ok) {
|
|
349
|
+
if (resp.status === 401 || resp.status === 403) throw new AixAuthError(`signal token ${resp.status}`);
|
|
350
|
+
throw new AixError(`signal token ${resp.status}`);
|
|
351
|
+
}
|
|
352
|
+
return validateViewerGrant(await resp.json(), session);
|
|
353
|
+
}
|
|
302
354
|
|
|
303
355
|
// src/core/resources/http.ts
|
|
304
356
|
function buildQuery(query) {
|
|
@@ -334,7 +386,7 @@ var RestClient = class {
|
|
|
334
386
|
resp = await this.cfg.fetchFn(url, { method, headers, body, ...opts.signal ? { signal: opts.signal } : {} });
|
|
335
387
|
} catch (e) {
|
|
336
388
|
if (e instanceof AixError) throw e;
|
|
337
|
-
throw new AixError(`${method} ${path} request failed: ${String(e)}`, "
|
|
389
|
+
throw new AixError(`${method} ${path} request failed: ${String(e)}`, "network");
|
|
338
390
|
}
|
|
339
391
|
if (!resp.ok) {
|
|
340
392
|
const text = await resp.text().catch(() => "");
|
|
@@ -1461,6 +1513,49 @@ var ManagedProxiesApi = class {
|
|
|
1461
1513
|
}
|
|
1462
1514
|
};
|
|
1463
1515
|
|
|
1516
|
+
// src/core/resources/ip-commerce.ts
|
|
1517
|
+
var IpCommerceApi = class {
|
|
1518
|
+
constructor(c) {
|
|
1519
|
+
this.c = c;
|
|
1520
|
+
}
|
|
1521
|
+
capabilities(opts) {
|
|
1522
|
+
return this.c.get("/api/ip-commerce/capabilities", opts);
|
|
1523
|
+
}
|
|
1524
|
+
catalog(filters = {}, opts) {
|
|
1525
|
+
return this.c.get("/api/ip-commerce/catalog", { ...opts, query: { ...filters } });
|
|
1526
|
+
}
|
|
1527
|
+
quote(input, opts) {
|
|
1528
|
+
return this.c.post("/api/ip-commerce/quotes", input, opts);
|
|
1529
|
+
}
|
|
1530
|
+
purchase(input, opts) {
|
|
1531
|
+
return this.c.post("/api/ip-commerce/orders", input, opts);
|
|
1532
|
+
}
|
|
1533
|
+
order(id, opts) {
|
|
1534
|
+
return this.c.get(`/api/ip-commerce/orders/${encodeURIComponent(id)}`, opts);
|
|
1535
|
+
}
|
|
1536
|
+
orders(deviceId = "", opts) {
|
|
1537
|
+
return this.c.get("/api/ip-commerce/orders", { ...opts, query: { device_id: deviceId } });
|
|
1538
|
+
}
|
|
1539
|
+
resources(opts) {
|
|
1540
|
+
return this.c.get("/api/ip-commerce/resources", opts);
|
|
1541
|
+
}
|
|
1542
|
+
/** Sensitive independent credential. Resolve in a trusted backend, never log/cache it or use a platform key here.
|
|
1543
|
+
* Fresh supplier lookup; failure must disable the proxy, never fall back to a cached credential or direct connection.
|
|
1544
|
+
* Does not rotate, buy, or authorize browser/multiple-target reuse beyond supplier product terms. */
|
|
1545
|
+
resourceConnection(id, opts) {
|
|
1546
|
+
return this.c.post(`/api/ip-commerce/resources/${encodeURIComponent(id)}/connection`, {}, opts);
|
|
1547
|
+
}
|
|
1548
|
+
cancelQuote(id, opts) {
|
|
1549
|
+
return this.c.post(`/api/ip-commerce/orders/${encodeURIComponent(id)}/cancel-quote`, {}, opts);
|
|
1550
|
+
}
|
|
1551
|
+
createDevice(id, opts) {
|
|
1552
|
+
return this.c.post(`/api/ip-commerce/orders/${encodeURIComponent(id)}/create-device`, {}, opts);
|
|
1553
|
+
}
|
|
1554
|
+
apply(id, entitlementId, opts) {
|
|
1555
|
+
return this.c.post(`/api/ip-commerce/orders/${encodeURIComponent(id)}/apply`, { entitlement_id: entitlementId }, opts);
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
|
|
1464
1559
|
// src/core/resources/tokens.ts
|
|
1465
1560
|
var ApiTokensApi = class {
|
|
1466
1561
|
constructor(c) {
|
|
@@ -1504,6 +1599,37 @@ var AppTemplatesApi = class {
|
|
|
1504
1599
|
}
|
|
1505
1600
|
};
|
|
1506
1601
|
|
|
1602
|
+
// src/core/resources/snapshots.ts
|
|
1603
|
+
var SnapshotsApi = class {
|
|
1604
|
+
constructor(c) {
|
|
1605
|
+
this.c = c;
|
|
1606
|
+
}
|
|
1607
|
+
list(options) {
|
|
1608
|
+
return this.c.get("/api/snapshots", options);
|
|
1609
|
+
}
|
|
1610
|
+
create(input) {
|
|
1611
|
+
return this.c.post("/api/snapshots", input);
|
|
1612
|
+
}
|
|
1613
|
+
operation(id, options) {
|
|
1614
|
+
return this.c.get(`/api/snapshots/operations/${encodeURIComponent(id)}`, options);
|
|
1615
|
+
}
|
|
1616
|
+
restore(id, input = {}) {
|
|
1617
|
+
return this.c.post(`/api/snapshots/${encodeURIComponent(id)}/restore`, input);
|
|
1618
|
+
}
|
|
1619
|
+
grants(id) {
|
|
1620
|
+
return this.c.get(`/api/snapshots/${encodeURIComponent(id)}/grants`);
|
|
1621
|
+
}
|
|
1622
|
+
grant(id, userId) {
|
|
1623
|
+
return this.c.post(`/api/snapshots/${encodeURIComponent(id)}/grants`, { user_id: userId });
|
|
1624
|
+
}
|
|
1625
|
+
revoke(id, userId) {
|
|
1626
|
+
return this.c.del(`/api/snapshots/${encodeURIComponent(id)}/grants/${encodeURIComponent(userId)}`);
|
|
1627
|
+
}
|
|
1628
|
+
delete(id) {
|
|
1629
|
+
return this.c.del(`/api/snapshots/${encodeURIComponent(id)}`);
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1507
1633
|
// src/core/local-node.ts
|
|
1508
1634
|
function validatedBackendUrl(base) {
|
|
1509
1635
|
base = base.trim();
|
|
@@ -1670,8 +1796,10 @@ var AixClient = class {
|
|
|
1670
1796
|
this.images = new ImagesApi(this.http);
|
|
1671
1797
|
this.billing = new BillingApi(this.http);
|
|
1672
1798
|
this.proxies = new ManagedProxiesApi(this.http);
|
|
1799
|
+
this.ipCommerce = new IpCommerceApi(this.http);
|
|
1673
1800
|
this.tokens = new ApiTokensApi(this.http);
|
|
1674
1801
|
this.appTemplates = new AppTemplatesApi(this.http);
|
|
1802
|
+
this.snapshots = new SnapshotsApi(this.http);
|
|
1675
1803
|
if (this.cfg.localNode) {
|
|
1676
1804
|
this.localNode = new LocalNodeController(this, this.cfg.localNode);
|
|
1677
1805
|
if (this.cfg.localNode.auto) void this.localNode.ensure();
|
|
@@ -1687,7 +1815,7 @@ var AixClient = class {
|
|
|
1687
1815
|
* 即可,不必回依赖 client 实例)。
|
|
1688
1816
|
*/
|
|
1689
1817
|
async deviceSession(deviceId, opts = {}) {
|
|
1690
|
-
const { DeviceSession: DeviceSession2 } = await import('./device-session-
|
|
1818
|
+
const { DeviceSession: DeviceSession2 } = await import('./device-session-3XK2SZDF.js');
|
|
1691
1819
|
return DeviceSession2.open(this.cfg, deviceId, opts);
|
|
1692
1820
|
}
|
|
1693
1821
|
};
|
|
@@ -2338,4 +2466,4 @@ async function pullFile(source, deviceId, src, opts = {}) {
|
|
|
2338
2466
|
}
|
|
2339
2467
|
}
|
|
2340
2468
|
|
|
2341
|
-
export { AdminApi, AixAuthError, AixClient, AixDeviceOffline, AixError, AixLocked, AixProtocolError, AixTimeout, ApiTokensApi, AuthApi, BillingApi, ClustersApi, DeviceSession, DevicesApi, EnvRun, FleetApi, ImagesApi, LlmApi, LocalNodeController, LocatorsApi, ManagedProxiesApi, NodesApi, ProjectsApi, ReconnectingSocket, RestClient, ScriptsApi, ShortcutsApi, TasksApi, UsersApi, WebhooksApi, authHeader, buildAuthProvider, createCachedUserCredential, createClient, detectEnvOs, envBlocker, errorFromRet, executionStreamEventsAfter, executionWsTicketUrl, executionWsUrl, getIceServers, getLocale, isEnvEventFrame, isExecutionFrame, isFleetRunTerminal, isFridaEventFrame, isRetFrame, isScriptletEventFrame, isStatusFrame, joinUrl, mintViewerToken, parseIncoming, pullFile, pushFile, resolveConfig, restClient, runEnvToFinish, setLocale, summarizeEnv, t };
|
|
2469
|
+
export { AdminApi, AixAuthError, AixClient, AixDeviceOffline, AixError, AixLocked, AixProtocolError, AixTimeout, ApiTokensApi, AuthApi, BillingApi, ClustersApi, DeviceSession, DevicesApi, EnvRun, FleetApi, ImagesApi, IpCommerceApi, LlmApi, LocalNodeController, LocatorsApi, ManagedProxiesApi, NodesApi, ProjectsApi, ReconnectingSocket, RestClient, ScriptsApi, ShortcutsApi, SnapshotsApi, TasksApi, UsersApi, WebhooksApi, authHeader, buildAuthProvider, createCachedUserCredential, createClient, detectEnvOs, envBlocker, errorFromRet, executionStreamEventsAfter, executionWsTicketUrl, executionWsUrl, getIceServers, getLocale, isEnvEventFrame, isExecutionFrame, isFleetRunTerminal, isFridaEventFrame, isRetFrame, isScriptletEventFrame, isStatusFrame, joinUrl, mintViewerGrant, mintViewerToken, parseIncoming, pullFile, pushFile, resolveConfig, restClient, runEnvToFinish, setLocale, summarizeEnv, t, validUuid, validateViewerGrant };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, parseIncoming, isRetFrame, errorFromRet, isFridaEventFrame, isScriptletEventFrame, isStatusFrame, executionWsTicketUrl, isExecutionFrame, getIceServers, mintViewerToken, executionStreamEventsAfter } from './chunk-
|
|
1
|
+
import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, parseIncoming, isRetFrame, errorFromRet, isFridaEventFrame, isScriptletEventFrame, isStatusFrame, executionWsTicketUrl, isExecutionFrame, getIceServers, mintViewerToken, mintViewerGrant, validateViewerGrant, validUuid, executionStreamEventsAfter } from './chunk-2KPZSPV6.js';
|
|
2
2
|
|
|
3
3
|
// src/core/ws-access.ts
|
|
4
4
|
async function mintDeviceAccess(cfg, deviceId) {
|
|
@@ -524,6 +524,11 @@ var MirrorSession = class _MirrorSession {
|
|
|
524
524
|
this.socket = socket;
|
|
525
525
|
this.iceServers = iceServers;
|
|
526
526
|
this.token = token;
|
|
527
|
+
this.videoOnly = false;
|
|
528
|
+
this.verified = false;
|
|
529
|
+
this.nodePeer = null;
|
|
530
|
+
this.grant = null;
|
|
531
|
+
this.expiryTimer = null;
|
|
527
532
|
this.pc = null;
|
|
528
533
|
this.input = null;
|
|
529
534
|
this.requestedAudio = null;
|
|
@@ -542,7 +547,9 @@ var MirrorSession = class _MirrorSession {
|
|
|
542
547
|
* fresh RTCPeerConnection (see the `offer` handler) — no consumer action
|
|
543
548
|
* needed to restore the video track. The optional signal cancels a pending
|
|
544
549
|
* join; after it resolves, use leave() to end the returned session. */
|
|
545
|
-
static async join(cfg, session, signal) {
|
|
550
|
+
static async join(cfg, session, signal, options = {}) {
|
|
551
|
+
if (options.permission !== void 0 && options.permission !== "control" && options.permission !== "video_only") throw new Error("Invalid mirror permission");
|
|
552
|
+
if (options.permission === "video_only") return _MirrorSession.joinVideoOnly(cfg, session, signal);
|
|
546
553
|
const resolved = "fetchFn" in cfg ? cfg : resolveConfig(cfg);
|
|
547
554
|
const abortError = () => Object.assign(new Error("Viewer join cancelled"), { name: "AbortError" });
|
|
548
555
|
if (signal?.aborted) throw abortError();
|
|
@@ -604,6 +611,138 @@ var MirrorSession = class _MirrorSession {
|
|
|
604
611
|
signal?.removeEventListener("abort", onAbort);
|
|
605
612
|
}
|
|
606
613
|
}
|
|
614
|
+
static async joinVideoOnly(cfg, session, signal) {
|
|
615
|
+
const resolved = "fetchFn" in cfg ? cfg : resolveConfig(cfg);
|
|
616
|
+
const abortError = () => Object.assign(new Error("Viewer join cancelled"), { name: "AbortError" });
|
|
617
|
+
if (signal?.aborted) throw abortError();
|
|
618
|
+
let ms = null;
|
|
619
|
+
let grant = null;
|
|
620
|
+
let generation = 0;
|
|
621
|
+
let previousGrantId = null;
|
|
622
|
+
let previousPeerId = null;
|
|
623
|
+
let stopped = false;
|
|
624
|
+
let resolveReady;
|
|
625
|
+
let rejectReady;
|
|
626
|
+
const ready = new Promise((resolve, reject) => {
|
|
627
|
+
resolveReady = resolve;
|
|
628
|
+
rejectReady = reject;
|
|
629
|
+
});
|
|
630
|
+
const fail = (error) => {
|
|
631
|
+
stopped = true;
|
|
632
|
+
ms?.leave();
|
|
633
|
+
socket.close();
|
|
634
|
+
rejectReady(error);
|
|
635
|
+
};
|
|
636
|
+
const socket = new ReconnectingSocket({
|
|
637
|
+
urlProvider: async () => {
|
|
638
|
+
const current = ++generation;
|
|
639
|
+
if (ms?.expiryTimer) clearTimeout(ms.expiryTimer);
|
|
640
|
+
if (ms) ms.expiryTimer = setTimeout(() => fail(new Error("Video-only connection timeout")), 35e3);
|
|
641
|
+
try {
|
|
642
|
+
const next = await mintViewerGrant(resolved, session);
|
|
643
|
+
if (stopped || ms?.left || signal?.aborted || current !== generation) throw abortError();
|
|
644
|
+
if (previousGrantId === next.grant_id) throw new Error("Video-only grant cannot be reused");
|
|
645
|
+
const ice = await getIceServers(resolved);
|
|
646
|
+
if (stopped || ms?.left || signal?.aborted || current !== generation) throw abortError();
|
|
647
|
+
if (!Array.isArray(ice) || ice.length > 64) throw new Error("Invalid video-only ICE configuration");
|
|
648
|
+
validateViewerGrant(next, session);
|
|
649
|
+
if (ms) ms.iceServers = ice;
|
|
650
|
+
previousGrantId = next.grant_id;
|
|
651
|
+
grant = next;
|
|
652
|
+
return signalWsUrl(resolved.baseUrl);
|
|
653
|
+
} catch (error) {
|
|
654
|
+
if (!stopped && !ms?.left) fail(new Error("Video-only admission failed"));
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
wsFactory: resolved.wsFactory,
|
|
659
|
+
onOpen: () => {
|
|
660
|
+
if (stopped || !ms || !grant) return;
|
|
661
|
+
if (ms.expiryTimer) clearTimeout(ms.expiryTimer);
|
|
662
|
+
ms.expiryTimer = setTimeout(() => fail(new Error("Video-only welcome timeout")), 15e3);
|
|
663
|
+
ms.grant = grant;
|
|
664
|
+
ms.sendSignal({ type: "join", session, role: "viewer", token: grant.token, protocol_version: 2, node_connection: grant.node_connection });
|
|
665
|
+
},
|
|
666
|
+
onClose: () => {
|
|
667
|
+
if (!ms || stopped || ms.left) return;
|
|
668
|
+
ms.verified = false;
|
|
669
|
+
ms.nodePeer = null;
|
|
670
|
+
ms.grant = null;
|
|
671
|
+
if (ms.expiryTimer) clearTimeout(ms.expiryTimer);
|
|
672
|
+
ms.resetPeer();
|
|
673
|
+
ms.emitState("disconnected");
|
|
674
|
+
},
|
|
675
|
+
onMessage: (text) => {
|
|
676
|
+
if (!ms || stopped || !grant) return;
|
|
677
|
+
if (text.length > 65536) {
|
|
678
|
+
fail(new Error("Video-only signal exceeds limit"));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
let v;
|
|
682
|
+
try {
|
|
683
|
+
v = JSON.parse(text);
|
|
684
|
+
} catch {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
if (!v || typeof v !== "object") {
|
|
688
|
+
fail(new Error("Invalid video-only signaling"));
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (v.type === "error") {
|
|
692
|
+
fail(new Error("Video-only authorization ended"));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (ms.grant && ms.grant.expires_at_ms <= Date.now()) {
|
|
696
|
+
socket.reconnect();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (!ms.verified) {
|
|
700
|
+
if (v.type !== "welcome_v2") {
|
|
701
|
+
fail(new Error("Video-only welcome required"));
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const g = ms.grant;
|
|
705
|
+
if (!g || v.session !== session || v.permission !== "video_only" || v.protocol_version !== 2 || v.grant_id !== g.grant_id || v.expires_at_ms !== g.expires_at_ms || g.expires_at_ms <= Date.now() || !validUuid(v.peer_id) || v.peer_id === previousPeerId || !validUuid(v.node_peer_id) || !validUuid(v.signal_epoch) || v.node_connection?.node_id !== g.node_connection.node_id || v.node_connection?.generation !== g.node_connection.generation || v.node_connection?.session_id !== g.node_connection.session_id) {
|
|
706
|
+
fail(new Error("Video-only welcome proof mismatch"));
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
previousPeerId = v.peer_id;
|
|
710
|
+
ms.verified = true;
|
|
711
|
+
ms.peerId = v.peer_id;
|
|
712
|
+
ms.nodePeer = v.node_peer_id;
|
|
713
|
+
if (ms.expiryTimer) clearTimeout(ms.expiryTimer);
|
|
714
|
+
ms.expiryTimer = setTimeout(() => socket.reconnect(), Math.min(305e3, g.expires_at_ms - Date.now()));
|
|
715
|
+
resolveReady(ms);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (v.type === "error") {
|
|
719
|
+
fail(new Error("Video-only authorization ended"));
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
if (v.type === "welcome" || v.type === "welcome_v2") {
|
|
723
|
+
fail(new Error("Unexpected viewer welcome"));
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if ((v.type === "offer" || v.type === "ice") && (v.from !== ms.nodePeer || v.session !== session)) {
|
|
727
|
+
fail(new Error("Video-only signal source mismatch"));
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
void ms.onSignal(text).catch(() => fail(new Error("Video-only signaling failed")));
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
ms = new _MirrorSession(resolved, session, socket, [], "");
|
|
734
|
+
ms.videoOnly = true;
|
|
735
|
+
const abort = () => fail(abortError());
|
|
736
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
737
|
+
const timeout = setTimeout(() => fail(new Error("Video-only admission timeout")), 5e4);
|
|
738
|
+
void socket.start().catch((error) => fail(error instanceof Error ? error : new Error("Viewer connection failed")));
|
|
739
|
+
try {
|
|
740
|
+
return await ready;
|
|
741
|
+
} finally {
|
|
742
|
+
clearTimeout(timeout);
|
|
743
|
+
signal?.removeEventListener("abort", abort);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
607
746
|
get stream() {
|
|
608
747
|
return this._stream;
|
|
609
748
|
}
|
|
@@ -611,7 +750,7 @@ var MirrorSession = class _MirrorSession {
|
|
|
611
750
|
return this.left ? "closed" : this.pc?.connectionState ?? "connecting";
|
|
612
751
|
}
|
|
613
752
|
get controlReady() {
|
|
614
|
-
return !this.left && this.pc?.connectionState === "connected" && this.input?.readyState === "open";
|
|
753
|
+
return !this.videoOnly && !this.left && this.pc?.connectionState === "connected" && this.input?.readyState === "open";
|
|
615
754
|
}
|
|
616
755
|
onControlStateChange(cb) {
|
|
617
756
|
this.controlListeners.add(cb);
|
|
@@ -626,7 +765,7 @@ var MirrorSession = class _MirrorSession {
|
|
|
626
765
|
return () => this.streamListeners.delete(cb);
|
|
627
766
|
}
|
|
628
767
|
sendInput(msg) {
|
|
629
|
-
if (this.left) return;
|
|
768
|
+
if (this.left || this.videoOnly) return;
|
|
630
769
|
if (msg.t === "audio") {
|
|
631
770
|
this.requestedAudio = msg.enabled;
|
|
632
771
|
this.flushAudio();
|
|
@@ -643,7 +782,7 @@ var MirrorSession = class _MirrorSession {
|
|
|
643
782
|
for (const cb of this.controlListeners) cb(this.controlReady);
|
|
644
783
|
}
|
|
645
784
|
flushAudio() {
|
|
646
|
-
if (this.left || this.requestedAudio === null || this.input?.readyState !== "open") return;
|
|
785
|
+
if (this.videoOnly || this.left || this.requestedAudio === null || this.input?.readyState !== "open") return;
|
|
647
786
|
try {
|
|
648
787
|
this.input.send(JSON.stringify({ t: "audio", enabled: this.requestedAudio }));
|
|
649
788
|
} catch {
|
|
@@ -681,30 +820,56 @@ var MirrorSession = class _MirrorSession {
|
|
|
681
820
|
} catch {
|
|
682
821
|
}
|
|
683
822
|
}
|
|
823
|
+
livePeer(pc) {
|
|
824
|
+
if (this.left || this.pc !== pc) return false;
|
|
825
|
+
if (this.videoOnly) {
|
|
826
|
+
if (!this.verified || !this.grant) return false;
|
|
827
|
+
if (this.grant.expires_at_ms <= Date.now()) {
|
|
828
|
+
this.socket.reconnect();
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
684
834
|
ensurePc() {
|
|
685
835
|
if (this.pc) return this.pc;
|
|
686
836
|
const pc = this.cfg.rtcFactory({ iceServers: this.iceServers });
|
|
687
837
|
pc.ontrack = (ev) => {
|
|
688
|
-
if (this.
|
|
838
|
+
if (!this.livePeer(pc)) return;
|
|
689
839
|
if (ev.receiver && "playoutDelayHint" in ev.receiver) ev.receiver.playoutDelayHint = 0;
|
|
690
840
|
if (ev.streams && ev.streams[0]) {
|
|
691
|
-
this.
|
|
841
|
+
if (this.videoOnly) {
|
|
842
|
+
const tracks = ev.streams[0].getVideoTracks?.();
|
|
843
|
+
if (!tracks?.length || typeof MediaStream === "undefined") return;
|
|
844
|
+
this._stream = new MediaStream(tracks);
|
|
845
|
+
} else this._stream = ev.streams[0];
|
|
692
846
|
for (const cb of this.streamListeners) cb(this._stream);
|
|
693
847
|
}
|
|
694
848
|
};
|
|
695
849
|
pc.onicecandidate = (ev) => {
|
|
696
|
-
if (
|
|
850
|
+
if (this.livePeer(pc) && ev.candidate && this.remotePeer) this.sendSignal({ type: "ice", session: this.session, to: this.remotePeer, candidate: ev.candidate });
|
|
697
851
|
};
|
|
698
852
|
pc.ondatachannel = (ev) => {
|
|
699
|
-
if (
|
|
853
|
+
if (this.videoOnly || this.left || this.pc !== pc) {
|
|
854
|
+
try {
|
|
855
|
+
ev.channel.close();
|
|
856
|
+
} catch {
|
|
857
|
+
}
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
if (ev.channel.label === "control") this.attachInput(ev.channel);
|
|
700
861
|
};
|
|
701
862
|
pc.onconnectionstatechange = () => {
|
|
702
|
-
if (
|
|
863
|
+
if (this.livePeer(pc)) this.emitState(pc.connectionState);
|
|
703
864
|
};
|
|
704
865
|
this.pc = pc;
|
|
705
866
|
return pc;
|
|
706
867
|
}
|
|
707
868
|
attachInput(dc) {
|
|
869
|
+
if (this.videoOnly || this.left) {
|
|
870
|
+
dc.close();
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
708
873
|
if (this.input) {
|
|
709
874
|
this.input.onopen = null;
|
|
710
875
|
this.input.onclose = null;
|
|
@@ -768,32 +933,40 @@ var MirrorSession = class _MirrorSession {
|
|
|
768
933
|
this.remotePeer = m.from;
|
|
769
934
|
const pc = this.ensurePc();
|
|
770
935
|
await pc.setRemoteDescription({ type: "offer", sdp: m.sdp });
|
|
771
|
-
if (this.
|
|
936
|
+
if (!this.livePeer(pc)) return;
|
|
772
937
|
this.remoteDescriptionReady = true;
|
|
773
938
|
for (const candidate of this.pendingIce.splice(0)) {
|
|
774
939
|
await pc.addIceCandidate(candidate);
|
|
775
|
-
if (this.
|
|
940
|
+
if (!this.livePeer(pc)) return;
|
|
776
941
|
}
|
|
777
942
|
const answer = await pc.createAnswer();
|
|
778
|
-
if (this.
|
|
943
|
+
if (!this.livePeer(pc)) return;
|
|
779
944
|
await pc.setLocalDescription(answer);
|
|
780
|
-
if (this.
|
|
945
|
+
if (!this.livePeer(pc)) return;
|
|
781
946
|
this.sendSignal({ type: "answer", session: this.session, to: m.from, sdp: answer.sdp });
|
|
782
947
|
}
|
|
783
948
|
break;
|
|
784
949
|
case "ice":
|
|
785
950
|
if (m.candidate) {
|
|
786
|
-
if (!this.pc || !this.remoteDescriptionReady)
|
|
787
|
-
|
|
951
|
+
if (!this.pc || !this.remoteDescriptionReady) {
|
|
952
|
+
if (this.videoOnly && this.pendingIce.length >= 256) {
|
|
953
|
+
this.leave();
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
this.pendingIce.push(m.candidate);
|
|
957
|
+
} else await this.pc.addIceCandidate(m.candidate);
|
|
788
958
|
}
|
|
789
959
|
break;
|
|
790
960
|
}
|
|
791
961
|
}
|
|
792
962
|
leave() {
|
|
793
963
|
this.left = true;
|
|
964
|
+
this.verified = false;
|
|
965
|
+
if (this.expiryTimer) clearTimeout(this.expiryTimer);
|
|
794
966
|
this.requestedAudio = null;
|
|
795
967
|
this.sendSignal({ type: "leave", session: this.session });
|
|
796
968
|
this.resetPeer();
|
|
969
|
+
this.emitState("closed");
|
|
797
970
|
this.socket.close();
|
|
798
971
|
}
|
|
799
972
|
};
|
|
@@ -803,6 +976,9 @@ function metaStr(r, key) {
|
|
|
803
976
|
const v = r.meta?.[key];
|
|
804
977
|
return typeof v === "string" && v ? v : null;
|
|
805
978
|
}
|
|
979
|
+
function isManagedId(id) {
|
|
980
|
+
return /^rd-[A-Za-z0-9_-]+$/.test(id) && id.length <= 128;
|
|
981
|
+
}
|
|
806
982
|
function seenMs(r) {
|
|
807
983
|
return r.last_seen_at ? Date.parse(r.last_seen_at) || 0 : 0;
|
|
808
984
|
}
|
|
@@ -827,16 +1003,27 @@ function pickPrimary(group) {
|
|
|
827
1003
|
}
|
|
828
1004
|
function normalizeDevices(rows) {
|
|
829
1005
|
const serialnoSet = /* @__PURE__ */ new Set();
|
|
1006
|
+
const managedSerials = /* @__PURE__ */ new Map();
|
|
830
1007
|
for (const r of rows) {
|
|
831
1008
|
const sn = metaStr(r, "serialno");
|
|
832
1009
|
if (sn) serialnoSet.add(sn);
|
|
1010
|
+
if (isManagedId(r.external_id)) {
|
|
1011
|
+
for (const identity of /* @__PURE__ */ new Set([r.external_id, sn ?? r.external_id])) {
|
|
1012
|
+
const owners = managedSerials.get(identity) ?? /* @__PURE__ */ new Set();
|
|
1013
|
+
owners.add(r.external_id);
|
|
1014
|
+
managedSerials.set(identity, owners);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
833
1017
|
}
|
|
834
1018
|
const groups = /* @__PURE__ */ new Map();
|
|
835
1019
|
for (const r of rows) {
|
|
836
1020
|
const serialno = metaStr(r, "serialno");
|
|
837
1021
|
let key;
|
|
838
|
-
if (
|
|
839
|
-
key = `
|
|
1022
|
+
if (isManagedId(r.external_id)) {
|
|
1023
|
+
key = `ext:${r.external_id}`;
|
|
1024
|
+
} else if (serialno) {
|
|
1025
|
+
const managed = managedSerials.get(serialno);
|
|
1026
|
+
key = managed?.size === 1 ? `ext:${[...managed][0]}` : `sn:${serialno}`;
|
|
840
1027
|
} else if (serialnoSet.has(r.external_id)) {
|
|
841
1028
|
key = `sn:${r.external_id}`;
|
|
842
1029
|
} else {
|
|
@@ -18,13 +18,13 @@ function Dialog({
|
|
|
18
18
|
children,
|
|
19
19
|
maxWidth = "max-w-md"
|
|
20
20
|
}) {
|
|
21
|
-
return /* @__PURE__ */ jsx(DialogPrimitive.Root, { open, onOpenChange: onClose, children: /* @__PURE__ */ jsxs(DialogPrimitive.Portal, { children: [
|
|
22
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Overlay, { className: "fixed inset-0 bg-black/50 z-
|
|
21
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Root, { open, onOpenChange: onClose, children: /* @__PURE__ */ jsxs(DialogPrimitive.Portal, { container: typeof document !== "undefined" ? document.fullscreenElement ?? void 0 : void 0, children: [
|
|
22
|
+
/* @__PURE__ */ jsx(DialogPrimitive.Overlay, { className: "fixed inset-0 bg-black/50 z-[60]" }),
|
|
23
23
|
/* @__PURE__ */ jsxs(
|
|
24
24
|
DialogPrimitive.Content,
|
|
25
25
|
{
|
|
26
26
|
className: cn(
|
|
27
|
-
"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-card border border-border rounded-lg p-6 w-full z-
|
|
27
|
+
"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-card border border-border rounded-lg p-6 w-full max-h-[calc(100dvh-2rem)] overflow-y-auto z-[70] shadow-xl",
|
|
28
28
|
maxWidth
|
|
29
29
|
),
|
|
30
30
|
children: [
|