@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/dist/index.mjs CHANGED
@@ -91,7 +91,7 @@ import { z } from "zod";
91
91
  // package.json
92
92
  var package_default = {
93
93
  name: "@reactor-team/js-sdk",
94
- version: "2.11.2",
94
+ version: "2.12.1",
95
95
  description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
96
96
  license: "Apache-2.0",
97
97
  repository: {
@@ -147,6 +147,7 @@ var package_default = {
147
147
  },
148
148
  packageManager: "pnpm@10.12.1",
149
149
  dependencies: {
150
+ awaitqueue: "^3.3.0",
150
151
  mp4box: "^2.3.0",
151
152
  "sdp-transform": "^3.0.0",
152
153
  zod: "^4.4.3"
@@ -162,13 +163,14 @@ var package_default = {
162
163
  }
163
164
  },
164
165
  devDependencies: {
165
- "@roamhq/wrtc": "^0.8.0",
166
+ "@roamhq/wrtc": "^0.10.0",
166
167
  "@types/node": "^25",
167
168
  "@types/react": "^19.2.15",
169
+ "@types/sdp-transform": "^2.15.0",
168
170
  "hls.js": "^1.6.0",
169
- prettier: "^3.6.2",
171
+ prettier: "^3.8.4",
170
172
  tsup: "^8.5.0",
171
- typescript: "^5.8.3",
173
+ typescript: "^6.0.3",
172
174
  vitest: "^4.1.7"
173
175
  }
174
176
  };
@@ -260,8 +262,12 @@ var WebRTCSdpOfferRequestSchema = z.object({
260
262
  client_info: ClientInfoSchema.optional(),
261
263
  track_mapping: z.array(TrackMappingEntrySchema)
262
264
  });
265
+ var WebRTCSdpOfferResponseSchema = z.object({
266
+ connection_id: z.number().optional()
267
+ });
263
268
  var WebRTCSdpAnswerResponseSchema = z.object({
264
- sdp_answer: z.string()
269
+ sdp_answer: z.string(),
270
+ connection_id: z.number().optional()
265
271
  });
266
272
  var IceCandidateSchema = z.object({
267
273
  candidate: z.string(),
@@ -789,6 +795,9 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
789
795
  }
790
796
  };
791
797
 
798
+ // src/core/WebRTCTransportClient.ts
799
+ import { AwaitQueue } from "awaitqueue";
800
+
792
801
  // src/utils/sdp.ts
793
802
  import { parse, parsePayloads } from "sdp-transform";
794
803
  function sdpLineSeparator(sdp) {
@@ -839,13 +848,6 @@ function collectSanitizedCodecPayloadSet(media) {
839
848
  }
840
849
  return tracked.size > 0 ? tracked : null;
841
850
  }
842
- function mediaSectionNeedsSanitizedPtRelocate(media) {
843
- const pts = collectSanitizedCodecPayloadSet(media);
844
- if (!pts) {
845
- return false;
846
- }
847
- return [...pts].some((p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX);
848
- }
849
851
  function codecRelocationPriority(enc) {
850
852
  const u = (enc != null ? enc : "").toUpperCase();
851
853
  if (/^(H265|HEVC|HEV1|HVC1)/.test(u)) return 0;
@@ -879,7 +881,7 @@ function computeCodecRemapForMedia(media, forbidden) {
879
881
  return remap;
880
882
  }
881
883
  const relocate = [...tracked].filter(
882
- (p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX
884
+ (p) => p < DYNAMIC_PT_MIN || p > DYNAMIC_PT_MAX || forbidden.has(p)
883
885
  );
884
886
  if (relocate.length === 0) {
885
887
  return remap;
@@ -1116,7 +1118,7 @@ function stripTelephoneEventsPreserveOrder(sdp) {
1116
1118
  function transformOfferSdpCodecDynamicPts(sdp) {
1117
1119
  var _a;
1118
1120
  const session = parse(sdp);
1119
- if (!session.media.some(mediaSectionNeedsSanitizedPtRelocate)) {
1121
+ if (!session.media.some((m) => collectSanitizedCodecPayloadSet(m) !== null)) {
1120
1122
  return sdp;
1121
1123
  }
1122
1124
  const remaps = [];
@@ -1238,6 +1240,26 @@ function parseMessage(data) {
1238
1240
  }
1239
1241
  return data;
1240
1242
  }
1243
+ function complementDirection(direction) {
1244
+ if (direction === "sendonly") return "recvonly";
1245
+ if (direction === "recvonly") return "sendonly";
1246
+ return direction;
1247
+ }
1248
+ function replaceSdpDirectionForMid(sdp, mid, direction) {
1249
+ const [session, ...mediaSections] = sdp.split(/(?=\r\nm=)/);
1250
+ const updated = mediaSections.map((section) => {
1251
+ if (!section.includes(`\r
1252
+ a=mid:${mid}\r
1253
+ `)) return section;
1254
+ return section.replace(
1255
+ /\r\na=(sendonly|recvonly|sendrecv|inactive)\r\n/,
1256
+ `\r
1257
+ a=${direction}\r
1258
+ `
1259
+ );
1260
+ });
1261
+ return session + updated.join("");
1262
+ }
1241
1263
  function closePeerConnection(pc) {
1242
1264
  pc.close();
1243
1265
  }
@@ -1323,6 +1345,8 @@ var INITIAL_BACKOFF_MS = 200;
1323
1345
  var MAX_BACKOFF_MS = 15e3;
1324
1346
  var BACKOFF_MULTIPLIER = 2;
1325
1347
  var DEFAULT_MAX_POLL_ATTEMPTS = 6;
1348
+ var MIN_CONNECTION_ID = 1e3;
1349
+ var MAX_CONNECTION_ID = 9999;
1326
1350
  var ICE_CANDIDATE_BATCH_WINDOW_MS = 25;
1327
1351
  var WebRTCTransportClient = class {
1328
1352
  constructor(config) {
@@ -1330,8 +1354,14 @@ var WebRTCTransportClient = class {
1330
1354
  this.status = "disconnected";
1331
1355
  this.transceiverMap = /* @__PURE__ */ new Map();
1332
1356
  this.publishedTracks = /* @__PURE__ */ new Map();
1357
+ // Serializes all SDP renegotiations (pause/resume direction changes) and gates
1358
+ // them behind the connection-ready task. Reset on each prepare() call.
1359
+ this.peerConnectionQueue = new AwaitQueue();
1360
+ this.pendingControlRequests = /* @__PURE__ */ new Map();
1361
+ this.controlRequestCounter = 0;
1333
1362
  this.peerConnected = false;
1334
1363
  this.dataChannelOpen = false;
1364
+ this.controlChannelOpen = false;
1335
1365
  // Trickle ICE batching
1336
1366
  this.pendingIceCandidates = [];
1337
1367
  var _a, _b;
@@ -1436,11 +1466,34 @@ var WebRTCTransportClient = class {
1436
1466
  return iceServers;
1437
1467
  });
1438
1468
  }
1439
- sendSdpOffer(sdpOffer, trackMapping, method = "POST") {
1469
+ registerConnection() {
1440
1470
  return __async(this, null, function* () {
1471
+ console.debug("[WebRTCTransport] Registering connection...");
1472
+ const response = yield fetch(`${this.transportBaseUrl}/connections`, {
1473
+ method: "POST",
1474
+ headers: yield this.getHeaders(),
1475
+ signal: this.signal
1476
+ });
1477
+ yield this.checkVersionMismatch(response);
1478
+ if (response.status !== 201) {
1479
+ const errorText = yield response.text();
1480
+ throw new Error(
1481
+ `Failed to register connection: ${response.status} ${errorText}`
1482
+ );
1483
+ }
1484
+ const data = yield response.json();
1485
+ const connectionId = data.connection_id;
1441
1486
  console.debug(
1442
- `[WebRTCTransport] Sending SDP offer (${method}) for session:`,
1443
- this.sessionId
1487
+ `[WebRTCTransport] Connection registered: id=${connectionId}`
1488
+ );
1489
+ return connectionId;
1490
+ });
1491
+ }
1492
+ sendSdpOffer(connectionId, sdpOffer, trackMapping, reconnect = false) {
1493
+ return __async(this, null, function* () {
1494
+ const method = reconnect ? "PUT" : "POST";
1495
+ console.debug(
1496
+ `[WebRTCTransport] Sending SDP offer (${method}) connection=${connectionId}`
1444
1497
  );
1445
1498
  const requestBody = {
1446
1499
  sdp_offer: sdpOffer,
@@ -1450,17 +1503,30 @@ var WebRTCTransportClient = class {
1450
1503
  },
1451
1504
  track_mapping: trackMapping
1452
1505
  };
1453
- const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1454
- method,
1455
- headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1456
- "Content-Type": "application/json"
1457
- }),
1458
- body: JSON.stringify(requestBody),
1459
- signal: this.signal
1460
- });
1506
+ const response = yield fetch(
1507
+ `${this.transportBaseUrl}/connections/${connectionId}/sdp_params`,
1508
+ {
1509
+ method,
1510
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1511
+ "Content-Type": "application/json"
1512
+ }),
1513
+ body: JSON.stringify(requestBody),
1514
+ signal: this.signal
1515
+ }
1516
+ );
1461
1517
  yield this.checkVersionMismatch(response);
1462
1518
  if (response.status !== 202) {
1463
1519
  const errorText = yield response.text();
1520
+ if (response.status === 404) {
1521
+ throw new Error(
1522
+ `[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}`
1523
+ );
1524
+ }
1525
+ if (response.status === 400) {
1526
+ throw new Error(
1527
+ `[WebRTCTransport] Connection ${connectionId} rejected (400): ${errorText}`
1528
+ );
1529
+ }
1464
1530
  throw new Error(
1465
1531
  `Failed to send SDP offer: ${response.status} ${errorText}`
1466
1532
  );
@@ -1470,6 +1536,12 @@ var WebRTCTransportClient = class {
1470
1536
  }
1471
1537
  sendIceCandidates(candidates, is_final) {
1472
1538
  return __async(this, null, function* () {
1539
+ if (this.connectionId === void 0) {
1540
+ console.debug(
1541
+ "[WebRTCTransport] ICE candidates dropped: no active connection"
1542
+ );
1543
+ return;
1544
+ }
1473
1545
  console.debug(
1474
1546
  `[WebRTCTransport] Sending ICE candidates (count=${candidates.length}, is_final=${is_final})`
1475
1547
  );
@@ -1481,14 +1553,17 @@ var WebRTCTransportClient = class {
1481
1553
  sdk_type: REACTOR_SDK_TYPE
1482
1554
  }
1483
1555
  };
1484
- const response = yield fetch(`${this.transportBaseUrl}/ice_candidates`, {
1485
- method: "POST",
1486
- headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1487
- "Content-Type": "application/json"
1488
- }),
1489
- body: JSON.stringify(requestBody),
1490
- signal: this.signal
1491
- });
1556
+ const response = yield fetch(
1557
+ `${this.transportBaseUrl}/connections/${this.connectionId}/ice_candidates`,
1558
+ {
1559
+ method: "POST",
1560
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1561
+ "Content-Type": "application/json"
1562
+ }),
1563
+ body: JSON.stringify(requestBody),
1564
+ signal: this.signal
1565
+ }
1566
+ );
1492
1567
  yield this.checkVersionMismatch(response);
1493
1568
  if (response.status !== 202) {
1494
1569
  const errorText = yield response.text();
@@ -1497,7 +1572,6 @@ var WebRTCTransportClient = class {
1497
1572
  );
1498
1573
  }
1499
1574
  console.debug("[WebRTCTransport] ICE candidates accepted (202)");
1500
- return;
1501
1575
  });
1502
1576
  }
1503
1577
  /**
@@ -1532,9 +1606,10 @@ var WebRTCTransportClient = class {
1532
1606
  }
1533
1607
  this.pendingIceCandidates = [];
1534
1608
  }
1535
- pollSdpAnswer() {
1609
+ pollSdpAnswer(connectionId) {
1536
1610
  return __async(this, null, function* () {
1537
1611
  console.debug("[WebRTCTransport] Polling for SDP answer...");
1612
+ const pollUrl = `${this.transportBaseUrl}/connections/${connectionId}/sdp_params`;
1538
1613
  const pollStart = performance.now();
1539
1614
  let backoffMs = INITIAL_BACKOFF_MS;
1540
1615
  let attempt = 0;
@@ -1551,7 +1626,7 @@ var WebRTCTransportClient = class {
1551
1626
  console.debug(
1552
1627
  `[WebRTCTransport] SDP poll attempt ${attempt}/${this.maxPollAttempts}`
1553
1628
  );
1554
- const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1629
+ const response = yield fetch(pollUrl, {
1555
1630
  method: "GET",
1556
1631
  headers: yield this.getHeaders(),
1557
1632
  signal: this.signal
@@ -1606,16 +1681,34 @@ var WebRTCTransportClient = class {
1606
1681
  this.dataChannel.close();
1607
1682
  this.dataChannel = void 0;
1608
1683
  }
1684
+ if (this.controlChannel) {
1685
+ this.controlChannel.close();
1686
+ this.controlChannel = void 0;
1687
+ }
1609
1688
  if (this.peerConnection) {
1610
1689
  closePeerConnection(this.peerConnection);
1611
1690
  this.peerConnection = void 0;
1612
1691
  }
1613
1692
  this.peerConnected = false;
1614
1693
  this.dataChannelOpen = false;
1694
+ this.controlChannelOpen = false;
1695
+ this.peerConnectionQueue.stop();
1696
+ this.peerConnectionQueue = new AwaitQueue();
1697
+ this.peerConnectionQueue.push(
1698
+ () => new Promise((resolve) => {
1699
+ this.readyGateResolve = resolve;
1700
+ })
1701
+ ).catch(() => {
1702
+ });
1615
1703
  const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
1616
1704
  this.cachedIceServers = void 0;
1617
1705
  this.peerConnection = createPeerConnection({ iceServers });
1618
1706
  this.setupPeerConnectionHandlers();
1707
+ this.controlChannel = createDataChannel(
1708
+ this.peerConnection,
1709
+ "control"
1710
+ );
1711
+ this.setupControlChannelHandlers();
1619
1712
  this.dataChannel = createDataChannel(this.peerConnection);
1620
1713
  this.setupDataChannelHandlers();
1621
1714
  this.transceiverMap.clear();
@@ -1638,20 +1731,34 @@ var WebRTCTransportClient = class {
1638
1731
  console.debug("[WebRTCTransport] SDP offer prepared");
1639
1732
  });
1640
1733
  }
1641
- connect(reconnect = false) {
1734
+ connect(reconnect = false, connectionId) {
1642
1735
  return __async(this, null, function* () {
1643
1736
  if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
1644
1737
  throw new Error(
1645
1738
  "[WebRTCTransport] No prepared connection. Call prepare() first."
1646
1739
  );
1647
1740
  }
1648
- const method = reconnect ? "PUT" : "POST";
1649
1741
  const sdpOffer = this.pendingSdpOffer;
1650
1742
  const trackMapping = this.pendingTrackMapping;
1651
1743
  this.pendingSdpOffer = void 0;
1652
1744
  this.pendingTrackMapping = void 0;
1653
- yield this.sendSdpOffer(sdpOffer, trackMapping, method);
1654
- const answerResponse = yield this.pollSdpAnswer();
1745
+ if (connectionId !== void 0) {
1746
+ if (!Number.isInteger(connectionId) || connectionId <= MIN_CONNECTION_ID || connectionId > MAX_CONNECTION_ID) {
1747
+ throw new Error(
1748
+ `[WebRTCTransport] Invalid connectionId ${connectionId}: must be an integer in (${MIN_CONNECTION_ID}, ${MAX_CONNECTION_ID}]`
1749
+ );
1750
+ }
1751
+ this.connectionId = connectionId;
1752
+ } else if (!reconnect || this.connectionId === void 0) {
1753
+ this.connectionId = yield this.registerConnection();
1754
+ }
1755
+ yield this.sendSdpOffer(
1756
+ this.connectionId,
1757
+ sdpOffer,
1758
+ trackMapping,
1759
+ reconnect
1760
+ );
1761
+ const answerResponse = yield this.pollSdpAnswer(this.connectionId);
1655
1762
  this.iceStartTime = performance.now();
1656
1763
  yield setRemoteDescription(
1657
1764
  this.peerConnection,
@@ -1672,13 +1779,28 @@ var WebRTCTransportClient = class {
1672
1779
  this.dataChannel.close();
1673
1780
  this.dataChannel = void 0;
1674
1781
  }
1782
+ if (this.controlChannel) {
1783
+ this.controlChannel.close();
1784
+ this.controlChannel = void 0;
1785
+ }
1675
1786
  if (this.peerConnection) {
1676
1787
  closePeerConnection(this.peerConnection);
1677
1788
  this.peerConnection = void 0;
1678
1789
  }
1790
+ for (const [, pending] of this.pendingControlRequests) {
1791
+ clearTimeout(pending.timeout);
1792
+ pending.reject(
1793
+ new Error("[WebRTCTransport] Disconnected while waiting for response")
1794
+ );
1795
+ }
1796
+ this.pendingControlRequests.clear();
1797
+ this.readyGateResolve = void 0;
1798
+ this.peerConnectionQueue.stop();
1799
+ this.connectionId = void 0;
1679
1800
  this.transceiverMap.clear();
1680
1801
  this.peerConnected = false;
1681
1802
  this.dataChannelOpen = false;
1803
+ this.controlChannelOpen = false;
1682
1804
  this.resetTransportTimings();
1683
1805
  this.setStatus("disconnected");
1684
1806
  console.debug("[WebRTCTransport] Disconnected");
@@ -1741,6 +1863,119 @@ var WebRTCTransportClient = class {
1741
1863
  console.warn("[WebRTCTransport] Failed to send message:", error);
1742
1864
  }
1743
1865
  }
1866
+ sendControlMessage(command, data, reqId) {
1867
+ if (!this.controlChannel) {
1868
+ console.warn("[WebRTCTransport] Control channel not available");
1869
+ return;
1870
+ }
1871
+ try {
1872
+ if (this.controlChannel.readyState !== "open") {
1873
+ throw new Error(
1874
+ `Control channel not open: ${this.controlChannel.readyState}`
1875
+ );
1876
+ }
1877
+ this.controlChannel.send(
1878
+ JSON.stringify({ type: "notification", event: command, data })
1879
+ );
1880
+ } catch (error) {
1881
+ console.warn("[WebRTCTransport] Failed to send control message:", error);
1882
+ }
1883
+ }
1884
+ sendControlRequest(method, data, timeoutMs = 1e4) {
1885
+ return new Promise((resolve, reject) => {
1886
+ const requestId = `ctrl_${++this.controlRequestCounter}`;
1887
+ const timeout = setTimeout(() => {
1888
+ this.pendingControlRequests.delete(requestId);
1889
+ reject(new Error(`[WebRTCTransport] Request "${method}" timed out`));
1890
+ }, timeoutMs);
1891
+ this.pendingControlRequests.set(requestId, { resolve, reject, timeout });
1892
+ try {
1893
+ if (!this.controlChannel || this.controlChannel.readyState !== "open") {
1894
+ throw new Error("Control channel not available");
1895
+ }
1896
+ this.controlChannel.send(
1897
+ JSON.stringify({
1898
+ type: "request",
1899
+ method,
1900
+ request_id: requestId,
1901
+ data
1902
+ })
1903
+ );
1904
+ } catch (error) {
1905
+ clearTimeout(timeout);
1906
+ this.pendingControlRequests.delete(requestId);
1907
+ reject(error);
1908
+ }
1909
+ });
1910
+ }
1911
+ pauseTrack(name) {
1912
+ this.peerConnectionQueue.push(() => __async(this, null, function* () {
1913
+ var _a;
1914
+ const entry = this.transceiverMap.get(name);
1915
+ if ((_a = entry == null ? void 0 : entry.transceiver) == null ? void 0 : _a.mid) {
1916
+ entry.transceiver.direction = "inactive";
1917
+ yield this.applyDirectionLocally(entry.transceiver.mid, "inactive");
1918
+ }
1919
+ this.sendControlMessage("pause_track", { name });
1920
+ })).catch((e) => {
1921
+ console.warn("[WebRTCTransport] Failed to pause track:", e);
1922
+ });
1923
+ }
1924
+ resumeTrack(name) {
1925
+ this.peerConnectionQueue.push(() => __async(this, null, function* () {
1926
+ var _a;
1927
+ const entry = this.transceiverMap.get(name);
1928
+ if ((_a = entry == null ? void 0 : entry.transceiver) == null ? void 0 : _a.mid) {
1929
+ entry.transceiver.direction = entry.direction;
1930
+ yield this.applyDirectionLocally(
1931
+ entry.transceiver.mid,
1932
+ entry.direction
1933
+ );
1934
+ }
1935
+ this.sendControlMessage("resume_track", { name });
1936
+ })).catch((e) => {
1937
+ console.warn("[WebRTCTransport] Failed to resume track:", e);
1938
+ });
1939
+ }
1940
+ applyDirectionLocally(mid, localDirection) {
1941
+ return __async(this, null, function* () {
1942
+ var _a, _b;
1943
+ const pc = this.peerConnection;
1944
+ if (!pc) return;
1945
+ const tx = pc.getTransceivers().find((t) => t.mid === mid);
1946
+ if (tx && tx.currentDirection === localDirection) return;
1947
+ if (pc.signalingState !== "stable") return;
1948
+ const localSdp = (_a = pc.localDescription) == null ? void 0 : _a.sdp;
1949
+ const remoteSdp = (_b = pc.remoteDescription) == null ? void 0 : _b.sdp;
1950
+ if (!localSdp || !remoteSdp) return;
1951
+ const modifiedLocal = replaceSdpDirectionForMid(
1952
+ localSdp,
1953
+ mid,
1954
+ localDirection
1955
+ );
1956
+ const modifiedRemote = replaceSdpDirectionForMid(
1957
+ remoteSdp,
1958
+ mid,
1959
+ complementDirection(localDirection)
1960
+ );
1961
+ try {
1962
+ yield pc.setLocalDescription(
1963
+ new RTCSessionDescription({ type: "offer", sdp: modifiedLocal })
1964
+ );
1965
+ yield pc.setRemoteDescription(
1966
+ new RTCSessionDescription({ type: "answer", sdp: modifiedRemote })
1967
+ );
1968
+ } catch (e) {
1969
+ if (pc.signalingState === "have-local-offer") {
1970
+ try {
1971
+ yield pc.setLocalDescription({ type: "rollback" });
1972
+ } catch (e2) {
1973
+ }
1974
+ }
1975
+ throw e;
1976
+ }
1977
+ });
1978
+ }
1744
1979
  // ─────────────────────────────────────────────────────────────────────────
1745
1980
  // Track Publishing
1746
1981
  // ─────────────────────────────────────────────────────────────────────────
@@ -1767,6 +2002,7 @@ var WebRTCTransportClient = class {
1767
2002
  `[WebRTCTransport] Cannot publish track "${name}" - transceiver is recvonly`
1768
2003
  );
1769
2004
  }
2005
+ yield this.sendControlRequest("publish_track", { name });
1770
2006
  yield entry.transceiver.sender.replaceTrack(track);
1771
2007
  this.publishedTracks.set(name, track);
1772
2008
  console.debug(`[WebRTCTransport] Track "${name}" published successfully`);
@@ -1778,6 +2014,7 @@ var WebRTCTransportClient = class {
1778
2014
  if (!(entry == null ? void 0 : entry.transceiver) || !this.publishedTracks.has(name)) return;
1779
2015
  try {
1780
2016
  yield entry.transceiver.sender.replaceTrack(null);
2017
+ this.sendControlMessage("unpublish_track", { name });
1781
2018
  console.debug(
1782
2019
  `[WebRTCTransport] Track "${name}" unpublished successfully`
1783
2020
  );
@@ -1863,9 +2100,11 @@ var WebRTCTransportClient = class {
1863
2100
  // Internal Helpers
1864
2101
  // ─────────────────────────────────────────────────────────────────────────
1865
2102
  checkFullyConnected() {
1866
- if (this.peerConnected && this.dataChannelOpen) {
2103
+ if (this.peerConnected && this.dataChannelOpen && this.controlChannelOpen) {
1867
2104
  this.setStatus("connected");
1868
2105
  this.startStatsPolling();
2106
+ this.readyGateResolve();
2107
+ this.readyGateResolve = void 0;
1869
2108
  }
1870
2109
  }
1871
2110
  setStatus(newStatus) {
@@ -1985,6 +2224,46 @@ var WebRTCTransportClient = class {
1985
2224
  }
1986
2225
  };
1987
2226
  }
2227
+ setupControlChannelHandlers() {
2228
+ if (!this.controlChannel) return;
2229
+ this.controlChannel.onopen = () => {
2230
+ console.debug("[WebRTCTransport] Control channel open");
2231
+ this.controlChannelOpen = true;
2232
+ this.checkFullyConnected();
2233
+ };
2234
+ this.controlChannel.onclose = () => {
2235
+ console.debug("[WebRTCTransport] Control channel closed");
2236
+ this.controlChannelOpen = false;
2237
+ };
2238
+ this.controlChannel.onerror = (error) => {
2239
+ console.error("[WebRTCTransport] Control channel error:", error);
2240
+ };
2241
+ this.controlChannel.onmessage = (event) => {
2242
+ var _a, _b;
2243
+ const raw = parseMessage(event.data);
2244
+ if ((raw == null ? void 0 : raw.type) === "response") {
2245
+ const requestId = raw == null ? void 0 : raw.request_id;
2246
+ if (requestId) {
2247
+ const pending = this.pendingControlRequests.get(requestId);
2248
+ if (pending) {
2249
+ clearTimeout(pending.timeout);
2250
+ this.pendingControlRequests.delete(requestId);
2251
+ if (raw == null ? void 0 : raw.error) {
2252
+ pending.reject(
2253
+ new Error(
2254
+ `[WebRTCTransport] ${(_a = raw.method) != null ? _a : "request"} failed: ${(_b = raw.error.message) != null ? _b : "unknown error"}`
2255
+ )
2256
+ );
2257
+ } else {
2258
+ pending.resolve();
2259
+ }
2260
+ }
2261
+ }
2262
+ return;
2263
+ }
2264
+ console.debug("[WebRTCTransport] Received control message:", raw);
2265
+ };
2266
+ }
1988
2267
  };
1989
2268
 
1990
2269
  // src/core/Reactor.ts
@@ -2668,7 +2947,17 @@ var OptionsSchema = z3.object({
2668
2947
  var Reactor = class {
2669
2948
  constructor(options) {
2670
2949
  this.status = "disconnected";
2950
+ /**
2951
+ * True only when the active session was created by THIS connect flow
2952
+ * (via `createSession()`). False when the session was adopted via
2953
+ * `connect({ sessionId })`. We must never DELETE a session we did not
2954
+ * create — another client (or the backend that created it) owns its
2955
+ * lifecycle, so on disconnect/teardown/error an adopting client tears
2956
+ * down its own transport but leaves the session alive.
2957
+ */
2958
+ this.createdSession = false;
2671
2959
  this.tracks = [];
2960
+ this.autoResumeTracks = false;
2672
2961
  this.eventListeners = /* @__PURE__ */ new Map();
2673
2962
  const validatedOptions = OptionsSchema.parse(options);
2674
2963
  this.coordinatorUrl = validatedOptions.apiUrl;
@@ -2905,6 +3194,7 @@ var Reactor = class {
2905
3194
  "gpu",
2906
3195
  true
2907
3196
  );
3197
+ throw error;
2908
3198
  }
2909
3199
  });
