Skip to content

Commit

Permalink
Merge pull request #38703 from tienifr/fix/38696
Browse files Browse the repository at this point in the history
Fix: Infinite loading after denying camera access
  • Loading branch information
rlinoz authored Mar 20, 2024
2 parents 342d4c8 + 6ad4da1 commit 2b99e8a
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/pages/iou/request/step/IOURequestStepScan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,42 @@ function IOURequestStepScan({
return;
}

navigator.mediaDevices.getUserMedia({video: {facingMode: {exact: 'environment'}, zoom: {ideal: 1}}}).then((stream) => {
_.forEach(stream.getTracks(), (track) => track.stop());
// Only Safari 17+ supports zoom constraint
if (Browser.isMobileSafari() && stream.getTracks().length > 0) {
const deviceId = _.chain(stream.getTracks())
.map((track) => track.getSettings())
.find((setting) => setting.zoom === 1)
.get('deviceId')
.value();
if (deviceId) {
setVideoConstraints({deviceId});
return;
const defaultConstraints = {facingMode: {exact: 'environment'}};
navigator.mediaDevices
.getUserMedia({video: {facingMode: {exact: 'environment'}, zoom: {ideal: 1}}})
.then((stream) => {
_.forEach(stream.getTracks(), (track) => track.stop());
// Only Safari 17+ supports zoom constraint
if (Browser.isMobileSafari() && stream.getTracks().length > 0) {
const deviceId = _.chain(stream.getTracks())
.map((track) => track.getSettings())
.find((setting) => setting.zoom === 1)
.get('deviceId')
.value();
if (deviceId) {
setVideoConstraints({deviceId});
return;
}
}
}
if (!navigator.mediaDevices.enumerateDevices) {
setVideoConstraints({facingMode: {exact: 'environment'}});
return;
}
navigator.mediaDevices.enumerateDevices().then((devices) => {
const lastBackDeviceId = _.chain(devices)
.filter((item) => item.kind === 'videoinput')
.last()
.get('deviceId', '')
.value();

if (!lastBackDeviceId) {
setVideoConstraints({facingMode: {exact: 'environment'}});
if (!navigator.mediaDevices.enumerateDevices) {
setVideoConstraints(defaultConstraints);
return;
}
setVideoConstraints({deviceId: lastBackDeviceId});
});
});
navigator.mediaDevices.enumerateDevices().then((devices) => {
const lastBackDeviceId = _.chain(devices)
.filter((item) => item.kind === 'videoinput')
.last()
.get('deviceId', '')
.value();

if (!lastBackDeviceId) {
setVideoConstraints(defaultConstraints);
return;
}
setVideoConstraints({deviceId: lastBackDeviceId});
});
})
.catch(() => setVideoConstraints(defaultConstraints));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isTabActive]);

Expand Down

0 comments on commit 2b99e8a

Please sign in to comment.