diff --git a/src/libs/joystick/protocols/cockpit-actions.ts b/src/libs/joystick/protocols/cockpit-actions.ts index 8355ec11a..a9a836fe0 100644 --- a/src/libs/joystick/protocols/cockpit-actions.ts +++ b/src/libs/joystick/protocols/cockpit-actions.ts @@ -16,6 +16,7 @@ export enum CockpitActionsFunction { mavlink_disarm = 'mavlink_disarm', toggle_bottom_bar = 'toggle_bottom_bar', start_recording_all_streams = 'start_recording_all_streams', + stop_recording_all_streams = 'stop_recording_all_streams', } /** @@ -42,6 +43,7 @@ export const availableCockpitActions: { [key in CockpitActionsFunction]: Cockpit [CockpitActionsFunction.mavlink_disarm]: new CockpitAction(CockpitActionsFunction.mavlink_disarm, 'Mavlink disarm'), [CockpitActionsFunction.toggle_bottom_bar]: new CockpitAction(CockpitActionsFunction.toggle_bottom_bar, 'Toggle bottom bar'), [CockpitActionsFunction.start_recording_all_streams]: new CockpitAction(CockpitActionsFunction.start_recording_all_streams, 'Start recording all streams'), + [CockpitActionsFunction.stop_recording_all_streams]: new CockpitAction(CockpitActionsFunction.stop_recording_all_streams, 'Stop recording all streams'), } export type CockpitActionCallback = () => void diff --git a/src/stores/video.ts b/src/stores/video.ts index 8f74beffd..9bcdf685a 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -1,4 +1,4 @@ -import { useStorage } from '@vueuse/core' +import { useStorage, useThrottleFn } from '@vueuse/core' import { format } from 'date-fns' import { saveAs } from 'file-saver' import fixWebmDuration from 'fix-webm-duration' @@ -353,10 +353,31 @@ export const useVideoStore = defineStore('video', () => { alertStore.pushAlert(new Alert(AlertLevel.Success, `Started recording streams: ${streamsThatStarted.join(', ')}.`)) } + const stopRecordingAllStreams = (): void => { + const streamsThatStopped: string[] = [] + + namesAvailableStreams.value.forEach((streamName) => { + if (isRecording(streamName)) { + stopRecording(streamName) + streamsThatStopped.push(streamName) + } + }) + + if (streamsThatStopped.isEmpty()) { + alertStore.pushAlert(new Alert(AlertLevel.Error, 'No streams were being recorded.')) + return + } + alertStore.pushAlert(new Alert(AlertLevel.Success, `Stopped recording streams: ${streamsThatStopped.join(', ')}.`)) + } + registerActionCallback( availableCockpitActions.start_recording_all_streams, useThrottleFn(startRecordingAllStreams, 3000) ) + registerActionCallback( + availableCockpitActions.stop_recording_all_streams, + useThrottleFn(stopRecordingAllStreams, 3000) + ) return { availableIceIps,