From c575b27826644477198700ce9c0d88ce7de6e2ab Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 21 Feb 2024 18:03:20 -0300 Subject: [PATCH] video: Stop the recording if we get a clash in the video chunks --- src/stores/video.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stores/video.ts b/src/stores/video.ts index 99cc5c879..e02026bb2 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -171,7 +171,14 @@ export const useVideoStore = defineStore('video', () => { activeStreams.value[streamName]!.mediaRecorder!.start(1000) let chunksCount = 0 activeStreams.value[streamName]!.mediaRecorder!.ondataavailable = async (e) => { - await tempVideoChunksDB.setItem(`${recordingHash}_${chunksCount}`, e.data) + // Check first if this item is already in the database. If so, stop the recording and return. + const chunkName = `${recordingHash}_${chunksCount}` + const chunk = await tempVideoChunksDB.getItem(chunkName) + if (chunk) { + stopRecording(streamName) + return + } + await tempVideoChunksDB.setItem(chunkName, e.data) chunksCount++ }