Only adjust the camera barcode scanning live stream picture size once (fixes #734)

This commit is contained in:
Bernd Bestel 2020-04-13 22:34:52 +02:00
parent 2e625f330d
commit e897570968
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

View File

@ -1,5 +1,6 @@
Grocy.Components.BarcodeScanner = { }; Grocy.Components.BarcodeScanner = { };
Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false;
Grocy.Components.BarcodeScanner.CheckCapabilities = async function() Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
{ {
var track = Quagga.CameraAccess.getActiveTrack(); var track = Quagga.CameraAccess.getActiveTrack();
@ -28,18 +29,26 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
} }
// Reduce the height of the video, if it's heigher than then the viewport // Reduce the height of the video, if it's heigher than then the viewport
var bc = document.getElementById('barcodescanner-container'); if (!Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted)
if (bc) { {
var bcAspectRatio = bc.offsetWidth / bc.offsetHeight; var bc = document.getElementById('barcodescanner-container');
var settings = track.getSettings(); if (bc)
if (bcAspectRatio > settings.aspectRatio) { {
var v = document.querySelector('#barcodescanner-livestream video') var bcAspectRatio = bc.offsetWidth / bc.offsetHeight;
if (v) { var settings = track.getSettings();
var c = document.querySelector('#barcodescanner-livestream canvas') if (bcAspectRatio > settings.aspectRatio)
var newWidth = v.clientWidth / bcAspectRatio * settings.aspectRatio + 'px'; {
v.style.width = newWidth; var v = document.querySelector('#barcodescanner-livestream video')
c.style.width = newWidth; if (v)
{
var c = document.querySelector('#barcodescanner-livestream canvas')
var newWidth = v.clientWidth / bcAspectRatio * settings.aspectRatio + 'px';
v.style.width = newWidth;
c.style.width = newWidth;
}
} }
Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = true;
} }
} }
} }