Handling multiple devices
In some cases, users may have more than one camera or microphone attached to their device. This is especially the case on mobile devices that often have a front-facing camera and a rear-facing one. In this case, you want to search through the available cameras or microphones and select the appropriate device for your user's needs. Fortunately, to do this, an API called MediaSourceTrack
is exposed to the browser.
Note
On the other hand, since many of these APIs are still being created, not everything will be supported by all the browsers. This is especially the case with MediaSourceTrack
, which is only supported in the latest version of Chrome at the time of writing this book.
With MediaSourceTrack
, we can ask for a list of devices and select the one we need:
MediaStreamTrack.getSources(function(sources) { var audioSource = null; var videoSource = null; for (var i = 0; i < sources.length; ++i) { var source = sources[i]; if(source.kind...