mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-24 23:05:49 +00:00
Merge pull request #1003 from SomSamantray/fix/mic-audio-killed-on-cancel-699
Fix: mic audio killed after cancelling a native-capture recording (#699)
This commit is contained in:
@@ -397,6 +397,7 @@ 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") {
|
||||
@@ -404,6 +405,7 @@ function cancelRecording(
|
||||
}
|
||||
|
||||
if (isNativeRecording) {
|
||||
void stopMicFallbackRecorder?.();
|
||||
return { cancelled: true, wasNative: true };
|
||||
}
|
||||
|
||||
@@ -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"])] };
|
||||
|
||||
@@ -2394,7 +2394,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
|
||||
setRecording(false);
|
||||
window.electronAPI?.setRecordingState(false);
|
||||
void (async () => {
|
||||
await discardActiveNativeCapture();
|
||||
await Promise.allSettled([discardActiveNativeCapture(), stopMicFallbackRecorder()]);
|
||||
})();
|
||||
return;
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user