@reactor-team/js-sdk 2.12.0 → 2.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -88,18 +88,19 @@ __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,
95
94
  RecordingError: () => RecordingError,
96
95
  RuntimeRecordingMessageType: () => RuntimeRecordingMessageType,
96
+ SessionLostError: () => SessionLostError,
97
97
  WebcamStream: () => WebcamStream,
98
98
  clipFromPayload: () => clipFromPayload,
99
99
  createPlayableManifestUrl: () => createPlayableManifestUrl,
100
100
  downloadClipAsFile: () => downloadClipAsFile,
101
101
  fetchPlaylist: () => fetchPlaylist,
102
102
  isAbortError: () => isAbortError,
103
+ isSessionLostError: () => isSessionLostError,
103
104
  normalizeJwtSource: () => normalizeJwtSource,
104
105
  parsePlaylist: () => parsePlaylist,
105
106
  rewriteUrlHost: () => rewriteUrlHost,
@@ -138,6 +139,14 @@ var AbortError = class extends Error {
138
139
  function isAbortError(error) {
139
140
  return error instanceof AbortError || error instanceof Error && error.name === "AbortError";
140
141
  }
142
+ var SessionLostError = class extends Error {
143
+ constructor(message) {
144
+ super(message);
145
+ }
146
+ };
147
+ function isSessionLostError(error) {
148
+ return error instanceof SessionLostError;
149
+ }
141
150
 
142
151
  // src/core/auth.ts
143
152
  function normalizeJwtSource(source) {
@@ -153,7 +162,7 @@ var import_zod = require("zod");
153
162
  // package.json
154
163
  var package_default = {
155
164
  name: "@reactor-team/js-sdk",
156
- version: "2.12.0",
165
+ version: "2.12.2",
157
166
  description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
158
167
  license: "Apache-2.0",
159
168
  repository: {
@@ -225,14 +234,14 @@ var package_default = {
225
234
  }
226
235
  },
227
236
  devDependencies: {
228
- "@roamhq/wrtc": "^0.8.0",
237
+ "@roamhq/wrtc": "^0.10.0",
229
238
  "@types/node": "^25",
230
239
  "@types/react": "^19.2.15",
231
240
  "@types/sdp-transform": "^2.15.0",
232
241
  "hls.js": "^1.6.0",
233
- prettier: "^3.6.2",
242
+ prettier: "^3.8.4",
234
243
  tsup: "^8.5.0",
235
- typescript: "^5.8.3",
244
+ typescript: "^6.0.3",
236
245
  vitest: "^4.1.7"
237
246
  }
238
247
  };
@@ -755,6 +764,11 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
755
764
  });
