Switch devices during calls
SignalWire Video API allows you to host real-time video calls and conferences on your website. In this guide, we’ll learn to allow users to change the camera and microphone that’s being used in the call.
Getting Started
If you haven’t yet set up a video conference project using the Video SDK, you can check out the build a video application guide first. After you have a video application set up, you can continue with this guide.
Getting a list of supported input devices
First, we want to find out what devices are available as input. Getting the list of media devices is handled by the WebRTC object available via SignalWire.WebRTC from the SDK. The methods in the WebRTC allow you to get the list of microphones, cameras, and speakers.
Listing webcams
To get the list of connected devices that can be used via the browser, we use
the getCameraDevicesWithPermissions() method in WebRTC. The method returns
an array of
InputDeviceInfo
object, each of which have two attributes of interest to us here:
InputDeviceInfo.deviceId and InputDeviceInfo.label. The label will be used
to refer to the webcam via the UI, and looks like ‘Facetime HD Camera’ or ‘USB
camera’. The deviceId is used in your code to address a particular device.
Listing microphones
Exactly as with getCameraDevicesWithPermissions(), we can use the getMicrophoneDevicesWithPermissions() to get a list of allowed microphones.
Changing webcams and microphones
Once you have set up the video call with SignalWire.Video.joinRoom() or
equivalent methods, we can use Room.updateCamera() and
Room.updateMicrophone() to change devices.
As a simplified example:
Note that you don’t explicitly have to update camera and microphone. SignalWire Video SDK chooses the preferred input devices by default on setup. Only updateCamera or updateMicrophone when you want to switch to a non-default device.