Skip to content

Commit 417fcdd

Browse files
video-recovery: Reuse DB from store in components
1 parent cb17f67 commit 417fcdd

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

src/components/mini-widgets/MiniVideoRecorder.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { useMouseInElement, useTimestamp } from '@vueuse/core'
5757
import { format, intervalToDuration } from 'date-fns'
5858
import { saveAs } from 'file-saver'
5959
import fixWebmDuration from 'fix-webm-duration'
60-
import localforage from 'localforage'
6160
import { storeToRefs } from 'pinia'
6261
import Swal, { type SweetAlertResult } from 'sweetalert2'
6362
import { computed, onBeforeMount, onBeforeUnmount, ref, toRefs, watch } from 'vue'
@@ -103,14 +102,6 @@ const isRecording = computed(() => {
103102
return mediaRecorder.value !== undefined && mediaRecorder.value.state === 'recording'
104103
})
105104
106-
const cockpitVideoDB = localforage.createInstance({
107-
driver: localforage.INDEXEDDB,
108-
name: 'CockpitVideoDB',
109-
storeName: 'cockpit-video-db',
110-
version: 1.0,
111-
description: 'Local backups of Cockpit video recordings to be retrieved in case of failure.',
112-
})
113-
114105
onBeforeMount(async () => {
115106
// Set initial widget options if they don't exist
116107
if (Object.keys(miniWidget.value.options).length === 0) {
@@ -205,7 +196,7 @@ const startRecording = async (): Promise<SweetAlertResult | void> => {
205196
let chunks: Blob[] = []
206197
mediaRecorder.value.ondataavailable = async (e) => {
207198
chunks.push(e.data)
208-
await cockpitVideoDB.setItem(fileName, chunks)
199+
await videoStore.videoRecoveryDB.setItem(fileName, chunks)
209200
}
210201
211202
mediaRecorder.value.onstop = () => {
@@ -216,7 +207,7 @@ const startRecording = async (): Promise<SweetAlertResult | void> => {
216207
fixWebmDuration(blob, Date.now() - timeRecordingStart.value.getTime()).then((fixedBlob) => {
217208
saveAs(fixedBlob, `${fileName}.webm`)
218209
saveAs(logBlob, `${fileName}.ass`)
219-
cockpitVideoDB.removeItem(fileName)
210+
videoStore.videoRecoveryDB.removeItem(fileName)
220211
})
221212
chunks = []
222213
mediaRecorder.value = undefined

src/stores/video.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ export const useVideoStore = defineStore('video', () => {
7676
}
7777
}, 5000)
7878

79-
return { availableIceIps, allowedIceIps }
79+
return { availableIceIps, allowedIceIps, videoRecoveryDB }
8080
})

0 commit comments

Comments
 (0)