@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.d.mts
CHANGED
|
@@ -177,6 +177,17 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
177
177
|
apiUrl: z.ZodDefault<z.ZodString>;
|
|
178
178
|
modelName: z.ZodString;
|
|
179
179
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
180
|
+
modelTracks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
kind: z.ZodEnum<{
|
|
183
|
+
video: "video";
|
|
184
|
+
audio: "audio";
|
|
185
|
+
}>;
|
|
186
|
+
direction: z.ZodEnum<{
|
|
187
|
+
recvonly: "recvonly";
|
|
188
|
+
sendonly: "sendonly";
|
|
189
|
+
}>;
|
|
190
|
+
}, z.core.$strip>>>;
|
|
180
191
|
}, z.core.$strip>;
|
|
181
192
|
type Options = z.input<typeof OptionsSchema>;
|
|
182
193
|
|
|
@@ -195,6 +206,7 @@ declare class Reactor {
|
|
|
195
206
|
private connectionTimings?;
|
|
196
207
|
private capabilities?;
|
|
197
208
|
private tracks;
|
|
209
|
+
private presetTracks?;
|
|
198
210
|
private sessionResponse?;
|
|
199
211
|
constructor(options: Options);
|
|
200
212
|
private eventListeners;
|
|
@@ -219,7 +231,9 @@ declare class Reactor {
|
|
|
219
231
|
* (fires `@file_uploaded` on the model if registered)
|
|
220
232
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
221
233
|
*
|
|
222
|
-
*
|
|
234
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
235
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
236
|
+
* setups work correctly (REA-1573).
|
|
223
237
|
*/
|
|
224
238
|
uploadFile(file: File | Blob, options?: {
|
|
225
239
|
name?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -177,6 +177,17 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
177
177
|
apiUrl: z.ZodDefault<z.ZodString>;
|
|
178
178
|
modelName: z.ZodString;
|
|
179
179
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
180
|
+
modelTracks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
kind: z.ZodEnum<{
|
|
183
|
+
video: "video";
|
|
184
|
+
audio: "audio";
|
|
185
|
+
}>;
|
|
186
|
+
direction: z.ZodEnum<{
|
|
187
|
+
recvonly: "recvonly";
|
|
188
|
+
sendonly: "sendonly";
|
|
189
|
+
}>;
|
|
190
|
+
}, z.core.$strip>>>;
|
|
180
191
|
}, z.core.$strip>;
|
|
181
192
|
type Options = z.input<typeof OptionsSchema>;
|
|
182
193
|
|
|
@@ -195,6 +206,7 @@ declare class Reactor {
|
|
|
195
206
|
private connectionTimings?;
|
|
196
207
|
private capabilities?;
|
|
197
208
|
private tracks;
|
|
209
|
+
private presetTracks?;
|
|
198
210
|
private sessionResponse?;
|
|
199
211
|
constructor(options: Options);
|
|
200
212
|
private eventListeners;
|
|
@@ -219,7 +231,9 @@ declare class Reactor {
|
|
|
219
231
|
* (fires `@file_uploaded` on the model if registered)
|
|
220
232
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
221
233
|
*
|
|
222
|
-
*
|
|
234
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
235
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
236
|
+
* setups work correctly (REA-1573).
|
|
223
237
|
*/
|
|
224
238
|
uploadFile(file: File | Blob, options?: {
|
|
225
239
|
name?: string;
|
package/dist/index.js
CHANGED
|
@@ -130,7 +130,7 @@ var import_zod = require("zod");
|
|
|
130
130
|
// package.json
|
|
131
131
|
var package_default = {
|
|
132
132
|
name: "@reactor-team/js-sdk",
|
|
133
|
-
version: "2.9.
|
|
133
|
+
version: "2.9.2",
|
|
134
134
|
description: "Reactor JavaScript frontend SDK",
|
|
135
135
|
main: "dist/index.js",
|
|
136
136
|
module: "dist/index.mjs",
|
|
@@ -1079,45 +1079,20 @@ var WebRTCTransportClient = class {
|
|
|
1079
1079
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1080
1080
|
// Connection Lifecycle
|
|
1081
1081
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1082
|
-
|
|
1082
|
+
warmup() {
|
|
1083
1083
|
return __async(this, null, function* () {
|
|
1084
|
-
this.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
this.peerConnection = createPeerConnection({ iceServers });
|
|
1088
|
-
this.setupPeerConnectionHandlers();
|
|
1089
|
-
this.dataChannel = createDataChannel(this.peerConnection);
|
|
1090
|
-
this.setupDataChannelHandlers();
|
|
1091
|
-
this.transceiverMap.clear();
|
|
1092
|
-
for (const track of tracks) {
|
|
1093
|
-
const transceiver = this.peerConnection.addTransceiver(track.kind, {
|
|
1094
|
-
direction: track.direction
|
|
1095
|
-
});
|
|
1096
|
-
this.transceiverMap.set(track.name, {
|
|
1097
|
-
name: track.name,
|
|
1098
|
-
kind: track.kind,
|
|
1099
|
-
direction: track.direction,
|
|
1100
|
-
transceiver
|
|
1084
|
+
if (!this.cachedIceServers) {
|
|
1085
|
+
this.cachedIceServers = this.fetchIceServers();
|
|
1086
|
+
this.cachedIceServers.catch(() => {
|
|
1101
1087
|
});
|
|
1102
|
-
console.debug(
|
|
1103
|
-
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1104
|
-
);
|
|
1105
1088
|
}
|
|
1106
|
-
|
|
1107
|
-
const trackMapping = this.buildTrackMapping(tracks);
|
|
1108
|
-
yield this.sendSdpOffer(sdpOffer, trackMapping, "POST");
|
|
1109
|
-
const answerResponse = yield this.pollSdpAnswer();
|
|
1110
|
-
this.iceStartTime = performance.now();
|
|
1111
|
-
yield setRemoteDescription(
|
|
1112
|
-
this.peerConnection,
|
|
1113
|
-
answerResponse.sdp_answer
|
|
1114
|
-
);
|
|
1115
|
-
console.debug("[WebRTCTransport] Remote description set");
|
|
1089
|
+
yield this.cachedIceServers;
|
|
1116
1090
|
});
|
|
1117
1091
|
}
|
|
1118
|
-
|
|
1092
|
+
prepare(tracks) {
|
|
1119
1093
|
return __async(this, null, function* () {
|
|
1120
1094
|
this.setStatus("connecting");
|
|
1095
|
+
this.resetTransportTimings();
|
|
1121
1096
|
this.stopPing();
|
|
1122
1097
|
this.stopStatsPolling();
|
|
1123
1098
|
if (this.dataChannel) {
|
|
@@ -1130,8 +1105,8 @@ var WebRTCTransportClient = class {
|
|
|
1130
1105
|
}
|
|
1131
1106
|
this.peerConnected = false;
|
|
1132
1107
|
this.dataChannelOpen = false;
|
|
1133
|
-
this.
|
|
1134
|
-
|
|
1108
|
+
const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
|
|
1109
|
+
this.cachedIceServers = void 0;
|
|
1135
1110
|
this.peerConnection = createPeerConnection({ iceServers });
|
|
1136
1111
|
this.setupPeerConnectionHandlers();
|
|
1137
1112
|
this.dataChannel = createDataChannel(this.peerConnection);
|
|
@@ -1147,17 +1122,35 @@ var WebRTCTransportClient = class {
|
|
|
1147
1122
|
direction: track.direction,
|
|
1148
1123
|
transceiver
|
|
1149
1124
|
});
|
|
1125
|
+
console.debug(
|
|
1126
|
+
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
this.pendingSdpOffer = yield createOffer(this.peerConnection);
|
|
1130
|
+
this.pendingTrackMapping = this.buildTrackMapping(tracks);
|
|
1131
|
+
console.debug("[WebRTCTransport] SDP offer prepared");
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
connect(reconnect = false) {
|
|
1135
|
+
return __async(this, null, function* () {
|
|
1136
|
+
if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
|
|
1137
|
+
throw new Error(
|
|
1138
|
+
"[WebRTCTransport] No prepared connection. Call prepare() first."
|
|
1139
|
+
);
|
|
1150
1140
|
}
|
|
1151
|
-
const
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1141
|
+
const method = reconnect ? "PUT" : "POST";
|
|
1142
|
+
const sdpOffer = this.pendingSdpOffer;
|
|
1143
|
+
const trackMapping = this.pendingTrackMapping;
|
|
1144
|
+
this.pendingSdpOffer = void 0;
|
|
1145
|
+
this.pendingTrackMapping = void 0;
|
|
1146
|
+
yield this.sendSdpOffer(sdpOffer, trackMapping, method);
|
|
1154
1147
|
const answerResponse = yield this.pollSdpAnswer();
|
|
1155
1148
|
this.iceStartTime = performance.now();
|
|
1156
1149
|
yield setRemoteDescription(
|
|
1157
1150
|
this.peerConnection,
|
|
1158
1151
|
answerResponse.sdp_answer
|
|
1159
1152
|
);
|
|
1160
|
-
console.debug("[WebRTCTransport] Remote description set
|
|
1153
|
+
console.debug("[WebRTCTransport] Remote description set");
|
|
1161
1154
|
});
|
|
1162
1155
|
}
|
|
1163
1156
|
disconnect() {
|
|
@@ -1421,7 +1414,7 @@ var WebRTCTransportClient = class {
|
|
|
1421
1414
|
}
|
|
1422
1415
|
};
|
|
1423
1416
|
this.peerConnection.onicecandidateerror = (event) => {
|
|
1424
|
-
console.
|
|
1417
|
+
console.debug("[WebRTCTransport] ICE candidate error:", event);
|
|
1425
1418
|
};
|
|
1426
1419
|
this.peerConnection.ondatachannel = (event) => {
|
|
1427
1420
|
console.debug("[WebRTCTransport] Data channel received from remote");
|
|
@@ -1476,10 +1469,16 @@ var WebRTCTransportClient = class {
|
|
|
1476
1469
|
var import_zod2 = require("zod");
|
|
1477
1470
|
var LOCAL_COORDINATOR_URL = "http://localhost:8080";
|
|
1478
1471
|
var DEFAULT_BASE_URL = "https://api.reactor.inc";
|
|
1472
|
+
var TrackHintSchema = import_zod2.z.object({
|
|
1473
|
+
name: import_zod2.z.string(),
|
|
1474
|
+
kind: import_zod2.z.enum(["video", "audio"]),
|
|
1475
|
+
direction: import_zod2.z.enum(["recvonly", "sendonly"])
|
|
1476
|
+
});
|
|
1479
1477
|
var OptionsSchema = import_zod2.z.object({
|
|
1480
1478
|
apiUrl: import_zod2.z.string().default(DEFAULT_BASE_URL),
|
|
1481
1479
|
modelName: import_zod2.z.string(),
|
|
1482
|
-
local: import_zod2.z.boolean().default(false)
|
|
1480
|
+
local: import_zod2.z.boolean().default(false),
|
|
1481
|
+
modelTracks: import_zod2.z.array(TrackHintSchema).optional()
|
|
1483
1482
|
});
|
|
1484
1483
|
var Reactor = class {
|
|
1485
1484
|
constructor(options) {
|
|
@@ -1493,6 +1492,9 @@ var Reactor = class {
|
|
|
1493
1492
|
if (this.local && options.apiUrl === void 0) {
|
|
1494
1493
|
this.coordinatorUrl = LOCAL_COORDINATOR_URL;
|
|
1495
1494
|
}
|
|
1495
|
+
if (validatedOptions.modelTracks) {
|
|
1496
|
+
this.presetTracks = validatedOptions.modelTracks;
|
|
1497
|
+
}
|
|
1496
1498
|
}
|
|
1497
1499
|
on(event, handler) {
|
|
1498
1500
|
if (!this.eventListeners.has(event)) {
|
|
@@ -1567,7 +1569,9 @@ var Reactor = class {
|
|
|
1567
1569
|
* (fires `@file_uploaded` on the model if registered)
|
|
1568
1570
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
1569
1571
|
*
|
|
1570
|
-
*
|
|
1572
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
1573
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
1574
|
+
* setups work correctly (REA-1573).
|
|
1571
1575
|
*/
|
|
1572
1576
|
uploadFile(file, options) {
|
|
1573
1577
|
return __async(this, null, function* () {
|
|
@@ -1591,7 +1595,16 @@ var Reactor = class {
|
|
|
1591
1595
|
size,
|
|
1592
1596
|
mime_type: mimeType
|
|
1593
1597
|
});
|
|
1594
|
-
|
|
1598
|
+
let presignedUrl = slot.presigned_url;
|
|
1599
|
+
if (this.local) {
|
|
1600
|
+
const target = new URL(this.coordinatorUrl);
|
|
1601
|
+
const parsed = new URL(presignedUrl);
|
|
1602
|
+
parsed.protocol = target.protocol;
|
|
1603
|
+
parsed.hostname = target.hostname;
|
|
1604
|
+
parsed.port = target.port;
|
|
1605
|
+
presignedUrl = parsed.toString();
|
|
1606
|
+
}
|
|
1607
|
+
const putResponse = yield fetch(presignedUrl, {
|
|
1595
1608
|
method: "PUT",
|
|
1596
1609
|
body: file,
|
|
1597
1610
|
headers: {
|
|
@@ -1693,7 +1706,8 @@ var Reactor = class {
|
|
|
1693
1706
|
});
|
|
1694
1707
|
this.setupTransportHandlers();
|
|
1695
1708
|
}
|
|
1696
|
-
yield this.transportClient.
|
|
1709
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1710
|
+
yield this.transportClient.connect(true);
|
|
1697
1711
|
} catch (error) {
|
|
1698
1712
|
if (isAbortError(error)) return;
|
|
1699
1713
|
console.error("[Reactor] Failed to reconnect:", error);
|
|
@@ -1739,34 +1753,49 @@ var Reactor = class {
|
|
|
1739
1753
|
initialResponse.state
|
|
1740
1754
|
);
|
|
1741
1755
|
this.setStatus("waiting");
|
|
1742
|
-
const tPoll = performance.now();
|
|
1743
|
-
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1744
|
-
const sessionPollingMs = performance.now() - tPoll;
|
|
1745
|
-
this.sessionResponse = sessionResponse;
|
|
1746
|
-
this.capabilities = sessionResponse.capabilities;
|
|
1747
|
-
this.tracks = sessionResponse.capabilities.tracks;
|
|
1748
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
1749
|
-
console.debug(
|
|
1750
|
-
"[Reactor] Session ready, transport:",
|
|
1751
|
-
sessionResponse.selected_transport.protocol,
|
|
1752
|
-
"tracks:",
|
|
1753
|
-
this.tracks.length
|
|
1754
|
-
);
|
|
1755
|
-
const protocol = sessionResponse.selected_transport.protocol;
|
|
1756
|
-
if (protocol !== "webrtc") {
|
|
1757
|
-
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1758
|
-
}
|
|
1759
1756
|
this.transportClient = new WebRTCTransportClient({
|
|
1760
1757
|
baseUrl: this.coordinatorUrl,
|
|
1761
|
-
sessionId:
|
|
1758
|
+
sessionId: initialResponse.session_id,
|
|
1762
1759
|
jwtToken: this.local ? "local" : jwtToken,
|
|
1763
1760
|
webrtcVersion: REACTOR_WEBRTC_VERSION,
|
|
1764
1761
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|
|
1765
1762
|
});
|
|
1766
1763
|
this.setupTransportHandlers();
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1764
|
+
let sessionPollingMs;
|
|
1765
|
+
let transportConnectingMs;
|
|
1766
|
+
if (this.presetTracks) {
|
|
1767
|
+
const tParallel = performance.now();
|
|
1768
|
+
const [sessionResponse] = yield Promise.all([
|
|
1769
|
+
this.coordinatorClient.pollSessionReady(),
|
|
1770
|
+
this.transportClient.prepare(this.presetTracks)
|
|
1771
|
+
]);
|
|
1772
|
+
sessionPollingMs = performance.now() - tParallel;
|
|
1773
|
+
this.sessionResponse = sessionResponse;
|
|
1774
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1775
|
+
this.tracks = this.presetTracks;
|
|
1776
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1777
|
+
const tConnect = performance.now();
|
|
1778
|
+
yield this.transportClient.connect();
|
|
1779
|
+
transportConnectingMs = performance.now() - tConnect;
|
|
1780
|
+
} else {
|
|
1781
|
+
this.transportClient.warmup();
|
|
1782
|
+
const tPoll = performance.now();
|
|
1783
|
+
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1784
|
+
sessionPollingMs = performance.now() - tPoll;
|
|
1785
|
+
this.sessionResponse = sessionResponse;
|
|
1786
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1787
|
+
this.tracks = sessionResponse.capabilities.tracks;
|
|
1788
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1789
|
+
const protocol = sessionResponse.selected_transport.protocol;
|
|
1790
|
+
if (protocol !== "webrtc") {
|
|
1791
|
+
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1792
|
+
}
|
|
1793
|
+
const tTransport = performance.now();
|
|
1794
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1795
|
+
yield this.transportClient.connect();
|
|
1796
|
+
transportConnectingMs = performance.now() - tTransport;
|
|
1797
|
+
}
|
|
1798
|
+
console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
|
|
1770
1799
|
this.connectionTimings = {
|
|
1771
1800
|
sessionCreationMs: sessionCreationMs + sessionPollingMs,
|
|
1772
1801
|
transportConnectingMs,
|
|
@@ -2330,12 +2359,11 @@ function ReactorView({
|
|
|
2330
2359
|
videoObjectFit = "contain",
|
|
2331
2360
|
muted = true
|
|
2332
2361
|
}) {
|
|
2333
|
-
const { videoMediaTrack, audioMediaTrack
|
|
2362
|
+
const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
|
|
2334
2363
|
var _a, _b;
|
|
2335
2364
|
return {
|
|
2336
2365
|
videoMediaTrack: (_a = state.tracks[track]) != null ? _a : null,
|
|
2337
|
-
audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null
|
|
2338
|
-
status: state.status
|
|
2366
|
+
audioMediaTrack: audioTrack ? (_b = state.tracks[audioTrack]) != null ? _b : null : null
|
|
2339
2367
|
};
|
|
2340
2368
|
});
|
|
2341
2369
|
const videoRef = (0, import_react5.useRef)(null);
|
|
@@ -2374,8 +2402,7 @@ function ReactorView({
|
|
|
2374
2402
|
console.debug("[ReactorView] No tracks or element to attach");
|
|
2375
2403
|
}
|
|
2376
2404
|
}, [mediaStream]);
|
|
2377
|
-
|
|
2378
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2405
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2379
2406
|
"div",
|
|
2380
2407
|
{
|
|
2381
2408
|
style: __spreadValues(__spreadValues(__spreadValues({
|
|
@@ -2383,44 +2410,20 @@ function ReactorView({
|
|
|
2383
2410
|
background: "#000"
|
|
2384
2411
|
}, width && { width }), height && { height }), style),
|
|
2385
2412
|
className,
|
|
2386
|
-
children:
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
),
|
|
2401
|
-
showPlaceholder && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2402
|
-
"div",
|
|
2403
|
-
{
|
|
2404
|
-
style: {
|
|
2405
|
-
position: "absolute",
|
|
2406
|
-
top: 0,
|
|
2407
|
-
left: 0,
|
|
2408
|
-
width: "100%",
|
|
2409
|
-
height: "100%",
|
|
2410
|
-
color: "#fff",
|
|
2411
|
-
display: "flex",
|
|
2412
|
-
alignItems: "center",
|
|
2413
|
-
justifyContent: "center",
|
|
2414
|
-
fontSize: "16px",
|
|
2415
|
-
fontFamily: "monospace",
|
|
2416
|
-
textAlign: "center",
|
|
2417
|
-
padding: "20px",
|
|
2418
|
-
boxSizing: "border-box"
|
|
2419
|
-
},
|
|
2420
|
-
children: status
|
|
2421
|
-
}
|
|
2422
|
-
)
|
|
2423
|
-
]
|
|
2413
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2414
|
+
"video",
|
|
2415
|
+
{
|
|
2416
|
+
ref: videoRef,
|
|
2417
|
+
style: {
|
|
2418
|
+
width: "100%",
|
|
2419
|
+
height: "100%",
|
|
2420
|
+
objectFit: videoObjectFit,
|
|
2421
|
+
display: videoMediaTrack ? "block" : "none"
|
|
2422
|
+
},
|
|
2423
|
+
muted,
|
|
2424
|
+
playsInline: true
|
|
2425
|
+
}
|
|
2426
|
+
)
|
|
2424
2427
|
}
|
|
2425
2428
|
);
|
|
2426
2429
|
}
|
|
@@ -2428,16 +2431,22 @@ function ReactorView({
|
|
|
2428
2431
|
// src/react/ReactorController.tsx
|
|
2429
2432
|
var import_react6 = __toESM(require("react"));
|
|
2430
2433
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2434
|
+
function isFileParam(ps) {
|
|
2435
|
+
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
2436
|
+
}
|
|
2431
2437
|
function ReactorController({
|
|
2432
2438
|
className,
|
|
2433
2439
|
style
|
|
2434
2440
|
}) {
|
|
2435
|
-
const { sendCommand, status } = useReactor((state) => ({
|
|
2441
|
+
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
2436
2442
|
sendCommand: state.sendCommand,
|
|
2443
|
+
uploadFile: state.uploadFile,
|
|
2437
2444
|
status: state.status
|
|
2438
2445
|
}));
|
|
2439
2446
|
const [commands, setCommands] = (0, import_react6.useState)({});
|
|
2440
2447
|
const [formValues, setFormValues] = (0, import_react6.useState)({});
|
|
2448
|
+
const formRef = (0, import_react6.useRef)(formValues);
|
|
2449
|
+
formRef.current = formValues;
|
|
2441
2450
|
const [expandedCommands, setExpandedCommands] = (0, import_react6.useState)({});
|
|
2442
2451
|
import_react6.default.useEffect(() => {
|
|
2443
2452
|
if (status === "disconnected") {
|
|
@@ -2484,15 +2493,17 @@ function ReactorController({
|
|
|
2484
2493
|
initialExpanded[commandName] = false;
|
|
2485
2494
|
Object.entries(commandSchema.schema).forEach(
|
|
2486
2495
|
([paramName, paramSchema]) => {
|
|
2487
|
-
var _a2
|
|
2488
|
-
if (paramSchema
|
|
2496
|
+
var _a2;
|
|
2497
|
+
if (isFileParam(paramSchema)) {
|
|
2498
|
+
initialValues[commandName][paramName] = null;
|
|
2499
|
+
} else if (paramSchema.default !== void 0) {
|
|
2500
|
+
initialValues[commandName][paramName] = paramSchema.default;
|
|
2501
|
+
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2489
2502
|
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
2490
2503
|
} else if (paramSchema.type === "string") {
|
|
2491
2504
|
initialValues[commandName][paramName] = "";
|
|
2492
2505
|
} else if (paramSchema.type === "boolean") {
|
|
2493
2506
|
initialValues[commandName][paramName] = false;
|
|
2494
|
-
} else if (paramSchema.type === "integer") {
|
|
2495
|
-
initialValues[commandName][paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2496
2507
|
}
|
|
2497
2508
|
}
|
|
2498
2509
|
);
|
|
@@ -2519,12 +2530,16 @@ function ReactorController({
|
|
|
2519
2530
|
const handleCommandSubmit = (0, import_react6.useCallback)(
|
|
2520
2531
|
(commandName) => __async(null, null, function* () {
|
|
2521
2532
|
const commandSchema = commands[commandName];
|
|
2522
|
-
const formData =
|
|
2533
|
+
const formData = formRef.current[commandName] || {};
|
|
2523
2534
|
const data = {};
|
|
2524
2535
|
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
2525
|
-
var _a
|
|
2536
|
+
var _a;
|
|
2526
2537
|
const paramSchema = commandSchema.schema[paramName];
|
|
2527
2538
|
let value = formData[paramName];
|
|
2539
|
+
if (value instanceof FileRef) {
|
|
2540
|
+
data[paramName] = value;
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2528
2543
|
if (paramSchema.type === "number" && typeof value === "string") {
|
|
2529
2544
|
value = parseFloat(value) || 0;
|
|
2530
2545
|
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
@@ -2535,10 +2550,8 @@ function ReactorController({
|
|
|
2535
2550
|
if (value !== void 0 && value !== "" && value !== null) {
|
|
2536
2551
|
data[paramName] = value;
|
|
2537
2552
|
} else if (paramSchema.required) {
|
|
2538
|
-
if (paramSchema.type === "number") {
|
|
2553
|
+
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2539
2554
|
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
2540
|
-
} else if (paramSchema.type === "integer") {
|
|
2541
|
-
data[paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2542
2555
|
} else if (paramSchema.type === "string") {
|
|
2543
2556
|
data[paramName] = "";
|
|
2544
2557
|
} else if (paramSchema.type === "boolean") {
|
|
@@ -2546,14 +2559,28 @@ function ReactorController({
|
|
|
2546
2559
|
}
|
|
2547
2560
|
}
|
|
2548
2561
|
});
|
|
2549
|
-
console.log(`Executing command: ${commandName}`, data);
|
|
2550
2562
|
yield sendCommand(commandName, data);
|
|
2551
2563
|
}),
|
|
2552
|
-
[
|
|
2564
|
+
[sendCommand, commands]
|
|
2553
2565
|
);
|
|
2554
2566
|
const renderInput = (commandName, paramName, paramSchema) => {
|
|
2555
2567
|
var _a, _b;
|
|
2556
2568
|
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
2569
|
+
if (isFileParam(paramSchema)) {
|
|
2570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2571
|
+
FileParamInput,
|
|
2572
|
+
{
|
|
2573
|
+
commandName,
|
|
2574
|
+
paramName,
|
|
2575
|
+
description: paramSchema.description,
|
|
2576
|
+
value,
|
|
2577
|
+
onChange: handleInputChange,
|
|
2578
|
+
disabled: status !== "ready",
|
|
2579
|
+
uploadFile
|
|
2580
|
+
},
|
|
2581
|
+
`${commandName}-${paramName}`
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2557
2584
|
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2558
2585
|
const isInteger = paramSchema.type === "integer";
|
|
2559
2586
|
const step = isInteger ? 1 : 0.1;
|
|
@@ -2742,10 +2769,11 @@ function ReactorController({
|
|
|
2742
2769
|
const renderCommand = (commandName, commandSchema) => {
|
|
2743
2770
|
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
2744
2771
|
const isExpanded = expandedCommands[commandName];
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2772
|
+
const params = Object.values(commandSchema.schema);
|
|
2773
|
+
const allSliders = params.length > 0 && params.every(
|
|
2774
|
+
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
2747
2775
|
);
|
|
2748
|
-
const showExecuteButton = !
|
|
2776
|
+
const showExecuteButton = !allSliders;
|
|
2749
2777
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2750
2778
|
"div",
|
|
2751
2779
|
{
|
|
@@ -2883,6 +2911,89 @@ function ReactorController({
|
|
|
2883
2911
|
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
2884
2912
|
] }) }) });
|
|
2885
2913
|
}
|
|
2914
|
+
function FileParamInput({
|
|
2915
|
+
commandName,
|
|
2916
|
+
paramName,
|
|
2917
|
+
description,
|
|
2918
|
+
value,
|
|
2919
|
+
onChange,
|
|
2920
|
+
disabled,
|
|
2921
|
+
uploadFile
|
|
2922
|
+
}) {
|
|
2923
|
+
const inputRef = (0, import_react6.useRef)(null);
|
|
2924
|
+
const [uploading, setUploading] = (0, import_react6.useState)(false);
|
|
2925
|
+
const fileRef = value instanceof FileRef ? value : null;
|
|
2926
|
+
const handleFile = (e) => __async(null, null, function* () {
|
|
2927
|
+
var _a;
|
|
2928
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
2929
|
+
if (!file) return;
|
|
2930
|
+
e.target.value = "";
|
|
2931
|
+
setUploading(true);
|
|
2932
|
+
try {
|
|
2933
|
+
const ref = yield uploadFile(file);
|
|
2934
|
+
onChange(commandName, paramName, ref);
|
|
2935
|
+
} catch (err) {
|
|
2936
|
+
console.error("[FileParamInput] Upload failed:", err);
|
|
2937
|
+
} finally {
|
|
2938
|
+
setUploading(false);
|
|
2939
|
+
}
|
|
2940
|
+
});
|
|
2941
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
2942
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
2943
|
+
paramName,
|
|
2944
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
2945
|
+
description && ` - ${description}`
|
|
2946
|
+
] }),
|
|
2947
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2948
|
+
"div",
|
|
2949
|
+
{
|
|
2950
|
+
style: {
|
|
2951
|
+
display: "flex",
|
|
2952
|
+
alignItems: "center",
|
|
2953
|
+
gap: "8px",
|
|
2954
|
+
marginTop: "4px"
|
|
2955
|
+
},
|
|
2956
|
+
children: [
|
|
2957
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2958
|
+
"input",
|
|
2959
|
+
{
|
|
2960
|
+
ref: inputRef,
|
|
2961
|
+
type: "file",
|
|
2962
|
+
accept: "image/*",
|
|
2963
|
+
onChange: handleFile,
|
|
2964
|
+
style: { display: "none" }
|
|
2965
|
+
}
|
|
2966
|
+
),
|
|
2967
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2968
|
+
"button",
|
|
2969
|
+
{
|
|
2970
|
+
disabled: disabled || uploading,
|
|
2971
|
+
onClick: () => {
|
|
2972
|
+
var _a;
|
|
2973
|
+
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
2974
|
+
},
|
|
2975
|
+
style: {
|
|
2976
|
+
padding: "4px 12px",
|
|
2977
|
+
fontSize: "12px",
|
|
2978
|
+
backgroundColor: "#007bff",
|
|
2979
|
+
color: "white",
|
|
2980
|
+
border: "none",
|
|
2981
|
+
borderRadius: "4px",
|
|
2982
|
+
cursor: disabled || uploading ? "default" : "pointer",
|
|
2983
|
+
opacity: disabled || uploading ? 0.5 : 1
|
|
2984
|
+
},
|
|
2985
|
+
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
2986
|
+
}
|
|
2987
|
+
),
|
|
2988
|
+
fileRef && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
2989
|
+
"\\u2713 ",
|
|
2990
|
+
fileRef.name
|
|
2991
|
+
] })
|
|
2992
|
+
]
|
|
2993
|
+
}
|
|
2994
|
+
)
|
|
2995
|
+
] });
|
|
2996
|
+
}
|
|
2886
2997
|
|
|
2887
2998
|
// src/react/WebcamStream.tsx
|
|
2888
2999
|
var import_react7 = require("react");
|