Switches the audio input device based on user preference.

The options for switching the audio input.

The ID of the preferred audio input device.

The parameters required for switching the audio.

The default audio input device ID.

The current default audio input device ID.

The previously used audio input device ID.

Function to update the user's default audio input device.

Function to update the previous audio input device.

Function to switch the user's audio.

A promise that resolves when the audio input has been switched.

This function checks if the user's preferred audio device differs from the current default. If so, it updates the previous audio device and the current default audio device. It then calls the function to switch the user's audio.

const options: SwitchAudioOptions = {
audioPreference: 'newAudioDeviceID',
parameters: {
defAudioID: 'defaultAudioDeviceID',
userDefaultAudioInputDevice: 'currentAudioDeviceID',
prevAudioInputDevice: '',
updateUserDefaultAudioInputDevice: (deviceId) => console.log(`Updated to: ${deviceId}`),
updatePrevAudioInputDevice: (deviceId) => console.log(`Previous device was: ${deviceId}`),
switchUserAudio: async ({ audioPreference, parameters }) => {
console.log(`Switching audio to: ${audioPreference}`);
},
getUpdatedAllParams: () => {
return {
defAudioID: 'defaultAudioDeviceID',
userDefaultAudioInputDevice: 'currentAudioDeviceID',
prevAudioInputDevice: '',
};
},
},
};

const switchAudioService = new SwitchAudio();
await switchAudioService.switchAudio(options);

Constructors

Methods

Constructors

Methods