mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-25 15:25:44 +00:00
fix(recording): stop browser recorder before cleanup
This commit is contained in:
@@ -132,6 +132,11 @@ function stopRecording(
|
||||
if (webcamRecorder && webcamRecorder.state !== "inactive") {
|
||||
webcamRecorder.stop();
|
||||
}
|
||||
try {
|
||||
recorder.requestData();
|
||||
} catch {
|
||||
// Stopping should continue even if the browser refuses an explicit flush.
|
||||
}
|
||||
recorder.stop();
|
||||
return { stopped: true, wasNative: false };
|
||||
}
|
||||
@@ -328,6 +333,31 @@ describe("useScreenRecorder state machine", () => {
|
||||
expect(callOrder).toEqual(["resume", "stop"]);
|
||||
});
|
||||
|
||||
it("flushes the current recorder data before stopping", () => {
|
||||
const callOrder: string[] = [];
|
||||
recorder.requestData.mockImplementation(() => {
|
||||
callOrder.push("requestData");
|
||||
});
|
||||
recorder.stop.mockImplementation(() => {
|
||||
callOrder.push("stop");
|
||||
});
|
||||
|
||||
stopRecording(recorder, false);
|
||||
|
||||
expect(callOrder).toEqual(["requestData", "stop"]);
|
||||
});
|
||||
|
||||
it("still stops when the explicit data flush fails", () => {
|
||||
recorder.requestData.mockImplementation(() => {
|
||||
throw new Error("flush failed");
|
||||
});
|
||||
|
||||
const result = stopRecording(recorder, false);
|
||||
|
||||
expect(result.stopped).toBe(true);
|
||||
expect(recorder.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("still stops when resume throws from paused state", () => {
|
||||
recorder.pause();
|
||||
recorder.resume.mockImplementation(() => {
|
||||
|
||||
@@ -1092,7 +1092,11 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
|
||||
}
|
||||
}
|
||||
pendingWebcamPathPromise.current = stopWebcamRecorder();
|
||||
cleanupCapturedMedia();
|
||||
try {
|
||||
recorder.requestData();
|
||||
} catch (error) {
|
||||
console.warn("Failed to flush recorder before stopping:", error);
|
||||
}
|
||||
recorder.stop();
|
||||
setRecording(false);
|
||||
setFinalizing(true);
|
||||
|
||||
Reference in New Issue
Block a user