forked from bluerobotics/cockpit
/
ConfigurationVideoView.vue
296 lines (269 loc) · 10.9 KB
/
ConfigurationVideoView.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<template>
<BaseConfigurationView>
<template #title>{{ isVideoLibraryOnly ? 'Video Storage' : 'Video configuration' }}</template>
<template #content>
<div
v-if="!isVideoLibraryOnly"
class="flex flex-col items-center px-5 py-3 m-5 font-medium text-center border rounded-md text-grey-darken-1 bg-grey-lighten-5 w-[40%]"
>
<p class="font-bold">
This is the video configuration page. Here you can configure the behavior of your video streams and download
or discard saved videos and subtitle logs.
</p>
<br />
<p>
First of all, it's important that you select the IP (or IPs) that should be allowed to route video streams.
Those will usually be the ones for your wired connections. This configuration allows Cockpit to block other
available IPs, like those from WiFi and Hotspot connections, preventing lag and stuttering in your video
streams.
</p>
</div>
<div v-if="!isVideoLibraryOnly" class="flex w-[30rem] flex-wrap">
<v-combobox
v-model="allowedIceIps"
multiple
:items="availableIceIps"
label="Allowed WebRTC remote IP Addresses"
class="w-full my-3 uri-input"
variant="outlined"
chips
clearable
hint="IP Addresses of the Vehicle allowed to be used for the WebRTC ICE Routing. Usually, the IP of the tether/cabled interface. Blank means any route. E.g: 192.168.2.2"
/>
</div>
<div
v-if="nUnprocVideos > 0"
class="flex flex-col items-center px-5 py-3 m-5 font-medium text-center border rounded-md text-grey-darken-1 bg-grey-lighten-5 w-[40%]"
>
<span class="m-2 text-lg font-bold">Unprocessed videos detected</span>
<span class="text-sm text-slate-500/90">
You have {{ nUnprocVideos }} {{ nUnprocVideos === 1 ? 'video that was' : 'videos that were' }} not processed.
</span>
<div class="flex justify-center m-6 align-center">
<Button class="mx-2 w-fit" size="large" :disabled="nUnprocVideos === 0" @click="processUnprocessedVideos()">
Process
</Button>
<Button class="mx-2 w-fit" :disabled="nUnprocVideos === 0" @click="discardFailedUnprocessedVideos()">
Discard
</Button>
</div>
</div>
<div v-if="areThereVideosProcessing" class="max-w-[50%] bg-slate-100 rounded-md p-6 border mb-8">
<div class="flex justify-center w-full mb-4 text-2xl font-semibold text-center align-center text-slate-500">
<span>Processing videos</span>
<span class="ml-2 mdi mdi-loading animate-spin" />
</div>
<p class="text-center text-slate-400">
There are videos being processed in background. Please wait until they are finished to download or discard.
</p>
</div>
<div
v-if="availableVideosAndLogs?.isEmpty()"
:class="{ 'mb-4': isVideoLibraryOnly, 'mb-0': !isVideoLibraryOnly }"
class="max-w-[50%] bg-slate-100 rounded-md p-6 border"
>
<p class="mb-4 text-2xl font-semibold text-center text-slate-500">No videos available.</p>
<p class="text-center text-slate-400">
Use the MiniVideoRecorder widget to record some videos and them come back here to download or discard those.
</p>
</div>
<!-- @vue-ignore -->
<v-data-table
v-else
v-model="selectedFilesNames"
:headers="headers"
:items="availableVideosAndLogs"
item-value="filename"
density="compact"
show-select
loading-text="Loading... Please wait"
:loading="availableVideosAndLogs === undefined"
class="max-w-[90%] bg-slate-100/30 rounded-lg p-3 border"
:class="temporaryDbSize === 0 ? 'mb-10' : 'mb-0'"
>
<template #item.size="{ value }">
{{ formatBytes(value) }}
</template>
<template #item.actions="{ item }">
<span
v-if="selectedFilesNames.isEmpty()"
class="mx-1 transition-all cursor-pointer hover:text-slate-500/50 mdi mdi-trash-can"
@click="discardAndUpdateDB([item.filename])"
/>
<span
v-if="selectedFilesNames.isEmpty()"
class="mx-1 transition-all cursor-pointer hover:text-slate-500/50 mdi mdi-download"
@click="downloadAndUpdateDB([item.filename])"
/>
</template>
<template #footer.prepend>
<Transition name="horizontalFade">
<div v-if="!selectedFilesNames.isEmpty()" class="flex items-center justify-end w-full mr-4">
<span
class="mx-2 text-2xl transition-all cursor-pointer hover:text-slate-500/50 mdi mdi-trash-can"
@click="discardAndUpdateDB(selectedFilesNames)"
/>
<span
class="mx-2 text-2xl transition-all cursor-pointer hover:text-slate-500/50 mdi mdi-download"
@click="downloadAndUpdateDB(selectedFilesNames)"
/>
</div>
</Transition>
</template>
</v-data-table>
<div class="flex flex-row">
<div
v-if="temporaryDbSize > 0"
v-tooltip.bottom="'Remove video files used during the recording. This will not affect already saved videos.'"
class="flex flex-col items-center justify-center px-4 py-2 mx-4 mb-6 mt-8 transition-all rounded-md cursor-pointer bg-slate-600 text-slate-50 hover:bg-slate-500/80"
@click="clearTemporaryVideoFiles()"
>
<span class="text-md font-medium">Clear temporary video storage</span>
<span class="text-sm text-slate-300/90">Current size: {{ formatBytes(temporaryDbSize) }}</span>
</div>
<div
v-if="temporaryDbSize > 0"
class="flex flex-col items-center justify-center px-4 py-2 mx-4 mb-6 mt-8 transition-all rounded-md cursor-pointer bg-slate-600 text-slate-50 hover:bg-slate-500/80"
@click="videoStore.downloadTempVideoDB()"
>
<span class="text-md font-medium">Download temporary video chunks</span>
</div>
</div>
</template>
</BaseConfigurationView>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia'
import Swal from 'sweetalert2'
import { computed, onMounted, ref, watch, watchEffect } from 'vue'
import type { VDataTable } from 'vuetify/components'
import Button from '@/components/Button.vue'
import { formatBytes } from '@/libs/utils'
import { useVideoStore } from '@/stores/video'
import BaseConfigurationView from './BaseConfigurationView.vue'
const videoStore = useVideoStore()
const { allowedIceIps, availableIceIps } = storeToRefs(videoStore)
// Define dialog as video library only
const props = defineProps<{
/**
*
*/
asVideoLibrary?: boolean
}>()
const isVideoLibraryOnly = ref(props.asVideoLibrary)
watchEffect(() => {
isVideoLibraryOnly.value = props.asVideoLibrary ?? false
})
// List available videos and telemetry logs to be downloaded
/* eslint-disable jsdoc/require-jsdoc */
interface VideoStorageFile {
filename: string
size: number
}
/* eslint-enable jsdoc/require-jsdoc */
const availableVideosAndLogs = ref<VideoStorageFile[] | undefined>()
const temporaryDbSize = ref(0)
const selectedFilesNames = ref<string[]>([])
onMounted(async () => {
await fetchVideoAndLogsData()
await fetchTemporaryDbSize()
})
// Fetch available videos and telemetry logs from the storage
const fetchVideoAndLogsData = async (): Promise<void> => {
availableVideosAndLogs.value = undefined
const availableData: VideoStorageFile[] = []
await videoStore.videoStoringDB.iterate((_, fileName) => {
availableData.push({
filename: fileName,
size: 0,
})
})
for (const file of availableData) {
file.size = (await videoStore.videoStorageFileSize(file.filename)) ?? 0
}
availableVideosAndLogs.value = availableData
}
// Fetch temporary video data from the storage
const fetchTemporaryDbSize = async (): Promise<void> => {
const size = await videoStore.temporaryVideoDBSize()
temporaryDbSize.value = size
}
const discardAndUpdateDB = async (filenames: string[]): Promise<void> => {
await videoStore.discardFilesFromVideoDB(filenames)
await fetchVideoAndLogsData()
selectedFilesNames.value = []
}
const downloadAndUpdateDB = async (filenames: string[]): Promise<void> => {
await videoStore.downloadFilesFromVideoDB(filenames)
await fetchVideoAndLogsData()
selectedFilesNames.value = []
}
const clearTemporaryVideoFiles = async (): Promise<void> => {
const videosBeingRecorded = videoStore.keysAllUnprocessedVideos.length > videoStore.keysFailedUnprocessedVideos.length
if (videosBeingRecorded) {
Swal.fire({
icon: 'error',
title: 'Video(s) being recorded',
text: 'You must stop all ongoing video recordings before clearing the temporary storage.',
})
return
}
if (videoStore.keysAllUnprocessedVideos.length > 0) {
Swal.fire({
icon: 'error',
title: 'Unprocessed videos detected',
text: 'You must process or discard all unprocessed videos before clearing the temporary storage.',
})
return
}
await videoStore.clearTemporaryVideoDB()
await fetchTemporaryDbSize()
}
const processUnprocessedVideos = async (): Promise<void> => {
try {
await videoStore.processUnprocessedVideos()
Swal.fire({
icon: 'success',
title: 'Videos processed',
text: 'All unprocessed videos were successfully processed and are now available for download.',
showConfirmButton: false,
timer: 5000,
})
} catch (error) {
Swal.fire({
icon: 'error',
title: 'Error processing videos',
text: `Some of the videos could not be processed. ${error}`,
})
} finally {
await fetchVideoAndLogsData()
selectedFilesNames.value = []
}
}
const discardFailedUnprocessedVideos = async (): Promise<void> => {
await videoStore.discardUnprocessedVideos()
await fetchVideoAndLogsData()
selectedFilesNames.value = []
Swal.fire({
icon: 'success',
title: 'Videos discarded',
text: 'All unprocessed videos were successfully discarded.',
showConfirmButton: false,
timer: 5000,
})
}
// After the videos are processed, fetch the data again to update the video table
const { areThereVideosProcessing } = storeToRefs(videoStore)
watch(areThereVideosProcessing, async () => {
// Sleep for a second before fetching to allow for the sensors logging update
await new Promise((resolve) => setTimeout(resolve, 1000))
await fetchVideoAndLogsData()
})
const nUnprocVideos = computed(() => videoStore.keysFailedUnprocessedVideos.length)
type ReadonlyHeaders = VDataTable['$props']['headers']
const headers: ReadonlyHeaders = [
{ title: 'Name', align: 'start', key: 'filename', sortable: true },
{ title: 'Size', align: 'center', key: 'size', sortable: true },
{ title: 'Actions', align: 'center', key: 'actions', sortable: false },
]
</script>