Skip to content

Commit

Permalink
web-rtc: Add possibility of enabling/disabling custom configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl authored and ArturoManzoli committed Jun 18, 2024
1 parent 04341ce commit e0e5cbb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
data: defaultWebRTCSignallingURI.value,
enabled: false,
} as CustomParameter<string>)
const customWebRTCConfiguration = useStorage('cockpit-rtc-config', defaultRtcConfiguration)
const customWebRTCConfiguration = useStorage('cockpit-custom-rtc-config', {
data: defaultRtcConfiguration,
enabled: false,
})

const lastHeartbeat = ref<Date>()
const firmwareType = ref<MavAutopilot>()
Expand Down Expand Up @@ -133,7 +136,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
}
}
console.log('Using WebRTC configuration from storage.')
return customWebRTCConfiguration.value
return customWebRTCConfiguration.value.enabled ? customWebRTCConfiguration.value.data : defaultRtcConfiguration
})

/**
Expand Down
16 changes: 12 additions & 4 deletions src/views/ConfigurationGeneralView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,21 @@
/>
</v-form>
<span>Current address: {{ mainVehicleStore.webRTCSignallingURI.toString() }} </span><br />
<div class="my-4 ml-2">
<div class="my-4">
<span class="text-lg">Custom RTC configuration:</span>
<div class="mx-2">
<div class="mt-2">
<div class="flex">
<v-checkbox
v-model="mainVehicleStore.customWebRTCConfiguration.enabled"
v-tooltip.bottom="'Enable custom'"
class="mx-1 mb-5 pa-0"
rounded="lg"
hide-details
/>
<v-textarea
id="rtcConfigTextInput"
v-model="customRtcConfiguration"
:disabled="!mainVehicleStore.customWebRTCConfiguration.enabled"
variant="underlined"
label="Custom WebRTC Configuration"
clearable
Expand Down Expand Up @@ -348,11 +356,11 @@ const isValidSocketConnectionURI = (value: string): boolean | string => {
return true
}
const customRtcConfiguration = ref<string>(JSON.stringify(mainVehicleStore.customWebRTCConfiguration, null, 4))
const customRtcConfiguration = ref<string>(JSON.stringify(mainVehicleStore.customWebRTCConfiguration.data, null, 4))
const updateWebRtcConfiguration = (): void => {
try {
const newConfig = JSON.parse(customRtcConfiguration.value)
mainVehicleStore.customWebRTCConfiguration = newConfig
mainVehicleStore.customWebRTCConfiguration.data = newConfig
location.reload()
} catch (error) {
alert(`Could not update WebRTC configuration. ${error}.`)
Expand Down

0 comments on commit e0e5cbb

Please sign in to comment.