From bd429ec3628e0452a4d87b3c6405d59ae50dc47b Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Tue, 22 Mar 2016 10:36:19 +0100 Subject: [PATCH] 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 = {