How to select proper backfacing camera in Javascript?
I placed all the cameras by id into array like that
navigator.mediaDevices.enumerateDevices() .then(function(devices) { for(;devices[i];){ if(devices[i].kind == "videoinput"){ that.aCameras.push( [devices[i].deviceId , devices[i].label] ) j++; } i++; } });
Than on the event that flip the camera by pressing the button i did this:
var defaultsOpts = { audio: false, video: true }; defaultsOpts.video = { deviceId: that.aCameras[that.currentCamera][0] }; if ( that.aCameras.length-1 != that.currentCamera ){ that.currentCamera++; } else{ that.currentCamera = 0; } navigator.mediaDevices.getUserMedia(defaultsOpts) .then(function (stream) { vid.srcObject = stream; localstream = stream; vid.play(); }); });
like that instead of using user/enviroment,my problem was sort of solved.
hope will help you too.
Regards,Avi.