diff --git a/src/main/lib/videoGatewayOrigin.ts b/src/main/lib/videoGatewayOrigin.ts new file mode 100644 index 00000000..83b63e92 --- /dev/null +++ b/src/main/lib/videoGatewayOrigin.ts @@ -0,0 +1,31 @@ +import { session } from 'electron' + +// WHEP endpoint of the NethVoice video gateway (MediaMTX) +const VIDEO_GATEWAY_URLS = [ + 'https://*/streaming-gw/*', + 'http://*/streaming-gw/*', +] + +/** + * The pages of NethLink are loaded from file://, so their requests carry no + * Origin header while Chromium marks them as cross-site. The video gateway + * refuses a cross-site request without a valid origin before checking its + * token, and the door phone video is never shown. Send the requests to the + * gateway with the origin of the gateway itself: the access is still granted + * by the token of the request only. + */ +export function attachVideoGatewayOrigin() { + session.defaultSession.webRequest.onBeforeSendHeaders( + { urls: VIDEO_GATEWAY_URLS }, + (details, callback) => { + const requestHeaders = { ...details.requestHeaders } + const hasOrigin = Object.keys(requestHeaders).some( + (name) => name.toLowerCase() === 'origin', + ) + if (!hasOrigin) { + requestHeaders['Origin'] = new URL(details.url).origin + } + callback({ requestHeaders }) + }, + ) +} diff --git a/src/main/main.ts b/src/main/main.ts index 220d7148..ba547cb3 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -64,6 +64,7 @@ import Backend from 'i18next-fs-backend/cjs' import { uniq } from 'lodash' import { Registry } from 'rage-edit' import { useNethVoiceAPI } from '@shared/useNethVoiceAPI' +import { attachVideoGatewayOrigin } from './lib/videoGatewayOrigin' // get app parameter const params = process.argv @@ -297,6 +298,7 @@ function attachOnReadyProcess() { new SplashScreenController() new TrayController() new ScreenSharePickerController() + attachVideoGatewayOrigin() // I display the splashscreen when the splashscreen component is correctly loaded. SplashScreenController.instance.window.addOnBuildListener(() => {