2910
3200
  }
@@ -2924,6 +3214,14 @@ var Reactor = class {
2924
3214
  }
2925
3215
  });
2926
3216
  }
3217
+ pauseTrack(name) {
3218
+ var _a;
3219
+ (_a = this.transportClient) == null ? void 0 : _a.pauseTrack(name);
3220
+ }
3221
+ resumeTrack(name) {
3222
+ var _a;
3223
+ (_a = this.transportClient) == null ? void 0 : _a.resumeTrack(name);
3224
+ }
2927
3225
  /**
2928
3226
  * Reconnects to an existing session with a fresh transport.
2929
3227
  */
@@ -2982,6 +3280,7 @@ var Reactor = class {
2982
3280
  */
2983
3281
  connect(jwtToken, options) {
2984
3282
  return __async(this, null, function* () {
3283
+ var _a;
2985
3284
  console.debug("[Reactor] Connecting, status:", this.status);
2986
3285
  if (jwtToken == void 0 && !this.local) {
2987
3286
  throw new Error("No authentication provided and not in local mode");
@@ -3005,12 +3304,14 @@ var Reactor = class {
3005
3304
  if (options == null ? void 0 : options.sessionId) {
3006
3305
  yield this.coordinatorClient.adoptSession(options.sessionId);
3007
3306
  sessionId = options.sessionId;
3307
+ this.createdSession = false;
3008
3308
  console.debug("[Reactor] Attaching to existing session:", sessionId);
3009
3309
  } else {
3010
3310
  const tSession = performance.now();
3011
3311
  const initialResponse = yield this.coordinatorClient.createSession();
3012
3312
  sessionCreationMs = performance.now() - tSession;
3013
3313
  sessionId = initialResponse.session_id;
3314
+ this.createdSession = true;
3014
3315
  console.debug(
3015
3316
  "[Reactor] Session created:",
3016
3317
  sessionId,
@@ -3030,19 +3331,18 @@ var Reactor = class {
3030
3331
  this.setupTransportHandlers();
3031
3332
  let sessionPollingMs;
3032
3333
  let transportConnectingMs;
3334
+ this.autoResumeTracks = (_a = options == null ? void 0 : options.autoResumeTracks) != null ? _a : true;
3033
3335
  if (this.presetTracks) {
3336
+ this.tracks = this.presetTracks;
3034
3337
  const tParallel = performance.now();
3035
3338
  const [sessionResponse] = yield Promise.all([
3036
3339
  this.coordinatorClient.pollSessionReady(),
3037
- this.transportClient.prepare(this.presetTracks)
3340
+ this.transportClient.prepare(this.tracks)
3038
3341
  ]);
3039
3342
  sessionPollingMs = performance.now() - tParallel;
3040
3343
  this.sessionResponse = sessionResponse;
3041
- this.capabilities = sessionResponse.capabilities;
3042
- this.tracks = this.presetTracks;
3043
- this.emit("capabilitiesReceived", this.capabilities);
3044
3344
  const tConnect = performance.now();
3045
- yield this.transportClient.connect();
3345
+ yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
3046
3346
  transportConnectingMs = performance.now() - tConnect;
3047
3347
  } else {
3048
3348
  this.transportClient.warmup();
@@ -3050,16 +3350,14 @@ var Reactor = class {
3050
3350
  const sessionResponse = yield this.coordinatorClient.pollSessionReady();
3051
3351
  sessionPollingMs = performance.now() - tPoll;
3052
3352
  this.sessionResponse = sessionResponse;
3053
- this.capabilities = sessionResponse.capabilities;
3054
3353
  this.tracks = sessionResponse.capabilities.tracks;
3055
- this.emit("capabilitiesReceived", this.capabilities);
3056
3354
  const protocol = sessionResponse.selected_transport.protocol;
3057
3355
  if (protocol !== "webrtc") {
3058
3356
  throw new Error(`Unsupported transport protocol: ${protocol}`);
3059
3357
  }
3060
3358
  const tTransport = performance.now();
3061
3359
  yield this.transportClient.prepare(this.tracks);
3062
- yield this.transportClient.connect();
3360
+ yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
3063
3361
  transportConnectingMs = performance.now() - tTransport;
3064
3362
  }
3065
3363
  console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
@@ -3101,6 +3399,10 @@ var Reactor = class {
3101
3399
  if (scope === "application") {
3102
3400
  this.emit("message", message);
3103
3401
  } else if (scope === "runtime") {
3402
+ if (message && typeof message === "object" && message.type === "modelSchema" && message.data) {
3403
+ this.schema = message.data;
3404
+ this.emit("schemaReceived", this.schema);
3405
+ }
3104
3406
  this.emit("runtimeMessage", message);
3105
3407
  }
3106
3408
  });
@@ -3109,7 +3411,15 @@ var Reactor = class {
3109
3411
  switch (status) {
3110
3412
  case "connected":
3111
3413
  this.finalizeConnectionTimings();
3414
+ if (this.autoResumeTracks) {
3415
+ for (const track of this.tracks) {
3416
+ if (track.direction === "recvonly") {
3417
+ this.resumeTrack(track.name);
3418
+ }
3419
+ }
3420
+ }
3112
3421
  this.setStatus("ready");
3422
+ void this.sendCommand("requestSchema", {}, "runtime");
3113
3423
  break;
3114
3424
  case "disconnected":
3115
3425
  this.disconnect(true);
@@ -3130,6 +3440,13 @@ var Reactor = class {
3130
3440
  (name, track, stream) => {
3131
3441
  if (this.transportClient !== client) return;
3132
3442
  this.emit("trackReceived", name, track, stream);
3443
+ if (this.autoResumeTracks) {
3444
+ for (const track2 of this.tracks) {
3445
+ if (track2.direction === "recvonly") {
3446
+ this.resumeTrack(track2.name);
3447
+ }
3448
+ }
3449
+ }
3133
3450
  }
3134
3451
  );
3135
3452
  client.on("statsUpdate", (stats) => {
@@ -3152,10 +3469,16 @@ var Reactor = class {
3152
3469
  (_a = this.coordinatorClient) == null ? void 0 : _a.abort();
3153
3470
  (_b = this.transportClient) == null ? void 0 : _b.abort();
3154
3471
  if (this.coordinatorClient && !recoverable) {
3155
- try {
3156
- yield this.coordinatorClient.terminateSession();
3157
- } catch (error) {
3158
- console.error("[Reactor] Error terminating session:", error);
3472
+ if (this.createdSession) {
3473
+ try {
3474
+ yield this.coordinatorClient.terminateSession();
3475
+ } catch (error) {
3476
+ console.error("[Reactor] Error terminating session:", error);
3477
+ }
3478
+ } else {
3479
+ console.debug(
3480
+ "[Reactor] Adopted session (not the creator) \u2014 skipping DELETE, leaving it alive"
3481
+ );
3159
3482
  }
3160
3483
  this.coordinatorClient = void 0;
3161
3484
  }
@@ -3174,9 +3497,10 @@ var Reactor = class {
3174
3497
  if (!recoverable) {
3175
3498
  this.setSessionExpiration(void 0);
3176
3499
  this.setSessionId(void 0);
3177
- this.capabilities = void 0;
3500
+ this.schema = void 0;
3178
3501
  this.tracks = [];
3179
3502
  this.sessionResponse = void 0;
3503
+ this.createdSession = false;
3180
3504
  }
3181
3505
  });
3182
3506
  }
@@ -3198,8 +3522,13 @@ var Reactor = class {
3198
3522
  getLastError() {
3199
3523
  return this.lastError;
3200
3524
  }
3201
- getCapabilities() {
3202
- return this.capabilities;
3525
+ /**
3526
+ * The model's OpenAPI schema (events, outbound messages, tracks),
3527
+ * received over the runtime channel shortly after the session becomes
3528
+ * ready. `undefined` until the `schemaReceived` event has fired.
3529
+ */
3530
+ getSchema() {
3531
+ return this.schema;
3203
3532
  }
3204
3533
  getSessionInfo() {
3205
3534
  return this.sessionResponse;
@@ -3210,6 +3539,10 @@ var Reactor = class {
3210
3539
  if (!stats) return void 0;
3211
3540
  return __spreadProps(__spreadValues({}, stats), { connectionTimings: this.connectionTimings });
3212
3541
  }
3542
+ /** Timing breakdown from the most recent connect() handshake. */
3543
+ getConnectionTimings() {
3544
+ return this.connectionTimings;
3545
+ }
3213
3546
  // ─────────────────────────────────────────────────────────────────────────
3214
3547
  // Private State Management
3215
3548
  // ─────────────────────────────────────────────────────────────────────────
@@ -3286,7 +3619,8 @@ var defaultInitState = {
3286
3619
  lastError: void 0,
3287
3620
  sessionExpiration: void 0,
3288
3621
  jwtToken: void 0,
3289
- sessionId: void 0
3622
+ sessionId: void 0,
3623
+ connectOptions: void 0
3290
3624
  };
3291
3625
  var initReactorStore = (props) => {
3292
3626
  return __spreadValues(__spreadValues({}, defaultInitState), props);
@@ -3342,6 +3676,7 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
3342
3676
  });
3343
3677
  return __spreadProps(__spreadValues({}, publicState), {
3344
3678
  jwtToken: initProps.jwtToken,
3679
+ connectOptions: initProps.connectOptions,
3345
3680
  internal: { reactor },
3346
3681
  // actions
3347
3682
  onMessage: (handler) => {
@@ -3370,9 +3705,10 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
3370
3705
  if (jwtToken === void 0) {
3371
3706
  jwtToken = get().jwtToken;
3372
3707
  }
3708
+ const resolvedOptions = __spreadValues(__spreadValues({}, get().connectOptions), options);
3373
3709
  console.debug("[ReactorStore] Connect called.");
3374
3710
  try {
3375
- yield get().internal.reactor.connect(jwtToken, options);
3711
+ yield get().internal.reactor.connect(jwtToken, resolvedOptions);
3376
3712
  console.debug("[ReactorStore] Connect completed successfully");
3377
3713
  } catch (error) {
3378
3714
  console.error("[ReactorStore] Connect failed:", error);
@@ -3421,6 +3757,8 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
3421
3757
  throw error;
3422
3758
  }
3423
3759
  }),
3760
+ pauseTrack: (name) => get().internal.reactor.pauseTrack(name),
3761
+ resumeTrack: (name) => get().internal.reactor.resumeTrack(name),
3424
3762
  reconnect: (options) => __async(null, null, function* () {
3425
3763
  console.debug("[ReactorStore] Reconnecting");
3426
3764
  try {
@@ -3480,30 +3818,31 @@ function ReactorProvider(_a) {
3480
3818
  const storeRef = useRef(void 0);
3481
3819
  const firstRender = useRef(true);
3482
3820
  const [_storeVersion, setStoreVersion] = useState(0);
3821
+ const _a2 = connectOptions != null ? connectOptions : {}, { autoConnect = false } = _a2, pollingOptions = __objRest(_a2, ["autoConnect"]);
3483
3822
  if (storeRef.current === void 0) {
3484
3823
  console.debug("[ReactorProvider] Creating new reactor store");
3485
3824
  storeRef.current = createReactorStore(
3486
3825
  initReactorStore(__spreadProps(__spreadValues({}, props), {
3487
- jwtToken: jwtSource
3826
+ jwtToken: jwtSource,
3827
+ connectOptions: pollingOptions
3488
3828
  }))
3489
3829
  );
3490
3830
  console.debug("[ReactorProvider] Reactor store created successfully");
3491
3831
  }
3492
- const _a2 = connectOptions != null ? connectOptions : {}, { autoConnect = false } = _a2, pollingOptions = __objRest(_a2, ["autoConnect"]);
3493
3832
  const { apiUrl, modelName, local } = props;
3494
3833
  const maxAttempts = pollingOptions.maxAttempts;
3834
+ const { autoResumeTracks } = pollingOptions;
3835
+ useEffect(() => {
3836
+ var _a3;
3837
+ (_a3 = storeRef.current) == null ? void 0 : _a3.setState({ connectOptions: pollingOptions });
3838
+ }, [autoResumeTracks, maxAttempts]);
3495
3839
  useEffect(() => {
3496
3840
  const handleBeforeUnload = () => {
3497
3841
  var _a3;
3498
- console.debug(
3499
- "[ReactorProvider] Page unloading, performing non-recoverable disconnect"
3500
- );
3501
3842
  (_a3 = storeRef.current) == null ? void 0 : _a3.getState().internal.reactor.disconnect(false);
3502
3843
  };
3503
3844
  window.addEventListener("beforeunload", handleBeforeUnload);
3504
- return () => {
3505
- window.removeEventListener("beforeunload", handleBeforeUnload);
3506
- };
3845
+ return () => window.removeEventListener("beforeunload", handleBeforeUnload);
3507
3846
  }, []);
3508
3847
  useEffect(() => {
3509
3848
  if (firstRender.current) {
@@ -3546,7 +3885,8 @@ function ReactorProvider(_a) {
3546
3885
  apiUrl,
3547
3886
  modelName,
3548
3887
  local,
3549
- jwtToken: jwtSource
3888
+ jwtToken: jwtSource,
3889
+ connectOptions: pollingOptions
3550
3890
  })
3551
3891
  );
3552
3892
  const current = storeRef.current;
@@ -3672,26 +4012,39 @@ function ReactorView({
3672
4012
  hasVideoTrack: !!videoMediaTrack,
3673
4013
  hasAudioTrack: !!audioMediaTrack
3674
4014
  });
3675
- if (videoRef.current && mediaStream) {
3676
- console.debug("[ReactorView] Attaching media stream to element");
4015
+ const el = videoRef.current;
4016
+ if (!el || !mediaStream) {
4017
+ console.debug("[ReactorView] No tracks or element to attach");
4018
+ return;
4019
+ }
4020
+ const attach = (reset) => {
3677
4021
  try {
3678
- videoRef.current.srcObject = mediaStream;
3679
- videoRef.current.play().catch((e) => {
4022
+ if (reset) el.srcObject = null;
4023
+ el.srcObject = mediaStream;
4024
+ el.play().catch((e) => {
3680
4025
  console.warn("[ReactorView] Auto-play failed:", e);
3681
4026
  });
3682
- console.debug("[ReactorView] Media stream attached successfully");
3683
4027
  } catch (error) {
3684
4028
  console.error("[ReactorView] Failed to attach media stream:", error);
3685
4029
  }
3686
- return () => {
3687
- console.debug("[ReactorView] Detaching media stream from element");
3688
- if (videoRef.current) {
3689
- videoRef.current.srcObject = null;
3690
- }
3691
- };
3692
- } else {
3693
- console.debug("[ReactorView] No tracks or element to attach");
3694
- }
4030
+ };
4031
+ console.debug("[ReactorView] Attaching media stream to element");
4032
+ attach(false);
4033
+ const onUnmute = () => {
4034
+ console.debug(
4035
+ "[ReactorView] Track unmuted \u2014 re-attaching to render incoming media"
4036
+ );
4037
+ attach(true);
4038
+ };
4039
+ const tracks = mediaStream.getTracks();
4040
+ for (const t of tracks) t.addEventListener("unmute", onUnmute);
4041
+ return () => {
4042
+ console.debug("[ReactorView] Detaching media stream from element");
4043
+ for (const t of tracks) t.removeEventListener("unmute", onUnmute);
4044
+ if (videoRef.current) {
4045
+ videoRef.current.srcObject = null;
4046
+ }
4047
+ };
3695
4048
  }, [mediaStream]);
3696
4049
  return /* @__PURE__ */ jsx2(
3697
4050
  "div",
@@ -3719,576 +4072,9 @@ function ReactorView({
3719
4072
  );
3720
4073
  }
3721
4074
 
3722
- // src/react/ReactorController.tsx
3723
- import React, { useState as useState3, useCallback, useRef as useRef4 } from "react";
3724
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
3725
- function isFileParam(ps) {
3726
- return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
3727
- }
3728
- function ReactorController({
3729
- className,
3730
- style
3731
- }) {
3732
- const { sendCommand, uploadFile, status } = useReactor((state) => ({
3733
- sendCommand: state.sendCommand,
3734
- uploadFile: state.uploadFile,
3735
- status: state.status
3736
- }));
3737
- const [commands, setCommands] = useState3({});
3738
- const [formValues, setFormValues] = useState3({});
3739
- const formRef = useRef4(formValues);
3740
- formRef.current = formValues;
3741
- const [expandedCommands, setExpandedCommands] = useState3({});
3742
- React.useEffect(() => {
3743
- if (status === "disconnected") {
3744
- setCommands({});
3745
- setFormValues({});
3746
- setExpandedCommands({});
3747
- }
3748
- }, [status]);
3749
- const requestCapabilities = useCallback(() => {
3750
- if (status === "ready") {
3751
- sendCommand("requestCapabilities", {}, "runtime");
3752
- }
3753
- }, [status, sendCommand]);
3754
- React.useEffect(() => {
3755
- if (status === "ready") {
3756
- requestCapabilities();
3757
- }
3758
- }, [status, requestCapabilities]);
3759
- React.useEffect(() => {
3760
- if (status !== "ready" || Object.keys(commands).length > 0) {
3761
- return;
3762
- }
3763
- const interval = setInterval(() => {
3764
- requestCapabilities();
3765
- }, 5e3);
3766
- return () => clearInterval(interval);
3767
- }, [status, commands, requestCapabilities]);
3768
- useReactorInternalMessage((message) => {
3769
- var _a;
3770
- if (message && typeof message === "object" && message.type === "modelCapabilities" && message.data && "commands" in message.data) {
3771
- const commandsMessage = message.data;
3772
- const commandsRecord = {};
3773
- for (const cmd of commandsMessage.commands) {
3774
- commandsRecord[cmd.name] = {
3775
- description: cmd.description,
3776
- schema: (_a = cmd.schema) != null ? _a : {}
3777
- };
3778
- }
3779
- setCommands(commandsRecord);
3780
- const initialValues = {};
3781
- const initialExpanded = {};
3782
- Object.entries(commandsRecord).forEach(([commandName, commandSchema]) => {
3783
- initialValues[commandName] = {};
3784
- initialExpanded[commandName] = false;
3785
- Object.entries(commandSchema.schema).forEach(
3786
- ([paramName, paramSchema]) => {
3787
- var _a2;
3788
- if (isFileParam(paramSchema)) {
3789
- initialValues[commandName][paramName] = null;
3790
- } else if (paramSchema.default !== void 0) {
3791
- initialValues[commandName][paramName] = paramSchema.default;
3792
- } else if (paramSchema.type === "number" || paramSchema.type === "integer") {
3793
- initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
3794
- } else if (paramSchema.type === "string") {
3795
- initialValues[commandName][paramName] = "";
3796
- } else if (paramSchema.type === "boolean") {
3797
- initialValues[commandName][paramName] = false;
3798
- }
3799
- }
3800
- );
3801
- });
3802
- setFormValues(initialValues);
3803
- setExpandedCommands(initialExpanded);
3804
- }
3805
- });
3806
- const handleInputChange = useCallback(
3807
- (commandName, paramName, value) => {
3808
- setFormValues((prev) => __spreadProps(__spreadValues({}, prev), {
3809
- [commandName]: __spreadProps(__spreadValues({}, prev[commandName]), {
3810
- [paramName]: value
3811
- })
3812
- }));
3813
- },
3814
- []
3815
- );
3816
- const toggleCommandExpanded = useCallback((commandName) => {
3817
- setExpandedCommands((prev) => __spreadProps(__spreadValues({}, prev), {
3818
- [commandName]: !prev[commandName]
3819
- }));
3820
- }, []);
3821
- const handleCommandSubmit = useCallback(
3822
- (commandName) => __async(null, null, function* () {
3823
- const commandSchema = commands[commandName];
3824
- const formData = formRef.current[commandName] || {};
3825
- const data = {};
3826
- Object.keys(commandSchema.schema).forEach((paramName) => {
3827
- var _a;
3828
- const paramSchema = commandSchema.schema[paramName];
3829
- let value = formData[paramName];
3830
- if (value instanceof FileRef) {
3831
- data[paramName] = value;
3832
- return;
3833
- }
3834
- if (paramSchema.type === "number" && typeof value === "string") {
3835
- value = parseFloat(value) || 0;
3836
- } else if (paramSchema.type === "integer" && typeof value === "string") {
3837
- value = parseInt(value) || 0;
3838
- } else if (paramSchema.type === "boolean" && typeof value !== "boolean") {
3839
- value = Boolean(value);
3840
- }
3841
- if (value !== void 0 && value !== "" && value !== null) {
3842
- data[paramName] = value;
3843
- } else if (paramSchema.required) {
3844
- if (paramSchema.type === "number" || paramSchema.type === "integer") {
3845
- data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
3846
- } else if (paramSchema.type === "string") {
3847
- data[paramName] = "";
3848
- } else if (paramSchema.type === "boolean") {
3849
- data[paramName] = false;
3850
- }
3851
- }
3852
- });
3853
- yield sendCommand(commandName, data);
3854
- }),
3855
- [sendCommand, commands]
3856
- );
3857
- const renderInput = (commandName, paramName, paramSchema) => {
3858
- var _a, _b;
3859
- const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
3860
- if (isFileParam(paramSchema)) {
3861
- return /* @__PURE__ */ jsx3(
3862
- FileParamInput,
3863
- {
3864
- commandName,
3865
- paramName,
3866
- description: paramSchema.description,
3867
- value,
3868
- onChange: handleInputChange,
3869
- disabled: status !== "ready",
3870
- uploadFile
3871
- },
3872
- `${commandName}-${paramName}`
3873
- );
3874
- }
3875
- if (paramSchema.type === "number" || paramSchema.type === "integer") {
3876
- const isInteger = paramSchema.type === "integer";
3877
- const step = isInteger ? 1 : 0.1;
3878
- const parseValue = isInteger ? parseInt : parseFloat;
3879
- if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
3880
- return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3881
- /* @__PURE__ */ jsxs(
3882
- "label",
3883
- {
3884
- style: { fontSize: "12px", color: "#666", display: "block" },
3885
- children: [
3886
- paramName,
3887
- " (",
3888
- paramSchema.minimum,
3889
- " - ",
3890
- paramSchema.maximum,
3891
- ")",
3892
- paramSchema.description && ` - ${paramSchema.description}`,
3893
- paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
3894
- ]
3895
- }
3896
- ),
3897
- /* @__PURE__ */ jsx3(
3898
- "input",
3899
- {
3900
- type: "range",
3901
- min: paramSchema.minimum,
3902
- max: paramSchema.maximum,
3903
- step,
3904
- value,
3905
- onChange: (e) => {
3906
- const newValue = parseValue(e.target.value) || 0;
3907
- handleInputChange(commandName, paramName, newValue);
3908
- handleCommandSubmit(commandName);
3909
- },
3910
- style: { width: "100%", marginBottom: "4px" }
3911
- }
3912
- ),
3913
- /* @__PURE__ */ jsxs("div", { style: { fontSize: "11px", color: "#888" }, children: [
3914
- "Value: ",
3915
- value
3916
- ] })
3917
- ] });
3918
- } else {
3919
- return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3920
- /* @__PURE__ */ jsxs(
3921
- "label",
3922
- {
3923
- style: { fontSize: "12px", color: "#666", display: "block" },
3924
- children: [
3925
- paramName,
3926
- paramSchema.description && ` - ${paramSchema.description}`,
3927
- paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
3928
- ]
3929
- }
3930
- ),
3931
- /* @__PURE__ */ jsx3(
3932
- "input",
3933
- {
3934
- type: "number",
3935
- value,
3936
- min: paramSchema.minimum,
3937
- max: paramSchema.maximum,
3938
- step,
3939
- inputMode: "numeric",
3940
- onChange: (e) => {
3941
- const val = e.target.value;
3942
- if (val === "" || val === "-") {
3943
- handleInputChange(commandName, paramName, val);
3944
- } else {
3945
- const parsed = parseValue(val);
3946
- if (!isNaN(parsed)) {
3947
- handleInputChange(commandName, paramName, parsed);
3948
- }
3949
- }
3950
- },
3951
- onBlur: (e) => {
3952
- const val = e.target.value;
3953
- if (val === "" || val === "-") {
3954
- handleInputChange(commandName, paramName, 0);
3955
- }
3956
- },
3957
- style: {
3958
- width: "100%",
3959
- padding: "4px",
3960
- fontSize: "12px",
3961
- border: "1px solid #ccc",
3962
- borderRadius: "2px"
3963
- }
3964
- }
3965
- )
3966
- ] });
3967
- }
3968
- } else if (paramSchema.type === "string") {
3969
- if (paramSchema.enum) {
3970
- return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
3971
- /* @__PURE__ */ jsxs(
3972
- "label",
3973
- {
3974
- style: { fontSize: "12px", color: "#666", display: "block" },
3975
- children: [
3976
- paramName,
3977
- paramSchema.description && ` - ${paramSchema.description}`,
3978
- paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
3979
- ]
3980
- }
3981
- ),
3982
- /* @__PURE__ */ jsxs(
3983
- "select",
3984
- {
3985
- value,
3986
- onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
3987
- style: {
3988
- width: "100%",
3989
- padding: "4px",
3990
- fontSize: "12px",
3991
- border: "1px solid #ccc",
3992
- borderRadius: "2px"
3993
- },
3994
- children: [
3995
- /* @__PURE__ */ jsx3("option", { value: "", children: "Select..." }),
3996
- paramSchema.enum.map((option) => /* @__PURE__ */ jsx3("option", { value: option, children: option }, option))
3997
- ]
3998
- }
3999
- )
4000
- ] });
4001
- } else {
4002
- return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
4003
- /* @__PURE__ */ jsxs(
4004
- "label",
4005
- {
4006
- style: { fontSize: "12px", color: "#666", display: "block" },
4007
- children: [
4008
- paramName,
4009
- paramSchema.description && ` - ${paramSchema.description}`,
4010
- paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
4011
- ]
4012
- }
4013
- ),
4014
- /* @__PURE__ */ jsx3(
4015
- "input",
4016
- {
4017
- type: "text",
4018
- value,
4019
- onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
4020
- style: {
4021
- width: "100%",
4022
- padding: "4px",
4023
- fontSize: "12px",
4024
- border: "1px solid #ccc",
4025
- borderRadius: "2px"
4026
- }
4027
- }
4028
- )
4029
- ] });
4030
- }
4031
- } else if (paramSchema.type === "boolean") {
4032
- return /* @__PURE__ */ jsx3("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsxs(
4033
- "label",
4034
- {
4035
- style: {
4036
- fontSize: "12px",
4037
- color: "#666",
4038
- display: "flex",
4039
- alignItems: "center"
4040
- },
4041
- children: [
4042
- /* @__PURE__ */ jsx3(
4043
- "input",
4044
- {
4045
- type: "checkbox",
4046
- checked: value,
4047
- onChange: (e) => handleInputChange(commandName, paramName, e.target.checked),
4048
- style: { marginRight: "6px" }
4049
- }
4050
- ),
4051
- paramName,
4052
- paramSchema.description && ` - ${paramSchema.description}`,
4053
- paramSchema.required && /* @__PURE__ */ jsx3("span", { style: { color: "red" }, children: " *" })
4054
- ]
4055
- }
4056
- ) });
4057
- }
4058
- return null;
4059
- };
4060
- const renderCommand = (commandName, commandSchema) => {
4061
- const hasParams = Object.keys(commandSchema.schema).length > 0;
4062
- const isExpanded = expandedCommands[commandName];
4063
- const params = Object.values(commandSchema.schema);
4064
- const allSliders = params.length > 0 && params.every(
4065
- (ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
4066
- );
4067
- const showExecuteButton = !allSliders;
4068
- return /* @__PURE__ */ jsxs(
4069
- "div",
4070
- {
4071
- style: {
4072
- border: "1px solid #ddd",
4073
- borderRadius: "4px",
4074
- marginBottom: "8px",
4075
- backgroundColor: "#fafafa"
4076
- },
4077
- children: [
4078
- /* @__PURE__ */ jsxs(
4079
- "div",
4080
- {
4081
- onClick: () => toggleCommandExpanded(commandName),
4082
- style: {
4083
- padding: "8px 12px",
4084
- cursor: "pointer",
4085
- borderBottom: isExpanded ? "1px solid #ddd" : "none",
4086
- display: "flex",
4087
- justifyContent: "space-between",
4088
- alignItems: "center"
4089
- },
4090
- children: [
4091
- /* @__PURE__ */ jsxs("div", { children: [
4092
- /* @__PURE__ */ jsx3(
4093
- "h4",
4094
- {
4095
- style: {
4096
- margin: "0",
4097
- fontSize: "13px",
4098
- fontWeight: "bold"
4099
- },
4100
- children: commandName
4101
- }
4102
- ),
4103
- isExpanded && commandSchema.description && /* @__PURE__ */ jsx3(
4104
- "p",
4105
- {
4106
- style: { margin: "4px 0 0 0", fontSize: "11px", color: "#666" },
4107
- children: commandSchema.description
4108
- }
4109
- )
4110
- ] }),
4111
- /* @__PURE__ */ jsx3(
4112
- "div",
4113
- {
4114
- style: {
4115
- fontSize: "10px",
4116
- color: "#999",
4117
- transform: isExpanded ? "rotate(180deg)" : "rotate(0deg)",
4118
- transition: "transform 0.2s"
4119
- },
4120
- children: "\u25BC"
4121
- }
4122
- )
4123
- ]
4124
- }
4125
- ),
4126
- isExpanded && /* @__PURE__ */ jsxs("div", { style: { padding: "12px", paddingTop: "0" }, children: [
4127
- hasParams && /* @__PURE__ */ jsxs("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
4128
- /* @__PURE__ */ jsx3(
4129
- "div",
4130
- {
4131
- style: {
4132
- marginBottom: "8px",
4133
- fontSize: "12px",
4134
- fontWeight: "bold",
4135
- color: "#555"
4136
- },
4137
- children: "Parameters:"
4138
- }
4139
- ),
4140
- Object.entries(commandSchema.schema).map(
4141
- ([paramName, paramSchema]) => /* @__PURE__ */ jsx3(
4142
- "div",
4143
- {
4144
- style: { marginLeft: "8px" },
4145
- children: renderInput(commandName, paramName, paramSchema)
4146
- },
4147
- `${commandName}-${paramName}`
4148
- )
4149
- )
4150
- ] }),
4151
- !hasParams && /* @__PURE__ */ jsx3(
4152
- "div",
4153
- {
4154
- style: {
4155
- marginBottom: showExecuteButton ? "12px" : "0",
4156
- marginTop: "2px",
4157
- fontSize: "11px",
4158
- color: "#666",
4159
- fontStyle: "italic"
4160
- },
4161
- children: "No parameters required"
4162
- }
4163
- ),
4164
- showExecuteButton && /* @__PURE__ */ jsxs(
4165
- "button",
4166
- {
4167
- onClick: () => handleCommandSubmit(commandName),
4168
- style: {
4169
- padding: "8px 16px",
4170
- fontSize: "12px",
4171
- backgroundColor: "#007bff",
4172
- color: "white",
4173
- border: "none",
4174
- borderRadius: "4px",
4175
- cursor: "pointer",
4176
- fontWeight: "bold"
4177
- },
4178
- children: [
4179
- "Execute ",
4180
- commandName
4181
- ]
4182
- }
4183
- )
4184
- ] })
4185
- ]
4186
- },
4187
- commandName
4188
- );
4189
- };
4190
- return /* @__PURE__ */ jsx3("div", { className, style, children: /* @__PURE__ */ jsx3("div", { style: { fontFamily: "monospace", fontSize: "12px" }, children: Object.keys(commands).length === 0 ? /* @__PURE__ */ jsx3("div", { style: { padding: "12px", color: "#666", fontStyle: "italic" }, children: "Waiting for commands schema..." }) : /* @__PURE__ */ jsxs("div", { children: [
4191
- /* @__PURE__ */ jsx3(
4192
- "h3",
4193
- {
4194
- style: {
4195
- margin: "0 0 16px 0",
4196
- fontSize: "16px",
4197
- fontWeight: "bold"
4198
- },
4199
- children: "Reactor Commands"
4200
- }
4201
- ),
4202
- Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ jsx3("div", { children: renderCommand(commandName, commandSchema) }, commandName))
4203
- ] }) }) });
4204
- }
4205
- function FileParamInput({
4206
- commandName,
4207
- paramName,
4208
- description,
4209
- value,
4210
- onChange,
4211
- disabled,
4212
- uploadFile
4213
- }) {
4214
- const inputRef = useRef4(null);
4215
- const [uploading, setUploading] = useState3(false);
4216
- const fileRef = value instanceof FileRef ? value : null;
4217
- const handleFile = (e) => __async(null, null, function* () {
4218
- var _a;
4219
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
4220
- if (!file) return;
4221
- e.target.value = "";
4222
- setUploading(true);
4223
- try {
4224
- const ref = yield uploadFile(file);
4225
- onChange(commandName, paramName, ref);
4226
- } catch (err) {
4227
- console.error("[FileParamInput] Upload failed:", err);
4228
- } finally {
4229
- setUploading(false);
4230
- }
4231
- });
4232
- return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "8px" }, children: [
4233
- /* @__PURE__ */ jsxs("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
4234
- paramName,
4235
- /* @__PURE__ */ jsx3("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
4236
- description && ` - ${description}`
4237
- ] }),
4238
- /* @__PURE__ */ jsxs(
4239
- "div",
4240
- {
4241
- style: {
4242
- display: "flex",
4243
- alignItems: "center",
4244
- gap: "8px",
4245
- marginTop: "4px"
4246
- },
4247
- children: [
4248
- /* @__PURE__ */ jsx3(
4249
- "input",
4250
- {
4251
- ref: inputRef,
4252
- type: "file",
4253
- accept: "image/*",
4254
- onChange: handleFile,
4255
- style: { display: "none" }
4256
- }
4257
- ),
4258
- /* @__PURE__ */ jsx3(
4259
- "button",
4260
- {
4261
- disabled: disabled || uploading,
4262
- onClick: () => {
4263
- var _a;
4264
- return (_a = inputRef.current) == null ? void 0 : _a.click();
4265
- },
4266
- style: {
4267
- padding: "4px 12px",
4268
- fontSize: "12px",
4269
- backgroundColor: "#007bff",
4270
- color: "white",
4271
- border: "none",
4272
- borderRadius: "4px",
4273
- cursor: disabled || uploading ? "default" : "pointer",
4274
- opacity: disabled || uploading ? 0.5 : 1
4275
- },
4276
- children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
4277
- }
4278
- ),
4279
- fileRef && /* @__PURE__ */ jsxs("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
4280
- "\\u2713 ",
4281
- fileRef.name
4282
- ] })
4283
- ]
4284
- }
4285
- )
4286
- ] });
4287
- }
4288
-
4289
4075
  // src/react/WebcamStream.tsx
