feat: implement async restart recording functionality to ensure proper session handling

This commit is contained in:
Prayas Lashkari
2026-03-17 01:57:55 -04:00
parent 0727b61de7
commit 119c3acb18
+14 -2
View File
@@ -377,11 +377,23 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
recording ? stopRecording.current() : startRecording();
};
const restartRecording = () => {
const restartRecording = async () => {
if (!recording) return;
discardRecording.current = true;
// Wait for the old recorder's onstop to fully complete before starting
// a new session, so the discard logic doesn't race with new chunks.
const waitForStop = new Promise<void>((resolve) => {
if (mediaRecorder.current) {
mediaRecorder.current.addEventListener("stop", () => resolve(), { once: true });
} else {
resolve();
}
});
stopRecording.current();
startRecording();
await waitForStop;
await startRecording();
};
return {