@reactor-team/js-sdk 2.8.1 → 2.9.1
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 +54 -1
- package/dist/index.d.ts +54 -1
- package/dist/index.js +382 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +384 -85
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ __export(index_exports, {
|
|
|
82
82
|
AbortError: () => AbortError,
|
|
83
83
|
ConflictError: () => ConflictError,
|
|
84
84
|
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
85
|
+
FileRef: () => FileRef,
|
|
85
86
|
Reactor: () => Reactor,
|
|
86
87
|
ReactorController: () => ReactorController,
|
|
87
88
|
ReactorProvider: () => ReactorProvider,
|
|
@@ -96,6 +97,18 @@ __export(index_exports, {
|
|
|
96
97
|
});
|
|
97
98
|
module.exports = __toCommonJS(index_exports);
|
|
98
99
|
|
|
100
|
+
// src/core/FileRef.ts
|
|
101
|
+
var FileRef = class {
|
|
102
|
+
constructor(uploadId, name, mimeType, size) {
|
|
103
|
+
this.uploadId = uploadId;
|
|
104
|
+
this.name = name;
|
|
105
|
+
this.mimeType = mimeType;
|
|
106
|
+
this.size = size;
|
|
107
|
+
/** @internal Marker so sendCommand can detect FileRef values. */
|
|
108
|
+
this.__isFileRef = true;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
99
112
|
// src/types.ts
|
|
100
113
|
var ConflictError = class extends Error {
|
|
101
114
|
constructor(message) {
|
|
@@ -117,7 +130,7 @@ var import_zod = require("zod");
|
|
|
117
130
|
// package.json
|
|
118
131
|
var package_default = {
|
|
119
132
|
name: "@reactor-team/js-sdk",
|
|
120
|
-
version: "2.
|
|
133
|
+
version: "2.9.1",
|
|
121
134
|
description: "Reactor JavaScript frontend SDK",
|
|
122
135
|
main: "dist/index.js",
|
|
123
136
|
module: "dist/index.mjs",
|
|
@@ -156,7 +169,7 @@ var package_default = {
|
|
|
156
169
|
license: "MIT",
|
|
157
170
|
repository: {
|
|
158
171
|
type: "git",
|
|
159
|
-
url: "https://github.com/reactor-team/js-sdk"
|
|
172
|
+
url: "https://github.com/reactor-team/js-sdk.git"
|
|
160
173
|
},
|
|
161
174
|
packageManager: "pnpm@10.12.1",
|
|
162
175
|
devDependencies: {
|
|
@@ -245,6 +258,16 @@ var SessionResponseSchema = CreateSessionResponseSchema.extend({
|
|
|
245
258
|
var TerminateSessionRequestSchema = import_zod.z.object({
|
|
246
259
|
reason: import_zod.z.string().optional()
|
|
247
260
|
});
|
|
261
|
+
var CreateUploadRequestSchema = import_zod.z.object({
|
|
262
|
+
name: import_zod.z.string(),
|
|
263
|
+
size: import_zod.z.number().int().positive(),
|
|
264
|
+
mime_type: import_zod.z.string()
|
|
265
|
+
});
|
|
266
|
+
var CreateUploadResponseSchema = import_zod.z.object({
|
|
267
|
+
presigned_id: import_zod.z.string(),
|
|
268
|
+
presigned_url: import_zod.z.string(),
|
|
269
|
+
path: import_zod.z.string()
|
|
270
|
+
});
|
|
248
271
|
var IceServerCredentialsSchema = import_zod.z.object({
|
|
249
272
|
username: import_zod.z.string(),
|
|
250
273
|
password: import_zod.z.string()
|
|
@@ -581,6 +604,40 @@ var CoordinatorClient = class {
|
|
|
581
604
|
);
|
|
582
605
|
});
|
|
583
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* Allocates an upload slot for a file.
|
|
609
|
+
* Returns a presigned PUT URL the caller can use to upload the file
|
|
610
|
+
* directly to the object store (production) or local runtime (local dev).
|
|
611
|
+
*/
|
|
612
|
+
createUpload(sessionId, request) {
|
|
613
|
+
return __async(this, null, function* () {
|
|
614
|
+
console.debug("[CoordinatorClient] Creating upload slot...", {
|
|
615
|
+
sessionId,
|
|
616
|
+
name: request.name,
|
|
617
|
+
size: request.size
|
|
618
|
+
});
|
|
619
|
+
const response = yield fetch(
|
|
620
|
+
`${this.baseUrl}/sessions/${sessionId}/uploads`,
|
|
621
|
+
{
|
|
622
|
+
method: "POST",
|
|
623
|
+
headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
|
|
624
|
+
"Content-Type": "application/json"
|
|
625
|
+
}),
|
|
626
|
+
body: JSON.stringify(request),
|
|
627
|
+
signal: this.signal
|
|
628
|
+
}
|
|
629
|
+
);
|
|
630
|
+
yield this.checkVersionMismatch(response);
|
|
631
|
+
if (!response.ok) {
|
|
632
|
+
const errorText = yield response.text();
|
|
633
|
+
throw new Error(
|
|
634
|
+
`Failed to create upload slot: ${response.status} ${errorText}`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
const data = yield response.json();
|
|
638
|
+
return CreateUploadResponseSchema.parse(data);
|
|
639
|
+
});
|
|
640
|
+
}
|
|
584
641
|
getSessionId() {
|
|
585
642
|
return this.currentSessionId;
|
|
586
643
|
}
|
|
@@ -749,12 +806,15 @@ function waitForIceGathering(pc, timeoutMs = 5e3) {
|
|
|
749
806
|
}, timeoutMs);
|
|
750
807
|
});
|
|
751
808
|
}
|
|
752
|
-
function sendMessage(channel, command, data, scope = "application", maxBytes = DEFAULT_MAX_MESSAGE_BYTES) {
|
|
809
|
+
function sendMessage(channel, command, data, scope = "application", maxBytes = DEFAULT_MAX_MESSAGE_BYTES, uploads) {
|
|
753
810
|
if (channel.readyState !== "open") {
|
|
754
811
|
throw new Error(`Data channel not open: ${channel.readyState}`);
|
|
755
812
|
}
|
|
756
813
|
const jsonData = typeof data === "string" ? JSON.parse(data) : data;
|
|
757
814
|
const inner = { type: command, data: jsonData };
|
|
815
|
+
if (uploads && Object.keys(uploads).length > 0) {
|
|
816
|
+
inner.uploads = uploads;
|
|
817
|
+
}
|
|
758
818
|
const payload = { scope, data: inner };
|
|
759
819
|
const serialized = JSON.stringify(payload);
|
|
760
820
|
const byteLength = new TextEncoder().encode(serialized).byteLength;
|
|
@@ -1019,45 +1079,20 @@ var WebRTCTransportClient = class {
|
|
|
1019
1079
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1020
1080
|
// Connection Lifecycle
|
|
1021
1081
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1022
|
-
|
|
1082
|
+
warmup() {
|
|
1023
1083
|
return __async(this, null, function* () {
|
|
1024
|
-
this.
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
this.peerConnection = createPeerConnection({ iceServers });
|
|
1028
|
-
this.setupPeerConnectionHandlers();
|
|
1029
|
-
this.dataChannel = createDataChannel(this.peerConnection);
|
|
1030
|
-
this.setupDataChannelHandlers();
|
|
1031
|
-
this.transceiverMap.clear();
|
|
1032
|
-
for (const track of tracks) {
|
|
1033
|
-
const transceiver = this.peerConnection.addTransceiver(track.kind, {
|
|
1034
|
-
direction: track.direction
|
|
1084
|
+
if (!this.cachedIceServers) {
|
|
1085
|
+
this.cachedIceServers = this.fetchIceServers();
|
|
1086
|
+
this.cachedIceServers.catch(() => {
|
|
1035
1087
|
});
|
|
1036
|
-
this.transceiverMap.set(track.name, {
|
|
1037
|
-
name: track.name,
|
|
1038
|
-
kind: track.kind,
|
|
1039
|
-
direction: track.direction,
|
|
1040
|
-
transceiver
|
|
1041
|
-
});
|
|
1042
|
-
console.debug(
|
|
1043
|
-
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1044
|
-
);
|
|
1045
1088
|
}
|
|
1046
|
-
|
|
1047
|
-
const trackMapping = this.buildTrackMapping(tracks);
|
|
1048
|
-
yield this.sendSdpOffer(sdpOffer, trackMapping, "POST");
|
|
1049
|
-
const answerResponse = yield this.pollSdpAnswer();
|
|
1050
|
-
this.iceStartTime = performance.now();
|
|
1051
|
-
yield setRemoteDescription(
|
|
1052
|
-
this.peerConnection,
|
|
1053
|
-
answerResponse.sdp_answer
|
|
1054
|
-
);
|
|
1055
|
-
console.debug("[WebRTCTransport] Remote description set");
|
|
1089
|
+
yield this.cachedIceServers;
|
|
1056
1090
|
});
|
|
1057
1091
|
}
|
|
1058
|
-
|
|
1092
|
+
prepare(tracks) {
|
|
1059
1093
|
return __async(this, null, function* () {
|
|
1060
1094
|
this.setStatus("connecting");
|
|
1095
|
+
this.resetTransportTimings();
|
|
1061
1096
|
this.stopPing();
|
|
1062
1097
|
this.stopStatsPolling();
|
|
1063
1098
|
if (this.dataChannel) {
|
|
@@ -1070,8 +1105,8 @@ var WebRTCTransportClient = class {
|
|
|
1070
1105
|
}
|
|
1071
1106
|
this.peerConnected = false;
|
|
1072
1107
|
this.dataChannelOpen = false;
|
|
1073
|
-
this.
|
|
1074
|
-
|
|
1108
|
+
const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
|
|
1109
|
+
this.cachedIceServers = void 0;
|
|
1075
1110
|
this.peerConnection = createPeerConnection({ iceServers });
|
|
1076
1111
|
this.setupPeerConnectionHandlers();
|
|
1077
1112
|
this.dataChannel = createDataChannel(this.peerConnection);
|
|
@@ -1087,17 +1122,35 @@ var WebRTCTransportClient = class {
|
|
|
1087
1122
|
direction: track.direction,
|
|
1088
1123
|
transceiver
|
|
1089
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
|
+
);
|
|
1090
1140
|
}
|
|
1091
|
-
const
|
|
1092
|
-
const
|
|
1093
|
-
|
|
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);
|
|
1094
1147
|
const answerResponse = yield this.pollSdpAnswer();
|
|
1095
1148
|
this.iceStartTime = performance.now();
|
|
1096
1149
|
yield setRemoteDescription(
|
|
1097
1150
|
this.peerConnection,
|
|
1098
1151
|
answerResponse.sdp_answer
|
|
1099
1152
|
);
|
|
1100
|
-
console.debug("[WebRTCTransport] Remote description set
|
|
1153
|
+
console.debug("[WebRTCTransport] Remote description set");
|
|
1101
1154
|
});
|
|
1102
1155
|
}
|
|
1103
1156
|
disconnect() {
|
|
@@ -1163,7 +1216,7 @@ var WebRTCTransportClient = class {
|
|
|
1163
1216
|
var _a, _b, _c;
|
|
1164
1217
|
return (_c = (_b = (_a = this.peerConnection) == null ? void 0 : _a.sctp) == null ? void 0 : _b.maxMessageSize) != null ? _c : void 0;
|
|
1165
1218
|
}
|
|
1166
|
-
sendCommand(command, data, scope = "application") {
|
|
1219
|
+
sendCommand(command, data, scope = "application", uploads) {
|
|
1167
1220
|
if (!this.dataChannel) {
|
|
1168
1221
|
throw new Error("[WebRTCTransport] Data channel not available");
|
|
1169
1222
|
}
|
|
@@ -1173,7 +1226,8 @@ var WebRTCTransportClient = class {
|
|
|
1173
1226
|
command,
|
|
1174
1227
|
data,
|
|
1175
1228
|
scope,
|
|
1176
|
-
this.maxMessageBytes
|
|
1229
|
+
this.maxMessageBytes,
|
|
1230
|
+
uploads
|
|
1177
1231
|
);
|
|
1178
1232
|
} catch (error) {
|
|
1179
1233
|
console.warn("[WebRTCTransport] Failed to send message:", error);
|
|
@@ -1415,10 +1469,16 @@ var WebRTCTransportClient = class {
|
|
|
1415
1469
|
var import_zod2 = require("zod");
|
|
1416
1470
|
var LOCAL_COORDINATOR_URL = "http://localhost:8080";
|
|
1417
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
|
+
});
|
|
1418
1477
|
var OptionsSchema = import_zod2.z.object({
|
|
1419
1478
|
apiUrl: import_zod2.z.string().default(DEFAULT_BASE_URL),
|
|
1420
1479
|
modelName: import_zod2.z.string(),
|
|
1421
|
-
local: import_zod2.z.boolean().default(false)
|
|
1480
|
+
local: import_zod2.z.boolean().default(false),
|
|
1481
|
+
modelTracks: import_zod2.z.array(TrackHintSchema).optional()
|
|
1422
1482
|
});
|
|
1423
1483
|
var Reactor = class {
|
|
1424
1484
|
constructor(options) {
|
|
@@ -1432,6 +1492,9 @@ var Reactor = class {
|
|
|
1432
1492
|
if (this.local && options.apiUrl === void 0) {
|
|
1433
1493
|
this.coordinatorUrl = LOCAL_COORDINATOR_URL;
|
|
1434
1494
|
}
|
|
1495
|
+
if (validatedOptions.modelTracks) {
|
|
1496
|
+
this.presetTracks = validatedOptions.modelTracks;
|
|
1497
|
+
}
|
|
1435
1498
|
}
|
|
1436
1499
|
on(event, handler) {
|
|
1437
1500
|
if (!this.eventListeners.has(event)) {
|
|
@@ -1449,6 +1512,10 @@ var Reactor = class {
|
|
|
1449
1512
|
}
|
|
1450
1513
|
/**
|
|
1451
1514
|
* Sends a command to the model via the data channel.
|
|
1515
|
+
*
|
|
1516
|
+
* When any value in `data` is a {@link FileRef}, it is automatically
|
|
1517
|
+
* extracted and serialized into a separate `uploads` section on the
|
|
1518
|
+
* wire, keyed by the parameter name. Scalar values remain in `data`.
|
|
1452
1519
|
*/
|
|
1453
1520
|
sendCommand(command, data, scope = "application") {
|
|
1454
1521
|
return __async(this, null, function* () {
|
|
@@ -1459,7 +1526,28 @@ var Reactor = class {
|
|
|
1459
1526
|
return;
|
|
1460
1527
|
}
|
|
1461
1528
|
try {
|
|
1462
|
-
|
|
1529
|
+
let uploads;
|
|
1530
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
1531
|
+
const scalarData = {};
|
|
1532
|
+
const extractedUploads = {};
|
|
1533
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1534
|
+
if (value instanceof FileRef) {
|
|
1535
|
+
extractedUploads[key] = {
|
|
1536
|
+
upload_id: value.uploadId,
|
|
1537
|
+
name: value.name,
|
|
1538
|
+
mime_type: value.mimeType,
|
|
1539
|
+
size: value.size
|
|
1540
|
+
};
|
|
1541
|
+
} else {
|
|
1542
|
+
scalarData[key] = value;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (Object.keys(extractedUploads).length > 0) {
|
|
1546
|
+
uploads = extractedUploads;
|
|
1547
|
+
data = scalarData;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
(_a = this.transportClient) == null ? void 0 : _a.sendCommand(command, data, scope, uploads);
|
|
1463
1551
|
} catch (error) {
|
|
1464
1552
|
console.error("[Reactor] Failed to send message:", error);
|
|
1465
1553
|
this.createError(
|
|
@@ -1471,6 +1559,82 @@ var Reactor = class {
|
|
|
1471
1559
|
}
|
|
1472
1560
|
});
|
|
1473
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Uploads a file to the session's object store and returns a {@link FileRef}.
|
|
1564
|
+
*
|
|
1565
|
+
* Flow:
|
|
1566
|
+
* 1. POST /sessions/{id}/uploads → allocate presigned PUT URL
|
|
1567
|
+
* 2. PUT file bytes to the presigned URL
|
|
1568
|
+
* 3. Send `fileUploaded` notification on the runtime data channel
|
|
1569
|
+
* (fires `@file_uploaded` on the model if registered)
|
|
1570
|
+
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
1571
|
+
*
|
|
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).
|
|
1575
|
+
*/
|
|
1576
|
+
uploadFile(file, options) {
|
|
1577
|
+
return __async(this, null, function* () {
|
|
1578
|
+
var _a;
|
|
1579
|
+
if (this.status !== "ready") {
|
|
1580
|
+
throw new Error(
|
|
1581
|
+
`Cannot upload file, status is "${this.status}". Must be "ready".`
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
if (!this.coordinatorClient || !this.sessionId) {
|
|
1585
|
+
throw new Error("No active session. Call connect() first.");
|
|
1586
|
+
}
|
|
1587
|
+
const name = (_a = options == null ? void 0 : options.name) != null ? _a : file instanceof File ? file.name : "upload";
|
|
1588
|
+
const mimeType = file.type || "application/octet-stream";
|
|
1589
|
+
const size = file.size;
|
|
1590
|
+
if (size <= 0) {
|
|
1591
|
+
throw new Error("File is empty");
|
|
1592
|
+
}
|
|
1593
|
+
const slot = yield this.coordinatorClient.createUpload(this.sessionId, {
|
|
1594
|
+
name,
|
|
1595
|
+
size,
|
|
1596
|
+
mime_type: mimeType
|
|
1597
|
+
});
|
|
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, {
|
|
1608
|
+
method: "PUT",
|
|
1609
|
+
body: file,
|
|
1610
|
+
headers: {
|
|
1611
|
+
"Content-Length": String(size)
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
if (!putResponse.ok) {
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
`File upload failed: ${putResponse.status} ${putResponse.statusText}`
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
yield this.sendCommand(
|
|
1620
|
+
"fileUploaded",
|
|
1621
|
+
{
|
|
1622
|
+
upload_id: slot.presigned_id,
|
|
1623
|
+
name,
|
|
1624
|
+
mime_type: mimeType,
|
|
1625
|
+
size
|
|
1626
|
+
},
|
|
1627
|
+
"runtime"
|
|
1628
|
+
);
|
|
1629
|
+
console.debug("[Reactor] File uploaded:", {
|
|
1630
|
+
uploadId: slot.presigned_id,
|
|
1631
|
+
name,
|
|
1632
|
+
mimeType,
|
|
1633
|
+
size
|
|
1634
|
+
});
|
|
1635
|
+
return new FileRef(slot.presigned_id, name, mimeType, size);
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1474
1638
|
/**
|
|
1475
1639
|
* Publishes a MediaStreamTrack to a named sendonly track.
|
|
1476
1640
|
* The transceiver is already set up from capabilities — this just
|
|
@@ -1542,7 +1706,8 @@ var Reactor = class {
|
|
|
1542
1706
|
});
|
|
1543
1707
|
this.setupTransportHandlers();
|
|
1544
1708
|
}
|
|
1545
|
-
yield this.transportClient.
|
|
1709
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1710
|
+
yield this.transportClient.connect(true);
|
|
1546
1711
|
} catch (error) {
|
|
1547
1712
|
if (isAbortError(error)) return;
|
|
1548
1713
|
console.error("[Reactor] Failed to reconnect:", error);
|
|
@@ -1588,34 +1753,49 @@ var Reactor = class {
|
|
|
1588
1753
|
initialResponse.state
|
|
1589
1754
|
);
|
|
1590
1755
|
this.setStatus("waiting");
|
|
1591
|
-
const tPoll = performance.now();
|
|
1592
|
-
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1593
|
-
const sessionPollingMs = performance.now() - tPoll;
|
|
1594
|
-
this.sessionResponse = sessionResponse;
|
|
1595
|
-
this.capabilities = sessionResponse.capabilities;
|
|
1596
|
-
this.tracks = sessionResponse.capabilities.tracks;
|
|
1597
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
1598
|
-
console.debug(
|
|
1599
|
-
"[Reactor] Session ready, transport:",
|
|
1600
|
-
sessionResponse.selected_transport.protocol,
|
|
1601
|
-
"tracks:",
|
|
1602
|
-
this.tracks.length
|
|
1603
|
-
);
|
|
1604
|
-
const protocol = sessionResponse.selected_transport.protocol;
|
|
1605
|
-
if (protocol !== "webrtc") {
|
|
1606
|
-
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1607
|
-
}
|
|
1608
1756
|
this.transportClient = new WebRTCTransportClient({
|
|
1609
1757
|
baseUrl: this.coordinatorUrl,
|
|
1610
|
-
sessionId:
|
|
1758
|
+
sessionId: initialResponse.session_id,
|
|
1611
1759
|
jwtToken: this.local ? "local" : jwtToken,
|
|
1612
1760
|
webrtcVersion: REACTOR_WEBRTC_VERSION,
|
|
1613
1761
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|
|
1614
1762
|
});
|
|
1615
1763
|
this.setupTransportHandlers();
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
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);
|
|
1619
1799
|
this.connectionTimings = {
|
|
1620
1800
|
sessionCreationMs: sessionCreationMs + sessionPollingMs,
|
|
1621
1801
|
transportConnectingMs,
|
|
@@ -1977,6 +2157,17 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
1977
2157
|
console.error("[ReactorStore] Failed to reconnect:", error);
|
|
1978
2158
|
throw error;
|
|
1979
2159
|
}
|
|
2160
|
+
}),
|
|
2161
|
+
uploadFile: (file, options) => __async(null, null, function* () {
|
|
2162
|
+
console.debug("[ReactorStore] Uploading file");
|
|
2163
|
+
try {
|
|
2164
|
+
const result = yield get().internal.reactor.uploadFile(file, options);
|
|
2165
|
+
console.debug("[ReactorStore] File uploaded successfully", result);
|
|
2166
|
+
return result;
|
|
2167
|
+
} catch (error) {
|
|
2168
|
+
console.error("[ReactorStore] Failed to upload file:", error);
|
|
2169
|
+
throw error;
|
|
2170
|
+
}
|
|
1980
2171
|
})
|
|
1981
2172
|
});
|
|
1982
2173
|
});
|
|
@@ -2266,16 +2457,22 @@ function ReactorView({
|
|
|
2266
2457
|
// src/react/ReactorController.tsx
|
|
2267
2458
|
var import_react6 = __toESM(require("react"));
|
|
2268
2459
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2460
|
+
function isFileParam(ps) {
|
|
2461
|
+
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
2462
|
+
}
|
|
2269
2463
|
function ReactorController({
|
|
2270
2464
|
className,
|
|
2271
2465
|
style
|
|
2272
2466
|
}) {
|
|
2273
|
-
const { sendCommand, status } = useReactor((state) => ({
|
|
2467
|
+
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
2274
2468
|
sendCommand: state.sendCommand,
|
|
2469
|
+
uploadFile: state.uploadFile,
|
|
2275
2470
|
status: state.status
|
|
2276
2471
|
}));
|
|
2277
2472
|
const [commands, setCommands] = (0, import_react6.useState)({});
|
|
2278
2473
|
const [formValues, setFormValues] = (0, import_react6.useState)({});
|
|
2474
|
+
const formRef = (0, import_react6.useRef)(formValues);
|
|
2475
|
+
formRef.current = formValues;
|
|
2279
2476
|
const [expandedCommands, setExpandedCommands] = (0, import_react6.useState)({});
|
|
2280
2477
|
import_react6.default.useEffect(() => {
|
|
2281
2478
|
if (status === "disconnected") {
|
|
@@ -2322,15 +2519,17 @@ function ReactorController({
|
|
|
2322
2519
|
initialExpanded[commandName] = false;
|
|
2323
2520
|
Object.entries(commandSchema.schema).forEach(
|
|
2324
2521
|
([paramName, paramSchema]) => {
|
|
2325
|
-
var _a2
|
|
2326
|
-
if (paramSchema
|
|
2522
|
+
var _a2;
|
|
2523
|
+
if (isFileParam(paramSchema)) {
|
|
2524
|
+
initialValues[commandName][paramName] = null;
|
|
2525
|
+
} else if (paramSchema.default !== void 0) {
|
|
2526
|
+
initialValues[commandName][paramName] = paramSchema.default;
|
|
2527
|
+
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2327
2528
|
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
2328
2529
|
} else if (paramSchema.type === "string") {
|
|
2329
2530
|
initialValues[commandName][paramName] = "";
|
|
2330
2531
|
} else if (paramSchema.type === "boolean") {
|
|
2331
2532
|
initialValues[commandName][paramName] = false;
|
|
2332
|
-
} else if (paramSchema.type === "integer") {
|
|
2333
|
-
initialValues[commandName][paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2334
2533
|
}
|
|
2335
2534
|
}
|
|
2336
2535
|
);
|
|
@@ -2357,12 +2556,16 @@ function ReactorController({
|
|
|
2357
2556
|
const handleCommandSubmit = (0, import_react6.useCallback)(
|
|
2358
2557
|
(commandName) => __async(null, null, function* () {
|
|
2359
2558
|
const commandSchema = commands[commandName];
|
|
2360
|
-
const formData =
|
|
2559
|
+
const formData = formRef.current[commandName] || {};
|
|
2361
2560
|
const data = {};
|
|
2362
2561
|
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
2363
|
-
var _a
|
|
2562
|
+
var _a;
|
|
2364
2563
|
const paramSchema = commandSchema.schema[paramName];
|
|
2365
2564
|
let value = formData[paramName];
|
|
2565
|
+
if (value instanceof FileRef) {
|
|
2566
|
+
data[paramName] = value;
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2366
2569
|
if (paramSchema.type === "number" && typeof value === "string") {
|
|
2367
2570
|
value = parseFloat(value) || 0;
|
|
2368
2571
|
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
@@ -2373,10 +2576,8 @@ function ReactorController({
|
|
|
2373
2576
|
if (value !== void 0 && value !== "" && value !== null) {
|
|
2374
2577
|
data[paramName] = value;
|
|
2375
2578
|
} else if (paramSchema.required) {
|
|
2376
|
-
if (paramSchema.type === "number") {
|
|
2579
|
+
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2377
2580
|
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
2378
|
-
} else if (paramSchema.type === "integer") {
|
|
2379
|
-
data[paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2380
2581
|
} else if (paramSchema.type === "string") {
|
|
2381
2582
|
data[paramName] = "";
|
|
2382
2583
|
} else if (paramSchema.type === "boolean") {
|
|
@@ -2384,14 +2585,28 @@ function ReactorController({
|
|
|
2384
2585
|
}
|
|
2385
2586
|
}
|
|
2386
2587
|
});
|
|
2387
|
-
console.log(`Executing command: ${commandName}`, data);
|
|
2388
2588
|
yield sendCommand(commandName, data);
|
|
2389
2589
|
}),
|
|
2390
|
-
[
|
|
2590
|
+
[sendCommand, commands]
|
|
2391
2591
|
);
|
|
2392
2592
|
const renderInput = (commandName, paramName, paramSchema) => {
|
|
2393
2593
|
var _a, _b;
|
|
2394
2594
|
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
2595
|
+
if (isFileParam(paramSchema)) {
|
|
2596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2597
|
+
FileParamInput,
|
|
2598
|
+
{
|
|
2599
|
+
commandName,
|
|
2600
|
+
paramName,
|
|
2601
|
+
description: paramSchema.description,
|
|
2602
|
+
value,
|
|
2603
|
+
onChange: handleInputChange,
|
|
2604
|
+
disabled: status !== "ready",
|
|
2605
|
+
uploadFile
|
|
2606
|
+
},
|
|
2607
|
+
`${commandName}-${paramName}`
|
|
2608
|
+
);
|
|
2609
|
+
}
|
|
2395
2610
|
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2396
2611
|
const isInteger = paramSchema.type === "integer";
|
|
2397
2612
|
const step = isInteger ? 1 : 0.1;
|
|
@@ -2580,10 +2795,11 @@ function ReactorController({
|
|
|
2580
2795
|
const renderCommand = (commandName, commandSchema) => {
|
|
2581
2796
|
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
2582
2797
|
const isExpanded = expandedCommands[commandName];
|
|
2583
|
-
const
|
|
2584
|
-
|
|
2798
|
+
const params = Object.values(commandSchema.schema);
|
|
2799
|
+
const allSliders = params.length > 0 && params.every(
|
|
2800
|
+
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
2585
2801
|
);
|
|
2586
|
-
const showExecuteButton = !
|
|
2802
|
+
const showExecuteButton = !allSliders;
|
|
2587
2803
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2588
2804
|
"div",
|
|
2589
2805
|
{
|
|
@@ -2721,6 +2937,89 @@ function ReactorController({
|
|
|
2721
2937
|
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
2722
2938
|
] }) }) });
|
|
2723
2939
|
}
|
|
2940
|
+
function FileParamInput({
|
|
2941
|
+
commandName,
|
|
2942
|
+
paramName,
|
|
2943
|
+
description,
|
|
2944
|
+
value,
|
|
2945
|
+
onChange,
|
|
2946
|
+
disabled,
|
|
2947
|
+
uploadFile
|
|
2948
|
+
}) {
|
|
2949
|
+
const inputRef = (0, import_react6.useRef)(null);
|
|
2950
|
+
const [uploading, setUploading] = (0, import_react6.useState)(false);
|
|
2951
|
+
const fileRef = value instanceof FileRef ? value : null;
|
|
2952
|
+
const handleFile = (e) => __async(null, null, function* () {
|
|
2953
|
+
var _a;
|
|
2954
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
2955
|
+
if (!file) return;
|
|
2956
|
+
e.target.value = "";
|
|
2957
|
+
setUploading(true);
|
|
2958
|
+
try {
|
|
2959
|
+
const ref = yield uploadFile(file);
|
|
2960
|
+
onChange(commandName, paramName, ref);
|
|
2961
|
+
} catch (err) {
|
|
2962
|
+
console.error("[FileParamInput] Upload failed:", err);
|
|
2963
|
+
} finally {
|
|
2964
|
+
setUploading(false);
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
2968
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
2969
|
+
paramName,
|
|
2970
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
2971
|
+
description && ` - ${description}`
|
|
2972
|
+
] }),
|
|
2973
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2974
|
+
"div",
|
|
2975
|
+
{
|
|
2976
|
+
style: {
|
|
2977
|
+
display: "flex",
|
|
2978
|
+
alignItems: "center",
|
|
2979
|
+
gap: "8px",
|
|
2980
|
+
marginTop: "4px"
|
|
2981
|
+
},
|
|
2982
|
+
children: [
|
|
2983
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2984
|
+
"input",
|
|
2985
|
+
{
|
|
2986
|
+
ref: inputRef,
|
|
2987
|
+
type: "file",
|
|
2988
|
+
accept: "image/*",
|
|
2989
|
+
onChange: handleFile,
|
|
2990
|
+
style: { display: "none" }
|
|
2991
|
+
}
|
|
2992
|
+
),
|
|
2993
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2994
|
+
"button",
|
|
2995
|
+
{
|
|
2996
|
+
disabled: disabled || uploading,
|
|
2997
|
+
onClick: () => {
|
|
2998
|
+
var _a;
|
|
2999
|
+
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
3000
|
+
},
|
|
3001
|
+
style: {
|
|
3002
|
+
padding: "4px 12px",
|
|
3003
|
+
fontSize: "12px",
|
|
3004
|
+
backgroundColor: "#007bff",
|
|
3005
|
+
color: "white",
|
|
3006
|
+
border: "none",
|
|
3007
|
+
borderRadius: "4px",
|
|
3008
|
+
cursor: disabled || uploading ? "default" : "pointer",
|
|
3009
|
+
opacity: disabled || uploading ? 0.5 : 1
|
|
3010
|
+
},
|
|
3011
|
+
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
3012
|
+
}
|
|
3013
|
+
),
|
|
3014
|
+
fileRef && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
3015
|
+
"\\u2713 ",
|
|
3016
|
+
fileRef.name
|
|
3017
|
+
] })
|
|
3018
|
+
]
|
|
3019
|
+
}
|
|
3020
|
+
)
|
|
3021
|
+
] });
|
|
3022
|
+
}
|
|
2724
3023
|
|
|
2725
3024
|
// src/react/WebcamStream.tsx
|
|
2726
3025
|
var import_react7 = require("react");
|
|
@@ -2920,6 +3219,7 @@ function WebcamStream({
|
|
|
2920
3219
|
AbortError,
|
|
2921
3220
|
ConflictError,
|
|
2922
3221
|
DEFAULT_BASE_URL,
|
|
3222
|
+
FileRef,
|
|
2923
3223
|
Reactor,
|
|
2924
3224
|
ReactorController,
|
|
2925
3225
|
ReactorProvider,
|