Skip to content

Commit

Permalink
video: Warn user if they selected an IP that is not available in the …
Browse files Browse the repository at this point in the history
…ICE candidates
  • Loading branch information
rafaellehmkuhl committed Apr 29, 2024
1 parent 5cf2ff1 commit 8e32da8
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/stores/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,18 +587,45 @@ export const useVideoStore = defineStore('video', () => {
}

// Routine to make sure the user has chosen the allowed ICE candidate IPs, so the stream works as expected
let warningTimeout: NodeJS.Timeout | undefined = undefined
let noIpSelectedWarningTimeout: NodeJS.Timeout | undefined = undefined
let selectedIpNotAvailableWarningTimeout: NodeJS.Timeout | undefined = undefined
const iceIpCheckInterval = setInterval(async (): Promise<void> => {
// Pass if there are no available IPs yet
if (availableIceIps.value === undefined) return

// Cancel the check if the user has already set the allowed ICE IPs
if (!allowedIceIps.value.isEmpty()) {
// If the user has selected IPs that are not available, want them about it, since no video will be streamed.
const availableSelectedIps = availableIceIps.value.filter((ip) => allowedIceIps.value.includes(ip))
if (!availableSelectedIps.isEmpty()) {
clearInterval(iceIpCheckInterval)
clearTimeout(warningTimeout)
clearTimeout(noIpSelectedWarningTimeout)
return
}

if (selectedIpNotAvailableWarningTimeout) return
selectedIpNotAvailableWarningTimeout = setTimeout(() => {
console.warn('Selected ICE IP is not available. Warning user.')
Swal.fire({
html: `
<p>Cockpit detected that you selected an IP on the video configuration page that is not available
on the video server. This will lead to no video being streamed. This can happen if you changed your
network or the IP for your vehicle changed.</p>
</br>
<p>To solve this problem, please:</p>
<ol>
<li>1. Open the video configuration page (Main-menu > Configuration > Video).</li>
<li>2. Clear the selected IPs and select an available one from the list.</li>
</ol>
`,
icon: 'warning',
customClass: {
htmlContainer: 'text-left',
},
})
clearInterval(iceIpCheckInterval)
return
}, 5000)

// If there's more than one IP candidate available, try getting information about them from BlueOS. If not
// available, send a warning an clear the check routine.
if (availableIceIps.value.length >= 1) {
Expand All @@ -613,15 +640,15 @@ export const useVideoStore = defineStore('video', () => {
})
if (!allowedIceIps.value.isEmpty()) {
clearInterval(iceIpCheckInterval)
clearTimeout(warningTimeout)
clearTimeout(noIpSelectedWarningTimeout)
return
}
} catch (error) {
console.log(error)
}

if (warningTimeout) return
warningTimeout = setTimeout(() => {
if (noIpSelectedWarningTimeout) return
noIpSelectedWarningTimeout = setTimeout(() => {
console.info('No ICE IPs selected for the allowed list. Warning user.')
Swal.fire({
html: `
Expand Down

0 comments on commit 8e32da8

Please sign in to comment.