@reactor-team/js-sdk 2.12.0 → 2.12.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/README.md +15 -3
- package/dist/index.d.mts +124 -40
- package/dist/index.d.ts +124 -40
- package/dist/index.js +157 -659
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -644
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -76,6 +76,14 @@ var AbortError = class extends Error {
|
|
|
76
76
|
function isAbortError(error) {
|
|
77
77
|
return error instanceof AbortError || error instanceof Error && error.name === "AbortError";
|
|
78
78
|
}
|
|
79
|
+
var SessionLostError = class extends Error {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function isSessionLostError(error) {
|
|
85
|
+
return error instanceof SessionLostError;
|
|
86
|
+
}
|
|
79
87
|
|
|
80
88
|
// src/core/auth.ts
|
|
81
89
|
function normalizeJwtSource(source) {
|
|
@@ -91,7 +99,7 @@ import { z } from "zod";
|
|
|
91
99
|
// package.json
|
|
92
100
|
var package_default = {
|
|
93
101
|
name: "@reactor-team/js-sdk",
|
|
94
|
-
version: "2.12.
|
|
102
|
+
version: "2.12.2",
|
|
95
103
|
description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
|
|
96
104
|
license: "Apache-2.0",
|
|
97
105
|
repository: {
|
|
@@ -163,14 +171,14 @@ var package_default = {
|
|
|
163
171
|
}
|
|
164
172
|
},
|
|
165
173
|
devDependencies: {
|
|
166
|
-
"@roamhq/wrtc": "^0.
|
|
174
|
+
"@roamhq/wrtc": "^0.10.0",
|
|
167
175
|
"@types/node": "^25",
|
|
168
176
|
"@types/react": "^19.2.15",
|
|
169
177
|
"@types/sdp-transform": "^2.15.0",
|
|
170
178
|
"hls.js": "^1.6.0",
|
|
171
|
-
prettier: "^3.
|
|
179
|
+
prettier: "^3.8.4",
|
|
172
180
|
tsup: "^8.5.0",
|
|
173
|
-
typescript: "^
|
|
181
|
+
typescript: "^6.0.3",
|
|
174
182
|
vitest: "^4.1.7"
|
|
175
183
|
}
|
|
176
184
|
};
|
|
@@ -693,6 +701,11 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
693
701
|
});
|
|
694
702
|
if (!response.ok) {
|
|
695
703
|
const errorText = yield response.text();
|
|
704
|
+
if (response.status === 400) {
|
|
705
|
+
throw new SessionLostError(
|
|
706
|
+
`Failed to start session: ${response.status} ${errorText}`
|
|
707
|
+
);
|
|
708
|
+
}
|
|
696
709
|
throw new Error(
|
|
697
710
|
`Failed to start session: ${response.status} ${errorText}`
|
|
698
711
|
);
|
|
@@ -1477,6 +1490,11 @@ var WebRTCTransportClient = class {
|
|
|
1477
1490
|
yield this.checkVersionMismatch(response);
|
|
1478
1491
|
if (response.status !== 201) {
|
|
1479
1492
|
const errorText = yield response.text();
|
|
1493
|
+
if (response.status === 400) {
|
|
1494
|
+
throw new SessionLostError(
|
|
1495
|
+
`Failed to register connection: ${response.status} ${errorText}`
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1480
1498
|
throw new Error(
|
|
1481
1499
|
`Failed to register connection: ${response.status} ${errorText}`
|
|
1482
1500
|
);
|
|
@@ -1523,7 +1541,7 @@ var WebRTCTransportClient = class {
|
|
|
1523
1541
|
);
|
|
1524
1542
|
}
|
|
1525
1543
|
if (response.status === 400) {
|
|
1526
|
-
throw new
|
|
1544
|
+
throw new SessionLostError(
|
|
1527
1545
|
`[WebRTCTransport] Connection ${connectionId} rejected (400): ${errorText}`
|
|
1528
1546
|
);
|
|
1529
1547
|
}
|
|
@@ -1537,7 +1555,7 @@ var WebRTCTransportClient = class {
|
|
|
1537
1555
|
sendIceCandidates(candidates, is_final) {
|
|
1538
1556
|
return __async(this, null, function* () {
|
|
1539
1557
|
if (this.connectionId === void 0) {
|
|
1540
|
-
console.
|
|
1558
|
+
console.warn(
|
|
1541
1559
|
"[WebRTCTransport] ICE candidates dropped: no active connection"
|
|
1542
1560
|
);
|
|
1543
1561
|
return;
|
|
@@ -1590,6 +1608,12 @@ var WebRTCTransportClient = class {
|
|
|
1590
1608
|
clearTimeout(this.iceCandidateFlushTimer);
|
|
1591
1609
|
this.iceCandidateFlushTimer = void 0;
|
|
1592
1610
|
}
|
|
1611
|
+
if (this.connectionId === void 0) {
|
|
1612
|
+
console.debug(
|
|
1613
|
+
"[WebRTCTransportClient] skipping ICE candidate flush because the connection is not established yet"
|
|
1614
|
+
);
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1593
1617
|
const batch = this.pendingIceCandidates;
|
|
1594
1618
|
this.pendingIceCandidates = [];
|
|
1595
1619
|
if (batch.length === 0 && !isFinal) {
|
|
@@ -1758,6 +1782,11 @@ var WebRTCTransportClient = class {
|
|
|
1758
1782
|
trackMapping,
|
|
1759
1783
|
reconnect
|
|
1760
1784
|
);
|
|
1785
|
+
if (this.pendingIceCandidates.length > 0) {
|
|
1786
|
+
this.flushPendingIceCandidates(
|
|
1787
|
+
this.peerConnection !== void 0 && this.peerConnection.iceGatheringState === "complete"
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1761
1790
|
const answerResponse = yield this.pollSdpAnswer(this.connectionId);
|
|
1762
1791
|
this.iceStartTime = performance.now();
|
|
1763
1792
|
yield setRemoteDescription(
|
|
@@ -2328,13 +2357,15 @@ var DEFAULT_PLAYLIST_POLL_SLACK_MS = 15e3;
|
|
|
2328
2357
|
function fetchPlaylist(_0) {
|
|
2329
2358
|
return __async(this, arguments, function* (playlistUrl, options = {}) {
|
|
2330
2359
|
var _a, _b, _c, _d;
|
|
2331
|
-
const
|
|
2332
|
-
const
|
|
2333
|
-
const
|
|
2334
|
-
const fallbackMaxRetries = (_d = options.maxRetries) != null ? _d : 5;
|
|
2335
|
-
const hasDeadline = typeof options.predictedReadyAtMs === "number";
|
|
2360
|
+
const minDelay = Math.max(0, (_a = options.minRetryDelayMs) != null ? _a : 200);
|
|
2361
|
+
const maxDelay = Math.max(minDelay, (_b = options.maxRetryDelayMs) != null ? _b : 2e3);
|
|
2362
|
+
const hasDeadline = typeof options.slackMs === "number" && Number.isFinite(options.slackMs);
|
|
2336
2363
|
const startedPollingAt = Date.now();
|
|
2337
|
-
const deadlineMs = hasDeadline ? Math.max(
|
|
2364
|
+
const deadlineMs = hasDeadline ? Math.max(
|
|
2365
|
+
(_c = options.predictedReadyAtMs) != null ? _c : startedPollingAt,
|
|
2366
|
+
startedPollingAt
|
|
2367
|
+
) + options.slackMs : void 0;
|
|
2368
|
+
const maxRetries = typeof options.maxRetries === "number" ? options.maxRetries : void 0;
|
|
2338
2369
|
const headers = options.jwt ? { Authorization: `Bearer ${options.jwt}` } : void 0;
|
|
2339
2370
|
let attempt = 0;
|
|
2340
2371
|
let lastStatus = 0;
|
|
@@ -2353,16 +2384,15 @@ function fetchPlaylist(_0) {
|
|
|
2353
2384
|
}
|
|
2354
2385
|
lastStatus = response.status;
|
|
2355
2386
|
if (response.status === 202) {
|
|
2356
|
-
if (
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
} else if (attempt >= fallbackMaxRetries) {
|
|
2387
|
+
if (deadlineMs !== void 0 && Date.now() >= deadlineMs) {
|
|
2388
|
+
throw new RecordingError(
|
|
2389
|
+
"CLIP_NOT_READY",
|
|
2390
|
+
`Boundary chunk still pending after ${options.slackMs}ms grace (predicted ready ${new Date(
|
|
2391
|
+
(_d = options.predictedReadyAtMs) != null ? _d : startedPollingAt
|
|
2392
|
+
).toISOString()}). Runtime may have crashed mid-clip.`
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
if (maxRetries !== void 0 && attempt >= maxRetries) {
|
|
2366
2396
|
throw new RecordingError(
|
|
2367
2397
|
"CLIP_NOT_READY",
|
|
2368
2398
|
`Manifest still pending after ${attempt + 1} attempts (last status ${lastStatus})`
|
|
@@ -2373,7 +2403,7 @@ function fetchPlaylist(_0) {
|
|
|
2373
2403
|
minDelay
|
|
2374
2404
|
);
|
|
2375
2405
|
const delay = Math.min(maxDelay, Math.max(minDelay, headerDelay));
|
|
2376
|
-
const clampedDelay =
|
|
2406
|
+
const clampedDelay = deadlineMs !== void 0 ? Math.min(delay, Math.max(0, deadlineMs - Date.now())) : delay;
|
|
2377
2407
|
yield sleep(clampedDelay, options.signal);
|
|
2378
2408
|
attempt++;
|
|
2379
2409
|
continue;
|
|
@@ -2956,6 +2986,7 @@ var Reactor = class {
|
|
|
2956
2986
|
* down its own transport but leaves the session alive.
|
|
2957
2987
|
*/
|
|
2958
2988
|
this.createdSession = false;
|
|
2989
|
+
this.retryingSessionLoss = false;
|
|
2959
2990
|
this.tracks = [];
|
|
2960
2991
|
this.autoResumeTracks = false;
|
|
2961
2992
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
@@ -3280,7 +3311,7 @@ var Reactor = class {
|
|
|
3280
3311
|
*/
|
|
3281
3312
|
connect(jwtToken, options) {
|
|
3282
3313
|
return __async(this, null, function* () {
|
|
3283
|
-
var _a;
|
|
3314
|
+
var _a, _b, _c, _d;
|
|
3284
3315
|
console.debug("[Reactor] Connecting, status:", this.status);
|
|
3285
3316
|
if (jwtToken == void 0 && !this.local) {
|
|
3286
3317
|
throw new Error("No authentication provided and not in local mode");
|
|
@@ -3341,10 +3372,6 @@ var Reactor = class {
|
|
|
3341
3372
|
]);
|
|
3342
3373
|
sessionPollingMs = performance.now() - tParallel;
|
|
3343
3374
|
this.sessionResponse = sessionResponse;
|
|
3344
|
-
this.capabilities = __spreadProps(__spreadValues({}, sessionResponse.capabilities), {
|
|
3345
|
-
tracks: this.tracks
|
|
3346
|
-
});
|
|
3347
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
3348
3375
|
const tConnect = performance.now();
|
|
3349
3376
|
yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
|
|
3350
3377
|
transportConnectingMs = performance.now() - tConnect;
|
|
@@ -3355,10 +3382,6 @@ var Reactor = class {
|
|
|
3355
3382
|
sessionPollingMs = performance.now() - tPoll;
|
|
3356
3383
|
this.sessionResponse = sessionResponse;
|
|
3357
3384
|
this.tracks = sessionResponse.capabilities.tracks;
|
|
3358
|
-
this.capabilities = __spreadProps(__spreadValues({}, sessionResponse.capabilities), {
|
|
3359
|
-
tracks: this.tracks
|
|
3360
|
-
});
|
|
3361
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
3362
3385
|
const protocol = sessionResponse.selected_transport.protocol;
|
|
3363
3386
|
if (protocol !== "webrtc") {
|
|
3364
3387
|
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
@@ -3376,6 +3399,19 @@ var Reactor = class {
|
|
|
3376
3399
|
};
|
|
3377
3400
|
} catch (error) {
|
|
3378
3401
|
if (isAbortError(error)) return;
|
|
3402
|
+
if (!(options == null ? void 0 : options.sessionId) && !this.retryingSessionLoss && isSessionLostError(error)) {
|
|
3403
|
+
this.retryingSessionLoss = true;
|
|
3404
|
+
(_b = this.coordinatorClient) == null ? void 0 : _b.abort();
|
|
3405
|
+
(_c = this.transportClient) == null ? void 0 : _c.abort();
|
|
3406
|
+
(_d = this.transportClient) == null ? void 0 : _d.disconnect();
|
|
3407
|
+
this.setStatus("disconnected");
|
|
3408
|
+
try {
|
|
3409
|
+
yield this.connect(jwtToken, options);
|
|
3410
|
+
return;
|
|
3411
|
+
} finally {
|
|
3412
|
+
this.retryingSessionLoss = false;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3379
3415
|
console.error("[Reactor] Connection failed:", error);
|
|
3380
3416
|
this.createError(
|
|
3381
3417
|
"CONNECTION_FAILED",
|
|
@@ -3407,6 +3443,10 @@ var Reactor = class {
|
|
|
3407
3443
|
if (scope === "application") {
|
|
3408
3444
|
this.emit("message", message);
|
|
3409
3445
|
} else if (scope === "runtime") {
|
|
3446
|
+
if (message && typeof message === "object" && message.type === "modelSchema" && message.data) {
|
|
3447
|
+
this.schema = message.data;
|
|
3448
|
+
this.emit("schemaReceived", this.schema);
|
|
3449
|
+
}
|
|
3410
3450
|
this.emit("runtimeMessage", message);
|
|
3411
3451
|
}
|
|
3412
3452
|
});
|
|
@@ -3423,6 +3463,7 @@ var Reactor = class {
|
|
|
3423
3463
|
}
|
|
3424
3464
|
}
|
|
3425
3465
|
this.setStatus("ready");
|
|
3466
|
+
void this.sendCommand("requestSchema", {}, "runtime");
|
|
3426
3467
|
break;
|
|
3427
3468
|
case "disconnected":
|
|
3428
3469
|
this.disconnect(true);
|
|
@@ -3500,7 +3541,7 @@ var Reactor = class {
|
|
|
3500
3541
|
if (!recoverable) {
|
|
3501
3542
|
this.setSessionExpiration(void 0);
|
|
3502
3543
|
this.setSessionId(void 0);
|
|
3503
|
-
this.
|
|
3544
|
+
this.schema = void 0;
|
|
3504
3545
|
this.tracks = [];
|
|
3505
3546
|
this.sessionResponse = void 0;
|
|
3506
3547
|
this.createdSession = false;
|
|
@@ -3525,8 +3566,13 @@ var Reactor = class {
|
|
|
3525
3566
|
getLastError() {
|
|
3526
3567
|
return this.lastError;
|
|
3527
3568
|
}
|
|
3528
|
-
|
|
3529
|
-
|
|
3569
|
+
/**
|
|
3570
|
+
* The model's OpenAPI schema (events, outbound messages, tracks),
|
|
3571
|
+
* received over the runtime channel shortly after the session becomes
|
|
3572
|
+
* ready. `undefined` until the `schemaReceived` event has fired.
|
|
3573
|
+
*/
|
|
3574
|
+
getSchema() {
|
|
3575
|
+
return this.schema;
|
|
3530
3576
|
}
|
|
3531
3577
|
getSessionInfo() {
|
|
3532
3578
|
return this.sessionResponse;
|
|
@@ -3537,6 +3583,10 @@ var Reactor = class {
|
|
|
3537
3583
|
if (!stats) return void 0;
|
|
3538
3584
|
return __spreadProps(__spreadValues({}, stats), { connectionTimings: this.connectionTimings });
|
|
3539
3585
|
}
|
|
3586
|
+
/** Timing breakdown from the most recent connect() handshake. */
|
|
3587
|
+
getConnectionTimings() {
|
|
3588
|
+
return this.connectionTimings;
|
|
3589
|
+
}
|
|
3540
3590
|
// ─────────────────────────────────────────────────────────────────────────
|
|
3541
3591
|
// Private State Management
|
|
3542
3592
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -3751,6 +3801,8 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3751
3801
|
throw error;
|
|
3752
3802
|
}
|
|
3753
3803
|
}),
|
|
3804
|
+
pauseTrack: (name) => get().internal.reactor.pauseTrack(name),
|
|
3805
|
+
resumeTrack: (name) => get().internal.reactor.resumeTrack(name),
|
|
3754
3806
|
reconnect: (options) => __async(null, null, function* () {
|
|
3755
3807
|
console.debug("[ReactorStore] Reconnecting");
|
|
3756
3808
|
try {
|
|
@@ -4064,576 +4116,9 @@ function ReactorView({
|
|
|
4064
4116
|
);
|
|
4065
4117
|
}
|
|
4066
4118
|
|
|
4067
|
-
// src/react/ReactorController.tsx
|
|
4068
|
-
import React, { useState as useState3, useCallback, useRef as useRef4 } from "react";
|
|
4069
|
-
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
4070
|
-
function isFileParam(ps) {
|
|
4071
|
-
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
4072
|
-
}
|
|
4073
|
-
function ReactorController({
|
|
4074
|
-
className,
|
|
4075
|
-
style
|
|
4076
|
-
}) {
|
|
4077
|
-
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
4078
|
-
sendCommand: state.sendCommand,
|
|
4079
|
-
uploadFile: state.uploadFile,
|
|
4080
|
-
status: state.status
|
|
4081
|
-
}));
|
|
4082
|
-
const [commands, setCommands] = useState3({});
|
|
4083
|
-
const [formValues, setFormValues] = useState3({});
|
|
4084
|
-
const formRef = useRef4(formValues);
|
|
4085
|
-
formRef.current = formValues;
|
|
4086
|
-
const [expandedCommands, setExpandedCommands] = useState3({});
|
|
4087
|
-
React.useEffect(() => {
|
|
4088
|
-
if (status === "disconnected") {
|
|
4089
|
-
setCommands({});
|
|
4090
|
-
setFormValues({});
|
|
4091
|
-
setExpandedCommands({});
|
|
4092
|
-
}
|
|
4093
|
-
}, [status]);
|
|
4094
|
-
const requestCapabilities = useCallback(() => {
|
|
4095
|
-
if (status === "ready") {
|
|
4096
|
-
sendCommand("requestCapabilities", {}, "runtime");
|
|
4097
|
-
}
|
|
4098
|
-
}, [status, sendCommand]);
|
|
4099
|
-
React.useEffect(() => {
|
|
4100
|
-
if (status === "ready") {
|
|
4101
|
-
requestCapabilities();
|
|
4102
|
-
}
|
|
4103
|
-
}, [status, requestCapabilities]);
|
|
4104
|
-
React.useEffect(() => {
|
|
4105
|
-
if (status !== "ready" || Object.keys(commands).length > 0) {
|
|
4106
|
-
return;
|
|
4107
|
-
}
|
|
4108
|
-
const interval = setInterval(() => {
|
|
4109
|
-
requestCapabilities();
|
|
4110
|
-
}, 5e3);
|
|
4111
|
-
return () => clearInterval(interval);
|
|
4112
|
-
}, [status, commands, requestCapabilities]);
|
|
4113
|
-
useReactorInternalMessage((message) => {
|
|
4114
|
-
var _a;
|
|
4115
|
-
if (message && typeof message === "object" && message.type === "modelCapabilities" && message.data && "commands" in message.data) {
|
|
4116
|
-
const commandsMessage = message.data;
|
|
4117
|
-
const commandsRecord = {};
|
|
4118
|
-
for (const cmd of commandsMessage.commands) {
|
|
4119
|
-
commandsRecord[cmd.name] = {
|
|
4120
|
-
description: cmd.description,
|
|
4121
|
-
schema: (_a = cmd.schema) != null ? _a : {}
|
|
4122
|
-
};
|
|
4123
|
-
}
|
|
4124
|
-
setCommands(commandsRecord);
|
|
4125
|
-
const initialValues = {};
|
|
4126
|
-
const initialExpanded = {};
|
|
4127
|
-
Object.entries(commandsRecord).forEach(([commandName, commandSchema]) => {
|
|
4128
|
-
initialValues[commandName] = {};
|
|
4129
|
-
initialExpanded[commandName] = false;
|
|
4130
|
-
Object.entries(commandSchema.schema).forEach(
|
|
4131
|
-
([paramName, paramSchema]) => {
|
|
4132
|
-
var _a2;
|
|
4133
|
-
if (isFileParam(paramSchema)) {
|
|
4134
|
-
initialValues[commandName][paramName] = null;
|
|
4135
|
-
} else if (paramSchema.default !== void 0) {
|
|
4136
|
-
initialValues[commandName][paramName] = paramSchema.default;
|
|
4137
|
-
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
4138
|
-
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
4139
|
-
} else if (paramSchema.type === "string") {
|
|
4140
|
-
initialValues[commandName][paramName] = "";
|
|
4141
|
-
} else if (paramSchema.type === "boolean") {
|
|
4142
|
-
initialValues[commandName][paramName] = false;
|
|
4143
|
-
}
|
|
4144
|
-
}
|
|
4145
|
-
);
|
|
4146
|
-
});
|
|
4147
|
-
setFormValues(initialValues);
|
|
4148
|
-
setExpandedCommands(initialExpanded);
|
|
4149
|
-
}
|
|
4150
|
-
});
|
|
4151
|
-
const handleInputChange = useCallback(
|
|
4152
|
-
(commandName, paramName, value) => {
|
|
4153
|
-
setFormValues((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
4154
|
-
[commandName]: __spreadProps(__spreadValues({}, prev[commandName]), {
|
|
4155
|
-
[paramName]: value
|
|
4156
|
-
})
|
|
4157
|
-
}));
|
|
4158
|
-
},
|
|
4159
|
-
[]
|
|
4160
|
-
);
|
|
4161
|
-
const toggleCommandExpanded = useCallback((commandName) => {
|
|
4162
|
-
setExpandedCommands((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
4163
|
-
[commandName]: !prev[commandName]
|
|
4164
|
-
}));
|
|
4165
|
-
}, []);
|
|
4166
|
-
const handleCommandSubmit = useCallback(
|
|
4167
|
-
(commandName) => __async(null, null, function* () {
|
|
4168
|
-
const commandSchema = commands[commandName];
|
|
4169
|
-
const formData = formRef.current[commandName] || {};
|
|
4170
|
-
const data = {};
|
|
4171
|
-
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
4172
|
-
var _a;
|
|
4173
|
-
const paramSchema = commandSchema.schema[paramName];
|
|
4174
|
-
let value = formData[paramName];
|
|
4175
|
-
if (value instanceof FileRef) {
|
|
4176
|
-
data[paramName] = value;
|
|
4177
|
-
return;
|
|
4178
|
-
}
|
|
4179
|
-
if (paramSchema.type === "number" && typeof value === "string") {
|
|
4180
|
-
value = parseFloat(value) || 0;
|
|
4181
|
-
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
4182
|
-
value = parseInt(value) || 0;
|
|
4183
|
-
} else if (paramSchema.type === "boolean" && typeof value !== "boolean") {
|
|
4184
|
-
value = Boolean(value);
|
|
4185
|
-
}
|
|
4186
|
-
if (value !== void 0 && value !== "" && value !== null) {
|
|
4187
|
-
data[paramName] = value;
|
|
4188
|
-
} else if (paramSchema.required) {
|
|
4189
|
-
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
4190
|
-
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
4191
|
-
} else if (paramSchema.type === "string") {
|
|
4192
|
-
data[paramName] = "";
|
|
4193
|
-
} else if (paramSchema.type === "boolean") {
|
|
4194
|
-
data[paramName] = false;
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
});
|
|
4198
|
-
yield sendCommand(commandName, data);
|
|
4199
|
-
}),
|
|
4200
|
-
[sendCommand, commands]
|
|
4201
|
-
);
|
|
4202
|
-
const renderInput = (commandName, paramName, paramSchema) => {
|
|
4203
|
-
var _a, _b;
|
|
4204
|
-
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
4205
|
-
if (isFileParam(paramSchema)) {
|
|
4206
|
-
return /* @__PURE__ */ jsx3(
|
|
4207
|
-
FileParamInput,
|
|
4208
|
-
{
|
|
4209
|
-
commandName,
|
|
4210
|
-
paramName,
|
|
4211
|
-
description: paramSchema.description,
|
|
4212
|
-
value,
|
|
4213
|
-
onChange: handleInputChange,
|
|
4214
|
-
disabled: status !== "ready",
|
|
4215
|
-
uploadFile
|
|
4216
|
-
},
|
|
4217
|
-
`${commandName}-${paramName}`
|
|
4218
|
-
);
|
|
4219
|
-
}
|
|
4220
|
-
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
4221
|
-
const isInteger = paramSchema.type === "integer";
|
|
4222
|
-
const step = isInteger ? 1 : 0.1;
|
|
4223
|
-
const parseValue = isInteger ? parseInt : parseFloat;
|
|
4224
|
-
if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
|
|
4225
|
-
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
4226
|
-
/* @__PURE__ */ jsxs(
|
|
4227
|
-
"label",
|
|
4228
|
-
{
|
|
4229
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4230
|
-
children: [
|
|
4231
|
-
paramName,
|
|
4232
|
-
" (",
|
|
4233
|
-
paramSchema.minimum,
|
|
4234
|
-
" - ",
|
|
4235
|
-
paramSchema.maximum,
|
|
4236
|
-
")",
|
|
4237
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4238
|
-
paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
|
|
4239
|
-
]
|
|
4240
|
-
}
|
|
4241
|
-
),
|
|
4242
|
-
/* @__PURE__ */ jsx3(
|
|
4243
|
-
"input",
|
|
4244
|
-
{
|
|
4245
|
-
type: "range",
|
|
4246
|
-
min: paramSchema.minimum,
|
|
4247
|
-
max: paramSchema.maximum,
|
|
4248
|
-
step,
|
|
4249
|
-
value,
|
|
4250
|
-
onChange: (e) => {
|
|
4251
|
-
const newValue = parseValue(e.target.value) || 0;
|
|
4252
|
-
handleInputChange(commandName, paramName, newValue);
|
|
4253
|
-
handleCommandSubmit(commandName);
|
|
4254
|
-
},
|
|
4255
|
-
style: { width: "100%", marginBottom: "4px" }
|
|
4256
|
-
}
|
|
4257
|
-
),
|
|
4258
|
-
/* @__PURE__ */ jsxs("div", { style: { fontSize: "11px", color: "#888" }, children: [
|
|
4259
|
-
"Value: ",
|
|
4260
|
-
value
|
|
4261
|
-
] })
|
|
4262
|
-
] });
|
|
4263
|
-
} else {
|
|
4264
|
-
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
4265
|
-
/* @__PURE__ */ jsxs(
|
|
4266
|
-
"label",
|
|
4267
|
-
{
|
|
4268
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4269
|
-
children: [
|
|
4270
|
-
paramName,
|
|
4271
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4272
|
-
paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
|
|
4273
|
-
]
|
|
4274
|
-
}
|
|
4275
|
-
),
|
|
4276
|
-
/* @__PURE__ */ jsx3(
|
|
4277
|
-
"input",
|
|
4278
|
-
{
|
|
4279
|
-
type: "number",
|
|
4280
|
-
value,
|
|
4281
|
-
min: paramSchema.minimum,
|
|
4282
|
-
max: paramSchema.maximum,
|
|
4283
|
-
step,
|
|
4284
|
-
inputMode: "numeric",
|
|
4285
|
-
onChange: (e) => {
|
|
4286
|
-
const val = e.target.value;
|
|
4287
|
-
if (val === "" || val === "-") {
|
|
4288
|
-
handleInputChange(commandName, paramName, val);
|
|
4289
|
-
} else {
|
|
4290
|
-
const parsed = parseValue(val);
|
|
4291
|
-
if (!isNaN(parsed)) {
|
|
4292
|
-
handleInputChange(commandName, paramName, parsed);
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
},
|
|
4296
|
-
onBlur: (e) => {
|
|
4297
|
-
const val = e.target.value;
|
|
4298
|
-
if (val === "" || val === "-") {
|
|
4299
|
-
handleInputChange(commandName, paramName, 0);
|
|
4300
|
-
}
|
|
4301
|
-
},
|
|
4302
|
-
style: {
|
|
4303
|
-
width: "100%",
|
|
4304
|
-
padding: "4px",
|
|
4305
|
-
fontSize: "12px",
|
|
4306
|
-
border: "1px solid #ccc",
|
|
4307
|
-
borderRadius: "2px"
|
|
4308
|
-
}
|
|
4309
|
-
}
|
|
4310
|
-
)
|
|
4311
|
-
] });
|
|
4312
|
-
}
|
|
4313
|
-
} else if (paramSchema.type === "string") {
|
|
4314
|
-
if (paramSchema.enum) {
|
|
4315
|
-
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
4316
|
-
/* @__PURE__ */ jsxs(
|
|
4317
|
-
"label",
|
|
4318
|
-
{
|
|
4319
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4320
|
-
children: [
|
|
4321
|
-
paramName,
|
|
4322
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4323
|
-
paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
|
|
4324
|
-
]
|
|
4325
|
-
}
|
|
4326
|
-
),
|
|
4327
|
-
/* @__PURE__ */ jsxs(
|
|
4328
|
-
"select",
|
|
4329
|
-
{
|
|
4330
|
-
value,
|
|
4331
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
|
|
4332
|
-
style: {
|
|
4333
|
-
width: "100%",
|
|
4334
|
-
padding: "4px",
|
|
4335
|
-
fontSize: "12px",
|
|
4336
|
-
border: "1px solid #ccc",
|
|
4337
|
-
borderRadius: "2px"
|
|
4338
|
-
},
|
|
4339
|
-
children: [
|
|
4340
|
-
/* @__PURE__ */ jsx3("option", { value: "", children: "Select..." }),
|
|
4341
|
-
paramSchema.enum.map((option) => /* @__PURE__ */ jsx3("option", { value: option, children: option }, option))
|
|
4342
|
-
]
|
|
4343
|
-
}
|
|
4344
|
-
)
|
|
4345
|
-
] });
|
|
4346
|
-
} else {
|
|
4347
|
-
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
4348
|
-
/* @__PURE__ */ jsxs(
|
|
4349
|
-
"label",
|
|
4350
|
-
{
|
|
4351
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4352
|
-
children: [
|
|
4353
|
-
paramName,
|
|
4354
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4355
|
-
paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
|
|
4356
|
-
]
|
|
4357
|
-
}
|
|
4358
|
-
),
|
|
4359
|
-
/* @__PURE__ */ jsx3(
|
|
4360
|
-
"input",
|
|
4361
|
-
{
|
|
4362
|
-
type: "text",
|
|
4363
|
-
value,
|
|
4364
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
|
|
4365
|
-
style: {
|
|
4366
|
-
width: "100%",
|
|
4367
|
-
padding: "4px",
|
|
4368
|
-
fontSize: "12px",
|
|
4369
|
-
border: "1px solid #ccc",
|
|
4370
|
-
borderRadius: "2px"
|
|
4371
|
-
}
|
|
4372
|
-
}
|
|
4373
|
-
)
|
|
4374
|
-
] });
|
|
4375
|
-
}
|
|
4376
|
-
} else if (paramSchema.type === "boolean") {
|
|
4377
|
-
return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsxs(
|
|
4378
|
-
"label",
|
|
4379
|
-
{
|
|
4380
|
-
style: {
|
|
4381
|
-
fontSize: "12px",
|
|
4382
|
-
color: "#666",
|
|
4383
|
-
display: "flex",
|
|
4384
|
-
alignItems: "center"
|
|
4385
|
-
},
|
|
4386
|
-
children: [
|
|
4387
|
-
/* @__PURE__ */ jsx3(
|
|
4388
|
-
"input",
|
|
4389
|
-
{
|
|
4390
|
-
type: "checkbox",
|
|
4391
|
-
checked: value,
|
|
4392
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.checked),
|
|
4393
|
-
style: { marginRight: "6px" }
|
|
4394
|
-
}
|
|
4395
|
-
),
|
|
4396
|
-
paramName,
|
|
4397
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4398
|
-
paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
|
|
4399
|
-
]
|
|
4400
|
-
}
|
|
4401
|
-
) });
|
|
4402
|
-
}
|
|
4403
|
-
return null;
|
|
4404
|
-
};
|
|
4405
|
-
const renderCommand = (commandName, commandSchema) => {
|
|
4406
|
-
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
4407
|
-
const isExpanded = expandedCommands[commandName];
|
|
4408
|
-
const params = Object.values(commandSchema.schema);
|
|
4409
|
-
const allSliders = params.length > 0 && params.every(
|
|
4410
|
-
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
4411
|
-
);
|
|
4412
|
-
const showExecuteButton = !allSliders;
|
|
4413
|
-
return /* @__PURE__ */ jsxs(
|
|
4414
|
-
"div",
|
|
4415
|
-
{
|
|
4416
|
-
style: {
|
|
4417
|
-
border: "1px solid #ddd",
|
|
4418
|
-
borderRadius: "4px",
|
|
4419
|
-
marginBottom: "8px",
|
|
4420
|
-
backgroundColor: "#fafafa"
|
|
4421
|
-
},
|
|
4422
|
-
children: [
|
|
4423
|
-
/* @__PURE__ */ jsxs(
|
|
4424
|
-
"div",
|
|
4425
|
-
{
|
|
4426
|
-
onClick: () => toggleCommandExpanded(commandName),
|
|
4427
|
-
style: {
|
|
4428
|
-
padding: "8px 12px",
|
|
4429
|
-
cursor: "pointer",
|
|
4430
|
-
borderBottom: isExpanded ? "1px solid #ddd" : "none",
|
|
4431
|
-
display: "flex",
|
|
4432
|
-
justifyContent: "space-between",
|
|
4433
|
-
alignItems: "center"
|
|
4434
|
-
},
|
|
4435
|
-
children: [
|
|
4436
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4437
|
-
/* @__PURE__ */ jsx3(
|
|
4438
|
-
"h4",
|
|
4439
|
-
{
|
|
4440
|
-
style: {
|
|
4441
|
-
margin: "0",
|
|
4442
|
-
fontSize: "13px",
|
|
4443
|
-
fontWeight: "bold"
|
|
4444
|
-
},
|
|
4445
|
-
children: commandName
|
|
4446
|
-
}
|
|
4447
|
-
),
|
|
4448
|
-
isExpanded && commandSchema.description && /* @__PURE__ */ jsx3(
|
|
4449
|
-
"p",
|
|
4450
|
-
{
|
|
4451
|
-
style: { margin: "4px 0 0 0", fontSize: "11px", color: "#666" },
|
|
4452
|
-
children: commandSchema.description
|
|
4453
|
-
}
|
|
4454
|
-
)
|
|
4455
|
-
] }),
|
|
4456
|
-
/* @__PURE__ */ jsx3(
|
|
4457
|
-
"div",
|
|
4458
|
-
{
|
|
4459
|
-
style: {
|
|
4460
|
-
fontSize: "10px",
|
|
4461
|
-
color: "#999",
|
|
4462
|
-
transform: isExpanded ? "rotate(180deg)" : "rotate(0deg)",
|
|
4463
|
-
transition: "transform 0.2s"
|
|
4464
|
-
},
|
|
4465
|
-
children: "\u25BC"
|
|
4466
|
-
}
|
|
4467
|
-
)
|
|
4468
|
-
]
|
|
4469
|
-
}
|
|
4470
|
-
),
|
|
4471
|
-
isExpanded && /* @__PURE__ */ jsxs("div", { style: { padding: "12px", paddingTop: "0" }, children: [
|
|
4472
|
-
hasParams && /* @__PURE__ */ jsxs("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
|
|
4473
|
-
/* @__PURE__ */ jsx3(
|
|
4474
|
-
"div",
|
|
4475
|
-
{
|
|
4476
|
-
style: {
|
|
4477
|
-
marginBottom: "8px",
|
|
4478
|
-
fontSize: "12px",
|
|
4479
|
-
fontWeight: "bold",
|
|
4480
|
-
color: "#555"
|
|
4481
|
-
},
|
|
4482
|
-
children: "Parameters:"
|
|
4483
|
-
}
|
|
4484
|
-
),
|
|
4485
|
-
Object.entries(commandSchema.schema).map(
|
|
4486
|
-
([paramName, paramSchema]) => /* @__PURE__ */ jsx3(
|
|
4487
|
-
"div",
|
|
4488
|
-
{
|
|
4489
|
-
style: { marginLeft: "8px" },
|
|
4490
|
-
children: renderInput(commandName, paramName, paramSchema)
|
|
4491
|
-
},
|
|
4492
|
-
`${commandName}-${paramName}`
|
|
4493
|
-
)
|
|
4494
|
-
)
|
|
4495
|
-
] }),
|
|
4496
|
-
!hasParams && /* @__PURE__ */ jsx3(
|
|
4497
|
-
"div",
|
|
4498
|
-
{
|
|
4499
|
-
style: {
|
|
4500
|
-
marginBottom: showExecuteButton ? "12px" : "0",
|
|
4501
|
-
marginTop: "2px",
|
|
4502
|
-
fontSize: "11px",
|
|
4503
|
-
color: "#666",
|
|
4504
|
-
fontStyle: "italic"
|
|
4505
|
-
},
|
|
4506
|
-
children: "No parameters required"
|
|
4507
|
-
}
|
|
4508
|
-
),
|
|
4509
|
-
showExecuteButton && /* @__PURE__ */ jsxs(
|
|
4510
|
-
"button",
|
|
4511
|
-
{
|
|
4512
|
-
onClick: () => handleCommandSubmit(commandName),
|
|
4513
|
-
style: {
|
|
4514
|
-
padding: "8px 16px",
|
|
4515
|
-
fontSize: "12px",
|
|
4516
|
-
backgroundColor: "#007bff",
|
|
4517
|
-
color: "white",
|
|
4518
|
-
border: "none",
|
|
4519
|
-
borderRadius: "4px",
|
|
4520
|
-
cursor: "pointer",
|
|
4521
|
-
fontWeight: "bold"
|
|
4522
|
-
},
|
|
4523
|
-
children: [
|
|
4524
|
-
"Execute ",
|
|
4525
|
-
commandName
|
|
4526
|
-
]
|
|
4527
|
-
}
|
|
4528
|
-
)
|
|
4529
|
-
] })
|
|
4530
|
-
]
|
|
4531
|
-
},
|
|
4532
|
-
commandName
|
|
4533
|
-
);
|
|
4534
|
-
};
|
|
4535
|
-
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: [
|
|
4536
|
-
/* @__PURE__ */ jsx3(
|
|
4537
|
-
"h3",
|
|
4538
|
-
{
|
|
4539
|
-
style: {
|
|
4540
|
-
margin: "0 0 16px 0",
|
|
4541
|
-
fontSize: "16px",
|
|
4542
|
-
fontWeight: "bold"
|
|
4543
|
-
},
|
|
4544
|
-
children: "Reactor Commands"
|
|
4545
|
-
}
|
|
4546
|
-
),
|
|
4547
|
-
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ jsx3("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
4548
|
-
] }) }) });
|
|
4549
|
-
}
|
|
4550
|
-
function FileParamInput({
|
|
4551
|
-
commandName,
|
|
4552
|
-
paramName,
|
|
4553
|
-
description,
|
|
4554
|
-
value,
|
|
4555
|
-
onChange,
|
|
4556
|
-
disabled,
|
|
4557
|
-
uploadFile
|
|
4558
|
-
}) {
|
|
4559
|
-
const inputRef = useRef4(null);
|
|
4560
|
-
const [uploading, setUploading] = useState3(false);
|
|
4561
|
-
const fileRef = value instanceof FileRef ? value : null;
|
|
4562
|
-
const handleFile = (e) => __async(null, null, function* () {
|
|
4563
|
-
var _a;
|
|
4564
|
-
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
4565
|
-
if (!file) return;
|
|
4566
|
-
e.target.value = "";
|
|
4567
|
-
setUploading(true);
|
|
4568
|
-
try {
|
|
4569
|
-
const ref = yield uploadFile(file);
|
|
4570
|
-
onChange(commandName, paramName, ref);
|
|
4571
|
-
} catch (err) {
|
|
4572
|
-
console.error("[FileParamInput] Upload failed:", err);
|
|
4573
|
-
} finally {
|
|
4574
|
-
setUploading(false);
|
|
4575
|
-
}
|
|
4576
|
-
});
|
|
4577
|
-
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
|
|
4578
|
-
/* @__PURE__ */ jsxs("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
4579
|
-
paramName,
|
|
4580
|
-
/* @__PURE__ */ jsx3("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
4581
|
-
description && ` - ${description}`
|
|
4582
|
-
] }),
|
|
4583
|
-
/* @__PURE__ */ jsxs(
|
|
4584
|
-
"div",
|
|
4585
|
-
{
|
|
4586
|
-
style: {
|
|
4587
|
-
display: "flex",
|
|
4588
|
-
alignItems: "center",
|
|
4589
|
-
gap: "8px",
|
|
4590
|
-
marginTop: "4px"
|
|
4591
|
-
},
|
|
4592
|
-
children: [
|
|
4593
|
-
/* @__PURE__ */ jsx3(
|
|
4594
|
-
"input",
|
|
4595
|
-
{
|
|
4596
|
-
ref: inputRef,
|
|
4597
|
-
type: "file",
|
|
4598
|
-
accept: "image/*",
|
|
4599
|
-
onChange: handleFile,
|
|
4600
|
-
style: { display: "none" }
|
|
4601
|
-
}
|
|
4602
|
-
),
|
|
4603
|
-
/* @__PURE__ */ jsx3(
|
|
4604
|
-
"button",
|
|
4605
|
-
{
|
|
4606
|
-
disabled: disabled || uploading,
|
|
4607
|
-
onClick: () => {
|
|
4608
|
-
var _a;
|
|
4609
|
-
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
4610
|
-
},
|
|
4611
|
-
style: {
|
|
4612
|
-
padding: "4px 12px",
|
|
4613
|
-
fontSize: "12px",
|
|
4614
|
-
backgroundColor: "#007bff",
|
|
4615
|
-
color: "white",
|
|
4616
|
-
border: "none",
|
|
4617
|
-
borderRadius: "4px",
|
|
4618
|
-
cursor: disabled || uploading ? "default" : "pointer",
|
|
4619
|
-
opacity: disabled || uploading ? 0.5 : 1
|
|
4620
|
-
},
|
|
4621
|
-
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
4622
|
-
}
|
|
4623
|
-
),
|
|
4624
|
-
fileRef && /* @__PURE__ */ jsxs("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
4625
|
-
"\\u2713 ",
|
|
4626
|
-
fileRef.name
|
|
4627
|
-
] })
|
|
4628
|
-
]
|
|
4629
|
-
}
|
|
4630
|
-
)
|
|
4631
|
-
] });
|
|
4632
|
-
}
|
|
4633
|
-
|
|
4634
4119
|
// src/react/WebcamStream.tsx
|
|
4635
|
-
import { useEffect as useEffect4, useRef as
|
|
4636
|
-
import { jsx as
|
|
4120
|
+
import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
|
|
4121
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
4637
4122
|
function WebcamStream({
|
|
4638
4123
|
track,
|
|
4639
4124
|
audio = false,
|
|
@@ -4650,19 +4135,19 @@ function WebcamStream({
|
|
|
4650
4135
|
onPublished,
|
|
4651
4136
|
onError
|
|
4652
4137
|
}) {
|
|
4653
|
-
const [stream, setStream] =
|
|
4654
|
-
const [isPublishing, setIsPublishing] =
|
|
4655
|
-
const [permissionDenied, setPermissionDenied] =
|
|
4138
|
+
const [stream, setStream] = useState3(null);
|
|
4139
|
+
const [isPublishing, setIsPublishing] = useState3(false);
|
|
4140
|
+
const [permissionDenied, setPermissionDenied] = useState3(false);
|
|
4656
4141
|
const { status, publish, unpublish, reactor } = useReactor((state) => ({
|
|
4657
4142
|
status: state.status,
|
|
4658
4143
|
publish: state.publish,
|
|
4659
4144
|
unpublish: state.unpublish,
|
|
4660
4145
|
reactor: state.internal.reactor
|
|
4661
4146
|
}));
|
|
4662
|
-
const videoRef =
|
|
4663
|
-
const onPermissionDeniedRef =
|
|
4664
|
-
const onPublishedRef =
|
|
4665
|
-
const onErrorRef =
|
|
4147
|
+
const videoRef = useRef4(null);
|
|
4148
|
+
const onPermissionDeniedRef = useRef4(onPermissionDenied);
|
|
4149
|
+
const onPublishedRef = useRef4(onPublished);
|
|
4150
|
+
const onErrorRef = useRef4(onError);
|
|
4666
4151
|
useEffect4(() => {
|
|
4667
4152
|
onPermissionDeniedRef.current = onPermissionDenied;
|
|
4668
4153
|
onPublishedRef.current = onPublished;
|
|
@@ -4835,7 +4320,7 @@ function WebcamStream({
|
|
|
4835
4320
|
};
|
|
4836
4321
|
}, []);
|
|
4837
4322
|
const showPlaceholder = !stream;
|
|
4838
|
-
return /* @__PURE__ */
|
|
4323
|
+
return /* @__PURE__ */ jsxs(
|
|
4839
4324
|
"div",
|
|
4840
4325
|
{
|
|
4841
4326
|
style: __spreadValues({
|
|
@@ -4845,7 +4330,7 @@ function WebcamStream({
|
|
|
4845
4330
|
}, style),
|
|
4846
4331
|
className,
|
|
4847
4332
|
children: [
|
|
4848
|
-
/* @__PURE__ */
|
|
4333
|
+
/* @__PURE__ */ jsx3(
|
|
4849
4334
|
"video",
|
|
4850
4335
|
{
|
|
4851
4336
|
ref: videoRef,
|
|
@@ -4860,7 +4345,7 @@ function WebcamStream({
|
|
|
4860
4345
|
autoPlay: true
|
|
4861
4346
|
}
|
|
4862
4347
|
),
|
|
4863
|
-
showPlaceholder && /* @__PURE__ */
|
|
4348
|
+
showPlaceholder && /* @__PURE__ */ jsx3(
|
|
4864
4349
|
"div",
|
|
4865
4350
|
{
|
|
4866
4351
|
style: {
|
|
@@ -4881,11 +4366,11 @@ function WebcamStream({
|
|
|
4881
4366
|
flexDirection: "column",
|
|
4882
4367
|
gap: "12px"
|
|
4883
4368
|
},
|
|
4884
|
-
children: permissionDenied ? /* @__PURE__ */
|
|
4369
|
+
children: permissionDenied ? /* @__PURE__ */ jsxs("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
|
|
4885
4370
|
"Camera access denied.",
|
|
4886
|
-
/* @__PURE__ */
|
|
4371
|
+
/* @__PURE__ */ jsx3("br", {}),
|
|
4887
4372
|
"Please allow access in your browser settings."
|
|
4888
|
-
] }) : /* @__PURE__ */
|
|
4373
|
+
] }) : /* @__PURE__ */ jsx3("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
|
|
4889
4374
|
}
|
|
4890
4375
|
)
|
|
4891
4376
|
]
|
|
@@ -4894,8 +4379,8 @@ function WebcamStream({
|
|
|
4894
4379
|
}
|
|
4895
4380
|
|
|
4896
4381
|
// src/react/ClipPlayer.tsx
|
|
4897
|
-
import { useContext as useContext2, useEffect as useEffect5, useRef as
|
|
4898
|
-
import { jsx as
|
|
4382
|
+
import { useContext as useContext2, useEffect as useEffect5, useRef as useRef5, useState as useState4 } from "react";
|
|
4383
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4899
4384
|
function ClipPlayer({
|
|
4900
4385
|
clip,
|
|
4901
4386
|
getJwt,
|
|
@@ -4906,14 +4391,14 @@ function ClipPlayer({
|
|
|
4906
4391
|
style,
|
|
4907
4392
|
onError
|
|
4908
4393
|
}) {
|
|
4909
|
-
const videoRef =
|
|
4910
|
-
const [phase, setPhase] =
|
|
4394
|
+
const videoRef = useRef5(null);
|
|
4395
|
+
const [phase, setPhase] = useState4({ kind: "waiting" });
|
|
4911
4396
|
const store = useContext2(ReactorContext);
|
|
4912
|
-
const getJwtRef =
|
|
4913
|
-
const autoPlayRef =
|
|
4914
|
-
const slackMsRef =
|
|
4915
|
-
const onErrorRef =
|
|
4916
|
-
const storeRef =
|
|
4397
|
+
const getJwtRef = useRef5(getJwt);
|
|
4398
|
+
const autoPlayRef = useRef5(autoPlay);
|
|
4399
|
+
const slackMsRef = useRef5(slackMs);
|
|
4400
|
+
const onErrorRef = useRef5(onError);
|
|
4401
|
+
const storeRef = useRef5(store);
|
|
4917
4402
|
useEffect5(() => {
|
|
4918
4403
|
getJwtRef.current = getJwt;
|
|
4919
4404
|
autoPlayRef.current = autoPlay;
|
|
@@ -5030,7 +4515,7 @@ function ClipPlayer({
|
|
|
5030
4515
|
};
|
|
5031
4516
|
}, [clip]);
|
|
5032
4517
|
const overlayText = phase.kind === "waiting" ? "Waiting for clip\u2026" : phase.kind === "loading" ? "Loading player\u2026" : null;
|
|
5033
|
-
return /* @__PURE__ */
|
|
4518
|
+
return /* @__PURE__ */ jsxs2(
|
|
5034
4519
|
"div",
|
|
5035
4520
|
{
|
|
5036
4521
|
className,
|
|
@@ -5043,7 +4528,7 @@ function ClipPlayer({
|
|
|
5043
4528
|
justifyContent: "center"
|
|
5044
4529
|
}, style),
|
|
5045
4530
|
children: [
|
|
5046
|
-
/* @__PURE__ */
|
|
4531
|
+
/* @__PURE__ */ jsx4(
|
|
5047
4532
|
"video",
|
|
5048
4533
|
{
|
|
5049
4534
|
ref: videoRef,
|
|
@@ -5058,7 +4543,7 @@ function ClipPlayer({
|
|
|
5058
4543
|
}
|
|
5059
4544
|
}
|
|
5060
4545
|
),
|
|
5061
|
-
overlayText && /* @__PURE__ */
|
|
4546
|
+
overlayText && /* @__PURE__ */ jsx4(
|
|
5062
4547
|
"div",
|
|
5063
4548
|
{
|
|
5064
4549
|
style: {
|
|
@@ -5076,7 +4561,7 @@ function ClipPlayer({
|
|
|
5076
4561
|
children: overlayText
|
|
5077
4562
|
}
|
|
5078
4563
|
),
|
|
5079
|
-
phase.kind === "error" && /* @__PURE__ */
|
|
4564
|
+
phase.kind === "error" && /* @__PURE__ */ jsx4(
|
|
5080
4565
|
"div",
|
|
5081
4566
|
{
|
|
5082
4567
|
style: {
|
|
@@ -5100,28 +4585,35 @@ function ClipPlayer({
|
|
|
5100
4585
|
}
|
|
5101
4586
|
|
|
5102
4587
|
// src/react/ClipDownloadButton.tsx
|
|
5103
|
-
import { useEffect as useEffect7, useRef as
|
|
4588
|
+
import { useEffect as useEffect7, useRef as useRef7 } from "react";
|
|
5104
4589
|
|
|
5105
4590
|
// src/react/useClipDownload.ts
|
|
5106
|
-
import { useCallback
|
|
4591
|
+
import { useCallback, useContext as useContext3, useEffect as useEffect6, useRef as useRef6, useState as useState5 } from "react";
|
|
5107
4592
|
function useClipDownload(clip, options = {}) {
|
|
5108
4593
|
var _a;
|
|
5109
|
-
const [state, setState] =
|
|
4594
|
+
const [state, setState] = useState5({ kind: "idle" });
|
|
5110
4595
|
const store = useContext3(ReactorContext);
|
|
5111
|
-
const clipRef =
|
|
5112
|
-
const filenameRef =
|
|
4596
|
+
const clipRef = useRef6(clip);
|
|
4597
|
+
const filenameRef = useRef6(
|
|
5113
4598
|
(_a = options.filename) != null ? _a : "reactor-clip.mp4"
|
|
5114
4599
|
);
|
|
5115
|
-
const getJwtRef =
|
|
4600
|
+
const getJwtRef = useRef6(options.getJwt);
|
|
5116
4601
|
useEffect6(() => {
|
|
5117
4602
|
clipRef.current = clip;
|
|
5118
4603
|
filenameRef.current = options.filename === void 0 ? "reactor-clip.mp4" : options.filename;
|
|
5119
4604
|
getJwtRef.current = options.getJwt;
|
|
5120
4605
|
});
|
|
5121
|
-
const inFlightRef =
|
|
5122
|
-
const
|
|
4606
|
+
const inFlightRef = useRef6(false);
|
|
4607
|
+
const abortRef = useRef6(null);
|
|
4608
|
+
useEffect6(() => () => {
|
|
4609
|
+
var _a2;
|
|
4610
|
+
return (_a2 = abortRef.current) == null ? void 0 : _a2.abort();
|
|
4611
|
+
}, []);
|
|
4612
|
+
const download = useCallback(() => __async(null, null, function* () {
|
|
5123
4613
|
if (inFlightRef.current) return void 0;
|
|
5124
4614
|
inFlightRef.current = true;
|
|
4615
|
+
const abort = new AbortController();
|
|
4616
|
+
abortRef.current = abort;
|
|
5125
4617
|
setState({ kind: "downloading", fetched: 0, total: 0 });
|
|
5126
4618
|
try {
|
|
5127
4619
|
const explicit = getJwtRef.current;
|
|
@@ -5133,12 +4625,16 @@ function useClipDownload(clip, options = {}) {
|
|
|
5133
4625
|
filenameRef.current,
|
|
5134
4626
|
{
|
|
5135
4627
|
jwt,
|
|
4628
|
+
signal: abort.signal,
|
|
5136
4629
|
onProgress: ({ fetched, total }) => setState({ kind: "downloading", fetched, total })
|
|
5137
4630
|
}
|
|
5138
4631
|
);
|
|
5139
4632
|
setState({ kind: "idle" });
|
|
5140
4633
|
return blob;
|
|
5141
4634
|
} catch (err) {
|
|
4635
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
4636
|
+
return void 0;
|
|
4637
|
+
}
|
|
5142
4638
|
const message = err instanceof RecordingError ? `${err.code}: ${err.reason}` : err instanceof Error ? err.message : String(err);
|
|
5143
4639
|
setState({ kind: "error", message });
|
|
5144
4640
|
return void 0;
|
|
@@ -5146,12 +4642,12 @@ function useClipDownload(clip, options = {}) {
|
|
|
5146
4642
|
inFlightRef.current = false;
|
|
5147
4643
|
}
|
|
5148
4644
|
}), [store]);
|
|
5149
|
-
const reset =
|
|
4645
|
+
const reset = useCallback(() => setState({ kind: "idle" }), []);
|
|
5150
4646
|
return { state, download, reset };
|
|
5151
4647
|
}
|
|
5152
4648
|
|
|
5153
4649
|
// src/react/ClipDownloadButton.tsx
|
|
5154
|
-
import { jsx as
|
|
4650
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
5155
4651
|
function ClipDownloadButton({
|
|
5156
4652
|
clip,
|
|
5157
4653
|
getJwt,
|
|
@@ -5166,8 +4662,8 @@ function ClipDownloadButton({
|
|
|
5166
4662
|
const { state, download } = useClipDownload(clip, { filename, getJwt });
|
|
5167
4663
|
const downloading = state.kind === "downloading";
|
|
5168
4664
|
const isDisabled = downloading || !!disabled;
|
|
5169
|
-
const onSuccessRef =
|
|
5170
|
-
const onErrorRef =
|
|
4665
|
+
const onSuccessRef = useRef7(onSuccess);
|
|
4666
|
+
const onErrorRef = useRef7(onError);
|
|
5171
4667
|
useEffect7(() => {
|
|
5172
4668
|
onSuccessRef.current = onSuccess;
|
|
5173
4669
|
onErrorRef.current = onError;
|
|
@@ -5179,7 +4675,7 @@ function ClipDownloadButton({
|
|
|
5179
4675
|
}
|
|
5180
4676
|
}, [state]);
|
|
5181
4677
|
const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
|
|
5182
|
-
return /* @__PURE__ */
|
|
4678
|
+
return /* @__PURE__ */ jsx5(
|
|
5183
4679
|
"button",
|
|
5184
4680
|
{
|
|
5185
4681
|
type: "button",
|
|
@@ -5226,18 +4722,19 @@ export {
|
|
|
5226
4722
|
DEFAULT_PLAYLIST_POLL_SLACK_MS,
|
|
5227
4723
|
FileRef,
|
|
5228
4724
|
Reactor,
|
|
5229
|
-
ReactorController,
|
|
5230
4725
|
ReactorProvider,
|
|
5231
4726
|
ReactorView,
|
|
5232
4727
|
RecordingClient,
|
|
5233
4728
|
RecordingError,
|
|
5234
4729
|
RuntimeRecordingMessageType,
|
|
4730
|
+
SessionLostError,
|
|
5235
4731
|
WebcamStream,
|
|
5236
4732
|
clipFromPayload,
|
|
5237
4733
|
createPlayableManifestUrl,
|
|
5238
4734
|
downloadClipAsFile,
|
|
5239
4735
|
fetchPlaylist,
|
|
5240
4736
|
isAbortError,
|
|
4737
|
+
isSessionLostError,
|
|
5241
4738
|
normalizeJwtSource,
|
|
5242
4739
|
parsePlaylist,
|
|
5243
4740
|
rewriteUrlHost,
|