Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
Merge remote-tracking branch 'origin/main' into main
Siddharth0f123283b3d9
diff --cc src/components/launch/LaunchWindow.tsxindex ac4ed9cd7,ef3c3b3a2..e9a3fa282--- a/src/components/launch/LaunchWindow.tsx+++ b/src/components/launch/LaunchWindow.tsx@@@ -8,8 -8,7 +8,9 @@@ importMdMic,MdMicOff,MdMonitor,+ MdRestartAlt,+ MdVideocam,+ MdVideocamOff,MdVideoFile,MdVolumeOff,MdVolumeUp,@@@ -32,9 -31,8 +33,10 @@@ const ICON_CONFIG =volumeOff: { icon: MdVolumeOff, size: ICON_SIZE },micOn: { icon: MdMic, size: ICON_SIZE },micOff: { icon: MdMicOff, size: ICON_SIZE },+ webcamOn: { icon: MdVideocam, size: ICON_SIZE },+ webcamOff: { icon: MdVideocamOff, size: ICON_SIZE },stop: { icon: FaRegStopCircle, size: ICON_SIZE },+ restart: { icon: MdRestartAlt, size: ICON_SIZE },record: { icon: BsRecordCircle, size: ICON_SIZE },videoFile: { icon: MdVideoFile, size: ICON_SIZE },folder: { icon: FaFolderOpen, size: ICON_SIZE },diff --cc src/components/video-editor/VideoEditor.tsxindex a35098542,685c46807..829cde5b3--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@@ -1273,202 -1222,193 +1273,194 @@@ export default function VideoEditor()<div className="flex-1 p-5 gap-4 flex min-h-0 relative">{/* Left Column - Video & Timeline */}- <div className="flex-[7] flex flex-col gap-3 min-w-0 h-full">- <PanelGroup direction="vertical" className="gap-3">- {/* Top section: video preview and controls */}- <Panel defaultSize={70} minSize={40}>- <div className="w-full h-full flex flex-col items-center justify-center bg-black/40 rounded-2xl border border-white/5 shadow-2xl overflow-hidden">- {/* Video preview */}- <div- className="w-full flex justify-center items-center"- style={{ flex: "1 1 auto", margin: "6px 0 0" }}- >- <div- className="relative"- style={{- width: "auto",- height: "100%",- aspectRatio:- aspectRatio === "native"- ? getNativeAspectRatioValue(- videoPlaybackRef.current?.video?.videoWidth || 1920,- videoPlaybackRef.current?.video?.videoHeight || 1080,- cropRegion,- )- : getAspectRatioValue(aspectRatio),- maxWidth: "100%",- margin: "0 auto",- boxSizing: "border-box",- }}- >- <VideoPlayback- key={`${videoPath || "no-video"}:${webcamVideoPath || "no-webcam"}`}- aspectRatio={aspectRatio}- ref={videoPlaybackRef}- videoPath={videoPath || ""}- webcamVideoPath={webcamVideoPath || undefined}- onDurationChange={setDuration}- onTimeUpdate={setCurrentTime}- currentTime={currentTime}- onPlayStateChange={setIsPlaying}- onError={setError}- wallpaper={wallpaper}- zoomRegions={zoomRegions}- selectedZoomId={selectedZoomId}- onSelectZoom={handleSelectZoom}- onZoomFocusChange={handleZoomFocusChange}- onZoomFocusDragEnd={commitState}- isPlaying={isPlaying}- showShadow={shadowIntensity > 0}- shadowIntensity={shadowIntensity}- showBlur={showBlur}- motionBlurAmount={motionBlurAmount}- borderRadius={borderRadius}- padding={padding}- cropRegion={cropRegion}- trimRegions={trimRegions}- speedRegions={speedRegions}- annotationRegions={annotationRegions}- selectedAnnotationId={selectedAnnotationId}- onSelectAnnotation={handleSelectAnnotation}- onAnnotationPositionChange={handleAnnotationPositionChange}- onAnnotationSizeChange={handleAnnotationSizeChange}- />+ <PanelGroup direction="horizontal" className="gap-3">+ <Panel>+ <PanelGroup direction="vertical" className="gap-3">+ {/* Top section: video preview and controls */}+ <Panel defaultSize={70} maxSize={70} minSize={40}>+ <div className="w-full h-full flex flex-col items-center justify-center bg-black/40 rounded-2xl border border-white/5 shadow-2xl overflow-hidden">+ {/* Video preview */}+ <div className="w-full flex justify-center items-center flex-auto mt-1.5">+ <div+ className="relative flex justify-center items-center w-auto h-full max-w-full box-border"+ style={{+ aspectRatio:+ aspectRatio === "native"+ ? getNativeAspectRatioValue(+ videoPlaybackRef.current?.video?.videoWidth || 1920,+ videoPlaybackRef.current?.video?.videoHeight || 1080,+ cropRegion,+ )+ : getAspectRatioValue(aspectRatio),+ }}+ >+ <VideoPlayback- key={videoPath || "no-video"}++ key={`${videoPath || "no-video"}:${webcamVideoPath || "no-webcam"}`}+ aspectRatio={aspectRatio}+ ref={videoPlaybackRef}+ videoPath={videoPath || ""}++ webcamVideoPath={webcamVideoPath || undefined}+ onDurationChange={setDuration}+ onTimeUpdate={setCurrentTime}+ currentTime={currentTime}+ onPlayStateChange={setIsPlaying}+ onError={setError}+ wallpaper={wallpaper}+ zoomRegions={zoomRegions}+ selectedZoomId={selectedZoomId}+ onSelectZoom={handleSelectZoom}+ onZoomFocusChange={handleZoomFocusChange}+ onZoomFocusDragEnd={commitState}+ isPlaying={isPlaying}+ showShadow={shadowIntensity > 0}+ shadowIntensity={shadowIntensity}+ showBlur={showBlur}+ motionBlurAmount={motionBlurAmount}+ borderRadius={borderRadius}+ padding={padding}+ cropRegion={cropRegion}+ trimRegions={trimRegions}+ speedRegions={speedRegions}+ annotationRegions={annotationRegions}+ selectedAnnotationId={selectedAnnotationId}+ onSelectAnnotation={handleSelectAnnotation}+ onAnnotationPositionChange={handleAnnotationPositionChange}+ onAnnotationSizeChange={handleAnnotationSizeChange}+ />+ </div></div>- </div>- {/* Playback controls */}- <div- className="w-full flex justify-center items-center"- style={{- height: "48px",- flexShrink: 0,- padding: "6px 12px",- margin: "6px 0 6px 0",- }}- >- <div style={{ width: "100%", maxWidth: "700px" }}>- <PlaybackControls- isPlaying={isPlaying}- currentTime={currentTime}- duration={duration}- onTogglePlayPause={togglePlayPause}- onSeek={handleSeek}- />+ {/* Playback controls */}+ <div className="w-full flex justify-center items-center h-12 flex-shrink-0 px-3 py-1.5 my-1.5">+ <div className="w-full max-w-[700px]">+ <PlaybackControls+ isPlaying={isPlaying}+ currentTime={currentTime}+ duration={duration}+ onTogglePlayPause={togglePlayPause}+ onSeek={handleSeek}+ />+ </div></div></div>- </div>- </Panel>-- <PanelResizeHandle className="h-3 bg-[#09090b]/80 hover:bg-[#09090b] transition-colors rounded-full mx-4 flex items-center justify-center">- <div className="w-8 h-1 bg-white/20 rounded-full"></div>- </PanelResizeHandle>-- {/* Timeline section */}- <Panel defaultSize={30} minSize={20}>- <div className="h-full bg-[#09090b] rounded-2xl border border-white/5 shadow-lg overflow-hidden flex flex-col">- <TimelineEditor- videoDuration={duration}- currentTime={currentTime}- onSeek={handleSeek}- cursorTelemetry={cursorTelemetry}- zoomRegions={zoomRegions}- onZoomAdded={handleZoomAdded}- onZoomSuggested={handleZoomSuggested}- onZoomSpanChange={handleZoomSpanChange}- onZoomDelete={handleZoomDelete}- selectedZoomId={selectedZoomId}- onSelectZoom={handleSelectZoom}- trimRegions={trimRegions}- onTrimAdded={handleTrimAdded}- onTrimSpanChange={handleTrimSpanChange}- onTrimDelete={handleTrimDelete}- selectedTrimId={selectedTrimId}- onSelectTrim={handleSelectTrim}- speedRegions={speedRegions}- onSpeedAdded={handleSpeedAdded}- onSpeedSpanChange={handleSpeedSpanChange}- onSpeedDelete={handleSpeedDelete}- selectedSpeedId={selectedSpeedId}- onSelectSpeed={handleSelectSpeed}- annotationRegions={annotationRegions}- onAnnotationAdded={handleAnnotationAdded}- onAnnotationSpanChange={handleAnnotationSpanChange}- onAnnotationDelete={handleAnnotationDelete}- selectedAnnotationId={selectedAnnotationId}- onSelectAnnotation={handleSelectAnnotation}- aspectRatio={aspectRatio}- onAspectRatioChange={(ar) => pushState({ aspectRatio: ar })}- />- </div>- </Panel>- </PanelGroup>- </div>-- {/* Right section: settings panel */}- <SettingsPanel- selected={wallpaper}- onWallpaperChange={(w) => pushState({ wallpaper: w })}- selectedZoomDepth={- selectedZoomId ? zoomRegions.find((z) => z.id === selectedZoomId)?.depth : null- }- onZoomDepthChange={(depth) => selectedZoomId && handleZoomDepthChange(depth)}- selectedZoomId={selectedZoomId}- onZoomDelete={handleZoomDelete}- selectedTrimId={selectedTrimId}- onTrimDelete={handleTrimDelete}- shadowIntensity={shadowIntensity}- onShadowChange={(v) => updateState({ shadowIntensity: v })}- onShadowCommit={commitState}- showBlur={showBlur}- onBlurChange={(v) => pushState({ showBlur: v })}- motionBlurAmount={motionBlurAmount}- onMotionBlurChange={(v) => updateState({ motionBlurAmount: v })}- onMotionBlurCommit={commitState}- borderRadius={borderRadius}- onBorderRadiusChange={(v) => updateState({ borderRadius: v })}- onBorderRadiusCommit={commitState}- padding={padding}- onPaddingChange={(v) => updateState({ padding: v })}- onPaddingCommit={commitState}- cropRegion={cropRegion}- onCropChange={(r) => pushState({ cropRegion: r })}- aspectRatio={aspectRatio}- videoElement={videoPlaybackRef.current?.video || null}- exportQuality={exportQuality}- onExportQualityChange={setExportQuality}- exportFormat={exportFormat}- onExportFormatChange={setExportFormat}- gifFrameRate={gifFrameRate}- onGifFrameRateChange={setGifFrameRate}- gifLoop={gifLoop}- onGifLoopChange={setGifLoop}- gifSizePreset={gifSizePreset}- onGifSizePresetChange={setGifSizePreset}- gifOutputDimensions={calculateOutputDimensions(- videoPlaybackRef.current?.video?.videoWidth || 1920,- videoPlaybackRef.current?.video?.videoHeight || 1080,- gifSizePreset,- GIF_SIZE_PRESETS,- )}- onExport={handleOpenExportDialog}- selectedAnnotationId={selectedAnnotationId}- annotationRegions={annotationRegions}- onAnnotationContentChange={handleAnnotationContentChange}- onAnnotationTypeChange={handleAnnotationTypeChange}- onAnnotationStyleChange={handleAnnotationStyleChange}- onAnnotationFigureDataChange={handleAnnotationFigureDataChange}- onAnnotationDelete={handleAnnotationDelete}- onSaveProject={handleSaveProject}- onLoadProject={handleLoadProject}- selectedSpeedId={selectedSpeedId}- selectedSpeedValue={- selectedSpeedId- ? (speedRegions.find((r) => r.id === selectedSpeedId)?.speed ?? null)- : null- }- onSpeedChange={handleSpeedChange}- onSpeedDelete={handleSpeedDelete}- />+ </Panel>++ <PanelResizeHandle className="bg-[#09090b]/80 hover:bg-[#09090b] transition-colors rounded-full flex items-center justify-center">+ <div className="w-8 h-1 bg-white/20 rounded-full"></div>+ </PanelResizeHandle>++ {/* Timeline section */}+ <Panel defaultSize={30} maxSize={60} minSize={30}>+ <div className="h-full bg-[#09090b] rounded-2xl border border-white/5 shadow-lg overflow-hidden flex flex-col">+ <TimelineEditor+ videoDuration={duration}+ currentTime={currentTime}+ onSeek={handleSeek}+ cursorTelemetry={cursorTelemetry}+ zoomRegions={zoomRegions}+ onZoomAdded={handleZoomAdded}+ onZoomSuggested={handleZoomSuggested}+ onZoomSpanChange={handleZoomSpanChange}+ onZoomDelete={handleZoomDelete}+ selectedZoomId={selectedZoomId}+ onSelectZoom={handleSelectZoom}+ trimRegions={trimRegions}+ onTrimAdded={handleTrimAdded}+ onTrimSpanChange={handleTrimSpanChange}+ onTrimDelete={handleTrimDelete}+ selectedTrimId={selectedTrimId}+ onSelectTrim={handleSelectTrim}+ speedRegions={speedRegions}+ onSpeedAdded={handleSpeedAdded}+ onSpeedSpanChange={handleSpeedSpanChange}+ onSpeedDelete={handleSpeedDelete}+ selectedSpeedId={selectedSpeedId}+ onSelectSpeed={handleSelectSpeed}+ annotationRegions={annotationRegions}+ onAnnotationAdded={handleAnnotationAdded}+ onAnnotationSpanChange={handleAnnotationSpanChange}+ onAnnotationDelete={handleAnnotationDelete}+ selectedAnnotationId={selectedAnnotationId}+ onSelectAnnotation={handleSelectAnnotation}+ aspectRatio={aspectRatio}+ onAspectRatioChange={(ar) => pushState({ aspectRatio: ar })}+ />+ </div>+ </Panel>+ </PanelGroup>+ </Panel>++ <PanelResizeHandle className="h-full bg-[#09090b]/80 hover:bg-[#09090b] transition-colors rounded-full flex items-center justify-center">+ <div className="w-1 h-8 bg-white/20 rounded-full"></div>+ </PanelResizeHandle>++ {/* Right section: settings panel */}+ <Panel defaultSize={30} minSize={25} maxSize={50}>+ <SettingsPanel+ selected={wallpaper}+ onWallpaperChange={(w) => pushState({ wallpaper: w })}+ selectedZoomDepth={+ selectedZoomId ? zoomRegions.find((z) => z.id === selectedZoomId)?.depth : null+ }+ onZoomDepthChange={(depth) => selectedZoomId && handleZoomDepthChange(depth)}+ selectedZoomId={selectedZoomId}+ onZoomDelete={handleZoomDelete}+ selectedTrimId={selectedTrimId}+ onTrimDelete={handleTrimDelete}+ shadowIntensity={shadowIntensity}+ onShadowChange={(v) => updateState({ shadowIntensity: v })}+ onShadowCommit={commitState}+ showBlur={showBlur}+ onBlurChange={(v) => pushState({ showBlur: v })}+ motionBlurAmount={motionBlurAmount}+ onMotionBlurChange={(v) => updateState({ motionBlurAmount: v })}+ onMotionBlurCommit={commitState}+ borderRadius={borderRadius}+ onBorderRadiusChange={(v) => updateState({ borderRadius: v })}+ onBorderRadiusCommit={commitState}+ padding={padding}+ onPaddingChange={(v) => updateState({ padding: v })}+ onPaddingCommit={commitState}+ cropRegion={cropRegion}+ onCropChange={(r) => pushState({ cropRegion: r })}+ aspectRatio={aspectRatio}+ videoElement={videoPlaybackRef.current?.video || null}+ exportQuality={exportQuality}+ onExportQualityChange={setExportQuality}+ exportFormat={exportFormat}+ onExportFormatChange={setExportFormat}+ gifFrameRate={gifFrameRate}+ onGifFrameRateChange={setGifFrameRate}+ gifLoop={gifLoop}+ onGifLoopChange={setGifLoop}+ gifSizePreset={gifSizePreset}+ onGifSizePresetChange={setGifSizePreset}+ gifOutputDimensions={calculateOutputDimensions(+ videoPlaybackRef.current?.video?.videoWidth || 1920,+ videoPlaybackRef.current?.video?.videoHeight || 1080,+ gifSizePreset,+ GIF_SIZE_PRESETS,+ )}+ onExport={handleOpenExportDialog}+ selectedAnnotationId={selectedAnnotationId}+ annotationRegions={annotationRegions}+ onAnnotationContentChange={handleAnnotationContentChange}+ onAnnotationTypeChange={handleAnnotationTypeChange}+ onAnnotationStyleChange={handleAnnotationStyleChange}+ onAnnotationFigureDataChange={handleAnnotationFigureDataChange}+ onAnnotationDelete={handleAnnotationDelete}+ onSaveProject={handleSaveProject}+ onLoadProject={handleLoadProject}+ selectedSpeedId={selectedSpeedId}+ selectedSpeedValue={+ selectedSpeedId+ ? (speedRegions.find((r) => r.id === selectedSpeedId)?.speed ?? null)+ : null+ }+ onSpeedChange={handleSpeedChange}+ onSpeedDelete={handleSpeedDelete}+ />+ </Panel>+ </PanelGroup></div><Toaster theme="dark" className="pointer-events-auto" />diff --cc src/hooks/useScreenRecorder.tsindex 19893f10c,cce4df2a5..707b94f7d--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@@ -88,12 -59,11 +89,14 @@@ export function useScreenRecorder(): Usconst stream = useRef<MediaStream | null>(null);const screenStream = useRef<MediaStream | null>(null);const microphoneStream = useRef<MediaStream | null>(null);+ const webcamStream = useRef<MediaStream | null>(null);const mixingContext = useRef<AudioContext | null>(null);- const chunks = useRef<Blob[]>([]);const startTime = useRef<number>(0);- const discardRecording = useRef(false);+ const recordingId = useRef<number>(0);+ const finalizingRecordingId = useRef<number | null>(null);+ const allowAutoFinalize = useRef(false);++ const discardRecordingId = useRef<number | null>(null);+ const restarting = useRef(false);const selectMimeType = () => {const preferred = [@@@ -123,174 -93,29 +126,180 @@@return Math.round(BITRATE_BASE * highFrameRateBoost);};- const stopRecording = useRef(() => {- if (mediaRecorder.current?.state === "recording") {- if (stream.current) {- stream.current.getTracks().forEach((track) => track.stop());- }- if (screenStream.current) {- screenStream.current.getTracks().forEach((track) => track.stop());- screenStream.current = null;+ const teardownMedia = useCallback(() => {+ if (stream.current) {+ stream.current.getTracks().forEach((track) => track.stop());+ stream.current = null;+ }+ if (screenStream.current) {+ screenStream.current.getTracks().forEach((track) => track.stop());+ screenStream.current = null;+ }+ if (microphoneStream.current) {+ microphoneStream.current.getTracks().forEach((track) => track.stop());+ microphoneStream.current = null;+ }+ if (webcamStream.current) {+ webcamStream.current.getTracks().forEach((track) => track.stop());+ webcamStream.current = null;+ }+ if (mixingContext.current) {+ mixingContext.current.close().catch(() => {+ // Ignore close errors during recorder teardown.+ });+ mixingContext.current = null;+ }+ }, []);++ const setWebcamEnabled = useCallback(async (enabled: boolean) => {+ if (!enabled) {+ setWebcamEnabledState(false);+ return true;+ }++ const accessResult = await window.electronAPI.requestCameraAccess();+ if (!accessResult.success) {+ toast.error("Failed to request camera access.");+ return false;+ }++ if (!accessResult.granted) {+ toast.error("Camera access is blocked. Enable it in system settings to use the webcam.");+ return false;+ }++ try {+ const probeStream = await navigator.mediaDevices.getUserMedia({+ audio: false,+ video: true,+ });+ probeStream.getTracks().forEach((track) => track.stop());+ setWebcamEnabledState(true);+ return true;+ } catch (error) {+ console.warn("Failed to preflight webcam access:", error);+ toast.error("Camera access denied. Webcam overlay will stay disabled.");+ return false;+ }+ }, []);++ const finalizeRecording = useCallback(+ (+ activeScreenRecorder: RecorderHandle,+ activeWebcamRecorder: RecorderHandle | null,+ duration: number,+ activeRecordingId: number,+ ) => {+ if (finalizingRecordingId.current === activeRecordingId) {+ return;}- if (microphoneStream.current) {- microphoneStream.current.getTracks().forEach((track) => track.stop());- microphoneStream.current = null;+ finalizingRecordingId.current = activeRecordingId;++ if (screenRecorder.current === activeScreenRecorder) {+ screenRecorder.current = null;}- if (mixingContext.current) {- mixingContext.current.close().catch(() => {- // Ignore close errors during recorder teardown.- });- mixingContext.current = null;+ if (activeWebcamRecorder && webcamRecorder.current === activeWebcamRecorder) {+ webcamRecorder.current = null;}- mediaRecorder.current.stop();- setRecording(false);+ teardownMedia();+ setRecording(false);window.electronAPI?.setRecordingState(false);++ void (async () => {+ try {+ const screenBlob = await activeScreenRecorder.recordedBlobPromise;++ if (discardRecordingId.current === activeRecordingId) {++ return;++ }+ if (screenBlob.size === 0) {+ return;+ }++ const fixedScreenBlob = await fixWebmDuration(screenBlob, duration);+ let fixedWebcamBlob: Blob | null = null;+ if (activeWebcamRecorder) {+ const webcamBlob = await activeWebcamRecorder.recordedBlobPromise.catch(() => null);+ if (webcamBlob && webcamBlob.size > 0) {+ fixedWebcamBlob = await fixWebmDuration(webcamBlob, duration);+ }+ }++ const screenFileName = `${RECORDING_FILE_PREFIX}${activeRecordingId}${VIDEO_FILE_EXTENSION}`;+ const webcamFileName = `${RECORDING_FILE_PREFIX}${activeRecordingId}${WEBCAM_FILE_SUFFIX}${VIDEO_FILE_EXTENSION}`;+ const result = await window.electronAPI.storeRecordedSession({+ screen: {+ videoData: await fixedScreenBlob.arrayBuffer(),+ fileName: screenFileName,+ },+ webcam: fixedWebcamBlob+ ? {+ videoData: await fixedWebcamBlob.arrayBuffer(),+ fileName: webcamFileName,+ }+ : undefined,+ createdAt: activeRecordingId,+ });++ if (!result.success) {+ console.error("Failed to store recording session:", result.message);+ return;+ }++ if (result.session) {+ await window.electronAPI.setCurrentRecordingSession(result.session);+ } else if (result.path) {+ await window.electronAPI.setCurrentVideoPath(result.path);+ }++ await window.electronAPI.switchToEditor();+ } catch (error) {+ console.error("Error saving recording:", error);+ } finally {+ if (finalizingRecordingId.current === activeRecordingId) {+ finalizingRecordingId.current = null;+ }++ if (discardRecordingId.current === activeRecordingId) {++ discardRecordingId.current = null;++ }+ }+ })();+ },+ [teardownMedia],+ );++ const stopRecording = useRef(() => {+ const activeScreenRecorder = screenRecorder.current;+ if (!activeScreenRecorder) {+ return;+ }++ const activeWebcamRecorder = webcamRecorder.current;+ const duration = Date.now() - startTime.current;+ const activeRecordingId = recordingId.current;++ finalizeRecording(+ activeScreenRecorder,+ activeWebcamRecorder ?? null,+ duration,+ activeRecordingId,+ );++ if (activeScreenRecorder.recorder.state === "recording") {+ try {+ activeScreenRecorder.recorder.stop();+ } catch {+ // Recorder may already be stopping.+ }+ }+ if (activeWebcamRecorder) {+ if (activeWebcamRecorder.recorder.state === "recording") {+ try {+ activeWebcamRecorder.recorder.stop();+ } catch {+ // Recorder may already be stopping.+ }+ }}});@@@ -305,27 -130,30 +314,29 @@@return () => {if (cleanup) cleanup();+ allowAutoFinalize.current = false;++ restarting.current = false;++ discardRecordingId.current = null;- if (mediaRecorder.current?.state === "recording") {- mediaRecorder.current.stop();- }- if (stream.current) {- stream.current.getTracks().forEach((track) => track.stop());- stream.current = null;- }- if (screenStream.current) {- screenStream.current.getTracks().forEach((track) => track.stop());- screenStream.current = null;- }- if (microphoneStream.current) {- microphoneStream.current.getTracks().forEach((track) => track.stop());- microphoneStream.current = null;+ if (screenRecorder.current?.recorder.state === "recording") {+ try {+ screenRecorder.current.recorder.stop();+ } catch {+ // Ignore recorder teardown errors during cleanup.+ }}- if (mixingContext.current) {- mixingContext.current.close().catch(() => {- // Ignore close errors during cleanup.- });- mixingContext.current = null;+ if (webcamRecorder.current?.recorder.state === "recording") {+ try {+ webcamRecorder.current.recorder.stop();+ } catch {+ // Ignore recorder teardown errors during cleanup.+ }}+ screenRecorder.current = null;+ webcamRecorder.current = null;+ teardownMedia();};- }, []);+ }, [teardownMedia]);const startRecording = async () => {try {@@@ -546,6 -378,29 +557,44 @@@recording ? stopRecording.current() : startRecording();};+ const restartRecording = async () => {+ if (restarting.current) return;+- const recorder = mediaRecorder.current;- if (!recorder || recorder.state !== "recording") return;++ const activeScreenRecorder = screenRecorder.current;++ if (!activeScreenRecorder || activeScreenRecorder.recorder.state !== "recording") return;++++ const activeWebcamRecorder = webcamRecorder.current;++ const activeRecordingId = recordingId.current;++ restarting.current = true;- discardRecording.current = true;++ discardRecordingId.current = activeRecordingId;++++ const stopPromises = [++ new Promise<void>((resolve) => {++ activeScreenRecorder.recorder.addEventListener("stop", () => resolve(), { once: true });++ }),++ ];+- const waitForStop = new Promise<void>((resolve) => {- recorder.addEventListener("stop", () => resolve(), { once: true });- });++ if (activeWebcamRecorder?.recorder.state === "recording") {++ stopPromises.push(++ new Promise<void>((resolve) => {++ activeWebcamRecorder.recorder.addEventListener("stop", () => resolve(), {++ once: true,++ });++ }),++ );++ }++ stopRecording.current();- await waitForStop;++ await Promise.all(stopPromises);++ try {+ await startRecording();+ } finally {+ restarting.current = false;+ }+ };+return {recording,toggleRecording,