Hi everyone!
I try open front camera using set isFront = true but it not working (cannot stream local).
When I set isFront = false, It can stream local with back camera.
please help me !
This is my code:
useEffect(() => {
let isFront = false;
mediaDevices.enumerateDevices().then(sourceInfos => {
console.log(sourceInfos);
let videoSourceId;
for (let i = 0; i < sourceInfos.length; i++) {
const sourceInfo = sourceInfos[i];
if (sourceInfo.kind == “videoinput” && sourceInfo.facing == (isFront ? “front” : “environment”)) {
videoSourceId = sourceInfo.deviceId;
}
}
mediaDevices.getUserMedia({
audio: true,
video: {
mandatory: {
minWidth: 500, // Provide your own width, height and frame rate here
minHeight: 300,
minFrameRate: 30
},
facingMode: (isFront ? “user” : “environment”),
optional: (videoSourceId ? [{ sourceId: videoSourceId }] : [])
}
})
.then(stream => {
// Got stream!
setLocalStream(stream)
})
.catch(error => {
// Log error
});
});
}, [frontCamera]);