Skip to main content
Manage audio and video devices during calls, including selecting microphones, speakers, and cameras.

Get Available Devices

Audio Input Devices (Microphones)

Get a list of available microphones:
const audioInputDevices = CometChatCalls.getAudioInputDevices();
console.log(audioInputDevices);

Audio Output Devices (Speakers)

Get a list of available speakers:
const audioOutputDevices = CometChatCalls.getAudioOutputDevices();
console.log(audioOutputDevices);

Video Input Devices (Cameras)

Get a list of available cameras:
const videoInputDevices = CometChatCalls.getVideoInputDevices();
console.log(videoInputDevices);

Get Current Device

Current Audio Input Device

Get the currently selected microphone:
const currentMic = CometChatCalls.getCurrentAudioInputDevice();
console.log("Current microphone:", currentMic);

Current Audio Output Device

Get the currently selected speaker:
const currentSpeaker = CometChatCalls.getCurrentAudioOutputDevice();
console.log("Current speaker:", currentSpeaker);

Current Video Input Device

Get the currently selected camera:
const currentCamera = CometChatCalls.getCurrentVideoInputDevice();
console.log("Current camera:", currentCamera);

Change Device

Set Audio Input Device

Switch to a different microphone:
CometChatCalls.setAudioInputDevice(deviceId);

Set Audio Output Device

Switch to a different speaker:
CometChatCalls.setAudioOutputDevice(deviceId);

Set Video Input Device

Switch to a different camera:
CometChatCalls.setVideoInputDevice(deviceId);

Device Change Events

Device Selection Changed

Monitor when the selected device changes:
CometChatCalls.addEventListener("onAudioInputDeviceChanged", (device) => {
  console.log("Microphone changed:", device);
});

CometChatCalls.addEventListener("onAudioOutputDeviceChanged", (device) => {
  console.log("Speaker changed:", device);
});

CometChatCalls.addEventListener("onVideoInputDeviceChanged", (device) => {
  console.log("Camera changed:", device);
});

Available Devices Changed

Monitor when devices are connected or disconnected:
CometChatCalls.addEventListener("onAudioInputDevicesChanged", (devices) => {
  console.log("Available microphones updated:", devices);
});

CometChatCalls.addEventListener("onAudioOutputDevicesChanged", (devices) => {
  console.log("Available speakers updated:", devices);
});

CometChatCalls.addEventListener("onVideoInputDevicesChanged", (devices) => {
  console.log("Available cameras updated:", devices);
});

Settings Dialog

Open the built-in settings dialog for device selection:
// Show settings dialog
CometChatCalls.showSettingsDialog();

// Hide settings dialog
CometChatCalls.hideSettingsDialog();

Device Object

Each device object contains:
PropertyTypeDescription
deviceIdStringUnique identifier for the device
labelStringHuman-readable device name
kindStringDevice type (audioinput, audiooutput, videoinput)