Skip to content

Commit

Permalink
cockpit-actions: Allow stopping the recording of all available streams
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Feb 21, 2024
1 parent 7090f17 commit 2dd123b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/libs/joystick/protocols/cockpit-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

/**
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion src/stores/video.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useStorage } from '@vueuse/core'
import { useStorage, useThrottleFn } from '@vueuse/core'
import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js'
import { format } from 'date-fns'
import { saveAs } from 'file-saver'
Expand Down Expand Up @@ -374,10 +374,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,
Expand Down

0 comments on commit 2dd123b

Please sign in to comment.