Switch to default audio input device when it's connected in js

471 Views Asked by At

I'm using twilio sdk to implement web calling app. Let's say I'm making a call to someone with my laptop devices (mic and speakers). During the call I plugged-in my headset. In the system both audio input and output devices are changed. The call audio output signal is transferred fine (I can here my counterpart through my headphones). But the audio input device stays the same - app doesn't start to use the mic on my headset.

It there any way to update audio input track to switch to a headset once it's connected?

1

There are 1 best solutions below

0
On

First of all, get local praticipant tracks and filter audio track.

const publications = Array.from(this.participant.tracks.values());
const audioPublication = publications.find(item => item.kind === 'audio');

Then set the deviceId like this.

const constraints = { deviceId: { exact: deviceId } };
audioPublication.track.restart(constraints);