diff --git a/src/pages/Capture.tsx b/src/pages/Capture.tsx index 377a38f..35f128f 100644 --- a/src/pages/Capture.tsx +++ b/src/pages/Capture.tsx @@ -219,6 +219,15 @@ export default function Capture() { }, []); const selectCamera = useCallback(async (type: 'front' | 'back') => { + // If switching cameras while stream is active, stop current stream first + if (cameraType && cameraType !== type) { + console.log(`Switching camera from ${cameraType} to ${type}`); + stopAllMediaStreams(); + setPlaybackId(null); + setStreamId(null); + setIsPlaying(false); + } + setCameraType(type); const randomPrompt = type === 'front' ? FRONT_PROMPTS[Math.floor(Math.random() * FRONT_PROMPTS.length)] @@ -227,7 +236,7 @@ export default function Capture() { // Pass the initial prompt to initializeStream await initializeStream(type, randomPrompt); - }, [initializeStream]); + }, [initializeStream, cameraType, stopAllMediaStreams]); // Auto-start camera on desktop (non-mobile devices) useEffect(() => { @@ -886,6 +895,22 @@ export default function Capture() { )} + + {/* Camera Switch Button - only show on mobile devices with multiple cameras */} + {hasMultipleCameras() && ( +