756
765
  if (!response.ok) {
757
766
  const errorText = yield response.text();
767
+ if (response.status === 400) {
768
+ throw new SessionLostError(
769
+ `Failed to start session: ${response.status} ${errorText}`
770
+ );
771
+ }
758
772
  throw new Error(
759
773
  `Failed to start session: ${response.status} ${errorText}`
760
774
  );
@@ -1539,6 +1553,11 @@ var WebRTCTransportClient = class {
1539
1553
  yield this.checkVersionMismatch(response);
1540
1554
  if (response.status !== 201) {
1541
1555
  const errorText = yield response.text();
1556
+ if (response.status === 400) {
1557
+ throw new SessionLostError(
1558
+ `Failed to register connection: ${response.status} ${errorText}`
1559
+ );
1560
+ }
1542
1561
  throw new Error(
1543
1562
  `Failed to register connection: ${response.status} ${errorText}`
1544
1563
  );
@@ -1585,7 +1604,7 @@ var WebRTCTransportClient = class {
1585
1604
  );
1586
1605
  }
1587
1606
  if (response.status === 400) {
1588
- throw new Error(
1607
+ throw new SessionLostError(
1589
1608
  `[WebRTCTransport] Connection ${connectionId} rejected (400): ${errorText}`
1590
1609
  );
1591
1610
  }
@@ -1599,7 +1618,7 @@ var WebRTCTransportClient = class {
1599
1618
  sendIceCandidates(candidates, is_final) {
1600
1619
  return __async(this, null, function* () {
1601
1620
  if (this.connectionId === void 0) {
1602
- console.debug(
1621
+ console.warn(
1603
1622
  "[WebRTCTransport] ICE candidates dropped: no active connection"
1604
1623
  );
1605
1624
  return;
@@ -1652,6 +1671,12 @@ var WebRTCTransportClient = class {
1652
1671
  clearTimeout(this.iceCandidateFlushTimer);
1653
1672
  this.iceCandidateFlushTimer = void 0;
1654
1673
  }
1674
+ if (this.connectionId === void 0) {
1675
+ console.debug(
1676
+ "[WebRTCTransportClient] skipping ICE candidate flush because the connection is not established yet"
1677
+ );
1678
+ return;
1679
+ }
1655
1680
  const batch = this.pendingIceCandidates;
1656
1681
  this.pendingIceCandidates = [];
1657
1682
  if (batch.length === 0 && !isFinal) {
@@ -1820,6 +1845,11 @@ var WebRTCTransportClient = class {
1820
1845
  trackMapping,
1821
1846
  reconnect
1822
1847
  );
1848
+ if (this.pendingIceCandidates.length > 0) {
1849
+ this.flushPendingIceCandidates(
1850
+ this.peerConnection !== void 0 && this.peerConnection.iceGatheringState === "complete"
1851
+ );
1852
+ }
1823
1853
  const answerResponse = yield this.pollSdpAnswer(this.connectionId);
1824
1854
  this.iceStartTime = performance.now();
1825
1855
  yield setRemoteDescription(
@@ -2390,13 +2420,15 @@ var DEFAULT_PLAYLIST_POLL_SLACK_MS = 15e3;
2390
2420
  function fetchPlaylist(_0) {
2391
2421
  return __async(this, arguments, function* (playlistUrl, options = {}) {
2392
2422
  var _a, _b, _c, _d;
2393
- const slackMs = (_a = options.slackMs) != null ? _a : DEFAULT_PLAYLIST_POLL_SLACK_MS;
2394
- const minDelay = Math.max(0, (_b = options.minRetryDelayMs) != null ? _b : 200);
2395
- const maxDelay = Math.max(minDelay, (_c = options.maxRetryDelayMs) != null ? _c : 2e3);
2396
- const fallbackMaxRetries = (_d = options.maxRetries) != null ? _d : 5;
2397
- const hasDeadline = typeof options.predictedReadyAtMs === "number";
2423
+ const minDelay = Math.max(0, (_a = options.minRetryDelayMs) != null ? _a : 200);
2424
+ const maxDelay = Math.max(minDelay, (_b = options.maxRetryDelayMs) != null ? _b : 2e3);
2425
+ const hasDeadline = typeof options.slackMs === "number" && Number.isFinite(options.slackMs);
2398
2426
  const startedPollingAt = Date.now();
2399
- const deadlineMs = hasDeadline ? Math.max(options.predictedReadyAtMs, startedPollingAt) + slackMs : void 0;
2427
+ const deadlineMs = hasDeadline ? Math.max(
2428
+ (_c = options.predictedReadyAtMs) != null ? _c : startedPollingAt,
2429
+ startedPollingAt
2430
+ ) + options.slackMs : void 0;
2431
+ const maxRetries = typeof options.maxRetries === "number" ? options.maxRetries : void 0;
2400
2432
  const headers = options.jwt ? { Authorization: `Bearer ${options.jwt}` } : void 0;
2401
2433
  let attempt = 0;
2402
2434
  let lastStatus = 0;
@@ -2415,16 +2447,15 @@ function fetchPlaylist(_0) {
2415
2447
  }
2416
2448
  lastStatus = response.status;
2417
2449
  if (response.status === 202) {
2418
- if (hasDeadline) {
2419
- if (Date.now() >= deadlineMs) {
2420
- throw new RecordingError(
2421
- "CLIP_NOT_READY",
2422
- `Boundary chunk still pending after ${slackMs}ms grace (predicted ready ${new Date(
2423
- options.predictedReadyAtMs
2424
- ).toISOString()}). Runtime may have crashed mid-clip.`
2425
- );
2426
- }
2427
- } else if (attempt >= fallbackMaxRetries) {
2450
+ if (deadlineMs !== void 0 && Date.now() >= deadlineMs) {
2451
+ throw new RecordingError(
2452
+ "CLIP_NOT_READY",
2453
+ `Boundary chunk still pending after ${options.slackMs}ms grace (predicted ready ${new Date(
2454
+ (_d = options.predictedReadyAtMs) != null ? _d : startedPollingAt
2455
+ ).toISOString()}). Runtime may have crashed mid-clip.`
2456
+ );
2457
+ }
2458
+ if (maxRetries !== void 0 && attempt >= maxRetries) {
2428
2459
  throw new RecordingError(
2429
2460
  "CLIP_NOT_READY",
2430
2461
  `Manifest still pending after ${attempt + 1} attempts (last status ${lastStatus})`
@@ -2435,7 +2466,7 @@ function fetchPlaylist(_0) {
2435
2466
  minDelay
2436
2467
  );
2437
2468
  const delay = Math.min(maxDelay, Math.max(minDelay, headerDelay));
2438
- const clampedDelay = hasDeadline ? Math.min(delay, Math.max(0, deadlineMs - Date.now())) : delay;
2469
+ const clampedDelay = deadlineMs !== void 0 ? Math.min(delay, Math.max(0, deadlineMs - Date.now())) : delay;
2439
2470
  yield sleep(clampedDelay, options.signal);
2440
2471
  attempt++;
2441
2472
  continue;
@@ -3018,6 +3049,7 @@ var Reactor = class {
3018
3049
  * down its own transport but leaves the session alive.
3019
3050
  */
3020
3051
  this.createdSession = false;
3052
+ this.retryingSessionLoss = false;
3021
3053
  this.tracks = [];
3022
3054
  this.autoResumeTracks = false;
3023
3055
  this.eventListeners = /* @__PURE__ */ new Map();
@@ -3342,7 +3374,7 @@ var Reactor = class {
3342
3374
  */
3343
3375
  connect(jwtToken, options) {
3344
3376
  return __async(this, null, function* () {
3345
- var _a;
3377
+ var _a, _b, _c, _d;
3346
3378
  console.debug("[Reactor] Connecting, status:", this.status);
3347
3379
  if (jwtToken == void 0 && !this.local) {
3348
3380
  throw new Error("No authentication provided and not in local mode");
@@ -3403,10 +3435,6 @@ var Reactor = class {
3403
3435
  ]);
3404
3436
  sessionPollingMs = performance.now() - tParallel;
3405
3437
  this.sessionResponse = sessionResponse;
3406
- this.capabilities = __spreadProps(__spreadValues({}, sessionResponse.capabilities), {
3407
- tracks: this.tracks
3408
- });
3409
- this.emit("capabilitiesReceived", this.capabilities);
3410
3438
  const tConnect = performance.now();
3411
3439
  yield this.transportClient.connect(false, options == null ? void 0 : options.connectionId);
3412
3440
  transportConnectingMs = performance.now() - tConnect;
@@ -3417,10 +3445,6 @@ var Reactor = class {
3417
3445
  sessionPollingMs = performance.now() - tPoll;
3418
3446
  this.sessionResponse = sessionResponse;
3419
3447
  this.tracks = sessionResponse.capabilities.tracks;
3420
- this.capabilities = __spreadProps(__spreadValues({}, sessionResponse.capabilities), {
3421
- tracks: this.tracks
3422
- });
3423
- this.emit("capabilitiesReceived", this.capabilities);
3424
3448
  const protocol = sessionResponse.selected_transport.protocol;
3425
3449
  if (protocol !== "webrtc") {
3426
3450
  throw new Error(`Unsupported transport protocol: ${protocol}`);
@@ -3438,6 +3462,19 @@ var Reactor = class {
3438
3462
  };
3439
3463
  } catch (error) {
3440
3464
  if (isAbortError(error)) return;
3465
+ if (!(options == null ? void 0 : options.sessionId) && !this.retryingSessionLoss && isSessionLostError(error)) {
3466
+ this.retryingSessionLoss = true;
3467
+ (_b = this.coordinatorClient) == null ? void 0 : _b.abort();
3468
+ (_c = this.transportClient) == null ? void 0 : _c.abort();
3469
+ (_d = this.transportClient) == null ? void 0 : _d.disconnect();
3470
+ this.setStatus("disconnected");
3471
+ try {
3472
+ yield this.connect(jwtToken, options);
3473
+ return;
3474
+ } finally {
3475
+ this.retryingSessionLoss = false;
3476
+ }
3477
+ }
3441
3478
  console.error("[Reactor] Connection failed:", error);
3442
3479
  this.createError(
3443
3480
  "CONNECTION_FAILED",
@@ -3469,6 +3506,10 @@ var Reactor = class {
3469
3506
  if (scope === "application") {
3470
3507
  this.emit("message", message);
3471
3508
  } else if (scope === "runtime") {
3509
+ if (message && typeof message === "object" && message.type === "modelSchema" && message.data) {
3510
+ this.schema = message.data;
3511
+ this.emit("schemaReceived", this.schema);
3512
+ }
3472
3513
  this.emit("runtimeMessage", message);
3473
3514
  }
3474
3515
  });
@@ -3485,6 +3526,7 @@ var Reactor = class {
3485
3526
  }
3486
3527
  }
3487
3528
  this.setStatus("ready");
3529
+ void this.sendCommand("requestSchema", {}, "runtime");
3488
3530
  break;
3489
3531
  case "disconnected":
3490
3532
  this.disconnect(true);
@@ -3562,7 +3604,7 @@ var Reactor = class {
3562
3604
  if (!recoverable) {
3563
3605
  this.setSessionExpiration(void 0);
3564
3606
  this.setSessionId(void 0);
3565
- this.capabilities = void 0;
3607
+ this.schema = void 0;
3566
3608
  this.tracks = [];
3567
3609
  this.sessionResponse = void 0;
3568
3610
  this.createdSession = false;
@@ -3587,8 +3629,13 @@ var Reactor = class {
3587
3629
  getLastError() {
3588
3630
  return this.lastError;
3589
3631
  }
3590
- getCapabilities() {
3591
- return this.capabilities;
3632
+ /**
3633
+ * The model's OpenAPI schema (events, outbound messages, tracks),
3634
+ * received over the runtime channel shortly after the session becomes
3635
+ * ready. `undefined` until the `schemaReceived` event has fired.
3636
+ */
3637
+ getSchema() {
3638
+ return this.schema;
3592
3639
  }
3593
3640
  getSessionInfo() {
3594
3641
  return this.sessionResponse;
@@ -3599,6 +3646,10 @@ var Reactor = class {
3599
3646
  if (!stats) return void 0;
3600
3647
  return __spreadProps(__spreadValues({}, stats), { connectionTimings: this.connectionTimings });
3601
3648
  }
3649
+ /** Timing breakdown from the most recent connect() handshake. */
3650
+ getConnectionTimings() {
3651
+ return this.connectionTimings;
3652
+ }
3602
3653
  // ─────────────────────────────────────────────────────────────────────────
3603
3654
  // Private State Management
3604
3655
  // ─────────────────────────────────────────────────────────────────────────
@@ -3807,6 +3858,8 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
3807
3858
  throw error;
3808
3859
  }
3809
3860
  }),
3861
+ pauseTrack: (name) => get().internal.reactor.pauseTrack(name),
3862
+ resumeTrack: (name) => get().internal.reactor.resumeTrack(name),
3810
3863
  reconnect: (options) => __async(null, null, function* () {
3811
3864
  console.debug("[ReactorStore] Reconnecting");
3812
3865
  try {
@@ -4120,576 +4173,9 @@ function ReactorView({
4120
4173
  );
4121
4174
  }
4122
4175
 
4123
- // src/react/ReactorController.tsx
4124
- var import_react6 = __toESM(require("react"));
4125
- var import_jsx_runtime3 = require("react/jsx-runtime");
4126
- function isFileParam(ps) {
4127
- return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
4128
- }
4129
- function ReactorController({
4130
- className,
4131
- style
4132
- }) {
4133
- const { sendCommand, uploadFile, status } = useReactor((state) => ({
4134
- sendCommand: state.sendCommand,
4135
- uploadFile: state.uploadFile,
4136
- status: state.status
4137
- }));
4138
- const [commands, setCommands] = (0, import_react6.useState)({});
4139
- const [formValues, setFormValues] = (0, import_react6.useState)({});
4140
- const formRef = (0, import_react6.useRef)(formValues);
4141
- formRef.current = formValues;
4142
- const [expandedCommands, setExpandedCommands] = (0, import_react6.useState)({});
4143
- import_react6.default.useEffect(() => {
4144
- if (status === "disconnected") {
4145
- setCommands({});
4146
- setFormValues({});
4147
- setExpandedCommands({});
4148
- }
4149
- }, [status]);
4150
- const requestCapabilities = (0, import_react6.useCallback)(() => {
4151
- if (status === "ready") {
4152
- sendCommand("requestCapabilities", {}, "runtime");
4153
- }
4154
- }, [status, sendCommand]);
4155
- import_react6.default.useEffect(() => {
4156
- if (status === "ready") {
4157
- requestCapabilities();
4158
- }
4159
- }, [status, requestCapabilities]);
4160
- import_react6.default.useEffect(() => {
4161
- if (status !== "ready" || Object.keys(commands).length > 0) {
4162
- return;
4163
- }
4164
- const interval = setInterval(() => {
4165
- requestCapabilities();
4166
- }, 5e3);
4167
- return () => clearInterval(interval);
4168
- }, [status, commands, requestCapabilities]);
4169
- useReactorInternalMessage((message) => {
4170
- var _a;
4171
- if (message && typeof message === "object" && message.type === "modelCapabilities" && message.data && "commands" in message.data) {
4172
- const commandsMessage = message.data;
4173
- const commandsRecord = {};
4174
- for (const cmd of commandsMessage.commands) {
4175
- commandsRecord[cmd.name] = {
4176
- description: cmd.description,
4177
- schema: (_a = cmd.schema) != null ? _a : {}
4178
- };
4179
- }
4180
- setCommands(commandsRecord);
4181
- const initialValues = {};
4182
- const initialExpanded = {};
4183
- Object.entries(commandsRecord).forEach(([commandName, commandSchema]) => {
4184
- initialValues[commandName] = {};
4185
- initialExpanded[commandName] = false;
4186
- Object.entries(commandSchema.schema).forEach(
4187
- ([paramName, paramSchema]) => {
4188
- var _a2;
4189
- if (isFileParam(paramSchema)) {
4190
- initialValues[commandName][paramName] = null;
4191
- } else if (paramSchema.default !== void 0) {
4192
- initialValues[commandName][paramName] = paramSchema.default;
4193
- } else if (paramSchema.type === "number" || paramSchema.type === "integer") {
4194
- initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
4195
- } else if (paramSchema.type === "string") {
4196
- initialValues[commandName][paramName] = "";
4197
- } else if (paramSchema.type === "boolean") {
4198
- initialValues[commandName][paramName] = false;
4199
- }
4200
- }
4201
- );
4202
- });
4203
- setFormValues(initialValues);
4204
- setExpandedCommands(initialExpanded);
4205
- }
4206
- });
4207
- const handleInputChange = (0, import_react6.useCallback)(
4208
- (commandName, paramName, value) => {
4209
- setFormValues((prev) => __spreadProps(__spreadValues({}, prev), {
4210
- [commandName]: __spreadProps(__spreadValues({}, prev[commandName]), {
4211
- [paramName]: value
4212
- })
4213
- }));
4214
- },
4215
- []
4216
- );
4217
- const toggleCommandExpanded = (0, import_react6.useCallback)((commandName) => {
4218
- setExpandedCommands((prev) => __spreadProps(__spreadValues({}, prev), {
4219
- [commandName]: !prev[commandName]
4220
- }));
4221
- }, []);
4222
- const handleCommandSubmit = (0, import_react6.useCallback)(
4223
- (commandName) => __async(null, null, function* () {
4224
- const commandSchema = commands[commandName];
4225
- const formData = formRef.current[commandName] || {};
4226
- const data = {};
4227
- Object.keys(commandSchema.schema).forEach((paramName) => {
4228
- var _a;
4229
- const paramSchema = commandSchema.schema[paramName];
4230
- let value = formData[paramName];
4231
- if (value instanceof FileRef) {
4232
- data[paramName] = value;
4233
- return;
4234
- }
4235
- if (paramSchema.type === "number" && typeof value === "string") {
4236
- value = parseFloat(value) || 0;
4237
- } else if (paramSchema.type === "integer" && typeof value === "string") {
4238
- value = parseInt(value) || 0;
4239
- } else if (paramSchema.type === "boolean" && typeof value !== "boolean") {
4240
- value = Boolean(value);
4241
- }
4242
- if (value !== void 0 && value !== "" && value !== null) {
4243
- data[paramName] = value;
4244
- } else if (paramSchema.required) {
4245
- if (paramSchema.type === "number" || paramSchema.type === "integer") {
4246
- data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
4247
- } else if (paramSchema.type === "string") {
4248
- data[paramName] = "";
4249
- } else if (paramSchema.type === "boolean") {
4250
- data[paramName] = false;
4251
- }
4252
- }
4253
- });
4254
- yield sendCommand(commandName, data);
4255
- }),
4256
- [sendCommand, commands]
4257
- );
4258
- const renderInput = (commandName, paramName, paramSchema) => {
4259
- var _a, _b;
4260
- const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
4261
- if (isFileParam(paramSchema)) {
4262
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4263
- FileParamInput,
4264
- {
4265
- commandName,
4266
- paramName,
4267
- description: paramSchema.description,
4268
- value,
4269
- onChange: handleInputChange,
4270
- disabled: status !== "ready",
4271
- uploadFile
4272
- },
4273
- `${commandName}-${paramName}`
4274
- );
4275
- }
4276
- if (paramSchema.type === "number" || paramSchema.type === "integer") {
4277
- const isInteger = paramSchema.type === "integer";
4278
- const step = isInteger ? 1 : 0.1;
4279
- const parseValue = isInteger ? parseInt : parseFloat;
4280
- if (typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number") {
4281
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
4282
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4283
- "label",
4284
- {
4285
- style: { fontSize: "12px", color: "#666", display: "block" },
4286
- children: [
4287
- paramName,
4288
- " (",
4289
- paramSchema.minimum,
4290
- " - ",
4291
- paramSchema.maximum,
4292
- ")",
4293
- paramSchema.description && ` - ${paramSchema.description}`,
4294
- paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
4295
- ]
4296
- }
4297
- ),
4298
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4299
- "input",
4300
- {
4301
- type: "range",
4302
- min: paramSchema.minimum,
4303
- max: paramSchema.maximum,
4304
- step,
4305
- value,
4306
- onChange: (e) => {
4307
- const newValue = parseValue(e.target.value) || 0;
4308
- handleInputChange(commandName, paramName, newValue);
4309
- handleCommandSubmit(commandName);
4310
- },
4311
- style: { width: "100%", marginBottom: "4px" }
4312
- }
4313
- ),
4314
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { fontSize: "11px", color: "#888" }, children: [
4315
- "Value: ",
4316
- value
4317
- ] })
4318
- ] });
4319
- } else {
4320
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
4321
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4322
- "label",
4323
- {
4324
- style: { fontSize: "12px", color: "#666", display: "block" },
4325
- children: [
4326
- paramName,
4327
- paramSchema.description && ` - ${paramSchema.description}`,
4328
- paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
4329
- ]
4330
- }
4331
- ),
4332
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4333
- "input",
4334
- {
4335
- type: "number",
4336
- value,
4337
- min: paramSchema.minimum,
4338
- max: paramSchema.maximum,
4339
- step,
4340
- inputMode: "numeric",
4341
- onChange: (e) => {
4342
- const val = e.target.value;
4343
- if (val === "" || val === "-") {
4344
- handleInputChange(commandName, paramName, val);
4345
- } else {
4346
- const parsed = parseValue(val);
4347
- if (!isNaN(parsed)) {
4348
- handleInputChange(commandName, paramName, parsed);
4349
- }
4350
- }
4351
- },
4352
- onBlur: (e) => {
4353
- const val = e.target.value;
4354
- if (val === "" || val === "-") {
4355
- handleInputChange(commandName, paramName, 0);
4356
- }
4357
- },
4358
- style: {
4359
- width: "100%",
4360
- padding: "4px",
4361
- fontSize: "12px",
4362
- border: "1px solid #ccc",
4363
- borderRadius: "2px"
4364
- }
4365
- }
4366
- )
4367
- ] });
4368
- }
4369
- } else if (paramSchema.type === "string") {
4370
- if (paramSchema.enum) {
4371
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
4372
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4373
- "label",
4374
- {
4375
- style: { fontSize: "12px", color: "#666", display: "block" },
4376
- children: [
4377
- paramName,
4378
- paramSchema.description && ` - ${paramSchema.description}`,
4379
- paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
4380
- ]
4381
- }
4382
- ),
4383
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4384
- "select",
4385
- {
4386
- value,
4387
- onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
4388
- style: {
4389
- width: "100%",
4390
- padding: "4px",
4391
- fontSize: "12px",
4392
- border: "1px solid #ccc",
4393
- borderRadius: "2px"
4394
- },
4395
- children: [
4396
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "Select..." }),
4397
- paramSchema.enum.map((option) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: option, children: option }, option))
4398
- ]
4399
- }
4400
- )
4401
- ] });
4402
- } else {
4403
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
4404
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4405
- "label",
4406
- {
4407
- style: { fontSize: "12px", color: "#666", display: "block" },
4408
- children: [
4409
- paramName,
4410
- paramSchema.description && ` - ${paramSchema.description}`,
4411
- paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
4412
- ]
4413
- }
4414
- ),
4415
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4416
- "input",
4417
- {
4418
- type: "text",
4419
- value,
4420
- onChange: (e) => handleInputChange(commandName, paramName, e.target.value),
4421
- style: {
4422
- width: "100%",
4423
- padding: "4px",
4424
- fontSize: "12px",
4425
- border: "1px solid #ccc",
4426
- borderRadius: "2px"
4427
- }
4428
- }
4429
- )
4430
- ] });
4431
- }
4432
- } else if (paramSchema.type === "boolean") {
4433
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4434
- "label",
4435
- {
4436
- style: {
4437
- fontSize: "12px",
4438
- color: "#666",
4439
- display: "flex",
4440
- alignItems: "center"
4441
- },
4442
- children: [
4443
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4444
- "input",
4445
- {
4446
- type: "checkbox",
4447
- checked: value,
4448
- onChange: (e) => handleInputChange(commandName, paramName, e.target.checked),
4449
- style: { marginRight: "6px" }
4450
- }
4451
- ),
4452
- paramName,
4453
- paramSchema.description && ` - ${paramSchema.description}`,
4454
- paramSchema.required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "red" }, children: " *" })
4455
- ]
4456
- }
4457
- ) });
4458
- }
4459
- return null;
4460
- };
4461
- const renderCommand = (commandName, commandSchema) => {
4462
- const hasParams = Object.keys(commandSchema.schema).length > 0;
4463
- const isExpanded = expandedCommands[commandName];
4464
- const params = Object.values(commandSchema.schema);
4465
- const allSliders = params.length > 0 && params.every(
4466
- (ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
4467
- );
4468
- const showExecuteButton = !allSliders;
4469
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4470
- "div",
4471
- {
4472
- style: {
4473
- border: "1px solid #ddd",
4474
- borderRadius: "4px",
4475
- marginBottom: "8px",
4476
- backgroundColor: "#fafafa"
4477
- },
4478
- children: [
4479
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4480
- "div",
4481
- {
4482
- onClick: () => toggleCommandExpanded(commandName),
4483
- style: {
4484
- padding: "8px 12px",
4485
- cursor: "pointer",
4486
- borderBottom: isExpanded ? "1px solid #ddd" : "none",
4487
- display: "flex",
4488
- justifyContent: "space-between",
4489
- alignItems: "center"
4490
- },
4491
- children: [
4492
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
4493
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4494
- "h4",
4495
- {
4496
- style: {
4497
- margin: "0",
4498
- fontSize: "13px",
4499
- fontWeight: "bold"
4500
- },
4501
- children: commandName
4502
- }
4503
- ),
4504
- isExpanded && commandSchema.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4505
- "p",
4506
- {
4507
- style: { margin: "4px 0 0 0", fontSize: "11px", color: "#666" },
4508
- children: commandSchema.description
4509
- }
4510
- )
4511
- ] }),
4512
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4513
- "div",
4514
- {
4515
- style: {
4516
- fontSize: "10px",
4517
- color: "#999",
4518
- transform: isExpanded ? "rotate(180deg)" : "rotate(0deg)",
4519
- transition: "transform 0.2s"
4520
- },
4521
- children: "\u25BC"
4522
- }
4523
- )
4524
- ]
4525
- }
4526
- ),
4527
- isExpanded && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { padding: "12px", paddingTop: "0" }, children: [
4528
- hasParams && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: showExecuteButton ? "12px" : "0" }, children: [
4529
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4530
- "div",
4531
- {
4532
- style: {
4533
- marginBottom: "8px",
4534
- fontSize: "12px",
4535
- fontWeight: "bold",
4536
- color: "#555"
4537
- },
4538
- children: "Parameters:"
4539
- }
4540
- ),
4541
- Object.entries(commandSchema.schema).map(
4542
- ([paramName, paramSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4543
- "div",
4544
- {
4545
- style: { marginLeft: "8px" },
4546
- children: renderInput(commandName, paramName, paramSchema)
4547
- },
4548
- `${commandName}-${paramName}`
4549
- )
4550
- )
4551
- ] }),
4552
- !hasParams && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4553
- "div",
4554
- {
4555
- style: {
4556
- marginBottom: showExecuteButton ? "12px" : "0",
4557
- marginTop: "2px",
4558
- fontSize: "11px",
4559
- color: "#666",
4560
- fontStyle: "italic"
4561
- },
4562
- children: "No parameters required"
4563
- }
4564
- ),
4565
- showExecuteButton && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4566
- "button",
4567
- {
4568
- onClick: () => handleCommandSubmit(commandName),
4569
- style: {
4570
- padding: "8px 16px",
4571
- fontSize: "12px",
4572
- backgroundColor: "#007bff",
4573
- color: "white",
4574
- border: "none",
4575
- borderRadius: "4px",
4576
- cursor: "pointer",
4577
- fontWeight: "bold"
4578
- },
4579
- children: [
4580
- "Execute ",
4581
- commandName
4582
- ]
4583
- }
4584
- )
4585
- ] })
4586
- ]
4587
- },
4588
- commandName
4589
- );
4590
- };
4591
- 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: [
4592
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4593
- "h3",
4594
- {
4595
- style: {
4596
- margin: "0 0 16px 0",
4597
- fontSize: "16px",
4598
- fontWeight: "bold"
4599
- },
4600
- children: "Reactor Commands"
4601
- }
4602
- ),
4603
- Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: renderCommand(commandName, commandSchema) }, commandName))
4604
- ] }) }) });
4605
- }
4606
- function FileParamInput({
4607
- commandName,
4608
- paramName,
4609
- description,
4610
- value,
4611
- onChange,
4612
- disabled,
4613
- uploadFile
4614
- }) {
4615
- const inputRef = (0, import_react6.useRef)(null);
4616
- const [uploading, setUploading] = (0, import_react6.useState)(false);
4617
- const fileRef = value instanceof FileRef ? value : null;
4618
- const handleFile = (e) => __async(null, null, function* () {
4619
- var _a;
4620
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
4621
- if (!file) return;
4622
- e.target.value = "";
4623
- setUploading(true);
4624
- try {
4625
- const ref = yield uploadFile(file);
4626
- onChange(commandName, paramName, ref);
4627
- } catch (err) {
4628
- console.error("[FileParamInput] Upload failed:", err);
4629
- } finally {
4630
- setUploading(false);
4631
- }
4632
- });
4633
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
4634
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
4635
- paramName,
4636
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
4637
- description && ` - ${description}`
4638
- ] }),
4639
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4640
- "div",
4641
- {
4642
- style: {
4643
- display: "flex",
4644
- alignItems: "center",
4645
- gap: "8px",
4646
- marginTop: "4px"
4647
- },
4648
- children: [
4649
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4650
- "input",
4651
- {
4652
- ref: inputRef,
4653
- type: "file",
4654
- accept: "image/*",
4655
- onChange: handleFile,
4656
- style: { display: "none" }
4657
- }
4658
- ),
4659
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4660
- "button",
4661
- {
4662
- disabled: disabled || uploading,
4663
- onClick: () => {
4664
- var _a;
4665
- return (_a = inputRef.current) == null ? void 0 : _a.click();
4666
- },
4667
- style: {
4668
- padding: "4px 12px",
4669
- fontSize: "12px",
4670
- backgroundColor: "#007bff",
4671
- color: "white",
4672
- border: "none",
4673
- borderRadius: "4px",
4674
- cursor: disabled || uploading ? "default" : "pointer",
4675
- opacity: disabled || uploading ? 0.5 : 1
4676
- },
4677
- children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
4678
- }
4679
- ),
4680
- fileRef && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
4681
- "\\u2713 ",
4682
- fileRef.name
4683
- ] })
4684
- ]
4685
- }
4686
- )
4687
- ] });
4688
- }
4689
-
4690
4176
  // src/react/WebcamStream.tsx