4290
- import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
4291
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
4076
+ import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
4077
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
4292
4078
  function WebcamStream({
4293
4079
  track,
4294
4080
  audio = false,
@@ -4305,19 +4091,19 @@ function WebcamStream({
4305
4091
  onPublished,
4306
4092
  onError
4307
4093
  }) {
4308
- const [stream, setStream] = useState4(null);
4309
- const [isPublishing, setIsPublishing] = useState4(false);
4310
- const [permissionDenied, setPermissionDenied] = useState4(false);
4094
+ const [stream, setStream] = useState3(null);
4095
+ const [isPublishing, setIsPublishing] = useState3(false);
4096
+ const [permissionDenied, setPermissionDenied] = useState3(false);
4311
4097
  const { status, publish, unpublish, reactor } = useReactor((state) => ({
4312
4098
  status: state.status,
4313
4099
  publish: state.publish,
4314
4100
  unpublish: state.unpublish,
4315
4101
  reactor: state.internal.reactor
4316
4102
  }));
4317
- const videoRef = useRef5(null);
4318
- const onPermissionDeniedRef = useRef5(onPermissionDenied);
4319
- const onPublishedRef = useRef5(onPublished);
4320
- const onErrorRef = useRef5(onError);
4103
+ const videoRef = useRef4(null);
4104
+ const onPermissionDeniedRef = useRef4(onPermissionDenied);
4105
+ const onPublishedRef = useRef4(onPublished);
4106
+ const onErrorRef = useRef4(onError);
4321
4107
  useEffect4(() => {
4322
4108
  onPermissionDeniedRef.current = onPermissionDenied;
4323
4109
  onPublishedRef.current = onPublished;
@@ -4490,7 +4276,7 @@ function WebcamStream({
4490
4276
  };
4491
4277
  }, []);
4492
4278
  const showPlaceholder = !stream;
4493
- return /* @__PURE__ */ jsxs2(
4279
+ return /* @__PURE__ */ jsxs(
4494
4280
  "div",
4495
4281
  {
4496
4282
  style: __spreadValues({
@@ -4500,7 +4286,7 @@ function WebcamStream({
4500
4286
  }, style),
4501
4287
  className,
4502
4288
  children: [
4503
- /* @__PURE__ */ jsx4(
4289
+ /* @__PURE__ */ jsx3(
4504
4290
  "video",
4505
4291
  {
4506
4292
  ref: videoRef,
@@ -4515,7 +4301,7 @@ function WebcamStream({
4515
4301
  autoPlay: true
4516
4302
  }
4517
4303
  ),
4518
- showPlaceholder && /* @__PURE__ */ jsx4(
4304
+ showPlaceholder && /* @__PURE__ */ jsx3(
4519
4305
  "div",
4520
4306
  {
4521
4307
  style: {
@@ -4536,11 +4322,11 @@ function WebcamStream({
4536
4322
  flexDirection: "column",
4537
4323
  gap: "12px"
4538
4324
  },
4539
- children: permissionDenied ? /* @__PURE__ */ jsxs2("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
4325
+ children: permissionDenied ? /* @__PURE__ */ jsxs("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
4540
4326
  "Camera access denied.",
4541
- /* @__PURE__ */ jsx4("br", {}),
4327
+ /* @__PURE__ */ jsx3("br", {}),
4542
4328
  "Please allow access in your browser settings."
4543
- ] }) : /* @__PURE__ */ jsx4("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
4329
+ ] }) : /* @__PURE__ */ jsx3("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
4544
4330
  }
4545
4331
  )
4546
4332
  ]
@@ -4549,8 +4335,8 @@ function WebcamStream({
4549
4335
  }
4550
4336
 
4551
4337
  // src/react/ClipPlayer.tsx
4552
- import { useContext as useContext2, useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
4553
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
4338
+ import { useContext as useContext2, useEffect as useEffect5, useRef as useRef5, useState as useState4 } from "react";
4339
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
4554
4340
  function ClipPlayer({
4555
4341
  clip,
4556
4342
  getJwt,
@@ -4561,14 +4347,14 @@ function ClipPlayer({
4561
4347
  style,
4562
4348
  onError
4563
4349
  }) {
4564
- const videoRef = useRef6(null);
4565
- const [phase, setPhase] = useState5({ kind: "waiting" });
4350
+ const videoRef = useRef5(null);
4351
+ const [phase, setPhase] = useState4({ kind: "waiting" });
4566
4352
  const store = useContext2(ReactorContext);
4567
- const getJwtRef = useRef6(getJwt);
4568
- const autoPlayRef = useRef6(autoPlay);
4569
- const slackMsRef = useRef6(slackMs);
4570
- const onErrorRef = useRef6(onError);
4571
- const storeRef = useRef6(store);
4353
+ const getJwtRef = useRef5(getJwt);
4354
+ const autoPlayRef = useRef5(autoPlay);
4355
+ const slackMsRef = useRef5(slackMs);
4356
+ const onErrorRef = useRef5(onError);
4357
+ const storeRef = useRef5(store);
4572
4358
  useEffect5(() => {
4573
4359
  getJwtRef.current = getJwt;
4574
4360
  autoPlayRef.current = autoPlay;
@@ -4685,7 +4471,7 @@ function ClipPlayer({
4685
4471
  };
4686
4472
  }, [clip]);
4687
4473
  const overlayText = phase.kind === "waiting" ? "Waiting for clip\u2026" : phase.kind === "loading" ? "Loading player\u2026" : null;
4688
- return /* @__PURE__ */ jsxs3(
4474
+ return /* @__PURE__ */ jsxs2(
4689
4475
  "div",
4690
4476
  {
4691
4477
  className,
@@ -4698,7 +4484,7 @@ function ClipPlayer({
4698
4484
  justifyContent: "center"
4699
4485
  }, style),
4700
4486
  children: [
4701
- /* @__PURE__ */ jsx5(
4487
+ /* @__PURE__ */ jsx4(
4702
4488
  "video",
4703
4489
  {
4704
4490
  ref: videoRef,
@@ -4713,7 +4499,7 @@ function ClipPlayer({
4713
4499
  }
4714
4500
  }
4715
4501
  ),
4716
- overlayText && /* @__PURE__ */ jsx5(
4502
+ overlayText && /* @__PURE__ */ jsx4(
4717
4503
  "div",
4718
4504
  {
4719
4505
  style: {
@@ -4731,7 +4517,7 @@ function ClipPlayer({
4731
4517
  children: overlayText
4732
4518
  }
4733
4519
  ),
4734
- phase.kind === "error" && /* @__PURE__ */ jsx5(
4520
+ phase.kind === "error" && /* @__PURE__ */ jsx4(
4735
4521
  "div",
4736
4522
  {
4737
4523
  style: {
@@ -4755,26 +4541,26 @@ function ClipPlayer({
4755
4541
  }
4756
4542
 
4757
4543
  // src/react/ClipDownloadButton.tsx
4758
- import { useEffect as useEffect7, useRef as useRef8 } from "react";
4544
+ import { useEffect as useEffect7, useRef as useRef7 } from "react";
4759
4545
 
4760
4546
  // src/react/useClipDownload.ts
4761
- import { useCallback as useCallback2, useContext as useContext3, useEffect as useEffect6, useRef as useRef7, useState as useState6 } from "react";
4547
+ import { useCallback, useContext as useContext3, useEffect as useEffect6, useRef as useRef6, useState as useState5 } from "react";
4762
4548
  function useClipDownload(clip, options = {}) {
4763
4549
  var _a;
4764
- const [state, setState] = useState6({ kind: "idle" });
4550
+ const [state, setState] = useState5({ kind: "idle" });
4765
4551
  const store = useContext3(ReactorContext);
4766
- const clipRef = useRef7(clip);
4767
- const filenameRef = useRef7(
4552
+ const clipRef = useRef6(clip);
4553
+ const filenameRef = useRef6(
4768
4554
  (_a = options.filename) != null ? _a : "reactor-clip.mp4"
4769
4555
  );
4770
- const getJwtRef = useRef7(options.getJwt);
4556
+ const getJwtRef = useRef6(options.getJwt);
4771
4557
  useEffect6(() => {
4772
4558
  clipRef.current = clip;
4773
4559
  filenameRef.current = options.filename === void 0 ? "reactor-clip.mp4" : options.filename;
4774
4560
  getJwtRef.current = options.getJwt;
4775
4561
  });
4776
- const inFlightRef = useRef7(false);
4777
- const download = useCallback2(() => __async(null, null, function* () {
4562
+ const inFlightRef = useRef6(false);
4563
+ const download = useCallback(() => __async(null, null, function* () {
4778
4564
  if (inFlightRef.current) return void 0;
4779
4565
  inFlightRef.current = true;
4780
4566
  setState({ kind: "downloading", fetched: 0, total: 0 });
@@ -4801,12 +4587,12 @@ function useClipDownload(clip, options = {}) {
4801
4587
  inFlightRef.current = false;
4802
4588
  }
4803
4589
  }), [store]);
4804
- const reset = useCallback2(() => setState({ kind: "idle" }), []);
4590
+ const reset = useCallback(() => setState({ kind: "idle" }), []);
4805
4591
  return { state, download, reset };
4806
4592
  }
4807
4593
 
4808
4594
  // src/react/ClipDownloadButton.tsx
4809
- import { jsx as jsx6 } from "react/jsx-runtime";
4595
+ import { jsx as jsx5 } from "react/jsx-runtime";
4810
4596
  function ClipDownloadButton({
4811
4597
  clip,
4812
4598
  getJwt,
@@ -4821,8 +4607,8 @@ function ClipDownloadButton({
4821
4607
  const { state, download } = useClipDownload(clip, { filename, getJwt });
4822
4608
  const downloading = state.kind === "downloading";
4823
4609
  const isDisabled = downloading || !!disabled;
4824
- const onSuccessRef = useRef8(onSuccess);
4825
- const onErrorRef = useRef8(onError);
4610
+ const onSuccessRef = useRef7(onSuccess);
4611
+ const onErrorRef = useRef7(onError);
4826
4612
  useEffect7(() => {
4827
4613
  onSuccessRef.current = onSuccess;
4828
4614
  onErrorRef.current = onError;
@@ -4834,7 +4620,7 @@ function ClipDownloadButton({
4834
4620
  }
4835
4621
  }, [state]);
4836
4622
  const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
4837
- return /* @__PURE__ */ jsx6(
4623
+ return /* @__PURE__ */ jsx5(
4838
4624
  "button",
4839
4625
  {
4840
4626
  type: "button",
@@ -4881,7 +4667,6 @@ export {
4881
4667
  DEFAULT_PLAYLIST_POLL_SLACK_MS,
4882
4668
  FileRef,
4883
4669
  Reactor,
4884
- ReactorController,
4885
4670
  ReactorProvider,
4886
4671
  ReactorView,
4887
4672
  RecordingClient,