@reactor-team/js-sdk 2.11.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/dist/index.d.mts +80 -5
- package/dist/index.d.ts +80 -5
- package/dist/index.js +146 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
94
|
+
version: "2.11.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: {
|
|
@@ -2673,9 +2673,13 @@ var Reactor = class {
|
|
|
2673
2673
|
sendCommand(command, data, scope = "application") {
|
|
2674
2674
|
return __async(this, null, function* () {
|
|
2675
2675
|
var _a;
|
|
2676
|
-
if (
|
|
2677
|
-
|
|
2678
|
-
|
|
2676
|
+
if (this.status !== "ready") {
|
|
2677
|
+
this.createError(
|
|
2678
|
+
"NOT_READY",
|
|
2679
|
+
`Cannot send command "${command}" while status is "${this.status}". Must be "ready".`,
|
|
2680
|
+
"api",
|
|
2681
|
+
true
|
|
2682
|
+
);
|
|
2679
2683
|
return;
|
|
2680
2684
|
}
|
|
2681
2685
|
try {
|
|
@@ -3368,7 +3372,10 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3368
3372
|
console.error("[ReactorStore] Failed to upload file:", error);
|
|
3369
3373
|
throw error;
|
|
3370
3374
|
}
|
|
3371
|
-
})
|
|
3375
|
+
}),
|
|
3376
|
+
requestClip: (durationSeconds) => get().internal.reactor.requestClip(durationSeconds),
|
|
3377
|
+
requestRecording: () => get().internal.reactor.requestRecording(),
|
|
3378
|
+
downloadClipAsFile: (clip, filename, options) => get().internal.reactor.downloadClipAsFile(clip, filename, options)
|
|
3372
3379
|
});
|
|
3373
3380
|
});
|
|
3374
3381
|
};
|
|
@@ -3496,7 +3503,7 @@ function ReactorProvider(_a) {
|
|
|
3496
3503
|
console.error("[ReactorProvider] Failed to disconnect:", error);
|
|
3497
3504
|
});
|
|
3498
3505
|
};
|
|
3499
|
-
}, [apiUrl, modelName,
|
|
3506
|
+
}, [apiUrl, modelName, local, jwtSource]);
|
|
3500
3507
|
return /* @__PURE__ */ jsx(ReactorContext.Provider, { value: storeRef.current, children });
|
|
3501
3508
|
}
|
|
3502
3509
|
function useReactorStore(selector) {
|
|
@@ -3572,7 +3579,7 @@ function ReactorView({
|
|
|
3572
3579
|
className,
|
|
3573
3580
|
style,
|
|
3574
3581
|
videoObjectFit = "contain",
|
|
3575
|
-
muted =
|
|
3582
|
+
muted = audioTrack === void 0
|
|
3576
3583
|
}) {
|
|
3577
3584
|
const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
|
|
3578
3585
|
var _a, _b;
|
|
@@ -4215,6 +4222,8 @@ import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } fro
|
|
|
4215
4222
|
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4216
4223
|
function WebcamStream({
|
|
4217
4224
|
track,
|
|
4225
|
+
audio = false,
|
|
4226
|
+
audioTrack,
|
|
4218
4227
|
className,
|
|
4219
4228
|
style,
|
|
4220
4229
|
videoConstraints = {
|
|
@@ -4222,7 +4231,10 @@ function WebcamStream({
|
|
|
4222
4231
|
height: { ideal: 720 }
|
|
4223
4232
|
},
|
|
4224
4233
|
showWebcam = true,
|
|
4225
|
-
videoObjectFit = "contain"
|
|
4234
|
+
videoObjectFit = "contain",
|
|
4235
|
+
onPermissionDenied,
|
|
4236
|
+
onPublished,
|
|
4237
|
+
onError
|
|
4226
4238
|
}) {
|
|
4227
4239
|
const [stream, setStream] = useState4(null);
|
|
4228
4240
|
const [isPublishing, setIsPublishing] = useState4(false);
|
|
@@ -4234,12 +4246,28 @@ function WebcamStream({
|
|
|
4234
4246
|
reactor: state.internal.reactor
|
|
4235
4247
|
}));
|
|
4236
4248
|
const videoRef = useRef5(null);
|
|
4249
|
+
const onPermissionDeniedRef = useRef5(onPermissionDenied);
|
|
4250
|
+
const onPublishedRef = useRef5(onPublished);
|
|
4251
|
+
const onErrorRef = useRef5(onError);
|
|
4252
|
+
useEffect4(() => {
|
|
4253
|
+
onPermissionDeniedRef.current = onPermissionDenied;
|
|
4254
|
+
onPublishedRef.current = onPublished;
|
|
4255
|
+
onErrorRef.current = onError;
|
|
4256
|
+
});
|
|
4257
|
+
const audioRequested = audio !== false && audio !== void 0;
|
|
4258
|
+
const audioEnabled = audioRequested && !!audioTrack;
|
|
4259
|
+
if (audioRequested && !audioTrack) {
|
|
4260
|
+
console.warn(
|
|
4261
|
+
"[WebcamStream] `audio` was set but `audioTrack` is missing; capturing video-only."
|
|
4262
|
+
);
|
|
4263
|
+
}
|
|
4237
4264
|
const startWebcam = () => __async(null, null, function* () {
|
|
4265
|
+
var _a, _b;
|
|
4238
4266
|
console.debug("[WebcamPublisher] Starting webcam");
|
|
4239
4267
|
try {
|
|
4240
4268
|
const mediaStream = yield navigator.mediaDevices.getUserMedia({
|
|
4241
4269
|
video: videoConstraints,
|
|
4242
|
-
audio: false
|
|
4270
|
+
audio: audioEnabled ? audio === true ? true : audio : false
|
|
4243
4271
|
});
|
|
4244
4272
|
console.debug("[WebcamPublisher] Webcam started successfully");
|
|
4245
4273
|
setStream(mediaStream);
|
|
@@ -4249,16 +4277,34 @@ function WebcamStream({
|
|
|
4249
4277
|
if (err instanceof DOMException && (err.name === "NotAllowedError" || err.name === "PermissionDeniedError")) {
|
|
4250
4278
|
console.debug("[WebcamPublisher] Camera permission denied");
|
|
4251
4279
|
setPermissionDenied(true);
|
|
4280
|
+
(_a = onPermissionDeniedRef.current) == null ? void 0 : _a.call(onPermissionDeniedRef);
|
|
4281
|
+
} else {
|
|
4282
|
+
(_b = onErrorRef.current) == null ? void 0 : _b.call(
|
|
4283
|
+
onErrorRef,
|
|
4284
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4285
|
+
);
|
|
4252
4286
|
}
|
|
4253
4287
|
}
|
|
4254
4288
|
});
|
|
4255
4289
|
const stopWebcam = () => __async(null, null, function* () {
|
|
4290
|
+
var _a;
|
|
4256
4291
|
console.debug("[WebcamPublisher] Stopping webcam");
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
}
|
|
4261
|
-
|
|
4292
|
+
const unpublishTasks = [unpublish(track)];
|
|
4293
|
+
if (audioEnabled && audioTrack) {
|
|
4294
|
+
unpublishTasks.push(unpublish(audioTrack));
|
|
4295
|
+
}
|
|
4296
|
+
const results = yield Promise.allSettled(unpublishTasks);
|
|
4297
|
+
for (const r of results) {
|
|
4298
|
+
if (r.status === "rejected") {
|
|
4299
|
+
console.error(
|
|
4300
|
+
"[WebcamPublisher] Error unpublishing before stop:",
|
|
4301
|
+
r.reason
|
|
4302
|
+
);
|
|
4303
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4304
|
+
onErrorRef,
|
|
4305
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4262
4308
|
}
|
|
4263
4309
|
setIsPublishing(false);
|
|
4264
4310
|
stream == null ? void 0 : stream.getTracks().forEach((t) => {
|
|
@@ -4293,25 +4339,54 @@ function WebcamStream({
|
|
|
4293
4339
|
console.debug(
|
|
4294
4340
|
"[WebcamPublisher] Reactor ready, auto-publishing webcam stream"
|
|
4295
4341
|
);
|
|
4296
|
-
const
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4342
|
+
const videoMediaTrack = stream.getVideoTracks()[0];
|
|
4343
|
+
const audioMediaTrack = audioEnabled && audioTrack ? stream.getAudioTracks()[0] : null;
|
|
4344
|
+
const tasks = [];
|
|
4345
|
+
if (videoMediaTrack) tasks.push(publish(track, videoMediaTrack));
|
|
4346
|
+
if (audioMediaTrack && audioTrack)
|
|
4347
|
+
tasks.push(publish(audioTrack, audioMediaTrack));
|
|
4348
|
+
if (tasks.length === 0) return;
|
|
4349
|
+
Promise.all(tasks).then(() => {
|
|
4350
|
+
var _a;
|
|
4351
|
+
console.debug("[WebcamPublisher] Auto-publish successful");
|
|
4352
|
+
setIsPublishing(true);
|
|
4353
|
+
(_a = onPublishedRef.current) == null ? void 0 : _a.call(onPublishedRef);
|
|
4354
|
+
}).catch((err) => {
|
|
4355
|
+
var _a;
|
|
4356
|
+
console.error("[WebcamPublisher] Auto-publish failed:", err);
|
|
4357
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4358
|
+
onErrorRef,
|
|
4359
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4360
|
+
);
|
|
4361
|
+
});
|
|
4305
4362
|
} else if (status !== "ready" && isPublishing) {
|
|
4306
4363
|
console.debug("[WebcamPublisher] Reactor not ready, auto-unpublishing");
|
|
4307
|
-
unpublish(track)
|
|
4308
|
-
|
|
4364
|
+
const tasks = [unpublish(track)];
|
|
4365
|
+
if (audioEnabled && audioTrack) tasks.push(unpublish(audioTrack));
|
|
4366
|
+
Promise.allSettled(tasks).then((results) => {
|
|
4367
|
+
var _a;
|
|
4368
|
+
for (const r of results) {
|
|
4369
|
+
if (r.status === "rejected") {
|
|
4370
|
+
console.error("[WebcamPublisher] Auto-unpublish failed:", r.reason);
|
|
4371
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4372
|
+
onErrorRef,
|
|
4373
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4309
4377
|
setIsPublishing(false);
|
|
4310
|
-
}).catch((err) => {
|
|
4311
|
-
console.error("[WebcamPublisher] Auto-unpublish failed:", err);
|
|
4312
4378
|
});
|
|
4313
4379
|
}
|
|
4314
|
-
}, [
|
|
4380
|
+
}, [
|
|
4381
|
+
status,
|
|
4382
|
+
stream,
|
|
4383
|
+
isPublishing,
|
|
4384
|
+
publish,
|
|
4385
|
+
unpublish,
|
|
4386
|
+
track,
|
|
4387
|
+
audioEnabled,
|
|
4388
|
+
audioTrack
|
|
4389
|
+
]);
|
|
4315
4390
|
useEffect4(() => {
|
|
4316
4391
|
const handleError = (error) => {
|
|
4317
4392
|
console.debug("[WebcamPublisher] Received error event:", error);
|
|
@@ -4414,7 +4489,8 @@ function ClipPlayer({
|
|
|
4414
4489
|
autoPlay = true,
|
|
4415
4490
|
muted = true,
|
|
4416
4491
|
className,
|
|
4417
|
-
style
|
|
4492
|
+
style,
|
|
4493
|
+
onError
|
|
4418
4494
|
}) {
|
|
4419
4495
|
const videoRef = useRef6(null);
|
|
4420
4496
|
const [phase, setPhase] = useState5({ kind: "waiting" });
|
|
@@ -4422,13 +4498,21 @@ function ClipPlayer({
|
|
|
4422
4498
|
const getJwtRef = useRef6(getJwt);
|
|
4423
4499
|
const autoPlayRef = useRef6(autoPlay);
|
|
4424
4500
|
const slackMsRef = useRef6(slackMs);
|
|
4501
|
+
const onErrorRef = useRef6(onError);
|
|
4425
4502
|
const storeRef = useRef6(store);
|
|
4426
4503
|
useEffect5(() => {
|
|
4427
4504
|
getJwtRef.current = getJwt;
|
|
4428
4505
|
autoPlayRef.current = autoPlay;
|
|
4429
4506
|
slackMsRef.current = slackMs;
|
|
4507
|
+
onErrorRef.current = onError;
|
|
4430
4508
|
storeRef.current = store;
|
|
4431
4509
|
});
|
|
4510
|
+
useEffect5(() => {
|
|
4511
|
+
var _a;
|
|
4512
|
+
if (phase.kind === "error") {
|
|
4513
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, phase.error);
|
|
4514
|
+
}
|
|
4515
|
+
}, [phase]);
|
|
4432
4516
|
useEffect5(() => {
|
|
4433
4517
|
const video = videoRef.current;
|
|
4434
4518
|
if (!video) return;
|
|
@@ -4436,9 +4520,10 @@ function ClipPlayer({
|
|
|
4436
4520
|
let cancelled = false;
|
|
4437
4521
|
let hlsInstance = null;
|
|
4438
4522
|
let manifestBlobUrl = null;
|
|
4439
|
-
const fail = (
|
|
4523
|
+
const fail = (error) => {
|
|
4440
4524
|
if (cancelled) return;
|
|
4441
|
-
|
|
4525
|
+
const message = error instanceof RecordingError ? `${error.code}: ${error.reason}` : error.message;
|
|
4526
|
+
setPhase({ kind: "error", message, error });
|
|
4442
4527
|
};
|
|
4443
4528
|
const attachPlayer = (manifestUrl) => __async(null, null, function* () {
|
|
4444
4529
|
const canPlayNative = video.canPlayType("application/vnd.apple.mpegurl") !== "";
|
|
@@ -4457,13 +4542,17 @@ function ClipPlayer({
|
|
|
4457
4542
|
HlsCtor = mod.default;
|
|
4458
4543
|
} catch (e) {
|
|
4459
4544
|
fail(
|
|
4460
|
-
|
|
4545
|
+
new Error(
|
|
4546
|
+
"HLS playback unavailable in this browser. Install `hls.js` as a peer dependency, or use Download."
|
|
4547
|
+
)
|
|
4461
4548
|
);
|
|
4462
4549
|
return;
|
|
4463
4550
|
}
|
|
4464
4551
|
if (cancelled) return;
|
|
4465
4552
|
if (!HlsCtor.isSupported()) {
|
|
4466
|
-
fail(
|
|
4553
|
+
fail(
|
|
4554
|
+
new Error("This browser cannot play HLS clips. Use Download instead.")
|
|
4555
|
+
);
|
|
4467
4556
|
return;
|
|
4468
4557
|
}
|
|
4469
4558
|
const hls = new HlsCtor();
|
|
@@ -4481,7 +4570,7 @@ function ClipPlayer({
|
|
|
4481
4570
|
var _a;
|
|
4482
4571
|
if (cancelled) return;
|
|
4483
4572
|
if (data.fatal) {
|
|
4484
|
-
fail(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`);
|
|
4573
|
+
fail(new Error(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`));
|
|
4485
4574
|
return;
|
|
4486
4575
|
}
|
|
4487
4576
|
console.warn("[Reactor.ClipPlayer] hls.js non-fatal error", data);
|
|
@@ -4512,8 +4601,7 @@ function ClipPlayer({
|
|
|
4512
4601
|
if (err instanceof DOMException && err.name === "AbortError") {
|
|
4513
4602
|
return;
|
|
4514
4603
|
}
|
|
4515
|
-
|
|
4516
|
-
fail(message);
|
|
4604
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
4517
4605
|
}
|
|
4518
4606
|
});
|
|
4519
4607
|
setup();
|
|
@@ -4597,6 +4685,9 @@ function ClipPlayer({
|
|
|
4597
4685
|
);
|
|
4598
4686
|
}
|
|
4599
4687
|
|
|
4688
|
+
// src/react/ClipDownloadButton.tsx
|
|
4689
|
+
import { useEffect as useEffect7, useRef as useRef8 } from "react";
|
|
4690
|
+
|
|
4600
4691
|
// src/react/useClipDownload.ts
|
|
4601
4692
|
import { useCallback as useCallback2, useContext as useContext3, useEffect as useEffect6, useRef as useRef7, useState as useState6 } from "react";
|
|
4602
4693
|
function useClipDownload(clip, options = {}) {
|
|
@@ -4654,18 +4745,35 @@ function ClipDownloadButton({
|
|
|
4654
4745
|
children,
|
|
4655
4746
|
className,
|
|
4656
4747
|
style,
|
|
4657
|
-
disabled
|
|
4748
|
+
disabled,
|
|
4749
|
+
onSuccess,
|
|
4750
|
+
onError
|
|
4658
4751
|
}) {
|
|
4659
4752
|
const { state, download } = useClipDownload(clip, { filename, getJwt });
|
|
4660
4753
|
const downloading = state.kind === "downloading";
|
|
4661
4754
|
const isDisabled = downloading || !!disabled;
|
|
4755
|
+
const onSuccessRef = useRef8(onSuccess);
|
|
4756
|
+
const onErrorRef = useRef8(onError);
|
|
4757
|
+
useEffect7(() => {
|
|
4758
|
+
onSuccessRef.current = onSuccess;
|
|
4759
|
+
onErrorRef.current = onError;
|
|
4760
|
+
});
|
|
4761
|
+
useEffect7(() => {
|
|
4762
|
+
var _a;
|
|
4763
|
+
if (state.kind === "error") {
|
|
4764
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, new Error(state.message));
|
|
4765
|
+
}
|
|
4766
|
+
}, [state]);
|
|
4662
4767
|
const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
|
|
4663
4768
|
return /* @__PURE__ */ jsx6(
|
|
4664
4769
|
"button",
|
|
4665
4770
|
{
|
|
4666
4771
|
type: "button",
|
|
4667
4772
|
onClick: () => {
|
|
4668
|
-
void download()
|
|
4773
|
+
void download().then((blob) => {
|
|
4774
|
+
var _a;
|
|
4775
|
+
if (blob) (_a = onSuccessRef.current) == null ? void 0 : _a.call(onSuccessRef, blob);
|
|
4776
|
+
});
|
|
4669
4777
|
},
|
|
4670
4778
|
disabled: isDisabled,
|
|
4671
4779
|
title: state.kind === "error" ? state.message : void 0,
|