User Video Control
Camera control component with device selection and video preview
The UserVideoControl component provides a comprehensive camera control interface that includes camera toggle functionality, device selection, and optional video preview. It integrates with the Pipecat Client SDK to automatically manage camera state and device selection.
import { UserVideoComponent } from "@pipecat-ai/voice-ui-kit";
<UserVideoComponent
onClick={() => console.log("Toggle camera")}
availableCams={[
{deviceId: "cam1", label: "Built-in Camera"},
{deviceId: "cam2", label: "External USB Camera"},
]}
selectedCam={{deviceId: "cam1", label: "Built-in Camera"}}
updateCam={(deviceId) => console.log("Selected:", deviceId)}
isCamEnabled={true}
/>Component Variants
UserVideoControl
The UserVideoControl component is the connected variant that automatically integrates with the Pipecat Client SDK. It must be used within a PipecatClientProvider context.
You must call initDevices on the client before using the component.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl />| Prop | Type | Default |
|---|---|---|
variant? | "primary" | "secondary" | "outline" | "destructive" | "ghost" | "link" | "active" | "inactive" | "outline" |
size? | "sm" | "md" | "lg" | "xl" | "md" |
state? | "default" | "active" | "inactive" | undefined |
buttonProps? | Partial<ButtonProps> | undefined |
classNames? | { container?: string; video?: string; buttongroup?: string; button?: string; dropdownMenuTrigger?: string; dropdownMenuContent?: string; dropdownMenuCheckboxItem?: string; videoOffContainer?: string; videoOffText?: string; activeText?: string; inactiveText?: string; } | undefined |
dropdownButtonProps? | Partial<ButtonProps> | undefined |
deviceDropDownProps? | Partial<DeviceDropDownComponentProps> | undefined |
noDevicePicker? | boolean | false |
noVideo? | boolean | false |
videoProps? | Partial<PipecatClientVideoProps> | undefined |
noVideoText? | string | null | "Video disabled" |
noIcon? | boolean | false |
activeText? | string | undefined |
inactiveText? | string | undefined |
children? | React.ReactNode | undefined |
UserVideoComponent
The UserVideoComponent is the headless variant that accepts all camera state and callbacks as props. This allows you to use it with any framework or state management solution.
import { UserVideoComponent } from "@pipecat-ai/voice-ui-kit";
// Example with mock data
const mockCams = [
{ deviceId: "cam1", label: "Built-in Camera" },
{ deviceId: "cam2", label: "External USB Camera" },
];
function Demo() {
const [isCamEnabled, setIsCamEnabled] = React.useState(false);
const [selectedCam, setSelectedCam] = React.useState(mockCams[0]);
return (
<UserVideoComponent
isCamEnabled={isCamEnabled}
onClick={() => setIsCamEnabled(!isCamEnabled)}
availableCams={mockCams}
selectedCam={selectedCam}
updateCam={(deviceId) => {
const cam = mockCams.find(c => c.deviceId === deviceId);
if (cam) setSelectedCam(cam);
}}
activeText="Camera is on"
inactiveText="Click to start"
/>
);
}
render(<Demo />);| Prop | Type | Default |
|---|---|---|
onClick? | () => void | undefined |
isCamEnabled? | boolean | false |
availableCams? | MediaDeviceInfo[] | undefined |
selectedCam? | OptionalMediaDeviceInfo | undefined |
updateCam? | (deviceId: string) => void | undefined |
variant? | "primary" | "secondary" | "outline" | "destructive" | "ghost" | "link" | "active" | "inactive" | "outline" |
size? | "sm" | "md" | "lg" | "xl" | "md" |
state? | "default" | "active" | "inactive" | undefined |
buttonProps? | Partial<ButtonProps> | undefined |
classNames? | { container?: string; video?: string; buttongroup?: string; button?: string; dropdownMenuTrigger?: string; dropdownMenuContent?: string; dropdownMenuCheckboxItem?: string; videoOffContainer?: string; videoOffText?: string; activeText?: string; inactiveText?: string; } | undefined |
dropdownButtonProps? | Partial<ButtonProps> | undefined |
deviceDropDownProps? | Partial<DeviceDropDownComponentProps> | undefined |
noDevicePicker? | boolean | false |
noVideo? | boolean | false |
videoProps? | Partial<PipecatClientVideoProps> | undefined |
noVideoText? | string | null | "Video disabled" |
noIcon? | boolean | false |
activeText? | string | undefined |
inactiveText? | string | undefined |
children? | React.ReactNode | undefined |
Usage Examples
Basic Usage
The UserVideoControl component automatically manages camera state and device selection.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl />Custom Text Labels
You can customize the text displayed when the camera is active or inactive.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl
activeText="Camera is on"
inactiveText="Click to start camera"
/>Different Variants
The component supports different visual variants to match your design system.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<div className="flex gap-4">
<UserVideoControl variant="primary" />
<UserVideoControl variant="outline" />
<UserVideoControl variant="ghost" />
</div>Different Sizes
You can use different sizes for the video control.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<div className="flex gap-4 items-center">
<UserVideoControl size="sm" />
<UserVideoControl size="md" />
<UserVideoControl size="lg" />
<UserVideoControl size="xl" />
</div>Without Device Picker
Hide the device selection dropdown for a simpler interface.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl noDevicePicker />Without Video Preview
Hide the video element for a minimal camera button.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl noVideo />Disabled Video State
Show a disabled state when video functionality is not available.
import { UserVideoComponent } from "@pipecat-ai/voice-ui-kit";
function Demo() {
return (
<UserVideoComponent
noVideo={true}
noVideoText="Camera not available"
isCamEnabled={false}
onClick={() => {}}
/>
);
}
render(<Demo />);Custom Video Configuration
Customize the video element appearance and behavior.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl
videoProps={{
className: "border-2 border-primary",
style: { borderRadius: "8px" }
}}
/>Custom Device Dropdown Configuration
Customize the device dropdown behavior and appearance.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl
deviceDropDownProps={{
menuLabel: "Select Camera",
placeholder: "Choose a camera...",
}}
/>Custom Styling
Apply custom CSS classes to different parts of the component.
import { UserVideoControl } from "@pipecat-ai/voice-ui-kit";
<UserVideoControl
classNames={{
container: "border-2 border-primary",
button: "bg-primary text-white",
videoOffContainer: "bg-muted/50",
activeText: "font-bold text-green-600",
inactiveText: "text-gray-500",
}}
/>Features
- Camera Toggle: Click to enable/disable camera input
- Device Selection: Built-in dropdown for selecting different camera devices
- Video Preview: Optional real-time video preview display
- Loading States: Automatic loading indicators during connection setup
- Accessible: Includes proper ARIA labels and keyboard navigation
- Responsive: Adapts to different screen sizes and container widths
- Theme Support: Integrates with the Voice UI Kit theming system
- Flexible: Available in both connected and headless variants
Integration
The connected UserVideoControl component uses several hooks from the Pipecat Client React SDK:
usePipecatClientMediaDevicesfor device managementusePipecatClientTransportStatefor connection statePipecatClientCamTogglefor camera control
This means it must be used within a PipecatClientProvider context to function properly.
The component will automatically:
- Fetch available camera devices
- Display the currently selected camera
- Handle device selection changes
- Manage camera enable/disable state
- Show appropriate loading states during connection setup
- Update the Pipecat Client's camera configuration
Visual States
The component displays different visual states based on the camera status:
- Inactive: Shows camera off icon with inactive styling and placeholder text
- Active: Shows camera on icon with active styling and video preview
- Loading: Shows loading spinner during connection setup
- Disabled: Shows disabled state when video is not available
Device Management
The component includes a dropdown menu for device selection that:
- Lists all available camera devices
- Shows the currently selected device
- Allows switching between devices
- Can be hidden with the
noDevicePickerprop - Integrates with the
DeviceDropDowncomponent
Video Preview
The component can display a live video preview when the camera is enabled:
- Shows the local camera feed using
PipecatClientVideo - Automatically adjusts container size based on camera state
- Can be hidden with the
noVideoprop - Supports custom styling through
videoProps - Displays placeholder text when camera is off or disabled