This page is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2024.
We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide to assist you in minimizing any service disruption.
In this guide we'll show you how to configure audio and video input and output devices in your Twilio Video Rooms application.
You can use navigator.mediaDevices.enumerateDevices()
to select a specific video input like this:
_10const { connect, createLocalTracks } = require('twilio-video');_10_10navigator.mediaDevices.enumerateDevices().then(devices => {_10 const videoInput = devices.find(device => device.kind === 'videoinput');_10 return createLocalTracks({ audio: true, video: { deviceId: videoInput.deviceId } });_10}).then(localTracks => {_10 return connect('my-token', { name: 'my-room-name', tracks: localTracks });_10}).then(room => {_10 console.log('Connected to room ' + room.name);_10});
Audio inputs can also be selected in a similar fashion.
Selecting a specific audio input is the same as selecting a specific video input. Just select the audio input device ID and set it on the constraints:
_10const { connect, createLocalTracks } = require('twilio-video');_10_10navigator.mediaDevices.enumerateDevices().then(devices => {_10 const audioInput = devices.find(device => device.kind === 'audioinput');_10 return createLocalTracks({ audio: { deviceId: audioInput.deviceId }, video: true });_10}).then(localTracks => {_10 return connect('my-token', { name: 'my-room-name', tracks: localTracks });_10}).then(room => {_10 console.log('Connected to room ' + room.name);_10});
You can use navigator.mediaDevices.enumerateDevices()
along with HTMLMediaElement.setSinkId() to set the audio output device like this:
_17const { connect } = require('twilio-video');_17_17let audioOutputDevice;_17_17navigator.mediaDevices.enumerateDevices().then(devices => {_17 audioOutputDevice = devices.find(device => device.kind === 'audiooutput');_17 return connect('$TOKEN', { name: 'my-room-name' });_17}).then(room => {_17 room.on('trackSubscribed', track => {_17 if (track.kind === 'audio') {_17 const audioElement = track.attach();_17 audioElement.setSinkId(audioOutputDevice.deviceId).then(() => {_17 document.body.appendChild(audioElement);_17 });_17 }_17 });_17});