@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/README.md
CHANGED
|
@@ -112,7 +112,7 @@ For video-to-video models, drop `<WebcamStream>` inside the provider and name th
|
|
|
112
112
|
|
|
113
113
|
### Receive messages
|
|
114
114
|
|
|
115
|
-
Models emit structured messages back to your app, such as progress updates, state snapshots, or custom model events. Subscribe with `useReactorMessage
|
|
115
|
+
Models emit structured messages back to your app, such as progress updates, state snapshots, or custom model events. Subscribe with `useReactorMessage`. Select store fields one at a time so a component only re-renders when something it actually uses changes — passing `(s) => s` will rerender on every track frame, status flip, and error:
|
|
116
116
|
|
|
117
117
|
```tsx
|
|
118
118
|
import { useReactorMessage } from "@reactor-team/js-sdk";
|
|
@@ -135,7 +135,10 @@ function FrameCounter() {
|
|
|
135
135
|
Bind an `<input type="file">` to the model with `uploadFile` and then pass the returned [`FileRef`](https://docs.reactor.inc/api-reference/types#fileref) into any command:
|
|
136
136
|
|
|
137
137
|
```tsx
|
|
138
|
-
const { uploadFile, sendCommand } = useReactor((s) =>
|
|
138
|
+
const { uploadFile, sendCommand } = useReactor((s) => ({
|
|
139
|
+
uploadFile: s.uploadFile,
|
|
140
|
+
sendCommand: s.sendCommand,
|
|
141
|
+
}));
|
|
139
142
|
|
|
140
143
|
const ref = await uploadFile(file);
|
|
141
144
|
await sendCommand("set_image", { image: ref });
|
|
@@ -153,18 +156,17 @@ import { Reactor } from "@reactor-team/js-sdk";
|
|
|
153
156
|
const reactor = new Reactor({
|
|
154
157
|
apiUrl: "https://api.reactor.inc",
|
|
155
158
|
modelName: "your-model-name",
|
|
156
|
-
jwtToken: await fetchJwt(),
|
|
157
159
|
});
|
|
158
160
|
|
|
159
|
-
reactor.on("
|
|
161
|
+
reactor.on("statusChanged", (status) => console.log("status:", status));
|
|
160
162
|
reactor.on("message", (msg) => console.log("model:", msg));
|
|
163
|
+
reactor.on("trackReceived", (name, _track, stream) => {
|
|
164
|
+
if (name === "main_video") videoEl.srcObject = stream;
|
|
165
|
+
});
|
|
161
166
|
|
|
162
|
-
await reactor.connect();
|
|
167
|
+
await reactor.connect(await fetchJwt());
|
|
163
168
|
|
|
164
169
|
await reactor.sendCommand("set_prompt", { prompt: "a forest at dawn" });
|
|
165
|
-
|
|
166
|
-
const stream = reactor.getMediaStream("main_video");
|
|
167
|
-
videoEl.srcObject = stream;
|
|
168
170
|
```
|
|
169
171
|
|
|
170
172
|
---
|
package/dist/index.d.mts
CHANGED
|
@@ -727,6 +727,27 @@ interface ReactorActions {
|
|
|
727
727
|
uploadFile(file: File | Blob, options?: {
|
|
728
728
|
name?: string;
|
|
729
729
|
}): Promise<FileRef>;
|
|
730
|
+
/**
|
|
731
|
+
* Capture the trailing `durationSeconds` of the live session as a
|
|
732
|
+
* clip. Top-level alias for `internal.reactor.requestClip(…)` —
|
|
733
|
+
* lifted onto the store so consumers don't have to reach through
|
|
734
|
+
* `internal.reactor` for the common case. See
|
|
735
|
+
* {@link Reactor.requestClip}.
|
|
736
|
+
*/
|
|
737
|
+
requestClip(durationSeconds: number): Promise<Clip>;
|
|
738
|
+
/**
|
|
739
|
+
* Capture the entire session up to "now" as a clip. Top-level
|
|
740
|
+
* alias for `internal.reactor.requestRecording()`. See
|
|
741
|
+
* {@link Reactor.requestRecording}.
|
|
742
|
+
*/
|
|
743
|
+
requestRecording(): Promise<Clip>;
|
|
744
|
+
/**
|
|
745
|
+
* Stream the chunks referenced by `clip.playlistUrl` and trigger a
|
|
746
|
+
* native browser download of the assembled MP4. Top-level alias
|
|
747
|
+
* for `internal.reactor.downloadClipAsFile(…)`. See
|
|
748
|
+
* {@link Reactor.downloadClipAsFile}.
|
|
749
|
+
*/
|
|
750
|
+
downloadClipAsFile(clip: Clip, filename?: string | null, options?: DownloadClipOptions): Promise<Blob>;
|
|
730
751
|
}
|
|
731
752
|
interface ReactorInternalState {
|
|
732
753
|
reactor: Reactor;
|
|
@@ -784,7 +805,13 @@ interface ReactorViewProps {
|
|
|
784
805
|
className?: string;
|
|
785
806
|
style?: React.CSSProperties;
|
|
786
807
|
videoObjectFit?: NonNullable<React.VideoHTMLAttributes<HTMLVideoElement>["style"]>["objectFit"];
|
|
787
|
-
/**
|
|
808
|
+
/**
|
|
809
|
+
* Controls whether inbound audio plays. Default is `true`
|
|
810
|
+
* (muted) when no `audioTrack` is set — keeps the underlying
|
|
811
|
+
* `<video>` element within browser autoplay policies; `false`
|
|
812
|
+
* when an `audioTrack` is set. Pass an explicit value to
|
|
813
|
+
* override either default.
|
|
814
|
+
*/
|
|
788
815
|
muted?: boolean;
|
|
789
816
|
}
|
|
790
817
|
declare function ReactorView({ track, audioTrack, width, height, className, style, videoObjectFit, muted, }: ReactorViewProps): react_jsx_runtime.JSX.Element;
|
|
@@ -797,18 +824,49 @@ declare function ReactorController({ className, style, }: ReactorControllerProps
|
|
|
797
824
|
|
|
798
825
|
interface WebcamStreamProps {
|
|
799
826
|
/**
|
|
800
|
-
* The name of the sendonly track to publish the webcam to.
|
|
827
|
+
* The name of the sendonly **video** track to publish the webcam to.
|
|
801
828
|
* Must match a track name declared in the server capabilities.
|
|
802
829
|
* Check the model's documentation for available track names.
|
|
803
830
|
*/
|
|
804
831
|
track: string;
|
|
832
|
+
/**
|
|
833
|
+
* Capture and publish the microphone alongside the webcam. Pass
|
|
834
|
+
* `true` for default constraints, or an explicit
|
|
835
|
+
* `MediaTrackConstraints` to control sample rate / device / echo
|
|
836
|
+
* cancellation. Requires {@link audioTrack} so the SDK knows
|
|
837
|
+
* which sendonly track to publish the mic to. Default `false`.
|
|
838
|
+
*/
|
|
839
|
+
audio?: boolean | MediaTrackConstraints;
|
|
840
|
+
/**
|
|
841
|
+
* The name of the sendonly **audio** track to publish the mic to.
|
|
842
|
+
* Ignored when {@link audio} is `false` (the default); required
|
|
843
|
+
* otherwise.
|
|
844
|
+
*/
|
|
845
|
+
audioTrack?: string;
|
|
805
846
|
className?: string;
|
|
806
847
|
style?: React.CSSProperties;
|
|
807
848
|
videoConstraints?: MediaTrackConstraints;
|
|
808
849
|
showWebcam?: boolean;
|
|
809
850
|
videoObjectFit?: NonNullable<React.VideoHTMLAttributes<HTMLVideoElement>["style"]>["objectFit"];
|
|
851
|
+
/**
|
|
852
|
+
* Fires once `getUserMedia` is rejected with `NotAllowedError`
|
|
853
|
+
* or `PermissionDeniedError`.
|
|
854
|
+
*/
|
|
855
|
+
onPermissionDenied?: () => void;
|
|
856
|
+
/**
|
|
857
|
+
* Fires after the local media stream has been published (both
|
|
858
|
+
* video and audio when {@link audio} is enabled). Re-fires
|
|
859
|
+
* after a reconnect.
|
|
860
|
+
*/
|
|
861
|
+
onPublished?: () => void;
|
|
862
|
+
/**
|
|
863
|
+
* Fires on non-permission `getUserMedia` failures and on
|
|
864
|
+
* publish / unpublish rejections. Permission denials route to
|
|
865
|
+
* {@link onPermissionDenied} instead.
|
|
866
|
+
*/
|
|
867
|
+
onError?: (error: Error) => void;
|
|
810
868
|
}
|
|
811
|
-
declare function WebcamStream({ track, className, style, videoConstraints, showWebcam, videoObjectFit, }: WebcamStreamProps): react_jsx_runtime.JSX.Element;
|
|
869
|
+
declare function WebcamStream({ track, audio, audioTrack, className, style, videoConstraints, showWebcam, videoObjectFit, onPermissionDenied, onPublished, onError, }: WebcamStreamProps): react_jsx_runtime.JSX.Element;
|
|
812
870
|
|
|
813
871
|
/**
|
|
814
872
|
* Video preview for a captured {@link Clip}.
|
|
@@ -893,8 +951,15 @@ interface ClipPlayerProps {
|
|
|
893
951
|
muted?: boolean;
|
|
894
952
|
className?: string;
|
|
895
953
|
style?: React.CSSProperties;
|
|
954
|
+
/**
|
|
955
|
+
* Fires when the player enters its inline error state. Receives
|
|
956
|
+
* the originating error: a ``RecordingError`` for manifest-fetch
|
|
957
|
+
* failures, a plain ``Error`` for hls.js / native playback or
|
|
958
|
+
* missing-peer-dep cases.
|
|
959
|
+
*/
|
|
960
|
+
onError?: (error: Error) => void;
|
|
896
961
|
}
|
|
897
|
-
declare function ClipPlayer({ clip, getJwt, slackMs, autoPlay, muted, className, style, }: ClipPlayerProps): react_jsx_runtime.JSX.Element;
|
|
962
|
+
declare function ClipPlayer({ clip, getJwt, slackMs, autoPlay, muted, className, style, onError, }: ClipPlayerProps): react_jsx_runtime.JSX.Element;
|
|
898
963
|
|
|
899
964
|
/**
|
|
900
965
|
* State machine for an in-progress clip download.
|
|
@@ -1050,8 +1115,18 @@ interface ClipDownloadButtonProps {
|
|
|
1050
1115
|
style?: React.CSSProperties;
|
|
1051
1116
|
/** Forwarded to the underlying ``<button>``. ORed with the internal "downloading" state. */
|
|
1052
1117
|
disabled?: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* Fires when the download completes with the assembled MP4 ``Blob``.
|
|
1120
|
+
*/
|
|
1121
|
+
onSuccess?: (blob: Blob) => void;
|
|
1122
|
+
/**
|
|
1123
|
+
* Fires when the download fails. Message mirrors the in-button
|
|
1124
|
+
* state — ``"<CODE>: <reason>"`` for ``RecordingError``s, the
|
|
1125
|
+
* plain error message otherwise.
|
|
1126
|
+
*/
|
|
1127
|
+
onError?: (error: Error) => void;
|
|
1053
1128
|
}
|
|
1054
|
-
declare function ClipDownloadButton({ clip, getJwt, filename, children, className, style, disabled, }: ClipDownloadButtonProps): react_jsx_runtime.JSX.Element;
|
|
1129
|
+
declare function ClipDownloadButton({ clip, getJwt, filename, children, className, style, disabled, onSuccess, onError, }: ClipDownloadButtonProps): react_jsx_runtime.JSX.Element;
|
|
1055
1130
|
|
|
1056
1131
|
/**
|
|
1057
1132
|
* Generic hook for accessing selected parts of the Reactor store.
|
package/dist/index.d.ts
CHANGED
|
@@ -727,6 +727,27 @@ interface ReactorActions {
|
|
|
727
727
|
uploadFile(file: File | Blob, options?: {
|
|
728
728
|
name?: string;
|
|
729
729
|
}): Promise<FileRef>;
|
|
730
|
+
/**
|
|
731
|
+
* Capture the trailing `durationSeconds` of the live session as a
|
|
732
|
+
* clip. Top-level alias for `internal.reactor.requestClip(…)` —
|
|
733
|
+
* lifted onto the store so consumers don't have to reach through
|
|
734
|
+
* `internal.reactor` for the common case. See
|
|
735
|
+
* {@link Reactor.requestClip}.
|
|
736
|
+
*/
|
|
737
|
+
requestClip(durationSeconds: number): Promise<Clip>;
|
|
738
|
+
/**
|
|
739
|
+
* Capture the entire session up to "now" as a clip. Top-level
|
|
740
|
+
* alias for `internal.reactor.requestRecording()`. See
|
|
741
|
+
* {@link Reactor.requestRecording}.
|
|
742
|
+
*/
|
|
743
|
+
requestRecording(): Promise<Clip>;
|
|
744
|
+
/**
|
|
745
|
+
* Stream the chunks referenced by `clip.playlistUrl` and trigger a
|
|
746
|
+
* native browser download of the assembled MP4. Top-level alias
|
|
747
|
+
* for `internal.reactor.downloadClipAsFile(…)`. See
|
|
748
|
+
* {@link Reactor.downloadClipAsFile}.
|
|
749
|
+
*/
|
|
750
|
+
downloadClipAsFile(clip: Clip, filename?: string | null, options?: DownloadClipOptions): Promise<Blob>;
|
|
730
751
|
}
|
|
731
752
|
interface ReactorInternalState {
|
|
732
753
|
reactor: Reactor;
|
|
@@ -784,7 +805,13 @@ interface ReactorViewProps {
|
|
|
784
805
|
className?: string;
|
|
785
806
|
style?: React.CSSProperties;
|
|
786
807
|
videoObjectFit?: NonNullable<React.VideoHTMLAttributes<HTMLVideoElement>["style"]>["objectFit"];
|
|
787
|
-
/**
|
|
808
|
+
/**
|
|
809
|
+
* Controls whether inbound audio plays. Default is `true`
|
|
810
|
+
* (muted) when no `audioTrack` is set — keeps the underlying
|
|
811
|
+
* `<video>` element within browser autoplay policies; `false`
|
|
812
|
+
* when an `audioTrack` is set. Pass an explicit value to
|
|
813
|
+
* override either default.
|
|
814
|
+
*/
|
|
788
815
|
muted?: boolean;
|
|
789
816
|
}
|
|
790
817
|
declare function ReactorView({ track, audioTrack, width, height, className, style, videoObjectFit, muted, }: ReactorViewProps): react_jsx_runtime.JSX.Element;
|
|
@@ -797,18 +824,49 @@ declare function ReactorController({ className, style, }: ReactorControllerProps
|
|
|
797
824
|
|
|
798
825
|
interface WebcamStreamProps {
|
|
799
826
|
/**
|
|
800
|
-
* The name of the sendonly track to publish the webcam to.
|
|
827
|
+
* The name of the sendonly **video** track to publish the webcam to.
|
|
801
828
|
* Must match a track name declared in the server capabilities.
|
|
802
829
|
* Check the model's documentation for available track names.
|
|
803
830
|
*/
|
|
804
831
|
track: string;
|
|
832
|
+
/**
|
|
833
|
+
* Capture and publish the microphone alongside the webcam. Pass
|
|
834
|
+
* `true` for default constraints, or an explicit
|
|
835
|
+
* `MediaTrackConstraints` to control sample rate / device / echo
|
|
836
|
+
* cancellation. Requires {@link audioTrack} so the SDK knows
|
|
837
|
+
* which sendonly track to publish the mic to. Default `false`.
|
|
838
|
+
*/
|
|
839
|
+
audio?: boolean | MediaTrackConstraints;
|
|
840
|
+
/**
|
|
841
|
+
* The name of the sendonly **audio** track to publish the mic to.
|
|
842
|
+
* Ignored when {@link audio} is `false` (the default); required
|
|
843
|
+
* otherwise.
|
|
844
|
+
*/
|
|
845
|
+
audioTrack?: string;
|
|
805
846
|
className?: string;
|
|
806
847
|
style?: React.CSSProperties;
|
|
807
848
|
videoConstraints?: MediaTrackConstraints;
|
|
808
849
|
showWebcam?: boolean;
|
|
809
850
|
videoObjectFit?: NonNullable<React.VideoHTMLAttributes<HTMLVideoElement>["style"]>["objectFit"];
|
|
851
|
+
/**
|
|
852
|
+
* Fires once `getUserMedia` is rejected with `NotAllowedError`
|
|
853
|
+
* or `PermissionDeniedError`.
|
|
854
|
+
*/
|
|
855
|
+
onPermissionDenied?: () => void;
|
|
856
|
+
/**
|
|
857
|
+
* Fires after the local media stream has been published (both
|
|
858
|
+
* video and audio when {@link audio} is enabled). Re-fires
|
|
859
|
+
* after a reconnect.
|
|
860
|
+
*/
|
|
861
|
+
onPublished?: () => void;
|
|
862
|
+
/**
|
|
863
|
+
* Fires on non-permission `getUserMedia` failures and on
|
|
864
|
+
* publish / unpublish rejections. Permission denials route to
|
|
865
|
+
* {@link onPermissionDenied} instead.
|
|
866
|
+
*/
|
|
867
|
+
onError?: (error: Error) => void;
|
|
810
868
|
}
|
|
811
|
-
declare function WebcamStream({ track, className, style, videoConstraints, showWebcam, videoObjectFit, }: WebcamStreamProps): react_jsx_runtime.JSX.Element;
|
|
869
|
+
declare function WebcamStream({ track, audio, audioTrack, className, style, videoConstraints, showWebcam, videoObjectFit, onPermissionDenied, onPublished, onError, }: WebcamStreamProps): react_jsx_runtime.JSX.Element;
|
|
812
870
|
|
|
813
871
|
/**
|
|
814
872
|
* Video preview for a captured {@link Clip}.
|
|
@@ -893,8 +951,15 @@ interface ClipPlayerProps {
|
|
|
893
951
|
muted?: boolean;
|
|
894
952
|
className?: string;
|
|
895
953
|
style?: React.CSSProperties;
|
|
954
|
+
/**
|
|
955
|
+
* Fires when the player enters its inline error state. Receives
|
|
956
|
+
* the originating error: a ``RecordingError`` for manifest-fetch
|
|
957
|
+
* failures, a plain ``Error`` for hls.js / native playback or
|
|
958
|
+
* missing-peer-dep cases.
|
|
959
|
+
*/
|
|
960
|
+
onError?: (error: Error) => void;
|
|
896
961
|
}
|
|
897
|
-
declare function ClipPlayer({ clip, getJwt, slackMs, autoPlay, muted, className, style, }: ClipPlayerProps): react_jsx_runtime.JSX.Element;
|
|
962
|
+
declare function ClipPlayer({ clip, getJwt, slackMs, autoPlay, muted, className, style, onError, }: ClipPlayerProps): react_jsx_runtime.JSX.Element;
|
|
898
963
|
|
|
899
964
|
/**
|
|
900
965
|
* State machine for an in-progress clip download.
|
|
@@ -1050,8 +1115,18 @@ interface ClipDownloadButtonProps {
|
|
|
1050
1115
|
style?: React.CSSProperties;
|
|
1051
1116
|
/** Forwarded to the underlying ``<button>``. ORed with the internal "downloading" state. */
|
|
1052
1117
|
disabled?: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* Fires when the download completes with the assembled MP4 ``Blob``.
|
|
1120
|
+
*/
|
|
1121
|
+
onSuccess?: (blob: Blob) => void;
|
|
1122
|
+
/**
|
|
1123
|
+
* Fires when the download fails. Message mirrors the in-button
|
|
1124
|
+
* state — ``"<CODE>: <reason>"`` for ``RecordingError``s, the
|
|
1125
|
+
* plain error message otherwise.
|
|
1126
|
+
*/
|
|
1127
|
+
onError?: (error: Error) => void;
|
|
1053
1128
|
}
|
|
1054
|
-
declare function ClipDownloadButton({ clip, getJwt, filename, children, className, style, disabled, }: ClipDownloadButtonProps): react_jsx_runtime.JSX.Element;
|
|
1129
|
+
declare function ClipDownloadButton({ clip, getJwt, filename, children, className, style, disabled, onSuccess, onError, }: ClipDownloadButtonProps): react_jsx_runtime.JSX.Element;
|
|
1055
1130
|
|
|
1056
1131
|
/**
|
|
1057
1132
|
* Generic hook for accessing selected parts of the Reactor store.
|
package/dist/index.js
CHANGED
|
@@ -153,7 +153,7 @@ var import_zod = require("zod");
|
|
|
153
153
|
// package.json
|
|
154
154
|
var package_default = {
|
|
155
155
|
name: "@reactor-team/js-sdk",
|
|
156
|
-
version: "2.11.
|
|
156
|
+
version: "2.11.1",
|
|
157
157
|
description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
|
|
158
158
|
license: "Apache-2.0",
|
|
159
159
|
repository: {
|
|
@@ -2735,9 +2735,13 @@ var Reactor = class {
|
|
|
2735
2735
|
sendCommand(command, data, scope = "application") {
|
|
2736
2736
|
return __async(this, null, function* () {
|
|
2737
2737
|
var _a;
|
|
2738
|
-
if (
|
|
2739
|
-
|
|
2740
|
-
|
|
2738
|
+
if (this.status !== "ready") {
|
|
2739
|
+
this.createError(
|
|
2740
|
+
"NOT_READY",
|
|
2741
|
+
`Cannot send command "${command}" while status is "${this.status}". Must be "ready".`,
|
|
2742
|
+
"api",
|
|
2743
|
+
true
|
|
2744
|
+
);
|
|
2741
2745
|
return;
|
|
2742
2746
|
}
|
|
2743
2747
|
try {
|
|
@@ -3424,7 +3428,10 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
|
|
|
3424
3428
|
console.error("[ReactorStore] Failed to upload file:", error);
|
|
3425
3429
|
throw error;
|
|
3426
3430
|
}
|
|
3427
|
-
})
|
|
3431
|
+
}),
|
|
3432
|
+
requestClip: (durationSeconds) => get().internal.reactor.requestClip(durationSeconds),
|
|
3433
|
+
requestRecording: () => get().internal.reactor.requestRecording(),
|
|
3434
|
+
downloadClipAsFile: (clip, filename, options) => get().internal.reactor.downloadClipAsFile(clip, filename, options)
|
|
3428
3435
|
});
|
|
3429
3436
|
});
|
|
3430
3437
|
};
|
|
@@ -3552,7 +3559,7 @@ function ReactorProvider(_a) {
|
|
|
3552
3559
|
console.error("[ReactorProvider] Failed to disconnect:", error);
|
|
3553
3560
|
});
|
|
3554
3561
|
};
|
|
3555
|
-
}, [apiUrl, modelName,
|
|
3562
|
+
}, [apiUrl, modelName, local, jwtSource]);
|
|
3556
3563
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactorContext.Provider, { value: storeRef.current, children });
|
|
3557
3564
|
}
|
|
3558
3565
|
function useReactorStore(selector) {
|
|
@@ -3628,7 +3635,7 @@ function ReactorView({
|
|
|
3628
3635
|
className,
|
|
3629
3636
|
style,
|
|
3630
3637
|
videoObjectFit = "contain",
|
|
3631
|
-
muted =
|
|
3638
|
+
muted = audioTrack === void 0
|
|
3632
3639
|
}) {
|
|
3633
3640
|
const { videoMediaTrack, audioMediaTrack } = useReactor((state) => {
|
|
3634
3641
|
var _a, _b;
|
|
@@ -4271,6 +4278,8 @@ var import_react7 = require("react");
|
|
|
4271
4278
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4272
4279
|
function WebcamStream({
|
|
4273
4280
|
track,
|
|
4281
|
+
audio = false,
|
|
4282
|
+
audioTrack,
|
|
4274
4283
|
className,
|
|
4275
4284
|
style,
|
|
4276
4285
|
videoConstraints = {
|
|
@@ -4278,7 +4287,10 @@ function WebcamStream({
|
|
|
4278
4287
|
height: { ideal: 720 }
|
|
4279
4288
|
},
|
|
4280
4289
|
showWebcam = true,
|
|
4281
|
-
videoObjectFit = "contain"
|
|
4290
|
+
videoObjectFit = "contain",
|
|
4291
|
+
onPermissionDenied,
|
|
4292
|
+
onPublished,
|
|
4293
|
+
onError
|
|
4282
4294
|
}) {
|
|
4283
4295
|
const [stream, setStream] = (0, import_react7.useState)(null);
|
|
4284
4296
|
const [isPublishing, setIsPublishing] = (0, import_react7.useState)(false);
|
|
@@ -4290,12 +4302,28 @@ function WebcamStream({
|
|
|
4290
4302
|
reactor: state.internal.reactor
|
|
4291
4303
|
}));
|
|
4292
4304
|
const videoRef = (0, import_react7.useRef)(null);
|
|
4305
|
+
const onPermissionDeniedRef = (0, import_react7.useRef)(onPermissionDenied);
|
|
4306
|
+
const onPublishedRef = (0, import_react7.useRef)(onPublished);
|
|
4307
|
+
const onErrorRef = (0, import_react7.useRef)(onError);
|
|
4308
|
+
(0, import_react7.useEffect)(() => {
|
|
4309
|
+
onPermissionDeniedRef.current = onPermissionDenied;
|
|
4310
|
+
onPublishedRef.current = onPublished;
|
|
4311
|
+
onErrorRef.current = onError;
|
|
4312
|
+
});
|
|
4313
|
+
const audioRequested = audio !== false && audio !== void 0;
|
|
4314
|
+
const audioEnabled = audioRequested && !!audioTrack;
|
|
4315
|
+
if (audioRequested && !audioTrack) {
|
|
4316
|
+
console.warn(
|
|
4317
|
+
"[WebcamStream] `audio` was set but `audioTrack` is missing; capturing video-only."
|
|
4318
|
+
);
|
|
4319
|
+
}
|
|
4293
4320
|
const startWebcam = () => __async(null, null, function* () {
|
|
4321
|
+
var _a, _b;
|
|
4294
4322
|
console.debug("[WebcamPublisher] Starting webcam");
|
|
4295
4323
|
try {
|
|
4296
4324
|
const mediaStream = yield navigator.mediaDevices.getUserMedia({
|
|
4297
4325
|
video: videoConstraints,
|
|
4298
|
-
audio: false
|
|
4326
|
+
audio: audioEnabled ? audio === true ? true : audio : false
|
|
4299
4327
|
});
|
|
4300
4328
|
console.debug("[WebcamPublisher] Webcam started successfully");
|
|
4301
4329
|
setStream(mediaStream);
|
|
@@ -4305,16 +4333,34 @@ function WebcamStream({
|
|
|
4305
4333
|
if (err instanceof DOMException && (err.name === "NotAllowedError" || err.name === "PermissionDeniedError")) {
|
|
4306
4334
|
console.debug("[WebcamPublisher] Camera permission denied");
|
|
4307
4335
|
setPermissionDenied(true);
|
|
4336
|
+
(_a = onPermissionDeniedRef.current) == null ? void 0 : _a.call(onPermissionDeniedRef);
|
|
4337
|
+
} else {
|
|
4338
|
+
(_b = onErrorRef.current) == null ? void 0 : _b.call(
|
|
4339
|
+
onErrorRef,
|
|
4340
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4341
|
+
);
|
|
4308
4342
|
}
|
|
4309
4343
|
}
|
|
4310
4344
|
});
|
|
4311
4345
|
const stopWebcam = () => __async(null, null, function* () {
|
|
4346
|
+
var _a;
|
|
4312
4347
|
console.debug("[WebcamPublisher] Stopping webcam");
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
}
|
|
4317
|
-
|
|
4348
|
+
const unpublishTasks = [unpublish(track)];
|
|
4349
|
+
if (audioEnabled && audioTrack) {
|
|
4350
|
+
unpublishTasks.push(unpublish(audioTrack));
|
|
4351
|
+
}
|
|
4352
|
+
const results = yield Promise.allSettled(unpublishTasks);
|
|
4353
|
+
for (const r of results) {
|
|
4354
|
+
if (r.status === "rejected") {
|
|
4355
|
+
console.error(
|
|
4356
|
+
"[WebcamPublisher] Error unpublishing before stop:",
|
|
4357
|
+
r.reason
|
|
4358
|
+
);
|
|
4359
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4360
|
+
onErrorRef,
|
|
4361
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4362
|
+
);
|
|
4363
|
+
}
|
|
4318
4364
|
}
|
|
4319
4365
|
setIsPublishing(false);
|
|
4320
4366
|
stream == null ? void 0 : stream.getTracks().forEach((t) => {
|
|
@@ -4349,25 +4395,54 @@ function WebcamStream({
|
|
|
4349
4395
|
console.debug(
|
|
4350
4396
|
"[WebcamPublisher] Reactor ready, auto-publishing webcam stream"
|
|
4351
4397
|
);
|
|
4352
|
-
const
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4398
|
+
const videoMediaTrack = stream.getVideoTracks()[0];
|
|
4399
|
+
const audioMediaTrack = audioEnabled && audioTrack ? stream.getAudioTracks()[0] : null;
|
|
4400
|
+
const tasks = [];
|
|
4401
|
+
if (videoMediaTrack) tasks.push(publish(track, videoMediaTrack));
|
|
4402
|
+
if (audioMediaTrack && audioTrack)
|
|
4403
|
+
tasks.push(publish(audioTrack, audioMediaTrack));
|
|
4404
|
+
if (tasks.length === 0) return;
|
|
4405
|
+
Promise.all(tasks).then(() => {
|
|
4406
|
+
var _a;
|
|
4407
|
+
console.debug("[WebcamPublisher] Auto-publish successful");
|
|
4408
|
+
setIsPublishing(true);
|
|
4409
|
+
(_a = onPublishedRef.current) == null ? void 0 : _a.call(onPublishedRef);
|
|
4410
|
+
}).catch((err) => {
|
|
4411
|
+
var _a;
|
|
4412
|
+
console.error("[WebcamPublisher] Auto-publish failed:", err);
|
|
4413
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4414
|
+
onErrorRef,
|
|
4415
|
+
err instanceof Error ? err : new Error(String(err))
|
|
4416
|
+
);
|
|
4417
|
+
});
|
|
4361
4418
|
} else if (status !== "ready" && isPublishing) {
|
|
4362
4419
|
console.debug("[WebcamPublisher] Reactor not ready, auto-unpublishing");
|
|
4363
|
-
unpublish(track)
|
|
4364
|
-
|
|
4420
|
+
const tasks = [unpublish(track)];
|
|
4421
|
+
if (audioEnabled && audioTrack) tasks.push(unpublish(audioTrack));
|
|
4422
|
+
Promise.allSettled(tasks).then((results) => {
|
|
4423
|
+
var _a;
|
|
4424
|
+
for (const r of results) {
|
|
4425
|
+
if (r.status === "rejected") {
|
|
4426
|
+
console.error("[WebcamPublisher] Auto-unpublish failed:", r.reason);
|
|
4427
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(
|
|
4428
|
+
onErrorRef,
|
|
4429
|
+
r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
4430
|
+
);
|
|
4431
|
+
}
|
|
4432
|
+
}
|
|
4365
4433
|
setIsPublishing(false);
|
|
4366
|
-
}).catch((err) => {
|
|
4367
|
-
console.error("[WebcamPublisher] Auto-unpublish failed:", err);
|
|
4368
4434
|
});
|
|
4369
4435
|
}
|
|
4370
|
-
}, [
|
|
4436
|
+
}, [
|
|
4437
|
+
status,
|
|
4438
|
+
stream,
|
|
4439
|
+
isPublishing,
|
|
4440
|
+
publish,
|
|
4441
|
+
unpublish,
|
|
4442
|
+
track,
|
|
4443
|
+
audioEnabled,
|
|
4444
|
+
audioTrack
|
|
4445
|
+
]);
|
|
4371
4446
|
(0, import_react7.useEffect)(() => {
|
|
4372
4447
|
const handleError = (error) => {
|
|
4373
4448
|
console.debug("[WebcamPublisher] Received error event:", error);
|
|
@@ -4470,7 +4545,8 @@ function ClipPlayer({
|
|
|
4470
4545
|
autoPlay = true,
|
|
4471
4546
|
muted = true,
|
|
4472
4547
|
className,
|
|
4473
|
-
style
|
|
4548
|
+
style,
|
|
4549
|
+
onError
|
|
4474
4550
|
}) {
|
|
4475
4551
|
const videoRef = (0, import_react8.useRef)(null);
|
|
4476
4552
|
const [phase, setPhase] = (0, import_react8.useState)({ kind: "waiting" });
|
|
@@ -4478,13 +4554,21 @@ function ClipPlayer({
|
|
|
4478
4554
|
const getJwtRef = (0, import_react8.useRef)(getJwt);
|
|
4479
4555
|
const autoPlayRef = (0, import_react8.useRef)(autoPlay);
|
|
4480
4556
|
const slackMsRef = (0, import_react8.useRef)(slackMs);
|
|
4557
|
+
const onErrorRef = (0, import_react8.useRef)(onError);
|
|
4481
4558
|
const storeRef = (0, import_react8.useRef)(store);
|
|
4482
4559
|
(0, import_react8.useEffect)(() => {
|
|
4483
4560
|
getJwtRef.current = getJwt;
|
|
4484
4561
|
autoPlayRef.current = autoPlay;
|
|
4485
4562
|
slackMsRef.current = slackMs;
|
|
4563
|
+
onErrorRef.current = onError;
|
|
4486
4564
|
storeRef.current = store;
|
|
4487
4565
|
});
|
|
4566
|
+
(0, import_react8.useEffect)(() => {
|
|
4567
|
+
var _a;
|
|
4568
|
+
if (phase.kind === "error") {
|
|
4569
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, phase.error);
|
|
4570
|
+
}
|
|
4571
|
+
}, [phase]);
|
|
4488
4572
|
(0, import_react8.useEffect)(() => {
|
|
4489
4573
|
const video = videoRef.current;
|
|
4490
4574
|
if (!video) return;
|
|
@@ -4492,9 +4576,10 @@ function ClipPlayer({
|
|
|
4492
4576
|
let cancelled = false;
|
|
4493
4577
|
let hlsInstance = null;
|
|
4494
4578
|
let manifestBlobUrl = null;
|
|
4495
|
-
const fail = (
|
|
4579
|
+
const fail = (error) => {
|
|
4496
4580
|
if (cancelled) return;
|
|
4497
|
-
|
|
4581
|
+
const message = error instanceof RecordingError ? `${error.code}: ${error.reason}` : error.message;
|
|
4582
|
+
setPhase({ kind: "error", message, error });
|
|
4498
4583
|
};
|
|
4499
4584
|
const attachPlayer = (manifestUrl) => __async(null, null, function* () {
|
|
4500
4585
|
const canPlayNative = video.canPlayType("application/vnd.apple.mpegurl") !== "";
|
|
@@ -4513,13 +4598,17 @@ function ClipPlayer({
|
|
|
4513
4598
|
HlsCtor = mod.default;
|
|
4514
4599
|
} catch (e) {
|
|
4515
4600
|
fail(
|
|
4516
|
-
|
|
4601
|
+
new Error(
|
|
4602
|
+
"HLS playback unavailable in this browser. Install `hls.js` as a peer dependency, or use Download."
|
|
4603
|
+
)
|
|
4517
4604
|
);
|
|
4518
4605
|
return;
|
|
4519
4606
|
}
|
|
4520
4607
|
if (cancelled) return;
|
|
4521
4608
|
if (!HlsCtor.isSupported()) {
|
|
4522
|
-
fail(
|
|
4609
|
+
fail(
|
|
4610
|
+
new Error("This browser cannot play HLS clips. Use Download instead.")
|
|
4611
|
+
);
|
|
4523
4612
|
return;
|
|
4524
4613
|
}
|
|
4525
4614
|
const hls = new HlsCtor();
|
|
@@ -4537,7 +4626,7 @@ function ClipPlayer({
|
|
|
4537
4626
|
var _a;
|
|
4538
4627
|
if (cancelled) return;
|
|
4539
4628
|
if (data.fatal) {
|
|
4540
|
-
fail(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`);
|
|
4629
|
+
fail(new Error(`Playback error: ${(_a = data.details) != null ? _a : "unknown"}`));
|
|
4541
4630
|
return;
|
|
4542
4631
|
}
|
|
4543
4632
|
console.warn("[Reactor.ClipPlayer] hls.js non-fatal error", data);
|
|
@@ -4568,8 +4657,7 @@ function ClipPlayer({
|
|
|
4568
4657
|
if (err instanceof DOMException && err.name === "AbortError") {
|
|
4569
4658
|
return;
|
|
4570
4659
|
}
|
|
4571
|
-
|
|
4572
|
-
fail(message);
|
|
4660
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
4573
4661
|
}
|
|
4574
4662
|
});
|
|
4575
4663
|
setup();
|
|
@@ -4653,6 +4741,9 @@ function ClipPlayer({
|
|
|
4653
4741
|
);
|
|
4654
4742
|
}
|
|
4655
4743
|
|
|
4744
|
+
// src/react/ClipDownloadButton.tsx
|
|
4745
|
+
var import_react10 = require("react");
|
|
4746
|
+
|
|
4656
4747
|
// src/react/useClipDownload.ts
|
|
4657
4748
|
var import_react9 = require("react");
|
|
4658
4749
|
function useClipDownload(clip, options = {}) {
|
|
@@ -4710,18 +4801,35 @@ function ClipDownloadButton({
|
|
|
4710
4801
|
children,
|
|
4711
4802
|
className,
|
|
4712
4803
|
style,
|
|
4713
|
-
disabled
|
|
4804
|
+
disabled,
|
|
4805
|
+
onSuccess,
|
|
4806
|
+
onError
|
|
4714
4807
|
}) {
|
|
4715
4808
|
const { state, download } = useClipDownload(clip, { filename, getJwt });
|
|
4716
4809
|
const downloading = state.kind === "downloading";
|
|
4717
4810
|
const isDisabled = downloading || !!disabled;
|
|
4811
|
+
const onSuccessRef = (0, import_react10.useRef)(onSuccess);
|
|
4812
|
+
const onErrorRef = (0, import_react10.useRef)(onError);
|
|
4813
|
+
(0, import_react10.useEffect)(() => {
|
|
4814
|
+
onSuccessRef.current = onSuccess;
|
|
4815
|
+
onErrorRef.current = onError;
|
|
4816
|
+
});
|
|
4817
|
+
(0, import_react10.useEffect)(() => {
|
|
4818
|
+
var _a;
|
|
4819
|
+
if (state.kind === "error") {
|
|
4820
|
+
(_a = onErrorRef.current) == null ? void 0 : _a.call(onErrorRef, new Error(state.message));
|
|
4821
|
+
}
|
|
4822
|
+
}, [state]);
|
|
4718
4823
|
const content = typeof children === "function" ? children(state) : children !== void 0 ? children : defaultLabel(state);
|
|
4719
4824
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4720
4825
|
"button",
|
|
4721
4826
|
{
|
|
4722
4827
|
type: "button",
|
|
4723
4828
|
onClick: () => {
|
|
4724
|
-
void download()
|
|
4829
|
+
void download().then((blob) => {
|
|
4830
|
+
var _a;
|
|
4831
|
+
if (blob) (_a = onSuccessRef.current) == null ? void 0 : _a.call(onSuccessRef, blob);
|
|
4832
|
+
});
|
|
4725
4833
|
},
|
|
4726
4834
|
disabled: isDisabled,
|
|
4727
4835
|
title: state.kind === "error" ? state.message : void 0,
|