4691
- var import_react7 = require("react");
4692
- var import_jsx_runtime4 = require("react/jsx-runtime");
4177
+ var import_react6 = require("react");
4178
+ var import_jsx_runtime3 = require("react/jsx-runtime");
4693
4179
  function WebcamStream({
4694
4180
  track,
4695
4181
  audio = false,
@@ -4706,20 +4192,20 @@ function WebcamStream({
4706
4192
  onPublished,
4707
4193
  onError
4708
4194
  }) {
4709
- const [stream, setStream] = (0, import_react7.useState)(null);
4710
- const [isPublishing, setIsPublishing] = (0, import_react7.useState)(false);
4711
- const [permissionDenied, setPermissionDenied] = (0, import_react7.useState)(false);
4195
+ const [stream, setStream] = (0, import_react6.useState)(null);
4196
+ const [isPublishing, setIsPublishing] = (0, import_react6.useState)(false);
4197
+ const [permissionDenied, setPermissionDenied] = (0, import_react6.useState)(false);
4712
4198
  const { status, publish, unpublish, reactor } = useReactor((state) => ({
4713
4199
  status: state.status,
4714
4200
  publish: state.publish,
4715
4201
  unpublish: state.unpublish,
4716
4202
  reactor: state.internal.reactor
4717
4203
  }));
4718
- const videoRef = (0, import_react7.useRef)(null);
4719
- const onPermissionDeniedRef = (0, import_react7.useRef)(onPermissionDenied);
4720
- const onPublishedRef = (0, import_react7.useRef)(onPublished);
4721
- const onErrorRef = (0, import_react7.useRef)(onError);
4722
- (0, import_react7.useEffect)(() => {
4204
+ const videoRef = (0, import_react6.useRef)(null);
4205
+ const onPermissionDeniedRef = (0, import_react6.useRef)(onPermissionDenied);
4206
+ const onPublishedRef = (0, import_react6.useRef)(onPublished);
4207
+ const onErrorRef = (0, import_react6.useRef)(onError);
4208
+ (0, import_react6.useEffect)(() => {
4723
4209
  onPermissionDeniedRef.current = onPermissionDenied;
4724
4210
  onPublishedRef.current = onPublished;
4725
4211
  onErrorRef.current = onError;
@@ -4784,7 +4270,7 @@ function WebcamStream({
4784
4270
  setStream(null);
4785
4271
  console.debug("[WebcamPublisher] Webcam stopped");
4786
4272
  });
4787
- (0, import_react7.useEffect)(() => {
4273
+ (0, import_react6.useEffect)(() => {
4788
4274
  console.debug("[WebcamPublisher] Stream effect triggered", {
4789
4275
  hasVideoElement: !!videoRef.current,
4790
4276
  hasStream: !!stream
@@ -4801,7 +4287,7 @@ function WebcamStream({
4801
4287
  videoRef.current.srcObject = null;
4802
4288
  }
4803
4289
  }, [stream]);
4804
- (0, import_react7.useEffect)(() => {
4290
+ (0, import_react6.useEffect)(() => {
4805
4291
  if (!stream) {
4806
4292
  return;
4807
4293
  }
@@ -4857,7 +4343,7 @@ function WebcamStream({
4857
4343
  audioEnabled,
4858
4344
  audioTrack
4859
4345
  ]);
4860
- (0, import_react7.useEffect)(() => {
4346
+ (0, import_react6.useEffect)(() => {
4861
4347
  const handleError = (error) => {
4862
4348
  console.debug("[WebcamPublisher] Received error event:", error);
4863
4349
  if (error.code === "TRACK_PUBLISH_FAILED") {
@@ -4872,7 +4358,7 @@ function WebcamStream({
4872
4358
  reactor.off("error", handleError);
4873
4359
  };
4874
4360
  }, [reactor]);
4875
- (0, import_react7.useEffect)(() => {
4361
+ (0, import_react6.useEffect)(() => {
4876
4362
  if (status !== "ready") {
4877
4363
  console.debug(
4878
4364
  "[WebcamPublisher] Status changed to",
@@ -4882,7 +4368,7 @@ function WebcamStream({
4882
4368
  setIsPublishing(false);
4883
4369
  }
4884
4370
  }, [status, isPublishing]);
4885
- (0, import_react7.useEffect)(() => {
4371
+ (0, import_react6.useEffect)(() => {
4886
4372
  console.debug("[WebcamPublisher] Auto-starting webcam");
4887
4373
  startWebcam();
4888
4374
  return () => {
@@ -4891,7 +4377,7 @@ function WebcamStream({
4891
4377
  };
4892
4378
  }, []);
4893
4379
  const showPlaceholder = !stream;
4894
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
4380
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4895
4381
  "div",
4896
4382
  {
4897
4383
  style: __spreadValues({
@@ -4901,7 +4387,7 @@ function WebcamStream({
4901
4387
  }, style),
4902
4388
  className,
4903
4389
  children: [
4904
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4390
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4905
4391
  "video",
4906
4392
  {
4907
4393
  ref: videoRef,
@@ -4916,7 +4402,7 @@ function WebcamStream({
4916
4402
  autoPlay: true
4917
4403
  }
4918
4404
  ),
4919
- showPlaceholder && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4405
+ showPlaceholder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4920
4406
  "div",
4921
4407
  {
4922
4408
  style: {
@@ -4937,11 +4423,11 @@ function WebcamStream({
4937
4423
  flexDirection: "column",
4938
4424
  gap: "12px"
4939
4425
  },
4940
- children: permissionDenied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
4426
+ children: permissionDenied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: [
4941
4427
  "Camera access denied.",
4942
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("br", {}),
4428
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
4943
4429
  "Please allow access in your browser settings."
4944
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
4430
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "12px", fontFamily: "monospace" }, children: "Starting camera..." })
4945
4431
  }
4946
4432
  )
4947
4433
  ]
@@ -4950,8 +4436,8 @@ function WebcamStream({
4950
4436
  }
4951
4437
 
4952
4438
  // src/react/ClipPlayer.tsx
4953
- var import_react8 = require("react");
4954
- var import_jsx_runtime5 = require("react/jsx-runtime");
4439
+ var import_react7 = require("react");
4440
+ var import_jsx_runtime4 = require("react/jsx-runtime");
4955
4441
  function ClipPlayer({
4956
4442
  clip,
4957
4443
  getJwt,
@@ -4962,28 +4448,28 @@ function ClipPlayer({
4962
4448
  style,
4963
4449
  onError
4964
4450
  }) {
4965
- const videoRef = (0, import_react8.useRef)(null);
4966
- const [phase, setPhase] = (0, import_react8.useState)({ kind: "waiting" });
4967
- const store = (0, import_react8.useContext)(ReactorContext);
4968
- const getJwtRef = (0, import_react8.useRef)(getJwt);
4969
- const autoPlayRef = (0, import_react8.useRef)(autoPlay);
4970
- const slackMsRef = (0, import_react8.useRef)(slackMs);
4971
- const onErrorRef = (0, import_react8.useRef)(onError);
4972
- const storeRef = (0, import_react8.useRef)(store);
4973
- (0, import_react8.useEffect)(() => {
4451
+ const videoRef = (0, import_react7.useRef)(null);
4452
+ const [phase, setPhase] = (0, import_react7.useState)({ kind: "waiting" });
4453
+ const store = (0, import_react7.useContext)(ReactorContext);
4454
+ const getJwtRef = (0, import_react7.useRef)(getJwt);
4455
+ const autoPlayRef = (0, import_react7.useRef)(autoPlay);
4456
+ const slackMsRef = (0, import_react7.useRef)(slackMs);
4457
+ const onErrorRef = (0, import_react7.useRef)(onError);
4458
+ const storeRef = (0, import_react7.useRef)(store);
4459
+ (0, import_react7.useEffect)(() => {
4974
4460
  getJwtRef.current = getJwt;
4975
4461
  autoPlayRef.current = autoPlay;
4976
4462
  slackMsRef.current = slackMs;
4977
4463
  onErrorRef.current = onError;
4978
4464
  storeRef.current = store;
4979
4465
  });
4980
- (0, import_react8.useEffect)(() => {
4466
+ (0, import_react7.useEffect)(() => {
4981
4467
  var _a;
4982
4468
  if (phase.kind === "error") {
4983
4469
  (_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, phase.error);
4984
4470
  }
4985
4471
  }, [phase]);
4986
- (0, import_react8.useEffect)(() => {
4472
+ (0, import_react7.useEffect)(() => {
4987
4473
  const video = videoRef.current;
4988
4474
  if (!video) return;
4989
4475
  const abort = new AbortController();
@@ -5086,7 +4572,7 @@ function ClipPlayer({
5086
4572
  };
5087
4573
  }, [clip]);
5088
4574
  const overlayText = phase.kind === "waiting" ? "Waiting for clip\u2026" : phase.kind === "loading" ? "Loading player\u2026" : null;
5089
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4575
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5090
4576
  "div",
5091
4577
  {
5092
4578
  className,
@@ -5099,7 +4585,7 @@ function ClipPlayer({
5099
4585
  justifyContent: "center"
5100
4586
  }, style),
5101
4587
  children: [
5102
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4588
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5103
4589
  "video",
5104
4590
  {
5105
4591
  ref: videoRef,
@@ -5114,7 +4600,7 @@ function ClipPlayer({
5114
4600
  }
5115
4601
  }
5116
4602
  ),
5117
- overlayText && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4603
+ overlayText && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5118
4604
  "div",
5119
4605
  {
5120
4606
  style: {
@@ -5132,7 +4618,7 @@ function ClipPlayer({
5132
4618
  children: overlayText
5133
4619
  }
5134
4620
  ),
5135
- phase.kind === "error" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4621
+ phase.kind === "error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5136
4622
  "div",
5137
4623
  {
5138
4624
  style: {
@@ -5156,28 +4642,35 @@ function ClipPlayer({
5156
4642
  }
5157
4643
 
5158
4644
  // src/react/ClipDownloadButton.tsx
5159
- var import_react10 = require("react");
4645
+ var import_react9 = require("react");
5160
4646
 
5161
4647
  // src/react/useClipDownload.ts
5162
- var import_react9 = require("react");
4648
+ var import_react8 = require("react");
5163
4649
  function useClipDownload(clip, options = {}) {
5164
4650
  var _a;
5165
- const [state, setState] = (0, import_react9.useState)({ kind: "idle" });
5166
- const store = (0, import_react9.useContext)(ReactorContext);
5167
- const clipRef = (0, import_react9.useRef)(clip);
5168
- const filenameRef = (0, import_react9.useRef)(
4651
+ const [state, setState] = (0, import_react8.useState)({ kind: "idle" });
4652
+ const store = (0, import_react8.useContext)(ReactorContext);
4653
+ const clipRef = (0, import_react8.useRef)(clip);
4654
+ const filenameRef = (0, import_react8.useRef)(
5169
4655
  (_a = options.filename) != null ? _a : "reactor-clip.mp4"
5170
4656
  );
5171
- const getJwtRef = (0, import_react9.useRef)(options.getJwt);
5172
- (0, import_react9.useEffect)(() => {
4657
+ const getJwtRef = (0, import_react8.useRef)(options.getJwt);
4658
+ (0, import_react8.useEffect)(() => {
5173
4659
  clipRef.current = clip;
5174
4660
  filenameRef.current = options.filename === void 0 ? "reactor-clip.mp4" : options.filename;
5175
4661
  getJwtRef.current = options.getJwt;
5176
4662
  });
5177
- const inFlightRef = (0, import_react9.useRef)(false);
5178
- const download = (0, import_react9.useCallback)(() => __async(null, null, function* () {
4663
+ const inFlightRef = (0, import_react8.useRef)(false);
4664
+ const abortRef = (0, import_react8.useRef)(null);
4665
+ (0, import_react8.useEffect)(() => () => {
4666
+ var _a2;
4667
+ return (_a2 = abortRef.current) == null ? void 0 : _a2.abort();
4668
+ }, []);
4669
+ const download = (0, import_react8.useCallback)(() => __async(null, null, function* () {
5179
4670
  if (inFlightRef.current) return void 0;
5180
4671
  inFlightRef.current = true;
4672
+ const abort = new AbortController();
4673
+ abortRef.current = abort;
5181
4674
  setState({ kind: "downloading", fetched: 0, total: 0 });
5182
4675
  try {
5183
4676
  const explicit = getJwtRef.current;
@@ -5189,12 +4682,16 @@ function useClipDownload(clip, options = {}) {
5189
4682
  filenameRef.current,
5190
4683
  {
5191
4684
  jwt,
4685
+ signal: abort.signal,
5192
4686
  onProgress: ({ fetched, total }) => setState({ kind: "downloading", fetched, total })
5193
4687
  }
5194
4688
  );
5195
4689
  setState({ kind: "idle" });
5196
4690
  return blob;
5197
4691
  } catch (err) {
4692
+ if (err instanceof DOMException && err.name === "AbortError") {
4693
+ return void 0;
4694
+ }
5198
4695
  const message = err instanceof RecordingError ? `${err.code}: ${err.reason}` : err instanceof Error ? err.message : String(err);
5199
4696
  setState({ kind: "error", message });
5200
4697
  return void 0;
@@ -5202,12 +4699,12 @@ function useClipDownload(clip, options = {}) {
5202
4699
  inFlightRef.current = false;
5203
4700
  }
5204
4701
  }), [store]);
5205
- const reset = (0, import_react9.useCallback)(() => setState({ kind: "idle" }), []);
4702
+ const reset = (0, import_react8.useCallback)(() => setState({ kind: "idle" }), []);
5206
4703
  return { state, download, reset };
5207
4704
  }
5208
4705
 
5209
4706
  // src/react/ClipDownloadButton.tsx
5210
- var import_jsx_runtime6 = require("react/jsx-runtime");
4707
+ var import_jsx_runtime5 = require("react/jsx-runtime");
5211
4708
  function ClipDownloadButton({
5212
4709
  clip,
5213
4710
  getJwt,
@@ -5222,20 +4719,20 @@ function ClipDownloadButton({
5222
4719
  const { state, download } = useClipDownload(clip, { filename, getJwt });
5223
4720
  const downloading = state.kind === "downloading";
5224
4721
  const isDisabled = downloading || !!disabled;
5225
- const onSuccessRef = (0, import_react10.useRef)(onSuccess);
5226
- const onErrorRef = (0, import_react10.useRef)(onError);
5227
- (0, import_react10.useEffect)(() => {
4722
+ const onSuccessRef = (0, import_react9.useRef)(onSuccess);
4723
+ const onErrorRef = (0, import_react9.useRef)(onError);
4724
+ (0, import_react9.useEffect)(() => {
5228
4725
  onSuccessRef.current = onSuccess;
5229
4726
  onErrorRef.current = onError;
5230
4727
  });
5231
- (0, import_react10.useEffect)(() => {
4728
+ (0, import_react9.useEffect)(() => {
5232
4729
  var _a;
5233
4730
  if (state.kind === "error") {
5234
4731
  (_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, new Error(state.message));
5235
4732
  }
5236
4733
  }, [state]);
5237
4734
  const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
5238
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4735
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5239
4736
  "button",
5240
4737
  {
5241
4738
  type: "button",
@@ -5283,18 +4780,19 @@ function defaultLabel(state) {
5283
4780
  DEFAULT_PLAYLIST_POLL_SLACK_MS,
5284
4781
  FileRef,
5285
4782
  Reactor,
5286
- ReactorController,
5287
4783
  ReactorProvider,
5288
4784
  ReactorView,
5289
4785
  RecordingClient,
5290
4786
  RecordingError,
5291
4787
  RuntimeRecordingMessageType,
4788
+ SessionLostError,
5292
4789
  WebcamStream,
5293
4790
  clipFromPayload,
5294
4791
  createPlayableManifestUrl,
5295
4792
  downloadClipAsFile,
5296
4793
  fetchPlaylist,
5297
4794
  isAbortError,
4795
+ isSessionLostError,
5298
4796
  normalizeJwtSource,
5299
4797
  parsePlaylist,
5300
4798
  rewriteUrlHost,