@reactor-team/js-sdk 2.11.2 → 2.12.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/README.md +1 -1
- package/dist/index.d.mts +113 -10
- package/dist/index.d.ts +113 -10
- package/dist/index.js +489 -705
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +475 -690
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -88,7 +88,6 @@ __export(index_exports, {
|
|
|
88
88
|
DEFAULT_PLAYLIST_POLL_SLACK_MS: () => DEFAULT_PLAYLIST_POLL_SLACK_MS,
|
|
89
89
|
FileRef: () => FileRef,
|
|
90
90
|
Reactor: () => Reactor,
|
|
91
|
-
ReactorController: () => ReactorController,
|
|
92
91
|
ReactorProvider: () => ReactorProvider,
|
|
93
92
|
ReactorView: () => ReactorView,
|
|
94
93
|
RecordingClient: () => RecordingClient,
|
|
@@ -153,7 +152,7 @@ var import_zod = require("zod");
|
|
|
153
152
|
// package.json
|
|
154
153
|
var package_default = {
|
|
155
154
|
name: "@reactor-team/js-sdk",
|
|
156
|
-
version: "2.
|
|
155
|
+
version: "2.12.1",
|
|
157
156
|
description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
|
|
158
157
|
license: "Apache-2.0",
|
|
159
158
|
repository: {
|
|
@@ -209,6 +208,7 @@ var package_default = {
|
|
|
209
208
|
},
|
|
210
209
|
packageManager: "pnpm@10.12.1",
|
|
211
210
|
dependencies: {
|
|
211
|
+
awaitqueue: "^3.3.0",
|
|
212
212
|
mp4box: "^2.3.0",
|
|
213
213
|
"sdp-transform": "^3.0.0",
|
|
214
214
|
zod: "^4.4.3"
|
|
@@ -224,13 +224,14 @@ var package_default = {
|
|
|
224
224
|
}
|
|
225
225
|
},
|
|
226
226
|
devDependencies: {
|
|
227
|
-
"@roamhq/wrtc": "^0.
|
|
227
|
+
"@roamhq/wrtc": "^0.10.0",
|
|
228
228
|
"@types/node": "^25",
|
|
229
229
|
"@types/react": "^19.2.15",
|
|
230
|
+
"@types/sdp-transform": "^2.15.0",
|
|
230
231
|
"hls.js": "^1.6.0",
|
|
231
|
-
prettier: "^3.
|
|
232
|
+
prettier: "^3.8.4",
|
|
232
233
|
tsup: "^8.5.0",
|
|
233
|
-
typescript: "^
|
|
234
|
+
typescript: "^6.0.3",
|
|
234
235
|
vitest: "^4.1.7"
|
|
235
236
|
}
|
|
236
237
|
};
|
|
@@ -322,8 +323,12 @@ var WebRTCSdpOfferRequestSchema = import_zod.z.object({
|
|
|
322
323
|
client_info: ClientInfoSchema.optional(),
|
|
323
324
|
track_mapping: import_zod.z.array(TrackMappingEntrySchema)
|
|
324
325
|
});
|
|
326
|
+
var WebRTCSdpOfferResponseSchema = import_zod.z.object({
|
|
327
|
+
connection_id: import_zod.z.number().optional()
|
|
328
|
+
});
|
|
325
329
|
var WebRTCSdpAnswerResponseSchema = import_zod.z.object({
|
|
326
|
-
sdp_answer: import_zod.z.string()
|
|
330
|
+
sdp_answer: import_zod.z.string(),
|
|
331
|
+
connection_id: import_zod.z.number().optional()
|
|
327
332
|
});
|
|
328
333
|
var IceCandidateSchema = import_zod.z.object({
|
|
329
334
|
candidate: import_zod.z.string(),
|
|
@@ -851,6 +856,9 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
851
856
|
}
|
|
852
857
|
};
|
|
853
858
|
|
|
859
|
+
// src/core/WebRTCTransportClient.ts
|
|
860
|
+
var import_awaitqueue = require("awaitqueue");
|
|
861
|
+
|
|
854
862
|
// src/utils/sdp.ts
|
|
855
863
|
var import_sdp_transform = require("sdp-transform");
|
|
856
864
|
function sdpLineSeparator(sdp) {
|
|
@@ -901,13 +909,6 @@ function collectSanitizedCodecPayloadSet(media) {
|
|
|
901
909
|
}
|
|
902
910
|
return tracked.size > 0 ? tracked : null;
|
|
903
911
|
}
|
|
904
|
-
function mediaSectionNeedsSanitizedPtRelocate(media) {
|
|
905
|
-
const pts = collectSanitizedCodecPayloadSet(media);
|
|
906
|
-
if (!pts) {
|
|
907
|
-
return false;
|
|
908
|
-
}
|
|
909
|
-
return [...pts].some((p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX);
|
|
910
|
-
}
|
|
911
912
|
function codecRelocationPriority(enc) {
|
|
912
913
|
const u = (enc != null ? enc : "").toUpperCase();
|
|
913
914
|
if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return 0;
|
|
@@ -941,7 +942,7 @@ function computeCodecRemapForMedia(media, forbidden) {
|
|
|
941
942
|
return remap;
|
|
942
943
|
}
|
|
943
944
|
const relocate = [...tracked].filter(
|
|
944
|
-
(p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX
|
|
945
|
+
(p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX || forbidden.has(p)
|
|
945
946
|
);
|
|
946
947
|
if (relocate.length === 0) {
|
|
947
948
|
return remap;
|
|
@@ -1178,7 +1179,7 @@ function stripTelephoneEventsPreserveOrder(sdp) {
|
|
|
1178
1179
|
function transformOfferSdpCodecDynamicPts(sdp) {
|
|
1179
1180
|
var _a;
|
|
1180
1181
|
const session = (0, import_sdp_transform.parse)(sdp);
|
|
1181
|
-
if (!session.media.some(
|
|
1182
|
+
if (!session.media.some((m) => collectSanitizedCodecPayloadSet(m) !== null)) {
|
|
1182
1183
|
return sdp;
|
|
1183
1184
|
}
|
|
1184
1185
|
const remaps = [];
|
|
@@ -1300,6 +1301,26 @@ function parseMessage(data) {
|
|
|
1300
1301
|
}
|
|
1301
1302
|
return data;
|
|
1302
1303
|
}
|
|
1304
|
+
function complementDirection(direction) {
|
|
1305
|
+
if (direction === "sendonly") return "recvonly";
|
|
1306
|
+
if (direction === "recvonly") return "sendonly";
|
|
1307
|
+
return direction;
|
|
1308
|
+
}
|
|
1309
|
+
function replaceSdpDirectionForMid(sdp, mid, direction) {
|
|
1310
|
+
const [session, ...mediaSections] = sdp.split(/(?=\r\nm=)/);
|
|
1311
|
+
const updated = mediaSections.map((section) => {
|
|
1312
|
+
if (!section.includes(`\r
|
|
1313
|
+
a=mid:${mid}\r
|
|
1314
|
+
`)) return section;
|
|
1315
|
+
return section.replace(
|
|
1316
|
+
/\r\na=(sendonly|recvonly|sendrecv|inactive)\r\n/,
|
|
1317
|
+
`\r
|
|
1318
|
+
a=${direction}\r
|
|
1319
|
+
`
|
|
1320
|
+
);
|
|
1321
|
+
});
|
|
1322
|
+
return session + updated.join("");
|
|
1323
|
+
}
|
|
1303
1324
|
function closePeerConnection(pc) {
|
|
1304
1325
|
pc.close();
|
|
1305
1326
|
}
|
|
@@ -1385,6 +1406,8 @@ var INITIAL_BACKOFF_MS = 200;
|
|
|
1385
1406
|
var MAX_BACKOFF_MS = 15e3;
|
|
1386
1407
|
var BACKOFF_MULTIPLIER = 2;
|
|
1387
1408
|
var DEFAULT_MAX_POLL_ATTEMPTS = 6;
|
|
1409
|
+
var MIN_CONNECTION_ID = 1e3;
|
|
1410
|
+
var MAX_CONNECTION_ID = 9999;
|
|
1388
1411
|
var ICE_CANDIDATE_BATCH_WINDOW_MS = 25;
|
|
1389
1412
|
var WebRTCTransportClient = class {
|
|
1390
1413
|
constructor(config) {
|
|
@@ -1392,8 +1415,14 @@ var WebRTCTransportClient = class {
|
|
|
1392
1415
|
this.status = "disconnected";
|
|
1393
1416
|
this.transceiverMap = /* @__PURE__ */ new Map();
|
|
1394
1417
|
this.publishedTracks = /* @__PURE__ */ new Map();
|
|
1418
|
+
// Serializes all SDP renegotiations (pause/resume direction changes) and gates
|
|
1419
|
+
// them behind the connection-ready task. Reset on each prepare() call.
|
|
1420
|
+
this.peerConnectionQueue = new import_awaitqueue.AwaitQueue();
|
|
1421
|
+
this.pendingControlRequests = /* @__PURE__ */ new Map();
|
|
1422
|
+
this.controlRequestCounter = 0;
|
|
1395
1423
|
this.peerConnected = false;
|
|
1396
1424
|
this.dataChannelOpen = false;
|
|
1425
|
+
this.controlChannelOpen = false;
|
|
1397
1426
|
// Trickle ICE batching
|
|
1398
1427
|
this.pendingIceCandidates = [];
|
|
1399
1428
|
var _a, _b;
|
|
@@ -1498,11 +1527,34 @@ var WebRTCTransportClient = class {
|
|
|
1498
1527
|
return iceServers;
|
|
1499
1528
|
});
|
|
1500
1529
|
}
|
|
1501
|
-
|
|
1530
|
+
registerConnection() {
|
|
1502
1531
|
return __async(this, null, function* () {
|
|
1532
|
+
console.debug("[WebRTCTransport] Registering connection...");
|
|
1533
|
+
const response = yield fetch(`${this.transportBaseUrl}/connections`, {
|
|
1534
|
+
method: "POST",
|
|
1535
|
+
headers: yield this.getHeaders(),
|
|
1536
|
+
signal: this.signal
|
|
1537
|
+
});
|
|
1538
|
+
yield this.checkVersionMismatch(response);
|
|
1539
|
+
if (response.status !== 201) {
|
|
1540
|
+
const errorText = yield response.text();
|
|
1541
|
+
throw new Error(
|
|
1542
|
+
`Failed to register connection: ${response.status} ${errorText}`
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
const data = yield response.json();
|
|
1546
|
+
const connectionId = data.connection_id;
|
|
1503
1547
|
console.debug(
|
|
1504
|
-
`[WebRTCTransport]
|
|
1505
|
-
|
|
1548
|
+
`[WebRTCTransport] Connection registered: id=${connectionId}`
|
|
1549
|
+
);
|
|
1550
|
+
return connectionId;
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
sendSdpOffer(connectionId, sdpOffer, trackMapping, reconnect = false) {
|
|
1554
|
+
return __async(this, null, function* () {
|
|
1555
|
+
const method = reconnect ? "PUT" : "POST";
|
|
1556
|
+
console.debug(
|
|
1557
|
+
`[WebRTCTransport] Sending SDP offer (${method}) connection=${connectionId}`
|
|
1506
1558
|
);
|
|
1507
1559
|
const requestBody = {
|
|
1508
1560
|
sdp_offer: sdpOffer,
|
|
@@ -1512,17 +1564,30 @@ var WebRTCTransportClient = class {
|
|
|
1512
1564
|
},
|
|
1513
1565
|
track_mapping: trackMapping
|
|
1514
1566
|
};
|
|
1515
|
-
const response = yield fetch(
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1567
|
+
const response = yield fetch(
|
|
1568
|
+
`${this.transportBaseUrl}/connections/${connectionId}/sdp_params`,
|
|
1569
|
+
{
|
|
1570
|
+
method,
|
|
1571
|
+
headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
|
|
1572
|
+
"Content-Type": "application/json"
|
|
1573
|
+
}),
|
|
1574
|
+
body: JSON.stringify(requestBody),
|
|
1575
|
+
signal: this.signal
|
|
1576
|
+
}
|
|
1577
|
+
);
|
|
1523
1578
|
yield this.checkVersionMismatch(response);
|
|
1524
1579
|
if (response.status !== 202) {
|
|
1525
1580
|
const errorText = yield response.text();
|
|
1581
|
+
if (response.status === 404) {
|
|
1582
|
+
throw new Error(
|
|
1583
|
+
`[WebRTCTransport] Connection ${connectionId} not found or already closed (404). A supplied connectionId must reference a connection registered under this session (POST .../connections) that is still open. ${errorText}`
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
if (response.status === 400) {
|
|
1587
|
+
throw new Error(
|
|
1588
|
+
`[WebRTCTransport] Connection ${connectionId} rejected (400): ${errorText}`
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1526
1591
|
throw new Error(
|
|
1527
1592
|
`Failed to send SDP offer: ${response.status} ${errorText}`
|
|
1528
1593
|
);
|
|
@@ -1532,6 +1597,12 @@ var WebRTCTransportClient = class {
|
|
|
1532
1597
|
}
|
|
1533
1598
|
sendIceCandidates(candidates, is_final) {
|
|
1534
1599
|
return __async(this, null, function* () {
|
|
1600
|
+
if (this.connectionId === void 0) {
|
|
1601
|
+
console.debug(
|
|
1602
|
+
"[WebRTCTransport] ICE candidates dropped: no active connection"
|
|
1603
|
+
);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1535
1606
|
console.debug(
|
|
1536
1607
|
`[WebRTCTransport] Sending ICE candidates (count=${candidates.length}, is_final=${is_final})`
|
|
1537
1608
|
);
|
|
@@ -1543,14 +1614,17 @@ var WebRTCTransportClient = class {
|
|
|
1543
1614
|
sdk_type: REACTOR_SDK_TYPE
|
|
1544
1615
|
}
|
|
1545
1616
|
};
|
|
1546
|
-
const response = yield fetch(
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1617
|
+
const response = yield fetch(
|
|
1618
|
+
`${this.transportBaseUrl}/connections/${this.connectionId}/ice_candidates`,
|
|
1619
|
+
{
|
|
1620
|
+
method: "POST",
|
|
1621
|
+
headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
|
|
1622
|
+
"Content-Type": "application/json"
|
|
1623
|
+
}),
|
|
1624
|
+
body: JSON.stringify(requestBody),
|
|
1625
|
+
signal: this.signal
|
|
1626
|
+
}
|
|
1627
|
+
);
|
|
1554
1628
|
yield this.checkVersionMismatch(response);
|
|
1555
1629
|
if (response.status !== 202) {
|
|
1556
1630
|
const errorText = yield response.text();
|
|
@@ -1559,7 +1633,6 @@ var WebRTCTransportClient = class {
|
|
|
1559
1633
|
);
|
|
1560
1634
|
}
|
|
1561
1635
|
console.debug("[WebRTCTransport] ICE candidates accepted (202)");
|
|
1562
|
-
return;
|
|
1563
1636
|
});
|
|
1564
1637
|
}
|
|
1565
1638
|
/**
|
|
@@ -1594,9 +1667,10 @@ var WebRTCTransportClient = class {
|
|
|
1594
1667
|
}
|
|
1595
1668
|
this.pendingIceCandidates = [];
|
|
1596
1669
|
}
|
|
1597
|
-
pollSdpAnswer() {
|
|
1670
|
+
pollSdpAnswer(connectionId) {
|
|
1598
1671
|
return __async(this, null, function* () {
|
|
1599
1672
|
console.debug("[WebRTCTransport] Polling for SDP answer...");
|
|
1673
|
+
const pollUrl = `${this.transportBaseUrl}/connections/${connectionId}/sdp_params`;
|
|
1600
1674
|
const pollStart = performance.now();
|
|
1601
1675
|
let backoffMs = INITIAL_BACKOFF_MS;
|
|
1602
1676
|
let attempt = 0;
|
|
@@ -1613,7 +1687,7 @@ var WebRTCTransportClient = class {
|
|
|
1613
1687
|
console.debug(
|
|
1614
1688
|
`[WebRTCTransport] SDP poll attempt ${attempt}/${this.maxPollAttempts}`
|
|
1615
1689
|
);
|
|
1616
|
-
const response = yield fetch(
|
|
1690
|
+
const response = yield fetch(pollUrl, {
|
|
1617
1691
|
method: "GET",
|
|
1618
1692
|
headers: yield this.getHeaders(),
|
|
1619
1693
|
signal: this.signal
|
|
@@ -1668,16 +1742,34 @@ var WebRTCTransportClient = class {
|
|
|
1668
1742
|
this.dataChannel.close();
|
|
1669
1743
|
this.dataChannel = void 0;
|
|
1670
1744
|
}
|
|
1745
|
+
if (this.controlChannel) {
|
|
1746
|
+
this.controlChannel.close();
|
|
1747
|
+
this.controlChannel = void 0;
|
|
1748
|
+
}
|
|
1671
1749
|
if (this.peerConnection) {
|
|
1672
1750
|
closePeerConnection(this.peerConnection);
|
|
1673
1751
|
this.peerConnection = void 0;
|
|
1674
1752
|
}
|
|
1675
1753
|
this.peerConnected = false;
|
|
1676
1754
|
this.dataChannelOpen = false;
|
|
1755
|
+
this.controlChannelOpen = false;
|
|
1756
|
+
this.peerConnectionQueue.stop();
|
|
1757
|
+
this.peerConnectionQueue = new import_awaitqueue.AwaitQueue();
|
|
1758
|
+
this.peerConnectionQueue.push(
|
|
1759
|
+
() => new Promise((resolve) => {
|
|
1760
|
+
this.readyGateResolve = resolve;
|
|
1761
|
+
})
|
|
1762
|
+
).catch(() => {
|
|
1763
|
+
});
|
|
1677
1764
|
const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
|
|
1678
1765
|
this.cachedIceServers = void 0;
|
|
1679
1766
|
this.peerConnection = createPeerConnection({ iceServers });
|
|
1680
1767
|
this.setupPeerConnectionHandlers();
|
|
1768
|
+
this.controlChannel = createDataChannel(
|
|
1769
|
+
this.peerConnection,
|
|
1770
|
+
"control"
|
|
1771
|
+
);
|
|
1772
|
+
this.setupControlChannelHandlers();
|
|
1681
1773
|
this.dataChannel = createDataChannel(this.peerConnection);
|
|
1682
1774
|
this.setupDataChannelHandlers();
|
|
1683
1775
|
this.transceiverMap.clear();
|
|
@@ -1700,20 +1792,34 @@ var WebRTCTransportClient = class {
|
|
|
1700
1792
|
console.debug("[WebRTCTransport] SDP offer prepared");
|
|
1701
1793
|
});
|
|
1702
1794
|
}
|
|
1703
|
-
connect(reconnect = false) {
|
|
1795
|
+
connect(reconnect = false, connectionId) {
|
|
1704
1796
|
return __async(this, null, function* () {
|
|
1705
1797
|
if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
|
|
1706
1798
|
throw new Error(
|
|
1707
1799
|
"[WebRTCTransport] No prepared connection. Call prepare() first."
|
|
1708
1800
|
);
|
|
1709
1801
|
}
|
|
1710
|
-
const method = reconnect ? "PUT" : "POST";
|
|
1711
1802
|
const sdpOffer = this.pendingSdpOffer;
|
|
1712
1803
|
const trackMapping = this.pendingTrackMapping;
|
|
1713
1804
|
this.pendingSdpOffer = void 0;
|
|
1714
1805
|
this.pendingTrackMapping = void 0;
|
|
1715
|
-
|
|
1716
|
-
|
|
1806
|
+
if (connectionId !== void 0) {
|
|
1807
|
+
if (!Number.isInteger(connectionId) || connectionId <= MIN_CONNECTION_ID || connectionId > MAX_CONNECTION_ID) {
|
|
1808
|
+
throw new Error(
|
|
1809
|
+
`[WebRTCTransport] Invalid connectionId ${connectionId}: must be an integer in (${MIN_CONNECTION_ID}, ${MAX_CONNECTION_ID}]`
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
this.connectionId = connectionId;
|
|
1813
|
+
} else if (!reconnect || this.connectionId === void 0) {
|
|
1814
|
+
this.connectionId = yield this.registerConnection();
|
|
1815
|
+
}
|
|
1816
|
+
yield this.sendSdpOffer(
|
|
1817
|
+
this.connectionId,
|
|
1818
|
+
sdpOffer,
|
|
1819
|
+
trackMapping,
|
|
1820
|
+
reconnect
|
|
1821
|
+
);
|
|
1822
|
+
const answerResponse = yield this.pollSdpAnswer(this.connectionId);
|
|
1717
1823
|
this.iceStartTime = performance.now();
|
|
1718
1824
|
yield setRemoteDescription(
|
|
1719
1825
|
this.peerConnection,
|
|
@@ -1734,13 +1840,28 @@ var WebRTCTransportClient = class {
|
|
|
1734
1840
|
this.dataChannel.close();
|
|
1735
1841
|
this.dataChannel = void 0;
|
|
1736
1842
|
}
|
|
1843
|
+
if (this.controlChannel) {
|
|
1844
|
+
this.controlChannel.close();
|
|
1845
|
+
this.controlChannel = void 0;
|
|
1846
|
+
}
|
|
1737
1847
|
if (this.peerConnection) {
|
|
1738
1848
|
closePeerConnection(this.peerConnection);
|
|
1739
1849
|
this.peerConnection = void 0;
|
|
1740
1850
|
}
|
|
1851
|
+
for (const [, pending] of this.pendingControlRequests) {
|
|
1852
|
+
clearTimeout(pending.timeout);
|
|
1853
|
+
pending.reject(
|
|
1854
|
+
new Error("[WebRTCTransport] Disconnected while waiting for response")
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
this.pendingControlRequests.clear();
|
|
1858
|
+
this.readyGateResolve = void 0;
|
|
1859
|
+
this.peerConnectionQueue.stop();
|
|
1860
|
+
this.connectionId = void 0;
|
|
1741
1861
|
this.transceiverMap.clear();
|
|
1742
1862
|
this.peerConnected = false;
|
|
1743
1863
|
this.dataChannelOpen = false;
|
|
1864
|
+
this.controlChannelOpen = false;
|
|
1744
1865
|
this.resetTransportTimings();
|
|
1745
1866
|
this.setStatus("disconnected");
|
|
1746
1867
|
console.debug("[WebRTCTransport] Disconnected");
|
|
@@ -1803,6 +1924,119 @@ var WebRTCTransportClient = class {
|
|
|
1803
1924
|
console.warn("[WebRTCTransport] Failed to send message:", error);
|
|
1804
1925
|
}
|
|
1805
1926
|
}
|
|
1927
|
+
sendControlMessage(command, data, reqId) {
|
|
1928
|
+
if (!this.controlChannel) {
|
|
1929
|
+
console.warn("[WebRTCTransport] Control channel not available");
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
try {
|
|
1933
|
+
if (this.controlChannel.readyState !== "open") {
|
|
1934
|
+
throw new Error(
|
|
1935
|
+
`Control channel not open: ${this.controlChannel.readyState}`
|
|
1936
|
+
);
|
|
1937
|
+
}
|
|
1938
|
+
this.controlChannel.send(
|
|
1939
|
+
JSON.stringify({ type: "notification", event: command, data })
|
|
1940
|
+
);
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
console.warn("[WebRTCTransport] Failed to send control message:", error);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
sendControlRequest(method, data, timeoutMs = 1e4) {
|
|
1946
|
+
return new Promise((resolve, reject) => {
|
|
1947
|
+
const requestId = `ctrl_${++this.controlRequestCounter}`;
|
|
1948
|
+
const timeout = setTimeout(() => {
|
|
1949
|
+
this.pendingControlRequests.delete(requestId);
|
|
1950
|
+
reject(new Error(`[WebRTCTransport] Request "${method}" timed out`));
|
|
1951
|
+
}, timeoutMs);
|
|
1952
|
+
this.pendingControlRequests.set(requestId, { resolve, reject, timeout });
|
|
1953
|
+
try {
|
|
1954
|
+
if (!this.controlChannel || this.controlChannel.readyState !== "open") {
|
|
1955
|
+
throw new Error("Control channel not available");
|
|
1956
|
+
}
|
|
1957
|
+
this.controlChannel.send(
|
|
1958
|
+
JSON.stringify({
|
|
1959
|
+
type: "request",
|
|
1960
|
+
method,
|
|
1961
|
+
request_id: requestId,
|
|
1962
|
+
data
|
|
1963
|
+
})
|
|
1964
|
+
);
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
clearTimeout(timeout);
|
|
1967
|
+
this.pendingControlRequests.delete(requestId);
|
|
1968
|
+
reject(error);
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
pauseTrack(name) {
|
|
1973
|
+
this.peerConnectionQueue.push(() => __async(this, null, function* () {
|
|
1974
|
+
var _a;
|
|
1975
|
+
const entry = this.transceiverMap.get(name);
|
|
1976
|
+
if ((_a = entry == null ? void 0 : entry.transceiver) == null ? void 0 : _a.mid) {
|
|
1977
|
+
entry.transceiver.direction = "inactive";
|
|
1978
|
+
yield this.applyDirectionLocally(entry.transceiver.mid, "inactive");
|
|
1979
|
+
}
|
|
1980
|
+
this.sendControlMessage("pause_track", { name });
|
|
1981
|
+
})).catch((e) => {
|
|
1982
|
+
console.warn("[WebRTCTransport] Failed to pause track:", e);
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
resumeTrack(name) {
|
|
1986
|
+
this.peerConnectionQueue.push(() => __async(this, null, function* () {
|
|
1987
|
+
var _a;
|
|
1988
|
+
const entry = this.transceiverMap.get(name);
|
|
1989
|
+
if ((_a = entry == null ? void 0 : entry.transceiver) == null ? void 0 : _a.mid) {
|
|
1990
|
+
entry.transceiver.direction = entry.direction;
|
|
1991
|
+
yield this.applyDirectionLocally(
|
|
1992
|
+
entry.transceiver.mid,
|
|
1993
|
+
entry.direction
|
|
1994
|
+
);
|
|
1995
|
+
}
|
|
1996
|
+
this.sendControlMessage("resume_track", { name });
|
|
1997
|
+
})).catch((e) => {
|
|
1998
|
+
console.warn("[WebRTCTransport] Failed to resume track:", e);
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
applyDirectionLocally(mid, localDirection) {
|
|
2002
|
+
return __async(this, null, function* () {
|
|
2003
|
+
var _a, _b;
|
|
2004
|
+
const pc = this.peerConnection;
|
|
2005
|
+
if (!pc) return;
|
|
2006
|
+
const tx = pc.getTransceivers().find((t) => t.mid === mid);
|
|
2007
|
+
if (tx && tx.currentDirection === localDirection) return;
|
|
2008
|
+
if (pc.signalingState !== "stable") return;
|
|
2009
|
+
const localSdp = (_a = pc.localDescription) == null ? void 0 : _a.sdp;
|
|
2010
|
+
const remoteSdp = (_b = pc.remoteDescription) == null ? void 0 : _b.sdp;
|
|
2011
|
+
if (!localSdp || !remoteSdp) return;
|
|
2012
|
+
const modifiedLocal = replaceSdpDirectionForMid(
|
|
2013
|
+
localSdp,
|
|
2014
|
+
mid,
|
|
2015
|
+
localDirection
|
|
2016
|
+
);
|
|
2017
|
+
const modifiedRemote = replaceSdpDirectionForMid(
|
|
2018
|
+
remoteSdp,
|
|
2019
|
+
mid,
|
|
2020
|
+
complementDirection(localDirection)
|
|
2021
|
+
);
|
|
2022
|
+
try {
|
|
2023
|
+
yield pc.setLocalDescription(
|
|
2024
|
+
new RTCSessionDescription({ type: "offer", sdp: modifiedLocal })
|
|
2025
|
+
);
|
|
2026
|
+
yield pc.setRemoteDescription(
|
|
2027
|
+
new RTCSessionDescription({ type: "answer", sdp: modifiedRemote })
|
|
2028
|
+
);
|
|
2029
|
+
} catch (e) {
|
|
2030
|
+
if (pc.signalingState === "have-local-offer") {
|
|
2031
|
+
try {
|
|
2032
|
+
yield pc.setLocalDescription({ type: "rollback" });
|
|
2033
|
+
} catch (e2) {
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
throw e;
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
1806
2040
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1807
2041
|
// Track Publishing
|
|
1808
2042
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -1829,6 +2063,7 @@ var WebRTCTransportClient = class {
|
|
|
1829
2063
|
`[WebRTCTransport] Cannot publish track "${name}" - transceiver is recvonly`
|
|
1830
2064
|
);
|
|
1831
2065
|
}
|
|
2066
|
+
yield this.sendControlRequest("publish_track", { name });
|
|
1832
2067
|
yield entry.transceiver.sender.replaceTrack(track);
|
|
1833
2068
|
this.publishedTracks.set(name, track);
|
|
1834
2069
|
console.debug(`[WebRTCTransport] Track "${name}" published successfully`);
|
|
@@ -1840,6 +2075,7 @@ var WebRTCTransportClient = class {
|
|
|
1840
2075
|
if (!(entry == null ? void 0 : entry.transceiver) || !this.publishedTracks.has(name)) return;
|
|
1841
2076
|
try {
|
|
1842
2077
|
yield entry.transceiver.sender.replaceTrack(null);
|
|
2078
|
+
this.sendControlMessage("unpublish_track", { name });
|
|
1843
2079
|
console.debug(
|
|
1844
2080
|
`[WebRTCTransport] Track "${name}" unpublished successfully`
|
|
1845
2081
|
);
|
|
@@ -1925,9 +2161,11 @@ var WebRTCTransportClient = class {
|
|
|
1925
2161
|
// Internal Helpers
|
|
1926
2162
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1927
2163
|
checkFullyConnected() {
|
|
1928
|
-
if (this.peerConnected && this.dataChannelOpen) {
|
|
2164
|
+
if (this.peerConnected && this.dataChannelOpen && this.controlChannelOpen) {
|
|
1929
2165
|
this.setStatus("connected");
|
|
1930
2166
|
this.startStatsPolling();
|
|
2167
|
+
this.readyGateResolve();
|
|
2168
|
+
this.readyGateResolve = void 0;
|
|
1931
2169
|
}
|
|
1932
2170
|
}
|
|
1933
2171
|
setStatus(newStatus) {
|
|
@@ -2047,6 +2285,46 @@ var WebRTCTransportClient = class {
|
|
|
2047
2285
|
}
|
|
2048
2286
|
};
|
|
2049
2287
|
}
|
|
2288
|
+
setupControlChannelHandlers() {
|
|
2289
|
+
if (!this.controlChannel) return;
|
|
2290
|
+
this.controlChannel.onopen = () => {
|
|
2291
|
+
console.debug("[WebRTCTransport] Control channel open");
|
|
2292
|
+
this.controlChannelOpen = true;
|
|
2293
|
+
this.checkFullyConnected();
|
|
2294
|
+
};
|
|
2295
|
+
this.controlChannel.onclose = () => {
|
|
2296
|
+
console.debug("[WebRTCTransport] Control channel closed");
|
|
2297
|
+
this.controlChannelOpen = false;
|
|
2298
|
+
};
|
|
2299
|
+
this.controlChannel.onerror = (error) => {
|
|
2300
|
+
console.error("[WebRTCTransport] Control channel error:", error);
|
|
2301
|
+
};
|
|
2302
|
+
this.controlChannel.onmessage = (event) => {
|
|
2303
|
+
var _a, _b;
|
|
2304
|
+
const raw = parseMessage(event.data);
|
|
2305
|
+
if ((raw == null ? void 0 : raw.type) === "response") {
|
|
2306
|
+
const requestId = raw == null ? void 0 : raw.request_id;
|
|
2307
|
+
if (requestId) {
|
|
2308
|
+
const pending = this.pendingControlRequests.get(requestId);
|
|
2309
|
+
if (pending) {
|
|
2310
|
+
clearTimeout(pending.timeout);
|
|
2311
|
+
this.pendingControlRequests.delete(requestId);
|
|
2312
|
+
if (raw == null ? void 0 : raw.error) {
|
|
2313
|
+
pending.reject(
|
|
2314
|
+
new Error(
|
|
2315
|
+
`[WebRTCTransport] ${(_a = raw.method) != null ? _a : "request"} failed: ${(_b = raw.error.message) != null ? _b : "unknown error"}`
|
|
2316
|
+
)
|
|
2317
|
+
);
|
|
2318
|
+
} else {
|
|
2319
|
+
pending.resolve();
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
console.debug("[WebRTCTransport] Received control message:", raw);
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2050
2328
|
};
|
|
2051
2329
|
|
|
2052
2330
|
// src/core/Reactor.ts
|
|
@@ -2730,7 +3008,17 @@ var OptionsSchema = import_zod3.z.object({
|
|
|
2730
3008
|
var Reactor = class {
|
|
2731
3009
|
constructor(options) {
|
|
2732
3010
|
this.status = "disconnected";
|
|
3011
|
+
/**
|
|
3012
|
+
* True only when the active session was created by THIS connect flow
|
|
3013
|
+
* (via `createSession()`). False when the session was adopted via
|
|
3014
|
+
* `connect({ sessionId })`. We must never DELETE a session we did not
|
|
3015
|
+
* create — another client (or the backend that created it) owns its
|
|
3016
|
+
* lifecycle, so on disconnect/teardown/error an adopting client tears
|
|
3017
|
+
* down its own transport but leaves the session alive.
|
|
3018
|
+
*/
|
|
3019
|
+
this.createdSession = false;
|
|
2733
3020
|
this.tracks = [];
|
|
3021
|
+
this.autoResumeTracks = false;
|
|
2734
3022
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
2735
3023
|
const validatedOptions = OptionsSchema.parse(options);
|
|
2736
3024
|
this.coordinatorUrl = validatedOptions.apiUrl;
|
|
@@ -2967,6 +3255,7 @@ var Reactor = class {
|
|
|
2967
3255
|
"gpu",
|
|
2968
3256
|
true
|
|
2969
3257
|
);
|
|
3258
|
+
throw error;
|
|
2970
3259
|
}
|
|
2971
3260
|
});
|
|
2972
3261
|
}
|
|
@@ -2986,6 +3275,14 @@ var Reactor = class {
|
|
|
2986
3275
|
}
|
|
2987
3276
|
});
|
|
2988
3277
|
}
|
|
3278
|
+
pauseTrack(name) {
|
|
3279
|
+
var _a;
|
|
3280
|
+
(_a = this.transportClient) == null ? void 0 : _a.pauseTrack(name);
|
|
3281
|
+
}
|
|
3282
|
+
resumeTrack(name) {
|
|
3283
|
+
var _a;
|
|
3284
|
+
(_a = this.transportClient) == null ? void 0 : _a.resumeTrack(name);
|
|
3285
|
+
}
|
|
2989
3286
|
/**
|
|
2990
3287
|
* Reconnects to an existing session with a fresh transport.
|
|
2991
3288
|
*/
|
|
@@ -3044,6 +3341,7 @@ var Reactor = class {
|
|
|
3044
3341
|
*/
|
|
3045
3342
|
connect(jwtToken, options) {
|
|
3046
3343
|
return __async(this, null, function* () {
|
|
3344
|
+
var _a;
|
|
3047
3345
|
console.debug("[Reactor] Connecting, status:", this.status);
|
|
3048
3346
|
if (jwtToken == void 0 && !this.local) {
|
|
3049
3347
|
throw new Error("No authentication provided and not in local mode");
|
|
@@ -3067,12 +3365,14 @@ var Reactor = class {
|
|
|
3067
3365
|
if (options == null ? void 0 : options.sessionId) {
|
|
3068
3366
|
yield this.coordinatorClient.adoptSession(options.sessionId);
|
|
3069
3367
|
sessionId = options.sessionId;
|
|
3368
|
+
this.createdSession = false;
|
|
3070
3369
|
console.debug("[Reactor] Attaching to existing session:", sessionId);
|
|
3071
3370
|
} else {
|
|
3072
3371
|
const tSession = performance.now();
|
|
3073
3372
|
const initialResponse = yield this.coordinatorClient.createSession();
|
|
3074
3373
|
sessionCreationMs = performance.now() - tSession;
|
|
3075
3374
|
sessionId = initialResponse.session_id;
|
|
3375
|
+
this.createdSession = true;
|
|
3076
3376
|
console.debug(
|
|
3077
3377
|
"[Reactor] Session created:",
|
|
3078
3378
|
sessionId,
|
|
@@ -3092,19 +3392,18 @@ var Reactor = class {
|
|
|
3092
3392
|
this.setupTransportHandlers();
|
|
3093
3393
|
let sessionPollingMs;
|
|
3094
3394
|
let transportConnectingMs;
|
|
3395
|
+
this.autoResumeTracks = (_a = options == null ? void 0 : options.autoResumeTracks) != null ? _a : true;
|
|
3095
3396
|
if (this.presetTracks) {
|
|
3397
|
+
this.tracks = this.presetTracks;
|
|
3096
3398
|
const tParallel = performance.now();
|
|
3097
3399
|
const [sessionResponse] = yield Promise.all([
|
|
3098
3400
|
this.coordinatorClient.pollSessionReady(),
|
|
3099
|
-
this.transportClient.prepare(this.
|
|
3401
|
+
this.transportClient.prepare(this.tracks)
|
|
3100
3402
|
]);
|
|
3101
3403
|
sessionPollingMs = performance.now() - tParallel;
|
|
3102
3404
|
this.sessionResponse = sessionResponse;
|
|
3103
|
-
this.capabilities = sessionResponse.capabilities;
|
|
3104
|
-
this.tracks = this.presetTracks;
|
|
3105
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
3106
3405
|
const tConnect = performance.now();
|
|
3107
|
-
yield this.transportClient.connect();
|
|
3406
|
+
yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
|
|
3108
3407
|
transportConnectingMs = performance.now() - tConnect;
|
|
3109
3408
|
} else {
|
|
3110
3409
|
this.transportClient.warmup();
|
|
@@ -3112,16 +3411,14 @@ var Reactor = class {
|
|
|
3112
3411
|
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
3113
3412
|
sessionPollingMs = performance.now() - tPoll;
|
|
3114
3413
|
this.sessionResponse = sessionResponse;
|
|
3115
|
-
this.capabilities = sessionResponse.capabilities;
|
|
3116
3414
|
this.tracks = sessionResponse.capabilities.tracks;
|
|
3117
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
3118
3415
|
const protocol = sessionResponse.selected_transport.protocol;
|
|
3119
3416
|
if (protocol !== "webrtc") {
|
|
3120
3417
|
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
3121
3418
|
}
|
|
3122
3419
|
const tTransport = performance.now();
|
|
3123
3420
|
yield this.transportClient.prepare(this.tracks);
|
|
3124
|
-
yield this.transportClient.connect();
|
|
3421
|
+
yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
|
|
3125
3422
|
transportConnectingMs = performance.now() - tTransport;
|
|
3126
3423
|
}
|
|
3127
3424
|
console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
|
|
@@ -3163,6 +3460,10 @@ var Reactor = class {
|
|
|
3163
3460
|
if (scope === "application") {
|
|
3164
3461
|
this.emit("message", message);
|
|
3165
3462
|
} else if (scope === "runtime") {
|
|
3463
|
+
if (message && typeof message === "object" && message.type === "modelSchema" && message.data) {
|
|
3464
|
+
this.schema = message.data;
|
|
3465
|
+
this.emit("schemaReceived", this.schema);
|
|
3466
|
+
}
|
|
3166
3467
|
this.emit("runtimeMessage", message);
|
|
3167
3468
|
}
|
|
3168
3469
|
});
|
|
@@ -3171,7 +3472,15 @@ var Reactor = class {
|
|
|
3171
3472
|
switch (status) {
|
|
3172
3473
|
case "connected":
|
|
3173
3474
|
this.finalizeConnectionTimings();
|
|
3475
|
+
if (this.autoResumeTracks) {
|
|
3476
|
+
for (const track of this.tracks) {
|
|
3477
|
+
if (track.direction === "recvonly") {
|
|
3478
|
+
this.resumeTrack(track.name);
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3174
3482
|
this.setStatus("ready");
|
|
3483
|
+
void this.sendCommand("requestSchema", {}, "runtime");
|
|
3175
3484
|
break;
|
|
3176
3485
|
case "disconnected":
|
|
3177
3486
|
this.disconnect(true);
|
|
@@ -3192,6 +3501,13 @@ var Reactor = class {
|
|
|
3192
3501
|
(name, track, stream) => {
|
|
3193
3502
|
if (this.transportClient !== client) return;
|
|
3194
3503
|
this.emit("trackReceived", name, track, stream);
|
|
3504
|
+
if (this.autoResumeTracks) {
|
|
3505
|
+
for (const track2 of this.tracks) {
|
|
3506
|
+
if (track2.direction === "recvonly") {
|
|
3507
|
+
this.resumeTrack(track2.name);
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3195
3511
|
}
|
|
3196
3512
|
);
|
|
3197
3513
|
client.on("statsUpdate", (stats) => {
|
|
@@ -3214,10 +3530,16 @@ var Reactor = class {
|
|
|
3214
3530
|
(_a = this.coordinatorClient) == null ? void 0 : _a.abort();
|
|
3215
3531
|
(_b = this.transportClient) == null ? void 0 : _b.abort();
|
|
3216
3532
|
if (this.coordinatorClient && !recoverable) {
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3533
|
+
if (this.createdSession) {
|
|
3534
|
+
try {
|
|
3535
|
+
yield this.coordinatorClient.terminateSession();
|
|
3536
|
+
} catch (error) {
|
|
3537
|
+
console.error("[Reactor] Error terminating session:", error);
|
|
3538
|
+
}
|
|
3539
|
+
} else {
|
|
3540
|
+
console.debug(
|
|
3541
|
+
"[Reactor] Adopted session (not the creator) \u2014 skipping DELETE, leaving it alive"
|
|
3542
|
+
);
|
|
3221
3543
|
}
|
|
3222
3544
|
this.coordinatorClient = void 0;
|
|
3223
3545
|
}
|
|
@@ -3236,9 +3558,10 @@ var Reactor = class {
|
|
|
3236
3558
|
if (!recoverable) {
|
|
3237
3559
|
this.setSessionExpiration(void 0);
|
|
3238
3560
|
this.setSessionId(void 0);
|
|
3239
|
-
this.
|
|
3561
|
+
this.schema = void 0;
|
|
3240
3562
|
this.tracks = [];
|
|
3241
3563
|
this.sessionResponse = void 0;
|
|
3564
|
+
this.createdSession = false;
|
|
3242
3565
|
}
|
|
3243
3566
|
});
|
|
3244
3567
|
}
|
|
@@ -3260,8 +3583,13 @@ var Reactor = class {
|
|
|
3260
3583
|
getLastError() {
|
|
3261
3584
|
return this.lastError;
|
|
3262
3585
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3586
|
+
/**
|
|
3587
|
+
* The model's OpenAPI schema (events, outbound messages, tracks),
|
|
3588
|
+
* received over the runtime channel shortly after the session becomes
|
|
3589
|
+
* ready. `undefined` until the `schemaReceived` event has fired.
|
|
3590
|
+
*/
|
|
3591
|
+
getSchema() {
|
|
3592
|
+
return this.schema;
|
|
3265
3593
|
}
|
|
3266
3594
|
getSessionInfo() {
|
|
3267
3595
|
return this.sessionResponse;
|
|
@@ -3272,6 +3600,10 @@ var Reactor = class {
|
|
|
3272
3600
|
if (!stats) return void 0;
|
|
3273
3601
|
return __spreadProps(__spreadValues({}, stats), { connectionTimings: this.connectionTimings });
|
|
3274
3602
|
}
|
|
3603
|
+
/** Timing breakdown from the most recent connect() handshake. */
|
|
3604
|
+
getConnectionTimings() {
|
|
3605
|
+
return this.connectionTimings;
|
|
3606
|
+
}
|
|
3275
3607
|
// ─────────────────────────────────────────────────────────────────────────
|
|
3276
3608
|
// Private State Management
|
|
3277
3609
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -3342,7 +3674,8 @@ var defaultInitState = {
|
|
|
3342
3674
|
lastError: void 0,
|
|
3343
3675
|
sessionExpiration: void 0,
|
|
3344
3676
|
jwtToken: void 0,
|
|
3345
|
-
sessionId: void 0
|
|
3677
|
+
sessionId: void 0,
|
|
3678
|
+
connectOptions: void 0
|
|
3346
3679
|
};
|
|
3347
3680
|
var initReactorStore = (props) => {
|
|
3348
3681
|
return __spreadValues(__spreadValues({}, defaultInitState), props);
|
|
@@ -3398,6 +3731,7 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3398
3731
|
});
|
|
3399
3732
|
return __spreadProps(__spreadValues({}, publicState), {
|
|
3400
3733
|
jwtToken: initProps.jwtToken,
|
|
3734
|
+
connectOptions: initProps.connectOptions,
|
|
3401
3735
|
internal: { reactor },
|
|
3402
3736
|
// actions
|
|
3403
3737
|
onMessage: (handler) => {
|
|
@@ -3426,9 +3760,10 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3426
3760
|
if (jwtToken === void 0) {
|
|
3427
3761
|
jwtToken = get().jwtToken;
|
|
3428
3762
|
}
|
|
3763
|
+
const resolvedOptions = __spreadValues(__spreadValues({}, get().connectOptions), options);
|
|
3429
3764
|
console.debug("[ReactorStore] Connect called.");
|
|
3430
3765
|
try {
|
|
3431
|
-
yield get().internal.reactor.connect(jwtToken,
|
|
3766
|
+
yield get().internal.reactor.connect(jwtToken, resolvedOptions);
|
|
3432
3767
|
console.debug("[ReactorStore] Connect completed successfully");
|
|
3433
3768
|
} catch (error) {
|
|
3434
3769
|
console.error("[ReactorStore] Connect failed:", error);
|
|
@@ -3477,6 +3812,8 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3477
3812
|
throw error;
|
|
3478
3813
|
}
|
|
3479
3814
|
}),
|
|
3815
|
+
pauseTrack: (name) => get().internal.reactor.pauseTrack(name),
|
|
3816
|
+
resumeTrack: (name) => get().internal.reactor.resumeTrack(name),
|
|
3480
3817
|
reconnect: (options) => __async(null, null, function* () {
|
|
3481
3818
|
console.debug("[ReactorStore] Reconnecting");
|
|
3482
3819
|
try {
|
|
@@ -3536,30 +3873,31 @@ function ReactorProvider(_a) {
|
|
|
3536
3873
|
const storeRef = (0, import_react3.useRef)(void 0);
|
|
3537
3874
|
const firstRender = (0, import_react3.useRef)(true);
|
|
3538
3875
|
const [_storeVersion, setStoreVersion] = (0, import_react3.useState)(0);
|
|
3876
|
+
const _a2 = connectOptions != null ? connectOptions : {}, { autoConnect = false } = _a2, pollingOptions = __objRest(_a2, ["autoConnect"]);
|
|
3539
3877
|
if (storeRef.current === void 0) {
|
|
3540
3878
|
console.debug("[ReactorProvider] Creating new reactor store");
|
|
3541
3879
|
storeRef.current = createReactorStore(
|
|
3542
3880
|
initReactorStore(__spreadProps(__spreadValues({}, props), {
|
|
3543
|
-
jwtToken: jwtSource
|
|
3881
|
+
jwtToken: jwtSource,
|
|
3882
|
+
connectOptions: pollingOptions
|
|
3544
3883
|
}))
|
|
3545
3884
|
);
|
|
3546
3885
|
console.debug("[ReactorProvider] Reactor store created successfully");
|
|
3547
3886
|
}
|
|
3548
|
-
const _a2 = connectOptions != null ? connectOptions : {}, { autoConnect = false } = _a2, pollingOptions = __objRest(_a2, ["autoConnect"]);
|
|
3549
3887
|
const { apiUrl, modelName, local } = props;
|
|
3550
3888
|
const maxAttempts = pollingOptions.maxAttempts;
|
|
3889
|
+
const { autoResumeTracks } = pollingOptions;
|
|
3890
|
+
(0, import_react3.useEffect)(() => {
|
|
3891
|
+
var _a3;
|
|
3892
|
+
(_a3 = storeRef.current) == null ? void 0 : _a3.setState({ connectOptions: pollingOptions });
|
|
3893
|
+
}, [autoResumeTracks, maxAttempts]);
|
|
3551
3894
|
(0, import_react3.useEffect)(() => {
|
|
3552
3895
|
const handleBeforeUnload = () => {
|
|
3553
3896
|
var _a3;
|
|
3554
|
-
console.debug(
|
|
3555
|
-
"[ReactorProvider] Page unloading, performing non-recoverable disconnect"
|
|
3556
|
-
);
|
|
3557
3897
|
(_a3 = storeRef.current) == null ? void 0 : _a3.getState().internal.reactor.disconnect(false);
|
|
3558
3898
|
};
|
|
3559
3899
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
3560
|
-
return () =>
|
|
3561
|
-
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
3562
|
-
};
|
|
3900
|
+
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
3563
3901
|
}, []);
|
|
3564
3902
|
(0, import_react3.useEffect)(() => {
|
|
3565
3903
|
if (firstRender.current) {
|
|
@@ -3602,7 +3940,8 @@ function ReactorProvider(_a) {
|
|
|
3602
3940
|
apiUrl,
|
|
3603
3941
|
modelName,
|
|
3604
3942
|
local,
|
|
3605
|
-
jwtToken: jwtSource
|
|
3943
|
+
jwtToken: jwtSource,
|
|
3944
|
+
connectOptions: pollingOptions
|
|
3606
3945
|
})
|
|
3607
3946
|
);
|
|
3608
3947
|
const current = storeRef.current;
|
|
@@ -3728,26 +4067,39 @@ function ReactorView({
|
|
|
3728
4067
|
hasVideoTrack: !!videoMediaTrack,
|
|
3729
4068
|
hasAudioTrack: !!audioMediaTrack
|
|
3730
4069
|
});
|
|
3731
|
-
|
|
3732
|
-
|
|
4070
|
+
const el = videoRef.current;
|
|
4071
|
+
if (!el || !mediaStream) {
|
|
4072
|
+
console.debug("[ReactorView] No tracks or element to attach");
|
|
4073
|
+
return;
|
|
4074
|
+
}
|
|
4075
|
+
const attach = (reset) => {
|
|
3733
4076
|
try {
|
|
3734
|
-
|
|
3735
|
-
|
|
4077
|
+
if (reset) el.srcObject = null;
|
|
4078
|
+
el.srcObject = mediaStream;
|
|
4079
|
+
el.play().catch((e) => {
|
|
3736
4080
|
console.warn("[ReactorView] Auto-play failed:", e);
|
|
3737
4081
|
});
|
|
3738
|
-
console.debug("[ReactorView] Media stream attached successfully");
|
|
3739
4082
|
} catch (error) {
|
|
3740
4083
|
console.error("[ReactorView] Failed to attach media stream:", error);
|
|
3741
4084
|
}
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
}
|
|
4085
|
+
};
|
|
4086
|
+
console.debug("[ReactorView] Attaching media stream to element");
|
|
4087
|
+
attach(false);
|
|
4088
|
+
const onUnmute = () => {
|
|
4089
|
+
console.debug(
|
|
4090
|
+
"[ReactorView] Track unmuted \u2014 re-attaching to render incoming media"
|
|
4091
|
+
);
|
|
4092
|
+
attach(true);
|
|
4093
|
+
};
|
|
4094
|
+
const tracks = mediaStream.getTracks();
|
|
4095
|
+
for (const t of tracks) t.addEventListener("unmute", onUnmute);
|
|
4096
|
+
return () => {
|
|
4097
|
+
console.debug("[ReactorView] Detaching media stream from element");
|
|
4098
|
+
for (const t of tracks) t.removeEventListener("unmute", onUnmute);
|
|
4099
|
+
if (videoRef.current) {
|
|
4100
|
+
videoRef.current.srcObject = null;
|
|
4101
|
+
}
|
|
4102
|
+
};
|
|
3751
4103
|
}, [mediaStream]);
|
|
3752
4104
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3753
4105
|
"div",
|
|
@@ -3775,576 +4127,9 @@ function ReactorView({
|
|
|
3775
4127
|
);
|
|
3776
4128
|
}
|
|
3777
4129
|
|
|
3778
|
-
// src/react/ReactorController.tsx
|
|
3779
|
-
var import_react6 = __toESM(require("react"));
|
|
3780
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3781
|
-
function isFileParam(ps) {
|
|
3782
|
-
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
3783
|
-
}
|
|
3784
|
-
function ReactorController({
|
|
3785
|
-
className,
|
|
3786
|
-
style
|
|
3787
|
-
}) {
|
|
3788
|
-
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
3789
|
-
sendCommand: state.sendCommand,
|
|
3790
|
-
uploadFile: state.uploadFile,
|
|
3791
|
-
status: state.status
|
|
3792
|
-
}));
|
|
3793
|
-
const [commands, setCommands] = (0, import_react6.useState)({});
|
|
3794
|
-
const [formValues, setFormValues] = (0, import_react6.useState)({});
|
|
3795
|
-
const formRef = (0, import_react6.useRef)(formValues);
|
|
3796
|
-
formRef.current = formValues;
|
|
3797
|
-
const [expandedCommands, setExpandedCommands] = (0, import_react6.useState)({});
|
|
3798
|
-
import_react6.default.useEffect(() => {
|
|
3799
|
-
if (status === "disconnected") {
|
|
3800
|
-
setCommands({});
|
|
3801
|
-
setFormValues({});
|
|
3802
|
-
setExpandedCommands({});
|
|
3803
|
-
}
|
|
3804
|
-
}, [status]);
|
|
3805
|
-
const requestCapabilities = (0, import_react6.useCallback)(() => {
|
|
3806
|
-
if (status === "ready") {
|
|
3807
|
-
sendCommand("requestCapabilities", {}, "runtime");
|
|
3808
|
-
}
|
|
3809
|
-
}, [status, sendCommand]);
|
|
3810
|
-
import_react6.default.useEffect(() => {
|
|
3811
|
-
if (status === "ready") {
|
|
3812
|
-
requestCapabilities();
|
|
3813
|
-
}
|
|
3814
|
-
}, [status, requestCapabilities]);
|
|
3815
|
-
import_react6.default.useEffect(() => {
|
|
3816
|
-
if (status !== "ready" || Object.keys(commands).length > 0) {
|
|
3817
|
-
return;
|
|
3818
|
-
}
|
|
3819
|
-
const interval = setInterval(() => {
|
|
3820
|
-
requestCapabilities();
|
|
3821
|
-
}, 5e3);
|
|
3822
|
-
return () => clearInterval(interval);
|
|
3823
|
-
}, [status, commands, requestCapabilities]);
|
|
3824
|
-
useReactorInternalMessage((message) => {
|
|
3825
|
-
var _a;
|
|
3826
|
-
if (message && typeof message === "object" && message.type === "modelCapabilities" && message.data && "commands" in message.data) {
|
|
3827
|
-
const commandsMessage = message.data;
|
|
3828
|
-
const commandsRecord = {};
|
|
3829
|
-
for (const cmd of commandsMessage.commands) {
|
|
3830
|
-
commandsRecord[cmd.name] = {
|
|
3831
|
-
description: cmd.description,
|
|
3832
|
-
schema: (_a = cmd.schema) != null ? _a : {}
|
|
3833
|
-
};
|
|
3834
|
-
}
|
|
3835
|
-
setCommands(commandsRecord);
|
|
3836
|
-
const initialValues = {};
|
|
3837
|
-
const initialExpanded = {};
|
|
3838
|
-
Object.entries(commandsRecord).forEach(([commandName, commandSchema]) => {
|
|
3839
|
-
initialValues[commandName] = {};
|
|
3840
|
-
initialExpanded[commandName] = false;
|
|
3841
|
-
Object.entries(commandSchema.schema).forEach(
|
|
3842
|
-
([paramName, paramSchema]) => {
|
|
3843
|
-
var _a2;
|
|
3844
|
-
if (isFileParam(paramSchema)) {
|
|
3845
|
-
initialValues[commandName][paramName] = null;
|
|
3846
|
-
} else if (paramSchema.default !== void 0) {
|
|
3847
|
-
initialValues[commandName][paramName] = paramSchema.default;
|
|
3848
|
-
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
3849
|
-
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
3850
|
-
} else if (paramSchema.type === "string") {
|
|
3851
|
-
initialValues[commandName][paramName] = "";
|
|
3852
|
-
} else if (paramSchema.type === "boolean") {
|
|
3853
|
-
initialValues[commandName][paramName] = false;
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
);
|
|
3857
|
-
});
|
|
3858
|
-
setFormValues(initialValues);
|
|
3859
|
-
setExpandedCommands(initialExpanded);
|
|
3860
|
-
}
|
|
3861
|
-
});
|
|
3862
|
-
const handleInputChange = (0, import_react6.useCallback)(
|
|
3863
|
-
(commandName, paramName, value) => {
|
|
3864
|
-
setFormValues((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
3865
|
-
[commandName]: __spreadProps(__spreadValues({}, prev[commandName]), {
|
|
3866
|
-
[paramName]: value
|
|
3867
|
-
})
|
|
3868
|
-
}));
|
|
3869
|
-
},
|
|
3870
|
-
[]
|
|
3871
|
-
);
|
|
3872
|
-
const toggleCommandExpanded = (0, import_react6.useCallback)((commandName) => {
|
|
3873
|
-
setExpandedCommands((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
3874
|
-
[commandName]: !prev[commandName]
|
|
3875
|
-
}));
|
|
3876
|
-
}, []);
|
|
3877
|
-
const handleCommandSubmit = (0, import_react6.useCallback)(
|
|
3878
|
-
(commandName) => __async(null, null, function* () {
|
|
3879
|
-
const commandSchema = commands[commandName];
|
|
3880
|
-
const formData = formRef.current[commandName] || {};
|
|
3881
|
-
const data = {};
|
|
3882
|
-
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
3883
|
-
var _a;
|
|
3884
|
-
const paramSchema = commandSchema.schema[paramName];
|
|
3885
|
-
let value = formData[paramName];
|
|
3886
|
-
if (value instanceof FileRef) {
|
|
3887
|
-
data[paramName] = value;
|
|
3888
|
-
return;
|
|
3889
|
-
}
|
|
3890
|
-
if (paramSchema.type === "number" && typeof value === "string") {
|
|
3891
|
-
value = parseFloat(value) || 0;
|
|
3892
|
-
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
3893
|
-
value = parseInt(value) || 0;
|
|
3894
|
-
} else if (paramSchema.type === "boolean" && typeof value !== "boolean") {
|
|
3895
|
-
value = Boolean(value);
|
|
3896
|
-
}
|
|
3897
|
-
if (value !== void 0 && value !== "" && value !== null) {
|
|
3898
|
-
data[paramName] = value;
|
|
3899
|
-
} else if (paramSchema.required) {
|
|
3900
|
-
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
3901
|
-
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
3902
|
-
} else if (paramSchema.type === "string") {
|
|
3903
|
-
data[paramName] = "";
|
|
3904
|
-
} else if (paramSchema.type === "boolean") {
|
|
3905
|
-
data[paramName] = false;
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
|
-
});
|
|
3909
|
-
yield sendCommand(commandName, data);
|
|
3910
|
-
}),
|
|
3911
|
-
[sendCommand, commands]
|
|
3912
|
-
);
|
|
3913
|
-
const renderInput = (commandName, paramName, paramSchema) => {
|
|
3914
|
-
var _a, _b;
|
|
3915
|
-
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
3916
|
-
if (isFileParam(paramSchema)) {
|
|
3917
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
3918
|
-
FileParamInput,
|
|
3919
|
-
{
|
|
3920
|
-
commandName,
|
|
3921
|
-
paramName,
|
|
3922
|
-
description: paramSchema.description,
|
|
3923
|
-
value,
|
|
3924
|
-
onChange: handleInputChange,
|
|
3925
|
-
disabled: status !== "ready",
|
|
3926
|
-
uploadFile
|
|
3927
|
-
},
|
|
3928
|
-
`${commandName}-${paramName}`
|
|
3929
|
-
);
|
|
3930
|
-
}
|
|
3931
|
-
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
3932
|
-
const isInteger = paramSchema.type === "integer";
|
|
3933
|
-
const step = isInteger ? 1 : 0.1;
|
|
3934
|
-
const parseValue = isInteger ? parseInt : parseFloat;
|
|
3935
|
-
if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
|
|
3936
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
3937
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
3938
|
-
"label",
|
|
3939
|
-
{
|
|
3940
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
3941
|
-
children: [
|
|
3942
|
-
paramName,
|
|
3943
|
-
" (",
|
|
3944
|
-
paramSchema.minimum,
|
|
3945
|
-
" - ",
|
|
3946
|
-
paramSchema.maximum,
|
|
3947
|
-
")",
|
|
3948
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
3949
|
-
paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
|
|
3950
|
-
]
|
|
3951
|
-
}
|
|
3952
|
-
),
|
|
3953
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
3954
|
-
"input",
|
|
3955
|
-
{
|
|
3956
|
-
type: "range",
|
|
3957
|
-
min: paramSchema.minimum,
|
|
3958
|
-
max: paramSchema.maximum,
|
|
3959
|
-
step,
|
|
3960
|
-
value,
|
|
3961
|
-
onChange: (e) => {
|
|
3962
|
-
const newValue = parseValue(e.target.value) || 0;
|
|
3963
|
-
handleInputChange(commandName, paramName, newValue);
|
|
3964
|
-
handleCommandSubmit(commandName);
|
|
3965
|
-
},
|
|
3966
|
-
style: { width: "100%", marginBottom: "4px" }
|
|
3967
|
-
}
|
|
3968
|
-
),
|
|
3969
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { fontSize: "11px", color: "#888" }, children: [
|
|
3970
|
-
"Value: ",
|
|
3971
|
-
value
|
|
3972
|
-
] })
|
|
3973
|
-
] });
|
|
3974
|
-
} else {
|
|
3975
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
3976
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
3977
|
-
"label",
|
|
3978
|
-
{
|
|
3979
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
3980
|
-
children: [
|
|
3981
|
-
paramName,
|
|
3982
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
3983
|
-
paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
|
|
3984
|
-
]
|
|
3985
|
-
}
|
|
3986
|
-
),
|
|
3987
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
3988
|
-
"input",
|
|
3989
|
-
{
|
|
3990
|
-
type: "number",
|
|
3991
|
-
value,
|
|
3992
|
-
min: paramSchema.minimum,
|
|
3993
|
-
max: paramSchema.maximum,
|
|
3994
|
-
step,
|
|
3995
|
-
inputMode: "numeric",
|
|
3996
|
-
onChange: (e) => {
|
|
3997
|
-
const val = e.target.value;
|
|
3998
|
-
if (val === "" || val === "-") {
|
|
3999
|
-
handleInputChange(commandName, paramName, val);
|
|
4000
|
-
} else {
|
|
4001
|
-
const parsed = parseValue(val);
|
|
4002
|
-
if (!isNaN(parsed)) {
|
|
4003
|
-
handleInputChange(commandName, paramName, parsed);
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
},
|
|
4007
|
-
onBlur: (e) => {
|
|
4008
|
-
const val = e.target.value;
|
|
4009
|
-
if (val === "" || val === "-") {
|
|
4010
|
-
handleInputChange(commandName, paramName, 0);
|
|
4011
|
-
}
|
|
4012
|
-
},
|
|
4013
|
-
style: {
|
|
4014
|
-
width: "100%",
|
|
4015
|
-
padding: "4px",
|
|
4016
|
-
fontSize: "12px",
|
|
4017
|
-
border: "1px solid #ccc",
|
|
4018
|
-
borderRadius: "2px"
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
)
|
|
4022
|
-
] });
|
|
4023
|
-
}
|
|
4024
|
-
} else if (paramSchema.type === "string") {
|
|
4025
|
-
if (paramSchema.enum) {
|
|
4026
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
4027
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4028
|
-
"label",
|
|
4029
|
-
{
|
|
4030
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4031
|
-
children: [
|
|
4032
|
-
paramName,
|
|
4033
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4034
|
-
paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
|
|
4035
|
-
]
|
|
4036
|
-
}
|
|
4037
|
-
),
|
|
4038
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4039
|
-
"select",
|
|
4040
|
-
{
|
|
4041
|
-
value,
|
|
4042
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
|
|
4043
|
-
style: {
|
|
4044
|
-
width: "100%",
|
|
4045
|
-
padding: "4px",
|
|
4046
|
-
fontSize: "12px",
|
|
4047
|
-
border: "1px solid #ccc",
|
|
4048
|
-
borderRadius: "2px"
|
|
4049
|
-
},
|
|
4050
|
-
children: [
|
|
4051
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "Select..." }),
|
|
4052
|
-
paramSchema.enum.map((option) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: option, children: option }, option))
|
|
4053
|
-
]
|
|
4054
|
-
}
|
|
4055
|
-
)
|
|
4056
|
-
] });
|
|
4057
|
-
} else {
|
|
4058
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
4059
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4060
|
-
"label",
|
|
4061
|
-
{
|
|
4062
|
-
style: { fontSize: "12px", color: "#666", display: "block" },
|
|
4063
|
-
children: [
|
|
4064
|
-
paramName,
|
|
4065
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4066
|
-
paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
|
|
4067
|
-
]
|
|
4068
|
-
}
|
|
4069
|
-
),
|
|
4070
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4071
|
-
"input",
|
|
4072
|
-
{
|
|
4073
|
-
type: "text",
|
|
4074
|
-
value,
|
|
4075
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
|
|
4076
|
-
style: {
|
|
4077
|
-
width: "100%",
|
|
4078
|
-
padding: "4px",
|
|
4079
|
-
fontSize: "12px",
|
|
4080
|
-
border: "1px solid #ccc",
|
|
4081
|
-
borderRadius: "2px"
|
|
4082
|
-
}
|
|
4083
|
-
}
|
|
4084
|
-
)
|
|
4085
|
-
] });
|
|
4086
|
-
}
|
|
4087
|
-
} else if (paramSchema.type === "boolean") {
|
|
4088
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4089
|
-
"label",
|
|
4090
|
-
{
|
|
4091
|
-
style: {
|
|
4092
|
-
fontSize: "12px",
|
|
4093
|
-
color: "#666",
|
|
4094
|
-
display: "flex",
|
|
4095
|
-
alignItems: "center"
|
|
4096
|
-
},
|
|
4097
|
-
children: [
|
|
4098
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4099
|
-
"input",
|
|
4100
|
-
{
|
|
4101
|
-
type: "checkbox",
|
|
4102
|
-
checked: value,
|
|
4103
|
-
onChange: (e) => handleInputChange(commandName, paramName, e.target.checked),
|
|
4104
|
-
style: { marginRight: "6px" }
|
|
4105
|
-
}
|
|
4106
|
-
),
|
|
4107
|
-
paramName,
|
|
4108
|
-
paramSchema.description && ` - ${paramSchema.description}`,
|
|
4109
|
-
paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
|
|
4110
|
-
]
|
|
4111
|
-
}
|
|
4112
|
-
) });
|
|
4113
|
-
}
|
|
4114
|
-
return null;
|
|
4115
|
-
};
|
|
4116
|
-
const renderCommand = (commandName, commandSchema) => {
|
|
4117
|
-
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
4118
|
-
const isExpanded = expandedCommands[commandName];
|
|
4119
|
-
const params = Object.values(commandSchema.schema);
|
|
4120
|
-
const allSliders = params.length > 0 && params.every(
|
|
4121
|
-
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
4122
|
-
);
|
|
4123
|
-
const showExecuteButton = !allSliders;
|
|
4124
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4125
|
-
"div",
|
|
4126
|
-
{
|
|
4127
|
-
style: {
|
|
4128
|
-
border: "1px solid #ddd",
|
|
4129
|
-
borderRadius: "4px",
|
|
4130
|
-
marginBottom: "8px",
|
|
4131
|
-
backgroundColor: "#fafafa"
|
|
4132
|
-
},
|
|
4133
|
-
children: [
|
|
4134
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4135
|
-
"div",
|
|
4136
|
-
{
|
|
4137
|
-
onClick: () => toggleCommandExpanded(commandName),
|
|
4138
|
-
style: {
|
|
4139
|
-
padding: "8px 12px",
|
|
4140
|
-
cursor: "pointer",
|
|
4141
|
-
borderBottom: isExpanded ? "1px solid #ddd" : "none",
|
|
4142
|
-
display: "flex",
|
|
4143
|
-
justifyContent: "space-between",
|
|
4144
|
-
alignItems: "center"
|
|
4145
|
-
},
|
|
4146
|
-
children: [
|
|
4147
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
4148
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4149
|
-
"h4",
|
|
4150
|
-
{
|
|
4151
|
-
style: {
|
|
4152
|
-
margin: "0",
|
|
4153
|
-
fontSize: "13px",
|
|
4154
|
-
fontWeight: "bold"
|
|
4155
|
-
},
|
|
4156
|
-
children: commandName
|
|
4157
|
-
}
|
|
4158
|
-
),
|
|
4159
|
-
isExpanded && commandSchema.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4160
|
-
"p",
|
|
4161
|
-
{
|
|
4162
|
-
style: { margin: "4px 0 0 0", fontSize: "11px", color: "#666" },
|
|
4163
|
-
children: commandSchema.description
|
|
4164
|
-
}
|
|
4165
|
-
)
|
|
4166
|
-
] }),
|
|
4167
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4168
|
-
"div",
|
|
4169
|
-
{
|
|
4170
|
-
style: {
|
|
4171
|
-
fontSize: "10px",
|
|
4172
|
-
color: "#999",
|
|
4173
|
-
transform: isExpanded ? "rotate(180deg)" : "rotate(0deg)",
|
|
4174
|
-
transition: "transform 0.2s"
|
|
4175
|
-
},
|
|
4176
|
-
children: "\u25BC"
|
|
4177
|
-
}
|
|
4178
|
-
)
|
|
4179
|
-
]
|
|
4180
|
-
}
|
|
4181
|
-
),
|
|
4182
|
-
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { padding: "12px", paddingTop: "0" }, children: [
|
|
4183
|
-
hasParams && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
|
|
4184
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4185
|
-
"div",
|
|
4186
|
-
{
|
|
4187
|
-
style: {
|
|
4188
|
-
marginBottom: "8px",
|
|
4189
|
-
fontSize: "12px",
|
|
4190
|
-
fontWeight: "bold",
|
|
4191
|
-
color: "#555"
|
|
4192
|
-
},
|
|
4193
|
-
children: "Parameters:"
|
|
4194
|
-
}
|
|
4195
|
-
),
|
|
4196
|
-
Object.entries(commandSchema.schema).map(
|
|
4197
|
-
([paramName, paramSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4198
|
-
"div",
|
|
4199
|
-
{
|
|
4200
|
-
style: { marginLeft: "8px" },
|
|
4201
|
-
children: renderInput(commandName, paramName, paramSchema)
|
|
4202
|
-
},
|
|
4203
|
-
`${commandName}-${paramName}`
|
|
4204
|
-
)
|
|
4205
|
-
)
|
|
4206
|
-
] }),
|
|
4207
|
-
!hasParams && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4208
|
-
"div",
|
|
4209
|
-
{
|
|
4210
|
-
style: {
|
|
4211
|
-
marginBottom: showExecuteButton ? "12px" : "0",
|
|
4212
|
-
marginTop: "2px",
|
|
4213
|
-
fontSize: "11px",
|
|
4214
|
-
color: "#666",
|
|
4215
|
-
fontStyle: "italic"
|
|
4216
|
-
},
|
|
4217
|
-
children: "No parameters required"
|
|
4218
|
-
}
|
|
4219
|
-
),
|
|
4220
|
-
showExecuteButton && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4221
|
-
"button",
|
|
4222
|
-
{
|
|
4223
|
-
onClick: () => handleCommandSubmit(commandName),
|
|
4224
|
-
style: {
|
|
4225
|
-
padding: "8px 16px",
|
|
4226
|
-
fontSize: "12px",
|
|
4227
|
-
backgroundColor: "#007bff",
|
|
4228
|
-
color: "white",
|
|
4229
|
-
border: "none",
|
|
4230
|
-
borderRadius: "4px",
|
|
4231
|
-
cursor: "pointer",
|
|
4232
|
-
fontWeight: "bold"
|
|
4233
|
-
},
|
|
4234
|
-
children: [
|
|
4235
|
-
"Execute ",
|
|
4236
|
-
commandName
|
|
4237
|
-
]
|
|
4238
|
-
}
|
|
4239
|
-
)
|
|
4240
|
-
] })
|
|
4241
|
-
]
|
|
4242
|
-
},
|
|
4243
|
-
commandName
|
|
4244
|
-
);
|
|
4245
|
-
};
|
|
4246
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, style, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
4247
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4248
|
-
"h3",
|
|
4249
|
-
{
|
|
4250
|
-
style: {
|
|
4251
|
-
margin: "0 0 16px 0",
|
|
4252
|
-
fontSize: "16px",
|
|
4253
|
-
fontWeight: "bold"
|
|
4254
|
-
},
|
|
4255
|
-
children: "Reactor Commands"
|
|
4256
|
-
}
|
|
4257
|
-
),
|
|
4258
|
-
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
4259
|
-
] }) }) });
|
|
4260
|
-
}
|
|
4261
|
-
function FileParamInput({
|
|
4262
|
-
commandName,
|
|
4263
|
-
paramName,
|
|
4264
|
-
description,
|
|
4265
|
-
value,
|
|
4266
|
-
onChange,
|
|
4267
|
-
disabled,
|
|
4268
|
-
uploadFile
|
|
4269
|
-
}) {
|
|
4270
|
-
const inputRef = (0, import_react6.useRef)(null);
|
|
4271
|
-
const [uploading, setUploading] = (0, import_react6.useState)(false);
|
|
4272
|
-
const fileRef = value instanceof FileRef ? value : null;
|
|
4273
|
-
const handleFile = (e) => __async(null, null, function* () {
|
|
4274
|
-
var _a;
|
|
4275
|
-
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
4276
|
-
if (!file) return;
|
|
4277
|
-
e.target.value = "";
|
|
4278
|
-
setUploading(true);
|
|
4279
|
-
try {
|
|
4280
|
-
const ref = yield uploadFile(file);
|
|
4281
|
-
onChange(commandName, paramName, ref);
|
|
4282
|
-
} catch (err) {
|
|
4283
|
-
console.error("[FileParamInput] Upload failed:", err);
|
|
4284
|
-
} finally {
|
|
4285
|
-
setUploading(false);
|
|
4286
|
-
}
|
|
4287
|
-
});
|
|
4288
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
4289
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
4290
|
-
paramName,
|
|
4291
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
4292
|
-
description && ` - ${description}`
|
|
4293
|
-
] }),
|
|
4294
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4295
|
-
"div",
|
|
4296
|
-
{
|
|
4297
|
-
style: {
|
|
4298
|
-
display: "flex",
|
|
4299
|
-
alignItems: "center",
|
|
4300
|
-
gap: "8px",
|
|
4301
|
-
marginTop: "4px"
|
|
4302
|
-
},
|
|
4303
|
-
children: [
|
|
4304
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4305
|
-
"input",
|
|
4306
|
-
{
|
|
4307
|
-
ref: inputRef,
|
|
4308
|
-
type: "file",
|
|
4309
|
-
accept: "image/*",
|
|
4310
|
-
onChange: handleFile,
|
|
4311
|
-
style: { display: "none" }
|
|
4312
|
-
}
|
|
4313
|
-
),
|
|
4314
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4315
|
-
"button",
|
|
4316
|
-
{
|
|
4317
|
-
disabled: disabled || uploading,
|
|
4318
|
-
onClick: () => {
|
|
4319
|
-
var _a;
|
|
4320
|
-
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
4321
|
-
},
|
|
4322
|
-
style: {
|
|
4323
|
-
padding: "4px 12px",
|
|
4324
|
-
fontSize: "12px",
|
|
4325
|
-
backgroundColor: "#007bff",
|
|
4326
|
-
color: "white",
|
|
4327
|
-
border: "none",
|
|
4328
|
-
borderRadius: "4px",
|
|
4329
|
-
cursor: disabled || uploading ? "default" : "pointer",
|
|
4330
|
-
opacity: disabled || uploading ? 0.5 : 1
|
|
4331
|
-
},
|
|
4332
|
-
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
4333
|
-
}
|
|
4334
|
-
),
|
|
4335
|
-
fileRef && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
4336
|
-
"\\u2713 ",
|
|
4337
|
-
fileRef.name
|
|
4338
|
-
] })
|
|
4339
|
-
]
|
|
4340
|
-
}
|
|
4341
|
-
)
|
|
4342
|
-
] });
|
|
4343
|
-
}
|
|
4344
|
-
|
|
4345
4130
|
// src/react/WebcamStream.tsx
|
|
4346
|
-
var
|
|
4347
|
-
var
|
|
4131
|
+
var import_react6 = require("react");
|
|
4132
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
4348
4133
|
function WebcamStream({
|
|
4349
4134
|
track,
|
|
4350
4135
|
audio = false,
|
|
@@ -4361,20 +4146,20 @@ function WebcamStream({
|
|
|
4361
4146
|
onPublished,
|
|
4362
4147
|
onError
|
|
4363
4148
|
}) {
|
|
4364
|
-
const [stream, setStream] = (0,
|
|
4365
|
-
const [isPublishing, setIsPublishing] = (0,
|
|
4366
|
-
const [permissionDenied, setPermissionDenied] = (0,
|
|
4149
|
+
const [stream, setStream] = (0, import_react6.useState)(null);
|
|
4150
|
+
const [isPublishing, setIsPublishing] = (0, import_react6.useState)(false);
|
|
4151
|
+
const [permissionDenied, setPermissionDenied] = (0, import_react6.useState)(false);
|
|
4367
4152
|
const { status, publish, unpublish, reactor } = useReactor((state) => ({
|
|
4368
4153
|
status: state.status,
|
|
4369
4154
|
publish: state.publish,
|
|
4370
4155
|
unpublish: state.unpublish,
|
|
4371
4156
|
reactor: state.internal.reactor
|
|
4372
4157
|
}));
|
|
4373
|
-
const videoRef = (0,
|
|
4374
|
-
const onPermissionDeniedRef = (0,
|
|
4375
|
-
const onPublishedRef = (0,
|
|
4376
|
-
const onErrorRef = (0,
|
|
4377
|
-
(0,
|
|
4158
|
+
const videoRef = (0, import_react6.useRef)(null);
|
|
4159
|
+
const onPermissionDeniedRef = (0, import_react6.useRef)(onPermissionDenied);
|
|
4160
|
+
const onPublishedRef = (0, import_react6.useRef)(onPublished);
|
|
4161
|
+
const onErrorRef = (0, import_react6.useRef)(onError);
|
|
4162
|
+
(0, import_react6.useEffect)(() => {
|
|
4378
4163
|
onPermissionDeniedRef.current = onPermissionDenied;
|
|
4379
4164
|
onPublishedRef.current = onPublished;
|
|
4380
4165
|
onErrorRef.current = onError;
|
|
@@ -4439,7 +4224,7 @@ function WebcamStream({
|
|
|
4439
4224
|
setStream(null);
|
|
4440
4225
|
console.debug("[WebcamPublisher] Webcam stopped");
|
|
4441
4226
|
});
|
|
4442
|
-
(0,
|
|
4227
|
+
(0, import_react6.useEffect)(() => {
|
|
4443
4228
|
console.debug("[WebcamPublisher] Stream effect triggered", {
|
|
4444
4229
|
hasVideoElement: !!videoRef.current,
|
|
4445
4230
|
hasStream: !!stream
|
|
@@ -4456,7 +4241,7 @@ function WebcamStream({
|
|
|
4456
4241
|
videoRef.current.srcObject = null;
|
|
4457
4242
|
}
|
|
4458
4243
|
}, [stream]);
|
|
4459
|
-
(0,
|
|
4244
|
+
(0, import_react6.useEffect)(() => {
|
|
4460
4245
|
if (!stream) {
|
|
4461
4246
|
return;
|
|
4462
4247
|
}
|
|
@@ -4512,7 +4297,7 @@ function WebcamStream({
|
|
|
4512
4297
|
audioEnabled,
|
|
4513
4298
|
audioTrack
|
|
4514
4299
|
]);
|
|
4515
|
-
(0,
|
|
4300
|
+
(0, import_react6.useEffect)(() => {
|
|
4516
4301
|
const handleError = (error) => {
|
|
4517
4302
|
console.debug("[WebcamPublisher] Received error event:", error);
|
|
4518
4303
|
if (error.code === "TRACK_PUBLISH_FAILED") {
|
|
@@ -4527,7 +4312,7 @@ function WebcamStream({
|
|
|
4527
4312
|
reactor.off("error", handleError);
|
|
4528
4313
|
};
|
|
4529
4314
|
}, [reactor]);
|
|
4530
|
-
(0,
|
|
4315
|
+
(0, import_react6.useEffect)(() => {
|
|
4531
4316
|
if (status !== "ready") {
|
|
4532
4317
|
console.debug(
|
|
4533
4318
|
"[WebcamPublisher] Status changed to",
|
|
@@ -4537,7 +4322,7 @@ function WebcamStream({
|
|
|
4537
4322
|
setIsPublishing(false);
|
|
4538
4323
|
}
|
|
4539
4324
|
}, [status, isPublishing]);
|
|
4540
|
-
(0,
|
|
4325
|
+
(0, import_react6.useEffect)(() => {
|
|
4541
4326
|
console.debug("[WebcamPublisher] Auto-starting webcam");
|
|
4542
4327
|
startWebcam();
|
|
4543
4328
|
return () => {
|
|
@@ -4546,7 +4331,7 @@ function WebcamStream({
|
|
|
4546
4331
|
};
|
|
4547
4332
|
}, []);
|
|
4548
4333
|
const showPlaceholder = !stream;
|
|
4549
|
-
return /* @__PURE__ */ (0,
|
|
4334
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4550
4335
|
"div",
|
|
4551
4336
|
{
|
|
4552
4337
|
style: __spreadValues({
|
|
@@ -4556,7 +4341,7 @@ function WebcamStream({
|
|
|
4556
4341
|
}, style),
|
|
4557
4342
|
className,
|
|
4558
4343
|
children: [
|
|
4559
|
-
/* @__PURE__ */ (0,
|
|
4344
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4560
4345
|
"video",
|
|
4561
4346
|
{
|
|
4562
4347
|
ref: videoRef,
|
|
@@ -4571,7 +4356,7 @@ function WebcamStream({
|
|
|
4571
4356
|
autoPlay: true
|
|
4572
4357
|
}
|
|
4573
4358
|
),
|
|
4574
|
-
showPlaceholder && /* @__PURE__ */ (0,
|
|
4359
|
+
showPlaceholder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4575
4360
|
"div",
|
|
4576
4361
|
{
|
|
4577
4362
|
style: {
|
|
@@ -4592,11 +4377,11 @@ function WebcamStream({
|
|
|
4592
4377
|
flexDirection: "column",
|
|
4593
4378
|
gap: "12px"
|
|
4594
4379
|
},
|
|
4595
|
-
children: permissionDenied ? /* @__PURE__ */ (0,
|
|
4380
|
+
children: permissionDenied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
|
|
4596
4381
|
"Camera access denied.",
|
|
4597
|
-
/* @__PURE__ */ (0,
|
|
4382
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
|
|
4598
4383
|
"Please allow access in your browser settings."
|
|
4599
|
-
] }) : /* @__PURE__ */ (0,
|
|
4384
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
|
|
4600
4385
|
}
|
|
4601
4386
|
)
|
|
4602
4387
|
]
|
|
@@ -4605,8 +4390,8 @@ function WebcamStream({
|
|
|
4605
4390
|
}
|
|
4606
4391
|
|
|
4607
4392
|
// src/react/ClipPlayer.tsx
|
|
4608
|
-
var
|
|
4609
|
-
var
|
|
4393
|
+
var import_react7 = require("react");
|
|
4394
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4610
4395
|
function ClipPlayer({
|
|
4611
4396
|
clip,
|
|
4612
4397
|
getJwt,
|
|
@@ -4617,28 +4402,28 @@ function ClipPlayer({
|
|
|
4617
4402
|
style,
|
|
4618
4403
|
onError
|
|
4619
4404
|
}) {
|
|
4620
|
-
const videoRef = (0,
|
|
4621
|
-
const [phase, setPhase] = (0,
|
|
4622
|
-
const store = (0,
|
|
4623
|
-
const getJwtRef = (0,
|
|
4624
|
-
const autoPlayRef = (0,
|
|
4625
|
-
const slackMsRef = (0,
|
|
4626
|
-
const onErrorRef = (0,
|
|
4627
|
-
const storeRef = (0,
|
|
4628
|
-
(0,
|
|
4405
|
+
const videoRef = (0, import_react7.useRef)(null);
|
|
4406
|
+
const [phase, setPhase] = (0, import_react7.useState)({ kind: "waiting" });
|
|
4407
|
+
const store = (0, import_react7.useContext)(ReactorContext);
|
|
4408
|
+
const getJwtRef = (0, import_react7.useRef)(getJwt);
|
|
4409
|
+
const autoPlayRef = (0, import_react7.useRef)(autoPlay);
|
|
4410
|
+
const slackMsRef = (0, import_react7.useRef)(slackMs);
|
|
4411
|
+
const onErrorRef = (0, import_react7.useRef)(onError);
|
|
4412
|
+
const storeRef = (0, import_react7.useRef)(store);
|
|
4413
|
+
(0, import_react7.useEffect)(() => {
|
|
4629
4414
|
getJwtRef.current = getJwt;
|
|
4630
4415
|
autoPlayRef.current = autoPlay;
|
|
4631
4416
|
slackMsRef.current = slackMs;
|
|
4632
4417
|
onErrorRef.current = onError;
|
|
4633
4418
|
storeRef.current = store;
|
|
4634
4419
|
});
|
|
4635
|
-
(0,
|
|
4420
|
+
(0, import_react7.useEffect)(() => {
|
|
4636
4421
|
var _a;
|
|
4637
4422
|
if (phase.kind === "error") {
|
|
4638
4423
|
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, phase.error);
|
|
4639
4424
|
}
|
|
4640
4425
|
}, [phase]);
|
|
4641
|
-
(0,
|
|
4426
|
+
(0, import_react7.useEffect)(() => {
|
|
4642
4427
|
const video = videoRef.current;
|
|
4643
4428
|
if (!video) return;
|
|
4644
4429
|
const abort = new AbortController();
|
|
@@ -4741,7 +4526,7 @@ function ClipPlayer({
|
|
|
4741
4526
|
};
|
|
4742
4527
|
}, [clip]);
|
|
4743
4528
|
const overlayText = phase.kind === "waiting" ? "Waiting for clip\u2026" : phase.kind === "loading" ? "Loading player\u2026" : null;
|
|
4744
|
-
return /* @__PURE__ */ (0,
|
|
4529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4745
4530
|
"div",
|
|
4746
4531
|
{
|
|
4747
4532
|
className,
|
|
@@ -4754,7 +4539,7 @@ function ClipPlayer({
|
|
|
4754
4539
|
justifyContent: "center"
|
|
4755
4540
|
}, style),
|
|
4756
4541
|
children: [
|
|
4757
|
-
/* @__PURE__ */ (0,
|
|
4542
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4758
4543
|
"video",
|
|
4759
4544
|
{
|
|
4760
4545
|
ref: videoRef,
|
|
@@ -4769,7 +4554,7 @@ function ClipPlayer({
|
|
|
4769
4554
|
}
|
|
4770
4555
|
}
|
|
4771
4556
|
),
|
|
4772
|
-
overlayText && /* @__PURE__ */ (0,
|
|
4557
|
+
overlayText && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4773
4558
|
"div",
|
|
4774
4559
|
{
|
|
4775
4560
|
style: {
|
|
@@ -4787,7 +4572,7 @@ function ClipPlayer({
|
|
|
4787
4572
|
children: overlayText
|
|
4788
4573
|
}
|
|
4789
4574
|
),
|
|
4790
|
-
phase.kind === "error" && /* @__PURE__ */ (0,
|
|
4575
|
+
phase.kind === "error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4791
4576
|
"div",
|
|
4792
4577
|
{
|
|
4793
4578
|
style: {
|
|
@@ -4811,26 +4596,26 @@ function ClipPlayer({
|
|
|
4811
4596
|
}
|
|
4812
4597
|
|
|
4813
4598
|
// src/react/ClipDownloadButton.tsx
|
|
4814
|
-
var
|
|
4599
|
+
var import_react9 = require("react");
|
|
4815
4600
|
|
|
4816
4601
|
// src/react/useClipDownload.ts
|
|
4817
|
-
var
|
|
4602
|
+
var import_react8 = require("react");
|
|
4818
4603
|
function useClipDownload(clip, options = {}) {
|
|
4819
4604
|
var _a;
|
|
4820
|
-
const [state, setState] = (0,
|
|
4821
|
-
const store = (0,
|
|
4822
|
-
const clipRef = (0,
|
|
4823
|
-
const filenameRef = (0,
|
|
4605
|
+
const [state, setState] = (0, import_react8.useState)({ kind: "idle" });
|
|
4606
|
+
const store = (0, import_react8.useContext)(ReactorContext);
|
|
4607
|
+
const clipRef = (0, import_react8.useRef)(clip);
|
|
4608
|
+
const filenameRef = (0, import_react8.useRef)(
|
|
4824
4609
|
(_a = options.filename) != null ? _a : "reactor-clip.mp4"
|
|
4825
4610
|
);
|
|
4826
|
-
const getJwtRef = (0,
|
|
4827
|
-
(0,
|
|
4611
|
+
const getJwtRef = (0, import_react8.useRef)(options.getJwt);
|
|
4612
|
+
(0, import_react8.useEffect)(() => {
|
|
4828
4613
|
clipRef.current = clip;
|
|
4829
4614
|
filenameRef.current = options.filename === void 0 ? "reactor-clip.mp4" : options.filename;
|
|
4830
4615
|
getJwtRef.current = options.getJwt;
|
|
4831
4616
|
});
|
|
4832
|
-
const inFlightRef = (0,
|
|
4833
|
-
const download = (0,
|
|
4617
|
+
const inFlightRef = (0, import_react8.useRef)(false);
|
|
4618
|
+
const download = (0, import_react8.useCallback)(() => __async(null, null, function* () {
|
|
4834
4619
|
if (inFlightRef.current) return void 0;
|
|
4835
4620
|
inFlightRef.current = true;
|
|
4836
4621
|
setState({ kind: "downloading", fetched: 0, total: 0 });
|
|
@@ -4857,12 +4642,12 @@ function useClipDownload(clip, options = {}) {
|
|
|
4857
4642
|
inFlightRef.current = false;
|
|
4858
4643
|
}
|
|
4859
4644
|
}), [store]);
|
|
4860
|
-
const reset = (0,
|
|
4645
|
+
const reset = (0, import_react8.useCallback)(() => setState({ kind: "idle" }), []);
|
|
4861
4646
|
return { state, download, reset };
|
|
4862
4647
|
}
|
|
4863
4648
|
|
|
4864
4649
|
// src/react/ClipDownloadButton.tsx
|
|
4865
|
-
var
|
|
4650
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
4866
4651
|
function ClipDownloadButton({
|
|
4867
4652
|
clip,
|
|
4868
4653
|
getJwt,
|
|
@@ -4877,20 +4662,20 @@ function ClipDownloadButton({
|
|
|
4877
4662
|
const { state, download } = useClipDownload(clip, { filename, getJwt });
|
|
4878
4663
|
const downloading = state.kind === "downloading";
|
|
4879
4664
|
const isDisabled = downloading || !!disabled;
|
|
4880
|
-
const onSuccessRef = (0,
|
|
4881
|
-
const onErrorRef = (0,
|
|
4882
|
-
(0,
|
|
4665
|
+
const onSuccessRef = (0, import_react9.useRef)(onSuccess);
|
|
4666
|
+
const onErrorRef = (0, import_react9.useRef)(onError);
|
|
4667
|
+
(0, import_react9.useEffect)(() => {
|
|
4883
4668
|
onSuccessRef.current = onSuccess;
|
|
4884
4669
|
onErrorRef.current = onError;
|
|
4885
4670
|
});
|
|
4886
|
-
(0,
|
|
4671
|
+
(0, import_react9.useEffect)(() => {
|
|
4887
4672
|
var _a;
|
|
4888
4673
|
if (state.kind === "error") {
|
|
4889
4674
|
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, new Error(state.message));
|
|
4890
4675
|
}
|
|
4891
4676
|
}, [state]);
|
|
4892
4677
|
const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
|
|
4893
|
-
return /* @__PURE__ */ (0,
|
|
4678
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4894
4679
|
"button",
|
|
4895
4680
|
{
|
|
4896
4681
|
type: "button",
|
|
@@ -4938,7 +4723,6 @@ function defaultLabel(state) {
|
|
|
4938
4723
|
DEFAULT_PLAYLIST_POLL_SLACK_MS,
|
|
4939
4724
|
FileRef,
|
|
4940
4725
|
Reactor,
|
|
4941
|
-
ReactorController,
|
|
4942
4726
|
ReactorProvider,
|
|
4943
4727
|
ReactorView,
|
|
4944
4728
|
RecordingClient,
|