added config 'cameraIndex' to select the camera by index

pull/97/head
Matthias Jauernig 9 years ago
parent 82ef5b9397
commit bd429ec362

@ -84,11 +84,19 @@ function normalizeConstraints(config, cb) {
if ( typeof MediaStreamTrack !== 'undefined' && typeof MediaStreamTrack.getSources !== 'undefined') { if ( typeof MediaStreamTrack !== 'undefined' && typeof MediaStreamTrack.getSources !== 'undefined') {
MediaStreamTrack.getSources(function(sourceInfos) { MediaStreamTrack.getSources(function(sourceInfos) {
var videoSourceId; var videoSourceId, facingDetected, videoIndex = 0;
for (var i = 0; i < sourceInfos.length; ++i) { for (var i = 0; i < sourceInfos.length; ++i) {
var sourceInfo = sourceInfos[i]; var sourceInfo = sourceInfos[i];
if (sourceInfo.kind === "video" && sourceInfo.facing === videoConstraints.facing) { if (sourceInfo.kind === "video" && !facingDetected) {
videoSourceId = sourceInfo.id; if (sourceInfo.facing === videoConstraints.facing) {
facingDetected = true;
}
if (!config.cameraIndex || config.cameraIndex <= videoIndex) {
videoSourceId = sourceInfo.id;
}
videoIndex++;
} }
} }
constraints.video = { constraints.video = {

Loading…
Cancel
Save