Skip to content

Commit dad26b5

Browse files
committed
Update camera config with a rounded value for aspect ratio.
1 parent e574b39 commit dad26b5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

components/BarcodeScanner.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ export default {
9595
const defaultCameraId =
9696
backCameras.at(-1)?.deviceId ?? cameraList.value.at(-1)?.deviceId;
9797
await scanner.start(
98-
selectedCameraId.value ?? defaultCameraId,
99-
getCameraScanConfig(), onScanSuccess, onError
98+
{deviceId: {exact: selectedCameraId.value ?? defaultCameraId}},
99+
getCameraScanConfig(),
100+
onScanSuccess,
101+
onError
100102
);
101103
if(!selectedCameraId.value && cameraList.value.length) {
102104
const selectedCamera = scanner.getRunningTrackSettings()?.deviceId;
@@ -108,7 +110,7 @@ export default {
108110
}
109111
await getZoomConstraints();
110112
// Set focus mode
111-
scanner.applyVideoConstraints({
113+
await scanner.applyVideoConstraints({
112114
advanced: [
113115
{frameRate: 30},
114116
{resizeMode: 'none'},
@@ -212,11 +214,12 @@ export default {
212214
function getCameraScanConfig() {
213215
const width = window.innerWidth;
214216
const height = window.innerHeight;
215-
const landscapeAspectRatio = width / height;
216-
const portraitAspectRatio = height / width;
217+
// Must parse float aspect ratio value
218+
const landscapeAspectRatio = parseFloat((width / height).toFixed(3));
219+
const portraitAspectRatio = parseFloat((height / width).toFixed(3));
217220
return {
218221
videoConstraints: {
219-
facingMode: 'environment',
222+
facingMode: {exact: 'environment'},
220223
aspectRatio: width < height ?
221224
portraitAspectRatio :
222225
landscapeAspectRatio

0 commit comments

Comments
 (0)