From 370678ee7092e2d60b64b02a5c2d2857ff921209 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 21 Nov 2023 17:19:24 -0300 Subject: [PATCH] Save (and update) a backup of the video recording everytime new video data is available With this, there are no more chances of the user losing a video recording because of power loss or cockpit termination. --- src/components/mini-widgets/MiniVideoRecorder.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/mini-widgets/MiniVideoRecorder.vue b/src/components/mini-widgets/MiniVideoRecorder.vue index 4fdfceb17..f06607f33 100644 --- a/src/components/mini-widgets/MiniVideoRecorder.vue +++ b/src/components/mini-widgets/MiniVideoRecorder.vue @@ -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' @@ -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) { @@ -187,7 +196,10 @@ const startRecording = async (): Promise => { 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' })