@reactor-team/js-sdk 2.9.0 → 2.9.2
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.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +234 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -149
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -83,7 +83,7 @@ import { z } from "zod";
|
|
|
83
83
|
// package.json
|
|
84
84
|
var package_default = {
|
|
85
85
|
name: "@reactor-team/js-sdk",
|
|
86
|
-
version: "2.9.
|
|
86
|
+
version: "2.9.2",
|
|
87
87
|
description: "Reactor JavaScript frontend SDK",
|
|
88
88
|
main: "dist/index.js",
|
|
89
89
|
module: "dist/index.mjs",
|
|
@@ -1032,45 +1032,20 @@ var WebRTCTransportClient = class {
|
|
|
1032
1032
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1033
1033
|
// Connection Lifecycle
|
|
1034
1034
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1035
|
-
|
|
1035
|
+
warmup() {
|
|
1036
1036
|
return __async(this, null, function* () {
|
|
1037
|
-
this.
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
this.peerConnection = createPeerConnection({ iceServers });
|
|
1041
|
-
this.setupPeerConnectionHandlers();
|
|
1042
|
-
this.dataChannel = createDataChannel(this.peerConnection);
|
|
1043
|
-
this.setupDataChannelHandlers();
|
|
1044
|
-
this.transceiverMap.clear();
|
|
1045
|
-
for (const track of tracks) {
|
|
1046
|
-
const transceiver = this.peerConnection.addTransceiver(track.kind, {
|
|
1047
|
-
direction: track.direction
|
|
1048
|
-
});
|
|
1049
|
-
this.transceiverMap.set(track.name, {
|
|
1050
|
-
name: track.name,
|
|
1051
|
-
kind: track.kind,
|
|
1052
|
-
direction: track.direction,
|
|
1053
|
-
transceiver
|
|
1037
|
+
if (!this.cachedIceServers) {
|
|
1038
|
+
this.cachedIceServers = this.fetchIceServers();
|
|
1039
|
+
this.cachedIceServers.catch(() => {
|
|
1054
1040
|
});
|
|
1055
|
-
console.debug(
|
|
1056
|
-
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1057
|
-
);
|
|
1058
1041
|
}
|
|
1059
|
-
|
|
1060
|
-
const trackMapping = this.buildTrackMapping(tracks);
|
|
1061
|
-
yield this.sendSdpOffer(sdpOffer, trackMapping, "POST");
|
|
1062
|
-
const answerResponse = yield this.pollSdpAnswer();
|
|
1063
|
-
this.iceStartTime = performance.now();
|
|
1064
|
-
yield setRemoteDescription(
|
|
1065
|
-
this.peerConnection,
|
|
1066
|
-
answerResponse.sdp_answer
|
|
1067
|
-
);
|
|
1068
|
-
console.debug("[WebRTCTransport] Remote description set");
|
|
1042
|
+
yield this.cachedIceServers;
|
|
1069
1043
|
});
|
|
1070
1044
|
}
|
|
1071
|
-
|
|
1045
|
+
prepare(tracks) {
|
|
1072
1046
|
return __async(this, null, function* () {
|
|
1073
1047
|
this.setStatus("connecting");
|
|
1048
|
+
this.resetTransportTimings();
|
|
1074
1049
|
this.stopPing();
|
|
1075
1050
|
this.stopStatsPolling();
|
|
1076
1051
|
if (this.dataChannel) {
|
|
@@ -1083,8 +1058,8 @@ var WebRTCTransportClient = class {
|
|
|
1083
1058
|
}
|
|
1084
1059
|
this.peerConnected = false;
|
|
1085
1060
|
this.dataChannelOpen = false;
|
|
1086
|
-
this.
|
|
1087
|
-
|
|
1061
|
+
const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
|
|
1062
|
+
this.cachedIceServers = void 0;
|
|
1088
1063
|
this.peerConnection = createPeerConnection({ iceServers });
|
|
1089
1064
|
this.setupPeerConnectionHandlers();
|
|
1090
1065
|
this.dataChannel = createDataChannel(this.peerConnection);
|
|
@@ -1100,17 +1075,35 @@ var WebRTCTransportClient = class {
|
|
|
1100
1075
|
direction: track.direction,
|
|
1101
1076
|
transceiver
|
|
1102
1077
|
});
|
|
1078
|
+
console.debug(
|
|
1079
|
+
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
this.pendingSdpOffer = yield createOffer(this.peerConnection);
|
|
1083
|
+
this.pendingTrackMapping = this.buildTrackMapping(tracks);
|
|
1084
|
+
console.debug("[WebRTCTransport] SDP offer prepared");
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
connect(reconnect = false) {
|
|
1088
|
+
return __async(this, null, function* () {
|
|
1089
|
+
if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
|
|
1090
|
+
throw new Error(
|
|
1091
|
+
"[WebRTCTransport] No prepared connection. Call prepare() first."
|
|
1092
|
+
);
|
|
1103
1093
|
}
|
|
1104
|
-
const
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1094
|
+
const method = reconnect ? "PUT" : "POST";
|
|
1095
|
+
const sdpOffer = this.pendingSdpOffer;
|
|
1096
|
+
const trackMapping = this.pendingTrackMapping;
|
|
1097
|
+
this.pendingSdpOffer = void 0;
|
|
1098
|
+
this.pendingTrackMapping = void 0;
|
|
1099
|
+
yield this.sendSdpOffer(sdpOffer, trackMapping, method);
|
|
1107
1100
|
const answerResponse = yield this.pollSdpAnswer();
|
|
1108
1101
|
this.iceStartTime = performance.now();
|
|
1109
1102
|
yield setRemoteDescription(
|
|
1110
1103
|
this.peerConnection,
|
|
1111
1104
|
answerResponse.sdp_answer
|
|
1112
1105
|
);
|
|
1113
|
-
console.debug("[WebRTCTransport] Remote description set
|
|
1106
|
+
console.debug("[WebRTCTransport] Remote description set");
|
|
1114
1107
|
});
|
|
1115
1108
|
}
|
|
1116
1109
|
disconnect() {
|
|
@@ -1374,7 +1367,7 @@ var WebRTCTransportClient = class {
|
|
|
1374
1367
|
}
|
|
1375
1368
|
};
|
|
1376
1369
|
this.peerConnection.onicecandidateerror = (event) => {
|
|
1377
|
-
console.
|
|
1370
|
+
console.debug("[WebRTCTransport] ICE candidate error:", event);
|
|
1378
1371
|
};
|
|
1379
1372
|
this.peerConnection.ondatachannel = (event) => {
|
|
1380
1373
|
console.debug("[WebRTCTransport] Data channel received from remote");
|
|
@@ -1429,10 +1422,16 @@ var WebRTCTransportClient = class {
|
|
|
1429
1422
|
import { z as z2 } from "zod";
|
|
1430
1423
|
var LOCAL_COORDINATOR_URL = "http://localhost:8080";
|
|
1431
1424
|
var DEFAULT_BASE_URL = "https://api.reactor.inc";
|
|
1425
|
+
var TrackHintSchema = z2.object({
|
|
1426
|
+
name: z2.string(),
|
|
1427
|
+
kind: z2.enum(["video", "audio"]),
|
|
1428
|
+
direction: z2.enum(["recvonly", "sendonly"])
|
|
1429
|
+
});
|
|
1432
1430
|
var OptionsSchema = z2.object({
|
|
1433
1431
|
apiUrl: z2.string().default(DEFAULT_BASE_URL),
|
|
1434
1432
|
modelName: z2.string(),
|
|
1435
|
-
local: z2.boolean().default(false)
|
|
1433
|
+
local: z2.boolean().default(false),
|
|
1434
|
+
modelTracks: z2.array(TrackHintSchema).optional()
|
|
1436
1435
|
});
|
|
1437
1436
|
var Reactor = class {
|
|
1438
1437
|
constructor(options) {
|
|
@@ -1446,6 +1445,9 @@ var Reactor = class {
|
|
|
1446
1445
|
if (this.local && options.apiUrl === void 0) {
|
|
1447
1446
|
this.coordinatorUrl = LOCAL_COORDINATOR_URL;
|
|
1448
1447
|
}
|
|
1448
|
+
if (validatedOptions.modelTracks) {
|
|
1449
|
+
this.presetTracks = validatedOptions.modelTracks;
|
|
1450
|
+
}
|
|
1449
1451
|
}
|
|
1450
1452
|
on(event, handler) {
|
|
1451
1453
|
if (!this.eventListeners.has(event)) {
|
|
@@ -1520,7 +1522,9 @@ var Reactor = class {
|
|
|
1520
1522
|
* (fires `@file_uploaded` on the model if registered)
|
|
1521
1523
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
1522
1524
|
*
|
|
1523
|
-
*
|
|
1525
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
1526
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
1527
|
+
* setups work correctly (REA-1573).
|
|
1524
1528
|
*/
|
|
1525
1529
|
uploadFile(file, options) {
|
|
1526
1530
|
return __async(this, null, function* () {
|
|
@@ -1544,7 +1548,16 @@ var Reactor = class {
|
|
|
1544
1548
|
size,
|
|
1545
1549
|
mime_type: mimeType
|
|
1546
1550
|
});
|
|
1547
|
-
|
|
1551
|
+
let presignedUrl = slot.presigned_url;
|
|
1552
|
+
if (this.local) {
|
|
1553
|
+
const target = new URL(this.coordinatorUrl);
|
|
1554
|
+
const parsed = new URL(presignedUrl);
|
|
1555
|
+
parsed.protocol = target.protocol;
|
|
1556
|
+
parsed.hostname = target.hostname;
|
|
1557
|
+
parsed.port = target.port;
|
|
1558
|
+
presignedUrl = parsed.toString();
|
|
1559
|
+
}
|
|
1560
|
+
const putResponse = yield fetch(presignedUrl, {
|
|
1548
1561
|
method: "PUT",
|
|
1549
1562
|
body: file,
|
|
1550
1563
|
headers: {
|
|
@@ -1646,7 +1659,8 @@ var Reactor = class {
|
|
|
1646
1659
|
});
|
|
1647
1660
|
this.setupTransportHandlers();
|
|
1648
1661
|
}
|
|
1649
|
-
yield this.transportClient.
|
|
1662
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1663
|
+
yield this.transportClient.connect(true);
|
|
1650
1664
|
} catch (error) {
|
|
1651
1665
|
if (isAbortError(error)) return;
|
|
1652
1666
|
console.error("[Reactor] Failed to reconnect:", error);
|
|
@@ -1692,34 +1706,49 @@ var Reactor = class {
|
|
|
1692
1706
|
initialResponse.state
|
|
1693
1707
|
);
|
|
1694
1708
|
this.setStatus("waiting");
|
|
1695
|
-
const tPoll = performance.now();
|
|
1696
|
-
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1697
|
-
const sessionPollingMs = performance.now() - tPoll;
|
|
1698
|
-
this.sessionResponse = sessionResponse;
|
|
1699
|
-
this.capabilities = sessionResponse.capabilities;
|
|
1700
|
-
this.tracks = sessionResponse.capabilities.tracks;
|
|
1701
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
1702
|
-
console.debug(
|
|
1703
|
-
"[Reactor] Session ready, transport:",
|
|
1704
|
-
sessionResponse.selected_transport.protocol,
|
|
1705
|
-
"tracks:",
|
|
1706
|
-
this.tracks.length
|
|
1707
|
-
);
|
|
1708
|
-
const protocol = sessionResponse.selected_transport.protocol;
|
|
1709
|
-
if (protocol !== "webrtc") {
|
|
1710
|
-
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1711
|
-
}
|
|
1712
1709
|
this.transportClient = new WebRTCTransportClient({
|
|
1713
1710
|
baseUrl: this.coordinatorUrl,
|
|
1714
|
-
sessionId:
|
|
1711
|
+
sessionId: initialResponse.session_id,
|
|
1715
1712
|
jwtToken: this.local ? "local" : jwtToken,
|
|
1716
1713
|
webrtcVersion: REACTOR_WEBRTC_VERSION,
|
|
1717
1714
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|
|
1718
1715
|
});
|
|
1719
1716
|
this.setupTransportHandlers();
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1717
|
+
let sessionPollingMs;
|
|
1718
|
+
let transportConnectingMs;
|
|
1719
|
+
if (this.presetTracks) {
|
|
1720
|
+
const tParallel = performance.now();
|
|
1721
|
+
const [sessionResponse] = yield Promise.all([
|
|
1722
|
+
this.coordinatorClient.pollSessionReady(),
|
|
1723
|
+
this.transportClient.prepare(this.presetTracks)
|
|
1724
|
+
]);
|
|
1725
|
+
sessionPollingMs = performance.now() - tParallel;
|
|
1726
|
+
this.sessionResponse = sessionResponse;
|
|
1727
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1728
|
+
this.tracks = this.presetTracks;
|
|
1729
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1730
|
+
const tConnect = performance.now();
|
|
1731
|
+
yield this.transportClient.connect();
|
|
1732
|
+
transportConnectingMs = performance.now() - tConnect;
|
|
1733
|
+
} else {
|
|
1734
|
+
this.transportClient.warmup();
|
|
1735
|
+
const tPoll = performance.now();
|
|
1736
|
+
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1737
|
+
sessionPollingMs = performance.now() - tPoll;
|
|
1738
|
+
this.sessionResponse = sessionResponse;
|
|
1739
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1740
|
+
this.tracks = sessionResponse.capabilities.tracks;
|
|
1741
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1742
|
+
const protocol = sessionResponse.selected_transport.protocol;
|
|
1743
|
+
if (protocol !== "webrtc") {
|
|
1744
|
+
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1745
|
+
}
|
|
1746
|
+
const tTransport = performance.now();
|
|
1747
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1748
|
+
yield this.transportClient.connect();
|
|
1749
|
+
transportConnectingMs = performance.now() - tTransport;
|
|
1750
|
+
}
|
|
1751
|
+
console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
|
|
1723
1752
|
this.connectionTimings = {
|
|
1724
1753
|
sessionCreationMs: sessionCreationMs + sessionPollingMs,
|
|
1725
1754
|
transportConnectingMs,
|
|
@@ -2272,7 +2301,7 @@ function useStats() {
|
|
|
2272
2301
|
|
|
2273
2302
|
// src/react/ReactorView.tsx
|
|
2274
2303
|
import { useEffect as useEffect3, useMemo, useRef as useRef3 } from "react";
|
|
2275
|
-
import { jsx as jsx2
|
|
2304
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
2276
2305
|
function ReactorView({
|
|
2277
2306
|
track = "main_video",
|
|
2278
2307
|
audioTrack,
|
|
@@ -2283,12 +2312,11 @@ function ReactorView({
|
|
|
2283
2312
|
videoObjectFit = "contain",
|
|
2284
2313
|
muted = true
|
|
2285
2314
|
}) {
|
|
2286
|
-
const { videoMediaTrack, audioMediaTrack
|
|
2315
|
+
const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
|
|
2287
2316
|
var _a, _b;
|
|
2288
2317
|
return {
|
|
2289
2318
|
videoMediaTrack: (_a = state.tracks[track]) != null ? _a : null,
|
|
2290
|
-
audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null
|
|
2291
|
-
status: state.status
|
|
2319
|
+
audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null
|
|
2292
2320
|
};
|
|
2293
2321
|
});
|
|
2294
2322
|
const videoRef = useRef3(null);
|
|
@@ -2327,8 +2355,7 @@ function ReactorView({
|
|
|
2327
2355
|
console.debug("[ReactorView] No tracks or element to attach");
|
|
2328
2356
|
}
|
|
2329
2357
|
}, [mediaStream]);
|
|
2330
|
-
|
|
2331
|
-
return /* @__PURE__ */ jsxs(
|
|
2358
|
+
return /* @__PURE__ */ jsx2(
|
|
2332
2359
|
"div",
|
|
2333
2360
|
{
|
|
2334
2361
|
style: __spreadValues(__spreadValues(__spreadValues({
|
|
@@ -2336,61 +2363,43 @@ function ReactorView({
|
|
|
2336
2363
|
background: "#000"
|
|
2337
2364
|
}, width && { width }), height && { height }), style),
|
|
2338
2365
|
className,
|
|
2339
|
-
children:
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
),
|
|
2354
|
-
showPlaceholder && /* @__PURE__ */ jsx2(
|
|
2355
|
-
"div",
|
|
2356
|
-
{
|
|
2357
|
-
style: {
|
|
2358
|
-
position: "absolute",
|
|
2359
|
-
top: 0,
|
|
2360
|
-
left: 0,
|
|
2361
|
-
width: "100%",
|
|
2362
|
-
height: "100%",
|
|
2363
|
-
color: "#fff",
|
|
2364
|
-
display: "flex",
|
|
2365
|
-
alignItems: "center",
|
|
2366
|
-
justifyContent: "center",
|
|
2367
|
-
fontSize: "16px",
|
|
2368
|
-
fontFamily: "monospace",
|
|
2369
|
-
textAlign: "center",
|
|
2370
|
-
padding: "20px",
|
|
2371
|
-
boxSizing: "border-box"
|
|
2372
|
-
},
|
|
2373
|
-
children: status
|
|
2374
|
-
}
|
|
2375
|
-
)
|
|
2376
|
-
]
|
|
2366
|
+
children: /* @__PURE__ */ jsx2(
|
|
2367
|
+
"video",
|
|
2368
|
+
{
|
|
2369
|
+
ref: videoRef,
|
|
2370
|
+
style: {
|
|
2371
|
+
width: "100%",
|
|
2372
|
+
height: "100%",
|
|
2373
|
+
objectFit: videoObjectFit,
|
|
2374
|
+
display: videoMediaTrack ? "block" : "none"
|
|
2375
|
+
},
|
|
2376
|
+
muted,
|
|
2377
|
+
playsInline: true
|
|
2378
|
+
}
|
|
2379
|
+
)
|
|
2377
2380
|
}
|
|
2378
2381
|
);
|
|
2379
2382
|
}
|
|
2380
2383
|
|
|
2381
2384
|
// src/react/ReactorController.tsx
|
|
2382
|
-
import React, { useState as useState3, useCallback } from "react";
|
|
2383
|
-
import { jsx as jsx3, jsxs
|
|
2385
|
+
import React, { useState as useState3, useCallback, useRef as useRef4 } from "react";
|
|
2386
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
2387
|
+
function isFileParam(ps) {
|
|
2388
|
+
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
2389
|
+
}
|
|
2384
2390
|
function ReactorController({
|
|
2385
2391
|
className,
|
|
2386
2392
|
style
|
|
2387
2393
|
}) {
|
|
2388
|
-
const { sendCommand, status } = useReactor((state) => ({
|
|
2394
|
+
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
2389
2395
|
sendCommand: state.sendCommand,
|
|
2396
|
+
uploadFile: state.uploadFile,
|
|
2390
2397
|
status: state.status
|
|
2391
2398
|
}));
|
|
2392
2399
|
const [commands, setCommands] = useState3({});
|
|
2393
2400
|
const [formValues, setFormValues] = useState3({});
|
|
2401
|
+
const formRef = useRef4(formValues);
|
|
2402
|
+
formRef.current = formValues;
|
|
2394
2403
|
const [expandedCommands, setExpandedCommands] = useState3({});
|
|
2395
2404
|
React.useEffect(() => {
|
|
2396
2405
|
if (status === "disconnected") {
|
|
@@ -2437,15 +2446,17 @@ function ReactorController({
|
|
|
2437
2446
|
initialExpanded[commandName] = false;
|
|
2438
2447
|
Object.entries(commandSchema.schema).forEach(
|
|
2439
2448
|
([paramName, paramSchema]) => {
|
|
2440
|
-
var _a2
|
|
2441
|
-
if (paramSchema
|
|
2449
|
+
var _a2;
|
|
2450
|
+
if (isFileParam(paramSchema)) {
|
|
2451
|
+
initialValues[commandName][paramName] = null;
|
|
2452
|
+
} else if (paramSchema.default !== void 0) {
|
|
2453
|
+
initialValues[commandName][paramName] = paramSchema.default;
|
|
2454
|
+
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2442
2455
|
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
2443
2456
|
} else if (paramSchema.type === "string") {
|
|
2444
2457
|
initialValues[commandName][paramName] = "";
|
|
2445
2458
|
} else if (paramSchema.type === "boolean") {
|
|
2446
2459
|
initialValues[commandName][paramName] = false;
|
|
2447
|
-
} else if (paramSchema.type === "integer") {
|
|
2448
|
-
initialValues[commandName][paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2449
2460
|
}
|
|
2450
2461
|
}
|
|
2451
2462
|
);
|
|
@@ -2472,12 +2483,16 @@ function ReactorController({
|
|
|
2472
2483
|
const handleCommandSubmit = useCallback(
|
|
2473
2484
|
(commandName) => __async(null, null, function* () {
|
|
2474
2485
|
const commandSchema = commands[commandName];
|
|
2475
|
-
const formData =
|
|
2486
|
+
const formData = formRef.current[commandName] || {};
|
|
2476
2487
|
const data = {};
|
|
2477
2488
|
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
2478
|
-
var _a
|
|
2489
|
+
var _a;
|
|
2479
2490
|
const paramSchema = commandSchema.schema[paramName];
|
|
2480
2491
|
let value = formData[paramName];
|
|
2492
|
+
if (value instanceof FileRef) {
|
|
2493
|
+
data[paramName] = value;
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2481
2496
|
if (paramSchema.type === "number" && typeof value === "string") {
|
|
2482
2497
|
value = parseFloat(value) || 0;
|
|
2483
2498
|
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
@@ -2488,10 +2503,8 @@ function ReactorController({
|
|
|
2488
2503
|
if (value !== void 0 && value !== "" && value !== null) {
|
|
2489
2504
|
data[paramName] = value;
|
|
2490
2505
|
} else if (paramSchema.required) {
|
|
2491
|
-
if (paramSchema.type === "number") {
|
|
2506
|
+
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2492
2507
|
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
2493
|
-
} else if (paramSchema.type === "integer") {
|
|
2494
|
-
data[paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2495
2508
|
} else if (paramSchema.type === "string") {
|
|
2496
2509
|
data[paramName] = "";
|
|
2497
2510
|
} else if (paramSchema.type === "boolean") {
|
|
@@ -2499,21 +2512,35 @@ function ReactorController({
|
|
|
2499
2512
|
}
|
|
2500
2513
|
}
|
|
2501
2514
|
});
|
|
2502
|
-
console.log(`Executing command: ${commandName}`, data);
|
|
2503
2515
|
yield sendCommand(commandName, data);
|
|
2504
2516
|
}),
|
|
2505
|
-
[
|
|
2517
|
+
[sendCommand, commands]
|
|
2506
2518
|
);
|
|
2507
2519
|
const renderInput = (commandName, paramName, paramSchema) => {
|
|
2508
2520
|
var _a, _b;
|
|
2509
2521
|
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
2522
|
+
if (isFileParam(paramSchema)) {
|
|
2523
|
+
return /* @__PURE__ */ jsx3(
|
|
2524
|
+
FileParamInput,
|
|
2525
|
+
{
|
|
2526
|
+
commandName,
|
|
2527
|
+
paramName,
|
|
2528
|
+
description: paramSchema.description,
|
|
2529
|
+
value,
|
|
2530
|
+
onChange: handleInputChange,
|
|
2531
|
+
disabled: status !== "ready",
|
|
2532
|
+
uploadFile
|
|
2533
|
+
},
|
|
2534
|
+
`${commandName}-${paramName}`
|
|
2535
|
+
);
|
|
2536
|
+
}
|
|
2510
2537
|
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2511
2538
|
const isInteger = paramSchema.type === "integer";
|
|
2512
2539
|
const step = isInteger ? 1 : 0.1;
|
|
2513
2540
|
const parseValue = isInteger ? parseInt : parseFloat;
|
|
2514
2541
|
if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
|
|
2515
|
-
return /* @__PURE__ */
|
|
2516
|
-
/* @__PURE__ */
|
|
2542
|
+
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
2543
|
+
/* @__PURE__ */ jsxs(
|
|
2517
2544
|
"label",
|
|
2518
2545
|
{
|
|
2519
2546
|
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
@@ -2545,14 +2572,14 @@ function ReactorController({
|
|
|
2545
2572
|
style: { width: "100%", marginBottom: "4px" }
|
|
2546
2573
|
}
|
|
2547
2574
|
),
|
|
2548
|
-
/* @__PURE__ */
|
|
2575
|
+
/* @__PURE__ */ jsxs("div", { style: { fontSize: "11px", color: "#888" }, children: [
|
|
2549
2576
|
"Value: ",
|
|
2550
2577
|
value
|
|
2551
2578
|
] })
|
|
2552
2579
|
] });
|
|
2553
2580
|
} else {
|
|
2554
|
-
return /* @__PURE__ */
|
|
2555
|
-
/* @__PURE__ */
|
|
2581
|
+
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
2582
|
+
/* @__PURE__ */ jsxs(
|
|
2556
2583
|
"label",
|
|
2557
2584
|
{
|
|
2558
2585
|
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
@@ -2602,8 +2629,8 @@ function ReactorController({
|
|
|
2602
2629
|
}
|
|
2603
2630
|
} else if (paramSchema.type === "string") {
|
|
2604
2631
|
if (paramSchema.enum) {
|
|
2605
|
-
return /* @__PURE__ */
|
|
2606
|
-
/* @__PURE__ */
|
|
2632
|
+
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
2633
|
+
/* @__PURE__ */ jsxs(
|
|
2607
2634
|
"label",
|
|
2608
2635
|
{
|
|
2609
2636
|
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
@@ -2614,7 +2641,7 @@ function ReactorController({
|
|
|
2614
2641
|
]
|
|
2615
2642
|
}
|
|
2616
2643
|
),
|
|
2617
|
-
/* @__PURE__ */
|
|
2644
|
+
/* @__PURE__ */ jsxs(
|
|
2618
2645
|
"select",
|
|
2619
2646
|
{
|
|
2620
2647
|
value,
|
|
@@ -2634,8 +2661,8 @@ function ReactorController({
|
|
|
2634
2661
|
)
|
|
2635
2662
|
] });
|
|
2636
2663
|
} else {
|
|
2637
|
-
return /* @__PURE__ */
|
|
2638
|
-
/* @__PURE__ */
|
|
2664
|
+
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
2665
|
+
/* @__PURE__ */ jsxs(
|
|
2639
2666
|
"label",
|
|
2640
2667
|
{
|
|
2641
2668
|
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
@@ -2664,7 +2691,7 @@ function ReactorController({
|
|
|
2664
2691
|
] });
|
|
2665
2692
|
}
|
|
2666
2693
|
} else if (paramSchema.type === "boolean") {
|
|
2667
|
-
return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */
|
|
2694
|
+
return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsxs(
|
|
2668
2695
|
"label",
|
|
2669
2696
|
{
|
|
2670
2697
|
style: {
|
|
@@ -2695,11 +2722,12 @@ function ReactorController({
|
|
|
2695
2722
|
const renderCommand = (commandName, commandSchema) => {
|
|
2696
2723
|
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
2697
2724
|
const isExpanded = expandedCommands[commandName];
|
|
2698
|
-
const
|
|
2699
|
-
|
|
2725
|
+
const params = Object.values(commandSchema.schema);
|
|
2726
|
+
const allSliders = params.length > 0 && params.every(
|
|
2727
|
+
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
2700
2728
|
);
|
|
2701
|
-
const showExecuteButton = !
|
|
2702
|
-
return /* @__PURE__ */
|
|
2729
|
+
const showExecuteButton = !allSliders;
|
|
2730
|
+
return /* @__PURE__ */ jsxs(
|
|
2703
2731
|
"div",
|
|
2704
2732
|
{
|
|
2705
2733
|
style: {
|
|
@@ -2709,7 +2737,7 @@ function ReactorController({
|
|
|
2709
2737
|
backgroundColor: "#fafafa"
|
|
2710
2738
|
},
|
|
2711
2739
|
children: [
|
|
2712
|
-
/* @__PURE__ */
|
|
2740
|
+
/* @__PURE__ */ jsxs(
|
|
2713
2741
|
"div",
|
|
2714
2742
|
{
|
|
2715
2743
|
onClick: () => toggleCommandExpanded(commandName),
|
|
@@ -2722,7 +2750,7 @@ function ReactorController({
|
|
|
2722
2750
|
alignItems: "center"
|
|
2723
2751
|
},
|
|
2724
2752
|
children: [
|
|
2725
|
-
/* @__PURE__ */
|
|
2753
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2726
2754
|
/* @__PURE__ */ jsx3(
|
|
2727
2755
|
"h4",
|
|
2728
2756
|
{
|
|
@@ -2757,8 +2785,8 @@ function ReactorController({
|
|
|
2757
2785
|
]
|
|
2758
2786
|
}
|
|
2759
2787
|
),
|
|
2760
|
-
isExpanded && /* @__PURE__ */
|
|
2761
|
-
hasParams && /* @__PURE__ */
|
|
2788
|
+
isExpanded && /* @__PURE__ */ jsxs("div", { style: { padding: "12px", paddingTop: "0" }, children: [
|
|
2789
|
+
hasParams && /* @__PURE__ */ jsxs("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
|
|
2762
2790
|
/* @__PURE__ */ jsx3(
|
|
2763
2791
|
"div",
|
|
2764
2792
|
{
|
|
@@ -2795,7 +2823,7 @@ function ReactorController({
|
|
|
2795
2823
|
children: "No parameters required"
|
|
2796
2824
|
}
|
|
2797
2825
|
),
|
|
2798
|
-
showExecuteButton && /* @__PURE__ */
|
|
2826
|
+
showExecuteButton && /* @__PURE__ */ jsxs(
|
|
2799
2827
|
"button",
|
|
2800
2828
|
{
|
|
2801
2829
|
onClick: () => handleCommandSubmit(commandName),
|
|
@@ -2821,7 +2849,7 @@ function ReactorController({
|
|
|
2821
2849
|
commandName
|
|
2822
2850
|
);
|
|
2823
2851
|
};
|
|
2824
|
-
return /* @__PURE__ */ jsx3("div", { className, style, children: /* @__PURE__ */ jsx3("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ jsx3("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */
|
|
2852
|
+
return /* @__PURE__ */ jsx3("div", { className, style, children: /* @__PURE__ */ jsx3("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ jsx3("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
2825
2853
|
/* @__PURE__ */ jsx3(
|
|
2826
2854
|
"h3",
|
|
2827
2855
|
{
|
|
@@ -2836,10 +2864,93 @@ function ReactorController({
|
|
|
2836
2864
|
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ jsx3("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
2837
2865
|
] }) }) });
|
|
2838
2866
|
}
|
|
2867
|
+
function FileParamInput({
|
|
2868
|
+
commandName,
|
|
2869
|
+
paramName,
|
|
2870
|
+
description,
|
|
2871
|
+
value,
|
|
2872
|
+
onChange,
|
|
2873
|
+
disabled,
|
|
2874
|
+
uploadFile
|
|
2875
|
+
}) {
|
|
2876
|
+
const inputRef = useRef4(null);
|
|
2877
|
+
const [uploading, setUploading] = useState3(false);
|
|
2878
|
+
const fileRef = value instanceof FileRef ? value : null;
|
|
2879
|
+
const handleFile = (e) => __async(null, null, function* () {
|
|
2880
|
+
var _a;
|
|
2881
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
2882
|
+
if (!file) return;
|
|
2883
|
+
e.target.value = "";
|
|
2884
|
+
setUploading(true);
|
|
2885
|
+
try {
|
|
2886
|
+
const ref = yield uploadFile(file);
|
|
2887
|
+
onChange(commandName, paramName, ref);
|
|
2888
|
+
} catch (err) {
|
|
2889
|
+
console.error("[FileParamInput] Upload failed:", err);
|
|
2890
|
+
} finally {
|
|
2891
|
+
setUploading(false);
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
2895
|
+
/* @__PURE__ */ jsxs("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
2896
|
+
paramName,
|
|
2897
|
+
/* @__PURE__ */ jsx3("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
2898
|
+
description && ` - ${description}`
|
|
2899
|
+
] }),
|
|
2900
|
+
/* @__PURE__ */ jsxs(
|
|
2901
|
+
"div",
|
|
2902
|
+
{
|
|
2903
|
+
style: {
|
|
2904
|
+
display: "flex",
|
|
2905
|
+
alignItems: "center",
|
|
2906
|
+
gap: "8px",
|
|
2907
|
+
marginTop: "4px"
|
|
2908
|
+
},
|
|
2909
|
+
children: [
|
|
2910
|
+
/* @__PURE__ */ jsx3(
|
|
2911
|
+
"input",
|
|
2912
|
+
{
|
|
2913
|
+
ref: inputRef,
|
|
2914
|
+
type: "file",
|
|
2915
|
+
accept: "image/*",
|
|
2916
|
+
onChange: handleFile,
|
|
2917
|
+
style: { display: "none" }
|
|
2918
|
+
}
|
|
2919
|
+
),
|
|
2920
|
+
/* @__PURE__ */ jsx3(
|
|
2921
|
+
"button",
|
|
2922
|
+
{
|
|
2923
|
+
disabled: disabled || uploading,
|
|
2924
|
+
onClick: () => {
|
|
2925
|
+
var _a;
|
|
2926
|
+
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
2927
|
+
},
|
|
2928
|
+
style: {
|
|
2929
|
+
padding: "4px 12px",
|
|
2930
|
+
fontSize: "12px",
|
|
2931
|
+
backgroundColor: "#007bff",
|
|
2932
|
+
color: "white",
|
|
2933
|
+
border: "none",
|
|
2934
|
+
borderRadius: "4px",
|
|
2935
|
+
cursor: disabled || uploading ? "default" : "pointer",
|
|
2936
|
+
opacity: disabled || uploading ? 0.5 : 1
|
|
2937
|
+
},
|
|
2938
|
+
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
2939
|
+
}
|
|
2940
|
+
),
|
|
2941
|
+
fileRef && /* @__PURE__ */ jsxs("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
2942
|
+
"\\u2713 ",
|
|
2943
|
+
fileRef.name
|
|
2944
|
+
] })
|
|
2945
|
+
]
|
|
2946
|
+
}
|
|
2947
|
+
)
|
|
2948
|
+
] });
|
|
2949
|
+
}
|
|
2839
2950
|
|
|
2840
2951
|
// src/react/WebcamStream.tsx
|
|
2841
|
-
import { useEffect as useEffect4, useRef as
|
|
2842
|
-
import { jsx as jsx4, jsxs as
|
|
2952
|
+
import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
|
|
2953
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2843
2954
|
function WebcamStream({
|
|
2844
2955
|
track,
|
|
2845
2956
|
className,
|
|
@@ -2860,7 +2971,7 @@ function WebcamStream({
|
|
|
2860
2971
|
unpublish: state.unpublish,
|
|
2861
2972
|
reactor: state.internal.reactor
|
|
2862
2973
|
}));
|
|
2863
|
-
const videoRef =
|
|
2974
|
+
const videoRef = useRef5(null);
|
|
2864
2975
|
const startWebcam = () => __async(null, null, function* () {
|
|
2865
2976
|
console.debug("[WebcamPublisher] Starting webcam");
|
|
2866
2977
|
try {
|
|
@@ -2973,7 +3084,7 @@ function WebcamStream({
|
|
|
2973
3084
|
};
|
|
2974
3085
|
}, []);
|
|
2975
3086
|
const showPlaceholder = !stream;
|
|
2976
|
-
return /* @__PURE__ */
|
|
3087
|
+
return /* @__PURE__ */ jsxs2(
|
|
2977
3088
|
"div",
|
|
2978
3089
|
{
|
|
2979
3090
|
style: __spreadValues({
|
|
@@ -3019,7 +3130,7 @@ function WebcamStream({
|
|
|
3019
3130
|
flexDirection: "column",
|
|
3020
3131
|
gap: "12px"
|
|
3021
3132
|
},
|
|
3022
|
-
children: permissionDenied ? /* @__PURE__ */
|
|
3133
|
+
children: permissionDenied ? /* @__PURE__ */ jsxs2("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
|
|
3023
3134
|
"Camera access denied.",
|
|
3024
3135
|
/* @__PURE__ */ jsx4("br", {}),
|
|
3025
3136
|
"Please allow access in your browser settings."
|