Skip to content

Instantly share code, notes, and snippets.

@Anderson-Juhasc
Created February 24, 2017 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anderson-Juhasc/70626f413a84a03056698648bab318b9 to your computer and use it in GitHub Desktop.
Save Anderson-Juhasc/70626f413a84a03056698648bab318b9 to your computer and use it in GitHub Desktop.
//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