Skip to content

Commit

Permalink
video: Fix syntax around chunks sorting on recording stop
Browse files Browse the repository at this point in the history
The sorting happens in-place, and the previous syntax could let to think we are creating a copy of the original array, which is not the case.
  • Loading branch information
rafaellehmkuhl committed Mar 1, 2024
1 parent 9771bbd commit 2b9483b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/stores/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ export const useVideoStore = defineStore('video', () => {
}

// Make sure the chunks are sorted in the order they were created, not the order they are stored
const sortedChunks = chunks
.sort((a, b) => {
const splitA = a.name.split('_')
const splitB = b.name.split('_')
return Number(splitA[splitA.length - 1]) - Number(splitB[splitB.length - 1])
})
.map((chunk) => chunk.blob)
const mergedVideoBlob = (sortedChunks as Blob[]).reduce((a, b) => new Blob([a, b], { type: 'video/webm' }))
chunks.sort((a, b) => {
const splitA = a.name.split('_')
const splitB = b.name.split('_')
return Number(splitA[splitA.length - 1]) - Number(splitB[splitB.length - 1])
})

const chunkBlobs = chunks.map((chunk) => chunk.blob)

const mergedVideoBlob = chunkBlobs.reduce((a, b) => new Blob([a, b], { type: 'video/webm' }))
const durFixedBlob = await fixWebmDuration(mergedVideoBlob, Date.now() - streamData.timeRecordingStart!.getTime())
videoStoringDB.setItem(`${fileName}.webm`, durFixedBlob)

Expand Down

0 comments on commit 2b9483b

Please sign in to comment.