Skip to content

Commit

Permalink
Save (and update) a backup of the video recording everytime new video…
Browse files Browse the repository at this point in the history
… data is available

With this, there are no more chances of the user losing a video recording because of power loss or cockpit termination.
  • Loading branch information
rafaellehmkuhl committed Nov 21, 2023
1 parent 0904bc8 commit 396daaf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/mini-widgets/MiniVideoRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { useMouseInElement, useTimestamp } from '@vueuse/core'
import { format, intervalToDuration } from 'date-fns'
import { saveAs } from 'file-saver'
import fixWebmDuration from 'fix-webm-duration'
import localforage from 'localforage'
import { storeToRefs } from 'pinia'
import Swal, { type SweetAlertResult } from 'sweetalert2'
import { computed, onBeforeMount, onBeforeUnmount, ref, toRefs, watch } from 'vue'
Expand Down Expand Up @@ -101,6 +102,14 @@ const isRecording = computed(() => {
return mediaRecorder.value !== undefined && mediaRecorder.value.state === 'recording'
})
const cockpitVideoDB = localforage.createInstance({
driver: localforage.INDEXEDDB,
name: 'CockpitVideoDB',
storeName: 'cockpit-video-db',
version: 1.0,
description: 'Local backups of Cockpit video recordings to be retrieved in case of failure.',
})
onBeforeMount(async () => {
// Set initial widget options if they don't exist
if (Object.keys(miniWidget.value.options).length === 0) {
Expand Down Expand Up @@ -187,7 +196,10 @@ const startRecording = async (): Promise<SweetAlertResult | void> => {
mediaRecorder.value = new MediaRecorder(mediaStream.value)
mediaRecorder.value.start(1000)
let chunks: Blob[] = []
mediaRecorder.value.ondataavailable = (e) => chunks.push(e.data)
mediaRecorder.value.ondataavailable = async (e) => {
chunks.push(e.data)
await cockpitVideoDB.setItem(fileName, chunks)
}
mediaRecorder.value.onstop = () => {
const blob = new Blob(chunks, { type: 'video/webm' })
Expand Down

0 comments on commit 396daaf

Please sign in to comment.