Set Audio Input Device
Web only
This method is only available in the JavaScript/TypeScript SDK. On Android and iOS the operating system routes the microphone; see Audio Input For Calls.
Chooses the microphone calls use, instead of the one the browser prefers. Calls placed or answered afterwards open this device, and active calls switch to it straight away.
Without it, the SDK opens the browser's default microphone. Chrome uses the microphone remembered in its own site settings, which is not always the operating system's default, so a user with a headset can start a call on the laptop's built-in microphone.
Signature
setAudioInputDevice(deviceId: string | null): Promise<void>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
deviceId | string | null | Yes | The deviceId of an audioinput device from enumerateDevices(), or null for the browser's default |
Return Type
Returns a Promise that resolves once the choice is stored and every active call has switched to the device.
Usage Example
const devices = await navigator.mediaDevices.enumerateDevices();
const microphones = devices.filter((device) => device.kind === 'audioinput');
// Use the device the user picked, e.g. from a dropdown of `microphones`
const selected = microphones[0];
await client.setAudioInputDevice(selected.deviceId);
// Go back to the browser's default microphone
await client.setAudioInputDevice(null);Errors
The promise rejects only when an active call cannot open the device. It rejects with the browser's getUserMedia error, every call keeps its current microphone, and the previous choice stays in effect.
| Error name | Description |
|---|---|
OverconstrainedError | The device is not connected |
NotReadableError | The device is in use by another application, or failed |
NotAllowedError | Microphone permission was revoked |
Notes
- Web only
- Can be called at any time, before or during a call. With no active call it only stores the choice, so it never opens the microphone or prompts for permission
- Applies to every call the client places or answers, including emergency calls
- If the chosen device is no longer connected when a call starts, the call uses the browser's default microphone instead of failing. Read the call's actual device from
track.getSettings().deviceIdon the audio sender ofgetPeerConnection - Switching an active call replaces its microphone track without renegotiating, and keeps its mute state and its noise suppression, auto gain control and echo cancellation settings
- Also applies to
connectivityReport, which opens the microphone the same way a call does enumerateDevices()only returns device ids and labels once the page has microphone permission. Until then, list the devices after the first call, or after your own permission request
Related Actions
getAudioOutputElement- Choose the speaker withsetSinkIdon the returned elementgetPeerConnection- Retrieve the underlying RTCPeerConnection for an active call