only use images that have a minimum size and delete outdated images

This commit is contained in:
2023-07-10 22:34:51 +02:00
parent 9290cf195b
commit 52ddfe1f59
9 changed files with 95 additions and 15 deletions

35
www/js/webcam.js Normal file
View File

@ -0,0 +1,35 @@
const images = document.getElementsByClassName('current_webcam_image');
const reload_interval = setInterval(reloadImages, 10000);
window.onload = function() {
reloadImages();
};
function checkImageSource(image_url) {
var http_request = new XMLHttpRequest();
http_request.open('HEAD', image_url, false);
http_request.send();
return http_request.status;
}
function reloadImages() {
console.log('reload in progress');
Array.prototype.forEach.call(images, function(image) {
if (checkImageSource(image.src) == 200) {
if (!image.src.includes('?')) {
image.src = `${image.src}?${Date.now()}`;
} else {
image.src = image.src.slice(0, image.src.indexOf('?') + 1) + Date.now();
}
} else {
console.log('unable to find image on server');
image.alt = "Webcam nicht erreichbar."
}
});
console.log('reload finished');
}