Skip to content

Commit

Permalink
webrtc: Allow setting configuration from query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl authored and ArturoManzoli committed Jun 18, 2024
1 parent 6daab22 commit 40f5672
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
data: defaultWebRTCSignallingURI.value,
enabled: false,
} as CustomParameter<string>)
const rtcConfiguration = useStorage('cockpit-rtc-config', defaultRtcConfiguration)
const customWebRTCConfiguration = useStorage('cockpit-rtc-config', defaultRtcConfiguration)

const lastHeartbeat = ref<Date>()
const firmwareType = ref<MavAutopilot>()
Expand Down Expand Up @@ -125,6 +125,21 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
return lastHeartbeat.value !== undefined && new Date(timeNow.value).getTime() - lastHeartbeat.value.getTime() < 5000
})

const rtcConfiguration = computed(() => {
const queryWebRtcConfiguration = new URLSearchParams(window.location.search).get('webRTCConfiguration')
if (queryWebRtcConfiguration) {
console.log('Using WebRTC configuration from query parameter')
console.log(queryWebRtcConfiguration)
try {
return JSON.parse(queryWebRtcConfiguration)
} catch (error) {
console.error('Failed to parse WebRTC configuration from query parameter.', error)
}
}
console.log('Using WebRTC configuration from storage.')
return customWebRTCConfiguration.value
})

/**
* Arm the vehicle.
* Awaits user confirmation before arming the vehicle. Resolves when arming is successful or rejects if the action is cancelled.
Expand Down Expand Up @@ -509,6 +524,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
icon,
configurationPages,
rtcConfiguration,
customWebRTCConfiguration,
genericVariables,
availableGenericVariables,
registerUsageOfGenericVariable,
Expand Down
4 changes: 2 additions & 2 deletions src/views/ConfigurationGeneralView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ const isValidSocketConnectionURI = (value: string): boolean | string => {
return true
}
const customRtcConfiguration = ref<string>(JSON.stringify(mainVehicleStore.rtcConfiguration, null, 4))
const customRtcConfiguration = ref<string>(JSON.stringify(mainVehicleStore.customWebRTCConfiguration, null, 4))
const updateWebRtcConfiguration = (): void => {
try {
const newConfig = JSON.parse(customRtcConfiguration.value)
mainVehicleStore.rtcConfiguration = newConfig
mainVehicleStore.customWebRTCConfiguration = newConfig
location.reload()
} catch (error) {
alert(`Could not update WebRTC configuration. ${error}.`)
Expand Down

0 comments on commit 40f5672

Please sign in to comment.