diff --git a/src/stores/video.ts b/src/stores/video.ts index 4cce5a179..ee152c337 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -42,6 +42,7 @@ export const useVideoStore = defineStore('video', () => { console.debug('[WebRTC] Using webrtc-adapter for', adapter.browserDetails) const allowedIceIps = useBlueOsStorage('cockpit-allowed-stream-ips', []) + const enableAutoIceIpFetch = useBlueOsStorage('cockpit-enable-auto-ice-ip-fetch', true) const allowedIceProtocols = useBlueOsStorage('cockpit-allowed-stream-protocols', []) const jitterBufferTarget = useBlueOsStorage('cockpit-jitter-buffer-target', 0) const zipMultipleFiles = useBlueOsStorage('cockpit-zip-multiple-video-files', false) @@ -697,58 +698,60 @@ 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 noIpSelectedWarningIssued = false - let selectedIpNotAvailableWarningIssued = false - const iceIpCheckInterval = setInterval(async (): Promise => { - // Pass if there are no available IPs yet - if (availableIceIps.value.isEmpty()) return - - if (!allowedIceIps.value.isEmpty()) { - // If the user has selected IPs, but none of them are available, warn about it, since no video will be streamed. - // Otherwise, if IPs are selected and available, clear the check routine. - const availableSelectedIps = availableIceIps.value.filter((ip) => allowedIceIps.value.includes(ip)) - if (availableSelectedIps.isEmpty() && !selectedIpNotAvailableWarningIssued) { - console.warn('Selected ICE IPs are not available. Warning user.') - issueSelectedIpNotAvailableWarning() - selectedIpNotAvailableWarningIssued = true + if (enableAutoIceIpFetch.value) { + // Routine to make sure the user has chosen the allowed ICE candidate IPs, so the stream works as expected + let noIpSelectedWarningIssued = false + let selectedIpNotAvailableWarningIssued = false + const iceIpCheckInterval = setInterval(async (): Promise => { + // Pass if there are no available IPs yet + if (availableIceIps.value.isEmpty()) return + + if (!allowedIceIps.value.isEmpty()) { + // If the user has selected IPs, but none of them are available, warn about it, since no video will be streamed. + // Otherwise, if IPs are selected and available, clear the check routine. + const availableSelectedIps = availableIceIps.value.filter((ip) => allowedIceIps.value.includes(ip)) + if (availableSelectedIps.isEmpty() && !selectedIpNotAvailableWarningIssued) { + console.warn('Selected ICE IPs are not available. Warning user.') + issueSelectedIpNotAvailableWarning() + selectedIpNotAvailableWarningIssued = true + } + clearInterval(iceIpCheckInterval) } - clearInterval(iceIpCheckInterval) - } - // If the user has not selected any IPs and there's more than one IP candidate available, try getting information - // about them from BlueOS. If that fails, send a warning an clear the check routine. - if (allowedIceIps.value.isEmpty() && availableIceIps.value.length >= 1) { - // Try to select the IP automatically if it's a wired connection (based on BlueOS data). - try { - const ipsInfo = await getIpsInformationFromVehicle(globalAddress) - const newAllowedIps: string[] = [] - ipsInfo.forEach((ipInfo) => { - const isIceIp = availableIceIps.value.includes(ipInfo.ipv4Address) - const alreadyAllowedIp = [...allowedIceIps.value, ...newAllowedIps].includes(ipInfo.ipv4Address) - const theteredInterfaceTypes = ['WIRED', 'USB'] - if (!theteredInterfaceTypes.includes(ipInfo.interfaceType) || alreadyAllowedIp || !isIceIp) return - console.info(`Adding the wired address '${ipInfo.ipv4Address}' to the list of allowed ICE IPs.`) - newAllowedIps.push(ipInfo.ipv4Address) - }) - allowedIceIps.value = newAllowedIps - if (!allowedIceIps.value.isEmpty()) { - Swal.fire({ text: 'Preferred video stream routes fetched from BlueOS.', icon: 'success', timer: 5000 }) + // If the user has not selected any IPs and there's more than one IP candidate available, try getting information + // about them from BlueOS. If that fails, send a warning an clear the check routine. + if (allowedIceIps.value.isEmpty() && availableIceIps.value.length >= 1) { + // Try to select the IP automatically if it's a wired connection (based on BlueOS data). + try { + const ipsInfo = await getIpsInformationFromVehicle(globalAddress) + const newAllowedIps: string[] = [] + ipsInfo.forEach((ipInfo) => { + const isIceIp = availableIceIps.value.includes(ipInfo.ipv4Address) + const alreadyAllowedIp = [...allowedIceIps.value, ...newAllowedIps].includes(ipInfo.ipv4Address) + const theteredInterfaceTypes = ['WIRED', 'USB'] + if (!theteredInterfaceTypes.includes(ipInfo.interfaceType) || alreadyAllowedIp || !isIceIp) return + console.info(`Adding the wired address '${ipInfo.ipv4Address}' to the list of allowed ICE IPs.`) + newAllowedIps.push(ipInfo.ipv4Address) + }) + allowedIceIps.value = newAllowedIps + if (!allowedIceIps.value.isEmpty()) { + Swal.fire({ text: 'Preferred video stream routes fetched from BlueOS.', icon: 'success', timer: 5000 }) + } + } catch (error) { + console.error('Failed to get IP information from the vehicle:', error) } - } catch (error) { - console.error('Failed to get IP information from the vehicle:', error) - } - // If the system was still not able to populate the allowed IPs list yet, warn the user. - // Otherwise, clear the check routine. - if (allowedIceIps.value.isEmpty() && !noIpSelectedWarningIssued) { - console.info('No ICE IPs selected for the allowed list. Warning user.') - issueNoIpSelectedWarning() - noIpSelectedWarningIssued = true + // If the system was still not able to populate the allowed IPs list yet, warn the user. + // Otherwise, clear the check routine. + if (allowedIceIps.value.isEmpty() && !noIpSelectedWarningIssued) { + console.info('No ICE IPs selected for the allowed list. Warning user.') + issueNoIpSelectedWarning() + noIpSelectedWarningIssued = true + } + clearInterval(iceIpCheckInterval) } - clearInterval(iceIpCheckInterval) - } - }, 5000) + }, 5000) + } // Video recording actions const startRecordingAllStreams = (): void => { @@ -797,6 +800,7 @@ export const useVideoStore = defineStore('video', () => { return { availableIceIps, allowedIceIps, + enableAutoIceIpFetch, allowedIceProtocols, jitterBufferTarget, zipMultipleFiles, diff --git a/src/views/ConfigurationVideoView.vue b/src/views/ConfigurationVideoView.vue index 8334564ff..93bb3847d 100644 --- a/src/views/ConfigurationVideoView.vue +++ b/src/views/ConfigurationVideoView.vue @@ -6,12 +6,16 @@
- +