From a81584c399a107a1efbd160004af16010849002d Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Mon, 29 Apr 2024 11:59:48 -0300 Subject: [PATCH] video: Warn user if they selected an IP that is not available in the ICE candidates --- src/stores/video.ts | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/stores/video.ts b/src/stores/video.ts index 8c8dd243b..cb1abf646 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -587,18 +587,46 @@ 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 => { // 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, warn 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) + clearTimeout(selectedIpNotAvailableWarningTimeout) return } + if (selectedIpNotAvailableWarningTimeout) return + selectedIpNotAvailableWarningTimeout = setTimeout(() => { + console.warn('Selected ICE IP is not available. Warning user.') + Swal.fire({ + html: ` +

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.

+
+

To solve this problem, please:

+
    +
  1. 1. Open the video configuration page (Main-menu > Configuration > Video).
  2. +
  3. 2. Clear the selected IPs and select an available one from the list.
  4. +
+ `, + 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) { @@ -613,15 +641,16 @@ export const useVideoStore = defineStore('video', () => { }) if (!allowedIceIps.value.isEmpty()) { clearInterval(iceIpCheckInterval) - clearTimeout(warningTimeout) + clearTimeout(noIpSelectedWarningTimeout) + clearTimeout(selectedIpNotAvailableWarningTimeout) 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: `