@@ -32,7 +32,6 @@ export function PhoneIslandPage() {
3232 const isUrlOpening = useRef < boolean > ( false )
3333 const urlOpenAttempts = useRef < number > ( 0 )
3434 const urlOpenListenerRegistered = useRef < boolean > ( false )
35- const hasRunWarmup = useRef < boolean > ( false )
3635
3736 useEffect ( ( ) => {
3837 resize ( phoneIsalndSizes )
@@ -75,29 +74,31 @@ export function PhoneIslandPage() {
7574 eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-call-end' ] )
7675 } )
7776
78- window . electron . receive ( IPC_EVENTS . CHANGE_PREFERRED_DEVICES , ( devices : PreferredDevices ) => {
79- Log . info ( 'Received CHANGE_PREFERRED_DEVICES in PhoneIslandPage:' , devices )
77+ window . electron . receive ( IPC_EVENTS . CHANGE_PREFERRED_DEVICES , ( devices : PreferredDevices & { shouldRunWarmup ?: boolean } ) => {
78+ const { shouldRunWarmup, audioInput, videoInput, audioOutput } = devices
79+ Log . info ( 'Received CHANGE_PREFERRED_DEVICES in PhoneIslandPage:' , { devices, shouldRunWarmup } )
8080
8181 // Run audio warm-up first, only once after PhoneIsland is fully initialized
82- // Only on Windows/macOS where the issue occurs
83- if ( ! hasRunWarmup . current ) {
84- hasRunWarmup . current = true
85- Log . info ( 'Requesting audio warm-up from main process...' )
82+ // Main process tracks whether warmup has already run (survives re-renders/reconnections)
83+ // Phone-island also checks for active calls before running warmup
84+ if ( shouldRunWarmup ) {
85+ Log . info ( 'Requesting audio warm-up from main process (first initialization) ...' )
8686 setTimeout ( ( ) => {
8787 eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-init-audio' ] )
8888 } , 1000 )
8989
9090 // Dispatch device changes after warm-up completes (after ~5 seconds)
9191 setTimeout ( ( ) => {
92- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-input-change' ] , { deviceId : devices . audioInput } )
93- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-video-input-change' ] , { deviceId : devices . videoInput } )
94- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-output-change' ] , { deviceId : devices . audioOutput } )
92+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-input-change' ] , { deviceId : audioInput } )
93+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-video-input-change' ] , { deviceId : videoInput } )
94+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-output-change' ] , { deviceId : audioOutput } )
9595 } , 5000 )
9696 } else {
97- // If warm-up already done or not needed, dispatch immediately
98- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-input-change' ] , { deviceId : devices . audioInput } )
99- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-video-input-change' ] , { deviceId : devices . videoInput } )
100- eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-output-change' ] , { deviceId : devices . audioOutput } )
97+ // If warm-up already done or not needed (reconnection), dispatch device changes immediately
98+ Log . info ( 'Skipping audio warm-up (already done or reconnection), dispatching device changes immediately' )
99+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-input-change' ] , { deviceId : audioInput } )
100+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-video-input-change' ] , { deviceId : videoInput } )
101+ eventDispatch ( PHONE_ISLAND_EVENTS [ 'phone-island-audio-output-change' ] , { deviceId : audioOutput } )
101102 }
102103 } )
103104
0 commit comments