@@ -32,13 +32,12 @@ import { writeFileSync } from 'node:fs';
3232import { spawn } from 'node:child_process' ;
3333import { discordPresence } from './presence' ;
3434import { options } from './cli' ;
35- import { ServerStatusEvent } from 'electron/preload/interface' ;
35+ import { ServerStatusEvent , WebcamOfferRequest } from 'electron/preload/interface' ;
3636import { mkdir } from 'node:fs/promises' ;
3737import { MenuItem } from 'electron/main' ;
3838
39-
40- app . setPath ( 'userData' , getGuiDataFolder ( ) )
41- app . setPath ( 'sessionData' , join ( getGuiDataFolder ( ) , 'electron' ) )
39+ app . setPath ( 'userData' , getGuiDataFolder ( ) ) ;
40+ app . setPath ( 'sessionData' , join ( getGuiDataFolder ( ) , 'electron' ) ) ;
4241
4342// Register custom protocol to handle asset paths with leading slashes
4443protocol . registerSchemesAsPrivileged ( [
@@ -55,6 +54,13 @@ protocol.registerSchemesAsPrivileged([
5554
5655let mainWindow : BrowserWindow | null = null ;
5756
57+ function buildWebcamOfferUrl ( host : string , port : number ) {
58+ const normalizedHost =
59+ host . includes ( ':' ) && ! host . startsWith ( '[' ) ? `[${ host } ]` : host ;
60+
61+ return `http://${ normalizedHost } :${ port } /offer` ;
62+ }
63+
5864handleIpc ( IPC_CHANNELS . GH_FETCH , async ( e , options ) => {
5965 if ( options . type === 'fw-releases' ) {
6066 return fetch (
@@ -153,6 +159,31 @@ handleIpc(IPC_CHANNELS.DISCORD_PRESENCE, async (e, options) => {
153159 }
154160} ) ;
155161
162+ handleIpc ( IPC_CHANNELS . WEBCAM_OFFER , async ( e , request : WebcamOfferRequest ) => {
163+ const response = await fetch ( buildWebcamOfferUrl ( request . host , request . port ) , {
164+ method : 'POST' ,
165+ headers : {
166+ 'Content-Type' : 'application/json' ,
167+ } ,
168+ body : JSON . stringify ( {
169+ sdp : request . sdp ,
170+ } ) ,
171+ } ) ;
172+
173+ if ( ! response . ok ) {
174+ throw new Error ( `Offer request failed with status ${ response . status } ` ) ;
175+ }
176+
177+ const body = ( await response . json ( ) ) as { sdp ?: unknown } ;
178+ if ( typeof body . sdp !== 'string' || body . sdp . length === 0 ) {
179+ throw new Error ( 'Webcam response did not contain an SDP answer' ) ;
180+ }
181+
182+ return {
183+ sdp : body . sdp ,
184+ } ;
185+ } ) ;
186+
156187handleIpc ( IPC_CHANNELS . OPEN_FILE , ( e , folder ) => {
157188 const requestedPath = path . resolve ( folder ) ;
158189
@@ -339,8 +370,7 @@ function createWindow() {
339370 menu . append ( new MenuItem ( { label : 'Copy' , role : 'copy' } ) ) ;
340371 menu . append ( new MenuItem ( { label : 'Paste' , role : 'paste' } ) ) ;
341372
342- if ( mainWindow )
343- menu . popup ( { window : mainWindow } ) ;
373+ if ( mainWindow ) menu . popup ( { window : mainWindow } ) ;
344374 } ) ;
345375}
346376
0 commit comments