@reactor-team/js-sdk 2.10.0 → 2.10.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
@@ -77,15 +77,23 @@ function isAbortError(error) {
77
77
  return error instanceof AbortError || error instanceof Error && error.name === "AbortError";
78
78
  }
79
79
 
80
+ // src/core/auth.ts
81
+ function normalizeJwtSource(source) {
82
+ if (typeof source === "function") {
83
+ return source;
84
+ }
85
+ return () => source;
86
+ }
87
+
80
88
  // src/core/types.ts
81
89
  import { z } from "zod";
82
90
 
83
91
  // package.json
84
92
  var package_default = {
85
93
  name: "@reactor-team/js-sdk",
86
- version: "2.10.0",
94
+ version: "2.10.1",
87
95
  description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
88
- license: "MIT",
96
+ license: "Apache-2.0",
89
97
  repository: {
90
98
  type: "git",
91
99
  url: "https://github.com/reactor-team/js-sdk.git"
@@ -117,9 +125,13 @@ var package_default = {
117
125
  },
118
126
  files: [
119
127
  "dist",
120
- "README.md"
128
+ "README.md",
129
+ "LICENSE",
130
+ "NOTICE"
121
131
  ],
122
132
  scripts: {
133
+ prepack: "cp ../../LICENSE ../../NOTICE .",
134
+ postpack: "rm -f LICENSE NOTICE",
123
135
  build: "tsup",
124
136
  dev: "tsup --watch",
125
137
  test: "vitest run",
@@ -135,8 +147,9 @@ var package_default = {
135
147
  },
136
148
  packageManager: "pnpm@10.12.1",
137
149
  dependencies: {
150
+ mp4box: "^2.3.0",
138
151
  "sdp-transform": "^3.0.0",
139
- zod: "^4.0.5"
152
+ zod: "^4.4.3"
140
153
  },
141
154
  peerDependencies: {
142
155
  "hls.js": "^1.6.0",
@@ -150,13 +163,13 @@ var package_default = {
150
163
  },
151
164
  devDependencies: {
152
165
  "@roamhq/wrtc": "^0.8.0",
153
- "@types/node": "^20",
154
- "@types/react": "^18.2.8",
166
+ "@types/node": "^25",
167
+ "@types/react": "^19.2.15",
155
168
  "hls.js": "^1.6.0",
156
169
  prettier: "^3.6.2",
157
170
  tsup: "^8.5.0",
158
171
  typescript: "^5.8.3",
159
- vitest: "^3.0.0"
172
+ vitest: "^4.1.7"
160
173
  }
161
174
  };
162
175
 
@@ -259,7 +272,7 @@ var SESSION_POLL_DEFAULT_MAX_ATTEMPTS = 20;
259
272
  var CoordinatorClient = class {
260
273
  constructor(options) {
261
274
  this.baseUrl = options.baseUrl;
262
- this.jwtToken = options.jwtToken;
275
+ this.resolveJwt = normalizeJwtSource(options.jwtToken);
263
276
  this.model = options.model;
264
277
  this.abortController = new AbortController();
265
278
  }
@@ -279,14 +292,22 @@ var CoordinatorClient = class {
279
292
  return this.abortController.signal;
280
293
  }
281
294
  /**
282
- * Returns authorization + versioning headers for all coordinator requests.
295
+ * Returns authorization + versioning headers for all coordinator
296
+ * requests. Async so the JWT resolver can fetch a fresh token if
297
+ * needed; an empty token suppresses the `Authorization` header.
283
298
  */
284
299
  getHeaders() {
285
- return {
286
- Authorization: `Bearer ${this.jwtToken}`,
287
- [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
288
- [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
289
- };
300
+ return __async(this, null, function* () {
301
+ const headers = {
302
+ [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
303
+ [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
304
+ };
305
+ const jwt = yield this.resolveJwt();
306
+ if (jwt) {
307
+ headers.Authorization = `Bearer ${jwt}`;
308
+ }
309
+ return headers;
310
+ });
290
311
  }
291
312
  /**
292
313
  * Checks an HTTP response for version mismatch errors (426, 501).
@@ -347,7 +368,7 @@ var CoordinatorClient = class {
347
368
  }, extraArgs ? { extra_args: extraArgs } : {});
348
369
  const response = yield fetch(`${this.baseUrl}/sessions`, {
349
370
  method: "POST",
350
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
371
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
351
372
  "Content-Type": "application/json"
352
373
  }),
353
374
  body: JSON.stringify(requestBody),
@@ -402,7 +423,7 @@ var CoordinatorClient = class {
402
423
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
403
424
  {
404
425
  method: "GET",
405
- headers: this.getHeaders(),
426
+ headers: yield this.getHeaders(),
406
427
  signal: this.signal
407
428
  }
408
429
  );
@@ -455,7 +476,7 @@ var CoordinatorClient = class {
455
476
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
456
477
  {
457
478
  method: "GET",
458
- headers: this.getHeaders(),
479
+ headers: yield this.getHeaders(),
459
480
  signal: this.signal
460
481
  }
461
482
  );
@@ -480,7 +501,7 @@ var CoordinatorClient = class {
480
501
  `${this.baseUrl}/sessions/${this.currentSessionId}/info`,
481
502
  {
482
503
  method: "GET",
483
- headers: this.getHeaders(),
504
+ headers: yield this.getHeaders(),
484
505
  signal: this.signal
485
506
  }
486
507
  );
@@ -512,7 +533,7 @@ var CoordinatorClient = class {
512
533
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
513
534
  {
514
535
  method: "PUT",
515
- headers: this.getHeaders(),
536
+ headers: yield this.getHeaders(),
516
537
  signal: this.signal
517
538
  }
518
539
  );
@@ -544,7 +565,7 @@ var CoordinatorClient = class {
544
565
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
545
566
  __spreadProps(__spreadValues({
546
567
  method: "DELETE",
547
- headers: __spreadValues(__spreadValues({}, this.getHeaders()), body ? { "Content-Type": "application/json" } : {})
568
+ headers: __spreadValues(__spreadValues({}, yield this.getHeaders()), body ? { "Content-Type": "application/json" } : {})
548
569
  }, body ? { body: JSON.stringify(body) } : {}), {
549
570
  signal: this.signal
550
571
  })
@@ -583,7 +604,7 @@ var CoordinatorClient = class {
583
604
  `${this.baseUrl}/sessions/${sessionId}/uploads`,
584
605
  {
585
606
  method: "POST",
586
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
607
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
587
608
  "Content-Type": "application/json"
588
609
  }),
589
610
  body: JSON.stringify(request),
@@ -615,11 +636,14 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
615
636
  model
616
637
  });
617
638
  }
639
+ // Local runtime endpoints are auth-free; skip the Authorization header.
618
640
  getHeaders() {
619
- return {
620
- [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
621
- [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
622
- };
641
+ return __async(this, null, function* () {
642
+ return {
643
+ [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
644
+ [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
645
+ };
646
+ });
623
647
  }
624
648
  /**
625
649
  * Starts a session on the local runtime.
@@ -633,7 +657,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
633
657
  console.debug("[LocalCoordinatorClient] Starting session...");
634
658
  const response = yield fetch(`${this.baseUrl}/start_session`, {
635
659
  method: "POST",
636
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
660
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
637
661
  "Content-Type": "application/json"
638
662
  }),
639
663
  body: JSON.stringify(__spreadValues({}, extraArgs ? { extra_args: extraArgs } : {})),
@@ -689,7 +713,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
689
713
  try {
690
714
  yield fetch(`${this.baseUrl}/stop_session`, {
691
715
  method: "POST",
692
- headers: this.getHeaders(),
716
+ headers: yield this.getHeaders(),
693
717
  signal: this.signal
694
718
  });
695
719
  } catch (error) {
@@ -1269,7 +1293,7 @@ var WebRTCTransportClient = class {
1269
1293
  var _a, _b;
1270
1294
  this.baseUrl = config.baseUrl;
1271
1295
  this.sessionId = config.sessionId;
1272
- this.jwtToken = config.jwtToken;
1296
+ this.resolveJwt = normalizeJwtSource(config.jwtToken);
1273
1297
  this.webrtcVersion = (_a = config.webrtcVersion) != null ? _a : REACTOR_WEBRTC_VERSION;
1274
1298
  this.maxPollAttempts = (_b = config.maxPollAttempts) != null ? _b : DEFAULT_MAX_POLL_ATTEMPTS;
1275
1299
  this.abortController = new AbortController();
@@ -1300,11 +1324,19 @@ var WebRTCTransportClient = class {
1300
1324
  get transportBaseUrl() {
1301
1325
  return `${this.baseUrl}/sessions/${this.sessionId}/transport/webrtc`;
1302
1326
  }
1327
+ // Async so the JWT resolver can fetch a fresh token if needed; an
1328
+ // empty token suppresses the `Authorization` header.
1303
1329
  getHeaders() {
1304
- return {
1305
- Authorization: `Bearer ${this.jwtToken}`,
1306
- [WEBRTC_VERSION_HEADER]: this.webrtcVersion
1307
- };
1330
+ return __async(this, null, function* () {
1331
+ const headers = {
1332
+ [WEBRTC_VERSION_HEADER]: this.webrtcVersion
1333
+ };
1334
+ const jwt = yield this.resolveJwt();
1335
+ if (jwt) {
1336
+ headers.Authorization = `Bearer ${jwt}`;
1337
+ }
1338
+ return headers;
1339
+ });
1308
1340
  }
1309
1341
  checkVersionMismatch(response) {
1310
1342
  return __async(this, null, function* () {
@@ -1346,7 +1378,7 @@ var WebRTCTransportClient = class {
1346
1378
  console.debug("[WebRTCTransport] Fetching ICE servers...");
1347
1379
  const response = yield fetch(`${this.transportBaseUrl}/ice_servers`, {
1348
1380
  method: "GET",
1349
- headers: this.getHeaders(),
1381
+ headers: yield this.getHeaders(),
1350
1382
  signal: this.signal
1351
1383
  });
1352
1384
  yield this.checkVersionMismatch(response);
@@ -1376,7 +1408,7 @@ var WebRTCTransportClient = class {
1376
1408
  };
1377
1409
  const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1378
1410
  method,
1379
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
1411
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1380
1412
  "Content-Type": "application/json"
1381
1413
  }),
1382
1414
  body: JSON.stringify(requestBody),
@@ -1413,7 +1445,7 @@ var WebRTCTransportClient = class {
1413
1445
  );
1414
1446
  const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1415
1447
  method: "GET",
1416
- headers: this.getHeaders(),
1448
+ headers: yield this.getHeaders(),
1417
1449
  signal: this.signal
1418
1450
  });
1419
1451
  yield this.checkVersionMismatch(response);
@@ -2067,7 +2099,7 @@ function downloadClipAsFile(_0) {
2067
2099
  `Chunk ${i} returned HTTP ${response.status}`
2068
2100
  );
2069
2101
  }
2070
- const data = yield response.arrayBuffer();
2102
+ const data = new Uint8Array(yield response.arrayBuffer());
2071
2103
  parts.push(data);
2072
2104
  bytes += data.byteLength;
2073
2105
  (_a = options.onProgress) == null ? void 0 : _a.call(options, {
@@ -2076,7 +2108,8 @@ function downloadClipAsFile(_0) {
2076
2108
  bytes
2077
2109
  });
2078
2110
  }
2079
- const blob = new Blob(parts, { type: "video/mp4" });
2111
+ const finalBytes = yield maybeRemux(parts);
2112
+ const blob = new Blob([finalBytes], { type: "video/mp4" });
2080
2113
  if (filename === null) {
2081
2114
  return blob;
2082
2115
  }
@@ -2090,6 +2123,145 @@ function downloadClipAsFile(_0) {
2090
2123
  return blob;
2091
2124
  });
2092
2125
  }
2126
+ function maybeRemux(parts) {
2127
+ return __async(this, null, function* () {
2128
+ const input = concatUint8Arrays(parts);
2129
+ try {
2130
+ const MP4Box = yield loadMp4Box();
2131
+ return yield remuxFragmentedToFlat(input, MP4Box);
2132
+ } catch (error) {
2133
+ console.warn(
2134
+ "[Reactor] Clip remux failed, returning fragmented MP4 instead.",
2135
+ error
2136
+ );
2137
+ return input;
2138
+ }
2139
+ });
2140
+ }
2141
+ var __remuxInternals = {
2142
+ loadMp4Box: () => import("mp4box")
2143
+ };
2144
+ function loadMp4Box() {
2145
+ return __remuxInternals.loadMp4Box();
2146
+ }
2147
+ function remuxFragmentedToFlat(input, MP4Box) {
2148
+ return __async(this, null, function* () {
2149
+ return new Promise((resolve, reject) => {
2150
+ const inFile = MP4Box.createFile();
2151
+ const outFile = MP4Box.createFile();
2152
+ outFile.init({ brands: ["isom", "mp42", "avc1", "iso2"] });
2153
+ const inToOutTrack = /* @__PURE__ */ new Map();
2154
+ const trackBaselineDts = /* @__PURE__ */ new Map();
2155
+ let settled = false;
2156
+ const fail = (err) => {
2157
+ if (settled) return;
2158
+ settled = true;
2159
+ reject(err);
2160
+ };
2161
+ inFile.onError = (_module, message) => {
2162
+ fail(new Error(message));
2163
+ };
2164
+ inFile.onReady = (info) => {
2165
+ if (!info.tracks.length) {
2166
+ fail(new Error("no tracks in input"));
2167
+ return;
2168
+ }
2169
+ for (const track of info.tracks) {
2170
+ inFile.setExtractionOptions(track.id, null, { nbSamples: 1e3 });
2171
+ }
2172
+ inFile.start();
2173
+ };
2174
+ inFile.onSamples = (id, _user, samples) => {
2175
+ if (settled || samples.length === 0) return;
2176
+ let outId = inToOutTrack.get(id);
2177
+ let baseline = trackBaselineDts.get(id);
2178
+ if (outId === void 0) {
2179
+ const firstSample = samples[0];
2180
+ const sampleEntry = firstSample.description;
2181
+ const inputTrack = trackInfoById(inFile, id);
2182
+ outId = outFile.addTrack({
2183
+ type: sampleEntry.type,
2184
+ timescale: firstSample.timescale,
2185
+ width: inputTrack == null ? void 0 : inputTrack.track_width,
2186
+ height: inputTrack == null ? void 0 : inputTrack.track_height,
2187
+ language: inputTrack == null ? void 0 : inputTrack.language,
2188
+ hdlr: (inputTrack == null ? void 0 : inputTrack.video) ? "vide" : (inputTrack == null ? void 0 : inputTrack.audio) ? "soun" : void 0,
2189
+ // `boxes` is typed as `Box[]` but `description_boxes`
2190
+ // wants the narrower `BoxKind[]` union — at runtime they
2191
+ // are the same concrete instances, just typed loosely.
2192
+ description_boxes: sampleEntry.boxes
2193
+ });
2194
+ baseline = firstSample.dts;
2195
+ inToOutTrack.set(id, outId);
2196
+ trackBaselineDts.set(id, baseline);
2197
+ }
2198
+ const dtsShift = baseline;
2199
+ for (const sample of samples) {
2200
+ if (!sample.data) continue;
2201
+ outFile.addSample(outId, sample.data, {
2202
+ duration: sample.duration,
2203
+ dts: sample.dts - dtsShift,
2204
+ cts: sample.cts - dtsShift,
2205
+ is_sync: sample.is_sync
2206
+ });
2207
+ }
2208
+ };
2209
+ let buf;
2210
+ try {
2211
+ buf = MP4Box.MP4BoxBuffer.fromArrayBuffer(
2212
+ input.buffer.slice(
2213
+ input.byteOffset,
2214
+ input.byteOffset + input.byteLength
2215
+ ),
2216
+ 0
2217
+ );
2218
+ } catch (error) {
2219
+ fail(error);
2220
+ return;
2221
+ }
2222
+ try {
2223
+ inFile.appendBuffer(buf);
2224
+ inFile.flush();
2225
+ } catch (error) {
2226
+ fail(error);
2227
+ return;
2228
+ }
2229
+ if (settled) return;
2230
+ if (inToOutTrack.size === 0) {
2231
+ fail(new Error("no samples extracted from input"));
2232
+ return;
2233
+ }
2234
+ let output;
2235
+ try {
2236
+ const stream = outFile.getBuffer();
2237
+ output = new Uint8Array(
2238
+ stream.buffer.slice(0, stream.byteLength)
2239
+ );
2240
+ } catch (error) {
2241
+ fail(error);
2242
+ return;
2243
+ }
2244
+ settled = true;
2245
+ resolve(output);
2246
+ });
2247
+ });
2248
+ }
2249
+ function trackInfoById(file, id) {
2250
+ const info = file.getInfo();
2251
+ return info.tracks.find((t) => t.id === id);
2252
+ }
2253
+ function concatUint8Arrays(parts) {
2254
+ if (parts.length === 1) return parts[0];
2255
+ let total = 0;
2256
+ for (const p of parts) total += p.byteLength;
2257
+ const out = new Uint8Array(total);
2258
+ let offset = 0;
2259
+ for (const p of parts) {
2260
+ out.set(p, offset);
2261
+ offset += p.byteLength;
2262
+ }
2263
+ return out;
2264
+ }
2093
2265
  function resolveAgainst(target, base) {
2094
2266
  try {
2095
2267
  return new URL(target, base).toString();
@@ -2399,6 +2571,15 @@ var Reactor = class {
2399
2571
  getCoordinatorBaseUrl: () => this.coordinatorUrl
2400
2572
  });
2401
2573
  }
2574
+ /**
2575
+ * Returns the JWT resolver supplied to the most recent
2576
+ * {@link connect} call, or `undefined` if none was set (pre-connect
2577
+ * or local mode). Used by clip surfaces as a fallback when their
2578
+ * own `getJwt` prop is omitted.
2579
+ */
2580
+ getJwtResolver() {
2581
+ return this.jwtResolver;
2582
+ }
2402
2583
  on(event, handler) {
2403
2584
  if (!this.eventListeners.has(event)) {
2404
2585
  this.eventListeners.set(event, /* @__PURE__ */ new Set());
@@ -2661,7 +2842,10 @@ var Reactor = class {
2661
2842
  }
2662
2843
  /**
2663
2844
  * Connects to the coordinator, creates a session, then establishes
2664
- * the transport using server-declared capabilities.
2845
+ * the transport using server-declared capabilities. `jwtToken` may
2846
+ * be a static string or a {@link JwtSource} resolver; pass a
2847
+ * resolver when the token is short-lived so each Coordinator HTTP
2848
+ * hop sees a fresh value.
2665
2849
  */
2666
2850
  connect(jwtToken, options) {
2667
2851
  return __async(this, null, function* () {
@@ -2674,6 +2858,9 @@ var Reactor = class {
2674
2858
  }
2675
2859
  this.setStatus("connecting");
2676
2860
  this.connectStartTime = performance.now();
2861
+ if (!this.local && jwtToken !== void 0) {
2862
+ this.jwtResolver = normalizeJwtSource(jwtToken);
2863
+ }
2677
2864
  try {
2678
2865
  this.coordinatorClient = this.local ? new LocalCoordinatorClient(this.coordinatorUrl, this.model) : new CoordinatorClient({
2679
2866
  baseUrl: this.coordinatorUrl,
@@ -2937,7 +3124,13 @@ var Reactor = class {
2937
3124
  };
2938
3125
 
2939
3126
  // src/react/ReactorProvider.tsx
2940
- import { useContext, useEffect, useRef, useState } from "react";
3127
+ import {
3128
+ useContext,
3129
+ useEffect,
3130
+ useMemo,
3131
+ useRef,
3132
+ useState
3133
+ } from "react";
2941
3134
 
2942
3135
  // src/core/store.ts
2943
3136
  import { create } from "zustand/react";
@@ -3118,12 +3311,27 @@ function ReactorProvider(_a) {
3118
3311
  var _b = _a, {
3119
3312
  children,
3120
3313
  connectOptions,
3121
- jwtToken
3314
+ jwtToken,
3315
+ getJwt
3122
3316
  } = _b, props = __objRest(_b, [
3123
3317
  "children",
3124
3318
  "connectOptions",
3125
- "jwtToken"
3319
+ "jwtToken",
3320
+ "getJwt"
3126
3321
  ]);
3322
+ const getJwtRef = useRef(getJwt);
3323
+ useEffect(() => {
3324
+ getJwtRef.current = getJwt;
3325
+ });
3326
+ const hasGetJwt = getJwt !== void 0;
3327
+ const stableGetJwt = useMemo(() => {
3328
+ if (!hasGetJwt) return void 0;
3329
+ return () => __async(null, null, function* () {
3330
+ const r = getJwtRef.current;
3331
+ return r ? yield r() : "";
3332
+ });
3333
+ }, [hasGetJwt]);
3334
+ const jwtSource = stableGetJwt != null ? stableGetJwt : jwtToken;
3127
3335
  const storeRef = useRef(void 0);
3128
3336
  const firstRender = useRef(true);
3129
3337
  const [_storeVersion, setStoreVersion] = useState(0);
@@ -3131,7 +3339,7 @@ function ReactorProvider(_a) {
3131
3339
  console.debug("[ReactorProvider] Creating new reactor store");
3132
3340
  storeRef.current = createReactorStore(
3133
3341
  initReactorStore(__spreadProps(__spreadValues({}, props), {
3134
- jwtToken
3342
+ jwtToken: jwtSource
3135
3343
  }))
3136
3344
  );
3137
3345
  console.debug("[ReactorProvider] Reactor store created successfully");
@@ -3156,11 +3364,11 @@ function ReactorProvider(_a) {
3156
3364
  if (firstRender.current) {
3157
3365
  firstRender.current = false;
3158
3366
  const current2 = storeRef.current;
3159
- if (autoConnect && current2.getState().status === "disconnected" && jwtToken) {
3367
+ if (autoConnect && current2.getState().status === "disconnected" && jwtSource) {
3160
3368
  console.debug(
3161
3369
  "[ReactorProvider] Starting autoconnect in first render..."
3162
3370
  );
3163
- current2.getState().connect(jwtToken, pollingOptions).then(() => {
3371
+ current2.getState().connect(jwtSource, pollingOptions).then(() => {
3164
3372
  console.debug(
3165
3373
  "[ReactorProvider] Autoconnect successful in first render"
3166
3374
  );
@@ -3193,7 +3401,7 @@ function ReactorProvider(_a) {
3193
3401
  apiUrl,
3194
3402
  modelName,
3195
3403
  local,
3196
- jwtToken
3404
+ jwtToken: jwtSource
3197
3405
  })
3198
3406
  );
3199
3407
  const current = storeRef.current;
@@ -3201,9 +3409,9 @@ function ReactorProvider(_a) {
3201
3409
  console.debug(
3202
3410
  "[ReactorProvider] Reactor store updated successfully, and increased version"
3203
3411
  );
3204
- if (autoConnect && current.getState().status === "disconnected" && jwtToken) {
3412
+ if (autoConnect && current.getState().status === "disconnected" && jwtSource) {
3205
3413
  console.debug("[ReactorProvider] Starting autoconnect...");
3206
- current.getState().connect(jwtToken, pollingOptions).then(() => {
3414
+ current.getState().connect(jwtSource, pollingOptions).then(() => {
3207
3415
  console.debug("[ReactorProvider] Autoconnect successful");
3208
3416
  }).catch((error) => {
3209
3417
  console.error("[ReactorProvider] Failed to autoconnect:", error);
@@ -3219,7 +3427,7 @@ function ReactorProvider(_a) {
3219
3427
  console.error("[ReactorProvider] Failed to disconnect:", error);
3220
3428
  });
3221
3429
  };
3222
- }, [apiUrl, modelName, autoConnect, local, jwtToken, maxAttempts]);
3430
+ }, [apiUrl, modelName, autoConnect, local, jwtSource, maxAttempts]);
3223
3431
  return /* @__PURE__ */ jsx(ReactorContext.Provider, { value: storeRef.current, children });
3224
3432
  }
3225
3433
  function useReactorStore(selector) {
@@ -3285,7 +3493,7 @@ function useStats() {
3285
3493
  }
3286
3494
 
3287
3495
  // src/react/ReactorView.tsx
3288
- import { useEffect as useEffect3, useMemo, useRef as useRef3 } from "react";
3496
+ import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef3 } from "react";
3289
3497
  import { jsx as jsx2 } from "react/jsx-runtime";
3290
3498
  function ReactorView({
3291
3499
  track = "main_video",
@@ -3305,7 +3513,7 @@ function ReactorView({
3305
3513
  };
3306
3514
  });
3307
3515
  const videoRef = useRef3(null);
3308
- const mediaStream = useMemo(() => {
3516
+ const mediaStream = useMemo2(() => {
3309
3517
  const tracks = [];
3310
3518
  if (videoMediaTrack) tracks.push(videoMediaTrack);
3311
3519
  if (audioMediaTrack) tracks.push(audioMediaTrack);
@@ -4128,7 +4336,7 @@ function WebcamStream({
4128
4336
  }
4129
4337
 
4130
4338
  // src/react/ClipPlayer.tsx
4131
- import { useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
4339
+ import { useContext as useContext2, useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
4132
4340
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
4133
4341
  function ClipPlayer({
4134
4342
  clip,
@@ -4141,13 +4349,16 @@ function ClipPlayer({
4141
4349
  }) {
4142
4350
  const videoRef = useRef6(null);
4143
4351
  const [phase, setPhase] = useState5({ kind: "waiting" });
4352
+ const store = useContext2(ReactorContext);
4144
4353
  const getJwtRef = useRef6(getJwt);
4145
4354
  const autoPlayRef = useRef6(autoPlay);
4146
4355
  const slackMsRef = useRef6(slackMs);
4356
+ const storeRef = useRef6(store);
4147
4357
  useEffect5(() => {
4148
4358
  getJwtRef.current = getJwt;
4149
4359
  autoPlayRef.current = autoPlay;
4150
4360
  slackMsRef.current = slackMs;
4361
+ storeRef.current = store;
4151
4362
  });
4152
4363
  useEffect5(() => {
4153
4364
  const video = videoRef.current;
@@ -4209,9 +4420,13 @@ function ClipPlayer({
4209
4420
  hlsInstance = hls;
4210
4421
  });
4211
4422
  const setup = () => __async(null, null, function* () {
4423
+ var _a;
4212
4424
  try {
4213
4425
  setPhase({ kind: "waiting" });
4214
- const jwt = getJwtRef.current ? yield getJwtRef.current() : void 0;
4426
+ const explicit = getJwtRef.current;
4427
+ const fallback = (_a = storeRef.current) == null ? void 0 : _a.getState().internal.reactor.getJwtResolver();
4428
+ const resolver = explicit != null ? explicit : fallback;
4429
+ const jwt = resolver ? yield resolver() : void 0;
4215
4430
  if (cancelled) return;
4216
4431
  const body = yield fetchPlaylist(clip.playlistUrl, {
4217
4432
  predictedReadyAtMs: clip.predictedReadyAtMs,
@@ -4314,10 +4529,11 @@ function ClipPlayer({
4314
4529
  }
4315
4530
 
4316
4531
  // src/react/useClipDownload.ts
4317
- import { useCallback as useCallback2, useEffect as useEffect6, useRef as useRef7, useState as useState6 } from "react";
4532
+ import { useCallback as useCallback2, useContext as useContext3, useEffect as useEffect6, useRef as useRef7, useState as useState6 } from "react";
4318
4533
  function useClipDownload(clip, options = {}) {
4319
4534
  var _a;
4320
4535
  const [state, setState] = useState6({ kind: "idle" });
4536
+ const store = useContext3(ReactorContext);
4321
4537
  const clipRef = useRef7(clip);
4322
4538
  const filenameRef = useRef7(
4323
4539
  (_a = options.filename) != null ? _a : "reactor-clip.mp4"
@@ -4334,7 +4550,10 @@ function useClipDownload(clip, options = {}) {
4334
4550
  inFlightRef.current = true;
4335
4551
  setState({ kind: "downloading", fetched: 0, total: 0 });
4336
4552
  try {
4337
- const jwt = getJwtRef.current ? yield getJwtRef.current() : void 0;
4553
+ const explicit = getJwtRef.current;
4554
+ const fallback = store == null ? void 0 : store.getState().internal.reactor.getJwtResolver();
4555
+ const resolver = explicit != null ? explicit : fallback;
4556
+ const jwt = resolver ? yield resolver() : void 0;
4338
4557
  const blob = yield downloadClipAsFile(
4339
4558
  clipRef.current,
4340
4559
  filenameRef.current,
@@ -4352,7 +4571,7 @@ function useClipDownload(clip, options = {}) {
4352
4571
  } finally {
4353
4572
  inFlightRef.current = false;
4354
4573
  }
4355
- }), []);
4574
+ }), [store]);
4356
4575
  const reset = useCallback2(() => setState({ kind: "idle" }), []);
4357
4576
  return { state, download, reset };
4358
4577
  }
@@ -4428,6 +4647,7 @@ export {
4428
4647
  downloadClipAsFile,
4429
4648
  fetchPlaylist,
4430
4649
  isAbortError,
4650
+ normalizeJwtSource,
4431
4651
  parsePlaylist,
4432
4652
  rewriteUrlHost,
4433
4653
  useClipDownload,