Changing Call Audio Input
This guide covers how to change call audio input with the Vonage Client SDK. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS) and you are able to make or receive calls.
NOTE: There is currently no support for audio output routing in mobile browsers and Safari, so the below JavaScript examples are only applicable to desktop browsers as detailed in this compatibility table.
Android
Is there a way to change the input for Android?
iOS
Is there a way to change the input for iOS?
JavaScript (Desktop)
Can you change input in mobile browsers?
Getting Audio Input Devices
Before attempting to change audio input devices, you should check which devices are available to you:
const audioInputDevices = await navigator.mediaDevices.enumerateDevices().then(devices => devices.filter(d => d.kind == "audioinput"));
Changing Audio Input Devices
NOTE: A call must be in progress before you can change the audio input device.
With the current call ID, you can get the the Peer Connection with the Client SDK:
// After creating a session
const pc = client.getPeerConnection(curentCallId);
Then, you will get the audio track of the local stream from the input device you selected:
const localStream = await navigator.mediaDevices.getUserMedia({
audio: { deviceId: { exact: deviceId } }
});
const [track] = localStream.getAudioTracks();
Finally, you will replace the track of the peer connection's sender that is responsible for sending the audio into the call with the local audio track from the input device you selected:
const sender = pc.getSenders().find(sender => sender.track.kind === track.kind);
sender.replaceTrack(track);
Should I create a sample application and put into the Vonage Community GitHub repo?