import React from "react"; import { VideoOff } from "lucide-react"; import { useCameraStream } from "@/hooks/useCameraStream"; import { CameraRotation, cameraPreviewGeometry, cameraRotationError } from "@/lib/cameraConfig"; interface Props { deviceId: string; paused?: boolean; rotation?: CameraRotation; width?: number; height?: number; className?: string; fallback?: string; /** Saved reference frame, drawn over the live video as a translucent ghost. */ ghostSrc?: string; ghostOpacity?: number; } /** * Browser streams contain raw frames, so only browser previews use CSS rotation. * The box keeps the recorded capture size's shape even when the browser stream * has another size, so the preview frames the scene the way recording will. */ export default function BrowserCameraPreview({ deviceId, paused = false, rotation = 0, width = 640, height = 480, className = "", fallback, ghostSrc, ghostOpacity = 0.5, }: Props) { const rotationError = cameraRotationError({ rotation }); const { videoRef, hasError } = useCameraStream(deviceId, paused || !!rotationError, { width, height }); const geometry = rotationError ? { aspectRatio: `${width} / ${height}`, videoStyle: {} } : cameraPreviewGeometry(width, height, rotation); const showVideo = !rotationError && !paused && deviceId && !hasError; return (