merge-always-use-environment-camera #11
1 changed files with 13 additions and 3 deletions
|
@ -103,15 +103,25 @@ export const useScanner = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCameraId = useCallback(async () => {
|
const getCameraId = useCallback(async () => {
|
||||||
await navigator.mediaDevices.getUserMedia({
|
const stream = await navigator.mediaDevices.getUserMedia({
|
||||||
video: true,
|
video: { facingMode: "environment" },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
stream &&
|
||||||
|
stream.getVideoTracks().length &&
|
||||||
|
stream.getVideoTracks()[0].getSettings().deviceId
|
||||||
|
) {
|
||||||
|
return stream.getVideoTracks()[0].getSettings().deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
const devices = await navigator.mediaDevices
|
const devices = await navigator.mediaDevices
|
||||||
.enumerateDevices()
|
.enumerateDevices()
|
||||||
.then((ds) => ds.filter((d) => d.kind === "videoinput"));
|
.then((ds) => ds.filter((d) => d.kind === "videoinput"));
|
||||||
|
|
||||||
const back = devices.filter((d) => d.label === "Back Camera")[0];
|
const back = devices.filter((d) =>
|
||||||
|
d.label.toLowerCase().includes("back")
|
||||||
|
)[0];
|
||||||
|
|
||||||
return !back ? devices[0].deviceId : back.deviceId;
|
return !back ? devices[0].deviceId : back.deviceId;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
Loading…
Reference in a new issue