Created
February 24, 2017 17:42
-
-
Save Anderson-Juhasc/70626f413a84a03056698648bab318b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//check for getUserMedia | |
navigator.getUserMedia = navigator.getUserMedia || | |
navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia; | |
let devices = []; | |
if (navigator.mediaDevices) { | |
navigator.mediaDevices.enumerateDevices() | |
.then(function (deviceInfos) { | |
for (let i = 0; i !== deviceInfos.length; ++i) { | |
let deviceInfo = deviceInfos[i]; | |
if (deviceInfo.kind === 'videoinput') { | |
devices.push(deviceInfo) | |
} | |
} | |
let backCamera = devices.map(obj => { | |
if(obj.label.indexOf("back")){ | |
return obj.deviceId; | |
} | |
return false | |
}) | |
if (navigator.getUserMedia) { | |
navigator.getUserMedia({ audio: false, video: { width: 720, height: 1280, deviceId: { exact: backCamera[1] } } }, | |
function(stream) { | |
localstream = stream; | |
let video = document.querySelector('video'); | |
video.src = window.URL.createObjectURL(stream); | |
video.onloadedmetadata = function(e) { | |
video.play(); | |
}; | |
self.setState({ | |
gotCamera: true | |
}) | |
}, | |
function(err) { | |
console.log("The following error occurred: " + err.name); | |
} | |
); | |
} else { | |
console.log("getUserMedia not supported"); | |
} | |
}) | |
.catch(function (error) { | |
console.log("erro"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment