Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actions to start and stop video recording (for all streams simultaneously) #737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libs/joystick/protocols/cockpit-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum CockpitActionsFunction {
mavlink_arm = 'mavlink_arm',
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 @@ -40,6 +42,8 @@ export const availableCockpitActions: { [key in CockpitActionsFunction]: Cockpit
[CockpitActionsFunction.mavlink_arm]: new CockpitAction(CockpitActionsFunction.mavlink_arm, 'Mavlink arm'),
[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
52 changes: 51 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 All @@ -11,14 +11,20 @@ import adapter from 'webrtc-adapter'

import { WebRTCManager } from '@/composables/webRTC'
import { getIpsInformationFromVehicle } from '@/libs/blueos'
import { availableCockpitActions, registerActionCallback } from '@/libs/joystick/protocols/cockpit-actions'
import { datalogger } from '@/libs/sensors-logging'
import { isEqual } from '@/libs/utils'
import { useMainVehicleStore } from '@/stores/mainVehicle'
import { useMissionStore } from '@/stores/mission'
import { Alert, AlertLevel } from '@/types/alert'
import type { StreamData } from '@/types/video'

import { useAlertStore } from './alert'

export const useVideoStore = defineStore('video', () => {
const missionStore = useMissionStore()
const alertStore = useAlertStore()

const { globalAddress, rtcConfiguration, webRTCSignallingURI } = useMainVehicleStore()
console.debug('[WebRTC] Using webrtc-adapter for', adapter.browserDetails)

Expand Down Expand Up @@ -350,6 +356,50 @@ export const useVideoStore = defineStore('video', () => {
}
}, 5000)

// Video recording actions
const startRecordingAllStreams = (): void => {
const streamsThatStarted: string[] = []

namesAvailableStreams.value.forEach((streamName) => {
if (!isRecording(streamName)) {
startRecording(streamName)
streamsThatStarted.push(streamName)
}
})

if (streamsThatStarted.isEmpty()) {
alertStore.pushAlert(new Alert(AlertLevel.Error, 'No streams available to be recorded.'))
return
}
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,
allowedIceIps,
Expand Down
Loading