Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/hooks/useScreenRecorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ function cancelRecording(
chunks: { current: Blob[] },
webcamRecorder?: ReturnType<typeof createMockMediaRecorder> | null,
webcamChunks?: { current: Blob[] },
stopMicFallbackRecorder?: () => Promise<Blob | null>,
) {
if (webcamChunks) webcamChunks.current = [];
if (webcamRecorder && webcamRecorder.state !== "inactive") {
webcamRecorder.stop();
}

if (isNativeRecording) {
void stopMicFallbackRecorder?.();
return { cancelled: true, wasNative: true };
}

Expand Down Expand Up @@ -740,6 +742,23 @@ describe("useScreenRecorder state machine", () => {
expect(recorder.stop).not.toHaveBeenCalled();
});

it("stops the mic fallback recorder when cancelling native recording", () => {
const chunks = { current: [] as Blob[] };
const stopMicFallbackRecorder = vi.fn(() => Promise.resolve(null));

const result = cancelRecording(
recorder,
true,
chunks,
null,
undefined,
stopMicFallbackRecorder,
);

expect(result.wasNative).toBe(true);
expect(stopMicFallbackRecorder).toHaveBeenCalled();
});

it("handles cancel when recorder is already inactive", () => {
const inactiveRecorder = createMockMediaRecorder("inactive");
const chunks = { current: [new Blob(["data"])] };
Expand Down
10 changes: 8 additions & 2 deletions src/hooks/useScreenRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
setRecording(false);
window.electronAPI?.setRecordingState(false);
void (async () => {
await discardActiveNativeCapture();
await Promise.allSettled([discardActiveNativeCapture(), stopMicFallbackRecorder()]);
})();
return;
}
Expand All @@ -2408,7 +2408,13 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
setRecording(false);
window.electronAPI?.setRecordingState(false);
}
}, [cleanupCapturedMedia, discardActiveNativeCapture, markRecordingResumed, recording]);
}, [
cleanupCapturedMedia,
discardActiveNativeCapture,
markRecordingResumed,
recording,
stopMicFallbackRecorder,
]);

const toggleRecording = async () => {
if (starting || countdownActive || finalizing) {
Expand Down