only use images that have a minimum size and delete outdated images
This commit is contained in:
35
www/js/webcam.js
Normal file
35
www/js/webcam.js
Normal 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');
|
||||
}
|
Reference in New Issue
Block a user