@@ -508,6 +508,10 @@ export class CallingClass {
508508 RingRTC . handleOutgoingSignaling = this . #handleOutgoingSignaling. bind ( this ) ;
509509 RingRTC . handleIncomingCall = this . #handleIncomingCall. bind ( this ) ;
510510 RingRTC . handleStartCall = this . #handleStartCall. bind ( this ) ;
511+ RingRTC . handleOutputDeviceChanged =
512+ this . #handleOutputDeviceChanged. bind ( this ) ;
513+ RingRTC . handleInputDeviceChanged =
514+ this . #handleInputDeviceChanged. bind ( this ) ;
511515 RingRTC . handleAutoEndedIncomingCallRequest =
512516 this . #handleAutoEndedIncomingCallRequest. bind ( this ) ;
513517 RingRTC . handleLogMessage = this . #handleLogMessage. bind ( this ) ;
@@ -2688,8 +2692,7 @@ export class CallingClass {
26882692 return true ;
26892693 }
26902694
2691- async #pollForMediaDevices( ) : Promise < void > {
2692- const newSettings = await this . getMediaDeviceSettings ( ) ;
2695+ async #maybeUpdateDevices( newSettings : MediaDeviceSettings ) : Promise < void > {
26932696 if (
26942697 ! this . #mediaDeviceSettingsEqual(
26952698 this . #lastMediaDeviceSettings,
@@ -2708,10 +2711,19 @@ export class CallingClass {
27082711 }
27092712 }
27102713
2711- async getAvailableIODevices ( ) : Promise < AvailableIODevicesType > {
2714+ async #pollForMediaDevices( ) : Promise < void > {
2715+ const newSettings = await this . getMediaDeviceSettings ( ) ;
2716+ return this . #maybeUpdateDevices( newSettings ) ;
2717+ }
2718+
2719+ async #getAvailableIODevicesWithPrefetchedDevices(
2720+ prefetchedMicrophones : Array < AudioDevice > | undefined ,
2721+ prefetchedSpeakers : Array < AudioDevice > | undefined
2722+ ) : Promise < AvailableIODevicesType > {
27122723 const availableCameras = await this . #videoCapturer. enumerateDevices ( ) ;
2713- const availableMicrophones = RingRTC . getAudioInputs ( ) ;
2714- const availableSpeakers = RingRTC . getAudioOutputs ( ) ;
2724+ const availableMicrophones =
2725+ prefetchedMicrophones || RingRTC . getAudioInputs ( ) ;
2726+ const availableSpeakers = prefetchedSpeakers || RingRTC . getAudioOutputs ( ) ;
27152727
27162728 return {
27172729 availableCameras,
@@ -2720,9 +2732,22 @@ export class CallingClass {
27202732 } ;
27212733 }
27222734
2723- async getMediaDeviceSettings ( ) : Promise < MediaDeviceSettings > {
2735+ async getAvailableIODevices ( ) : Promise < AvailableIODevicesType > {
2736+ return this . #getAvailableIODevicesWithPrefetchedDevices(
2737+ undefined ,
2738+ undefined
2739+ ) ;
2740+ }
2741+
2742+ async #getMediaDeviceSettingsWithPrefetchedDevices(
2743+ prefetchedMicrophones : Array < AudioDevice > | undefined ,
2744+ prefetchedSpeakers : Array < AudioDevice > | undefined
2745+ ) : Promise < MediaDeviceSettings > {
27242746 const { availableCameras, availableMicrophones, availableSpeakers } =
2725- await this . getAvailableIODevices ( ) ;
2747+ await this . #getAvailableIODevicesWithPrefetchedDevices(
2748+ prefetchedMicrophones ,
2749+ prefetchedSpeakers
2750+ ) ;
27262751
27272752 const preferredMicrophone = getPreferredAudioInputDevice ( ) ;
27282753 const selectedMicIndex = findBestMatchingAudioDeviceIndex (
@@ -2766,6 +2791,13 @@ export class CallingClass {
27662791 } ;
27672792 }
27682793
2794+ async getMediaDeviceSettings ( ) : Promise < MediaDeviceSettings > {
2795+ return this . #getMediaDeviceSettingsWithPrefetchedDevices(
2796+ undefined ,
2797+ undefined
2798+ ) ;
2799+ }
2800+
27692801 setPreferredMicrophone ( device : AudioDevice ) : void {
27702802 log . info (
27712803 'MediaDevice: setPreferredMicrophone' ,
@@ -3730,6 +3762,22 @@ export class CallingClass {
37303762 return true ;
37313763 }
37323764
3765+ async #handleOutputDeviceChanged( devices : Array < AudioDevice > ) : Promise < void > {
3766+ const newSettings = await this . #getMediaDeviceSettingsWithPrefetchedDevices(
3767+ undefined ,
3768+ devices
3769+ ) ;
3770+ return this . #maybeUpdateDevices( newSettings ) ;
3771+ }
3772+
3773+ async #handleInputDeviceChanged( devices : Array < AudioDevice > ) : Promise < void > {
3774+ const newSettings = await this . #getMediaDeviceSettingsWithPrefetchedDevices(
3775+ devices ,
3776+ undefined
3777+ ) ;
3778+ return this . #maybeUpdateDevices( newSettings ) ;
3779+ }
3780+
37333781 public async updateCallHistoryForAdhocCall (
37343782 roomId : string ,
37353783 joinState : GroupCallJoinState | null ,
0 commit comments