Camera stream aspect ratio calculations

This commit is contained in:
Yegor Vialov
2020-02-20 21:48:22 +00:00
parent 35d8607484
commit 06f994a827
2 changed files with 24 additions and 14 deletions

View File

@ -1,18 +1,20 @@
var messageChannel = 'HA_entity_id_placeholder';
function fixCameraImgView() {
window.clearInterval(window.bodyDetectInterval);
var img = document.getElementsByTagName('img');
if (img && img.length) {
img[0].setAttribute('width', document.body.clientWidth);
img[0].setAttribute('style', 'margin-top: ' + ((document.body.clientHeight - img[0].offsetHeight) / 2));
}
var ovrl = document.getElementById('appOverlay');
if (ovrl) {
ovrl.remove();
img[0].removeAttribute('style');
setTimeout(function() {
window[messageChannel].postMessage(document.body.clientWidth / img[0].offsetHeight);
}, 100);
}
}
window.bodyDetectInterval = setInterval(function() {
if (document.body != null) {
setTimeout(fixCameraImgView, 1000);
if (document.body != null && document.getElementsByTagName('img').length) {
fixCameraImgView();
}
}, 100);