React Components
ReactorProvider
Context provider that manages Reactor state for React applications. Must wrap all other Reactor components and hooks.
<ReactorProvider {...props}>
{children}
</ReactorProvider>
Props
Prop | Type | Required | Description |
---|
modelName | string | Yes | The Reactor model to connect to |
insecureApiKey | string | Yes | Your Reactor API key |
queueing | boolean | No | When true, users are queued (FIFO) if no machines are available. When false, users are disconnected immediately if no machines are available (default: false) |
autoConnect | boolean | No | Automatically connect on mount (default: false) |
children | ReactNode | Yes | Child components |
Example
<ReactorProvider
modelName="longlive"
insecureApiKey={process.env.REACTOR_API_KEY}
>
<App />
</ReactorProvider>
ReactorView
Displays the video stream from the Reactor model. Automatically manages the video element lifecycle.
<ReactorView {...props} />
Props
Prop | Type | Required | Description |
---|
className | string | No | CSS class name for styling |
style | CSSProperties | No | Inline styles |
Example
<ReactorView
className="w-full h-96 rounded-lg"
style={{ maxWidth: '800px' }}
/>
WebcamStream
Captures and automatically publishes webcam video to the Reactor machine. This component handles camera permissions, stream lifecycle, and automatic publishing/unpublishing based on Reactor connection status.
<WebcamStream {...props} />
Props
Prop | Type | Required | Description |
---|
className | string | No | CSS class name for styling |
style | CSSProperties | No | Inline styles |
videoConstraints | MediaTrackConstraints | No | MediaStream video constraints (default: 1280x720) |
showWebcam | boolean | No | Whether to display the webcam preview (default: true) |
videoObjectFit | "contain" | "cover" | ... | No | CSS object-fit property for video element (default: “contain”) |
Behavior
- Auto-start: Automatically requests camera access on mount
- Auto-publish: Publishes video stream when Reactor status becomes
"ready"
- Auto-unpublish: Stops publishing when Reactor disconnects
- Error handling: Shows permission denied message if camera access is blocked
- Cleanup: Properly stops camera and unpublishes on unmount
Example
import { WebcamStream } from "@reactor-team/js-sdk";
function VideoInput() {
return (
<WebcamStream
className="w-full aspect-video rounded-lg"
videoConstraints={{
width: { ideal: 1920 },
height: { ideal: 1080 }
}}
videoObjectFit="cover"
/>
);
}
The WebcamStream component is particularly useful for video-to-video (V2V) models like StreamDiffusionV2. It handles all the complexity of camera management and video publishing automatically.
Complete Example
Here’s how to use both components together:
import { ReactorProvider, ReactorView } from "@reactor-team/js-sdk";
export default function App() {
return (
<ReactorProvider
modelName="matrix-2"
insecureApiKey={process.env.REACTOR_API_KEY!}
autoConnect={true}
>
<div className="container">
<h1>My Reactor App</h1>
<ReactorView className="video-player" />
</div>
</ReactorProvider>
);
}