From bd429ec3628e0452a4d87b3c6405d59ae50dc47b Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Tue, 22 Mar 2016 10:36:19 +0100 Subject: [PATCH 1/2] added config 'cameraIndex' to select the camera by index --- src/input/camera_access.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/input/camera_access.js b/src/input/camera_access.js index da20d61..5d7ef74 100644 --- a/src/input/camera_access.js +++ b/src/input/camera_access.js @@ -84,11 +84,19 @@ function normalizeConstraints(config, cb) { if ( typeof MediaStreamTrack !== 'undefined' && typeof MediaStreamTrack.getSources !== 'undefined') { MediaStreamTrack.getSources(function(sourceInfos) { - var videoSourceId; + var videoSourceId, facingDetected, videoIndex = 0; for (var i = 0; i < sourceInfos.length; ++i) { var sourceInfo = sourceInfos[i]; - if (sourceInfo.kind === "video" && sourceInfo.facing === videoConstraints.facing) { - videoSourceId = sourceInfo.id; + if (sourceInfo.kind === "video" && !facingDetected) { + if (sourceInfo.facing === videoConstraints.facing) { + facingDetected = true; + } + + if (!config.cameraIndex || config.cameraIndex <= videoIndex) { + videoSourceId = sourceInfo.id; + } + + videoIndex++; } } constraints.video = { From 0c5b9dbba5a89f0dd08c7009d4ddb43e495b9b60 Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Wed, 23 Mar 2016 22:50:23 +0100 Subject: [PATCH 2/2] fixed cameraIndex handling --- src/input/camera_access.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/input/camera_access.js b/src/input/camera_access.js index 5d7ef74..5bf0e26 100644 --- a/src/input/camera_access.js +++ b/src/input/camera_access.js @@ -84,15 +84,16 @@ function normalizeConstraints(config, cb) { if ( typeof MediaStreamTrack !== 'undefined' && typeof MediaStreamTrack.getSources !== 'undefined') { MediaStreamTrack.getSources(function(sourceInfos) { - var videoSourceId, facingDetected, videoIndex = 0; + var videoSourceId, videoIndex = 0; for (var i = 0; i < sourceInfos.length; ++i) { var sourceInfo = sourceInfos[i]; - if (sourceInfo.kind === "video" && !facingDetected) { + if (sourceInfo.kind === "video") { if (sourceInfo.facing === videoConstraints.facing) { - facingDetected = true; + videoSourceId = sourceInfo.id; + break; } - if (!config.cameraIndex || config.cameraIndex <= videoIndex) { + if (videoConstraints.cameraIndex === 'undefined' || videoConstraints.cameraIndex >= videoIndex) { videoSourceId = sourceInfo.id; }