WayloAIWaylo Docs
Web SDK

Choose microphone and speaker

List devices and let the visitor choose.

const { microphones, speakers, canChooseSpeaker } = await WayloVoice.listDevices();
// To get names before a call: WayloVoice.listDevices({ requestPermission: true }), from a click.

const [microphone] = microphones; // empty until the visitor has allowed the mic
const [speaker] = speakers;

if (microphone) await wayloVoice.setMicrophoneDevice(microphone.deviceId); // before or during the call
if (canChooseSpeaker && speaker) await wayloVoice.setSpeakerDevice(speaker.deviceId);

Listing

  • listDevices() never asks for permission. Until the visitor allows the microphone, the lists are empty or unnamed. List again when state.microphone becomes on, and on navigator.mediaDevices' devicechange.
  • listDevices({ requestPermission: true }) asks for the microphone first (call it from a click), closes it again and lists with names. It rejects with MICROPHONE_DENIED if the visitor blocks it.

Speakers

  • canChooseSpeaker is false where the browser can't route audio to a chosen speaker (Safari and every iOS browser). setSpeakerDevice() then rejects with SPEAKER_UNAVAILABLE.
  • Firefox before 140 can choose a speaker but lists none. Hide the speaker picker whenever speakers is empty.

When devices change

  • A device chosen before start() that is gone by then falls back to the system default, and the state shows the device in use.
  • Mid-call, a microphone that can't be opened rejects with MICROPHONE_UNAVAILABLE (MICROPHONE_IN_USE when another app holds it, MICROPHONE_DENIED when the browser blocks it). The call keeps a working microphone where it can.
  • A chosen microphone or speaker stays until it is unplugged; the call then moves to the system default ('default').
  • On 'default', Chrome and other Chromium browsers follow system default changes; Firefox and Safari keep the open microphone until it is unplugged.
  • An unplugged muted microphone stays muted and opens the system default on unmute.
  • A mid-call error event MICROPHONE_UNAVAILABLE means no microphone is left or none could be opened, muted or not; microphone is then off.

On this page