@reactor-team/js-sdk 2.10.1 → 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 +239 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +239 -62
- 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.
|