Skip to content

Commit

Permalink
Add more robust image fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tgk committed Nov 25, 2016
1 parent ade54fa commit f780c8c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions resources/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ var checkNewImage;
checkNewImage = function(){
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){

var load = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
pictureDomElement.src = xmlhttp.responseText;
setTimeout(checkNewImage, 10000);
deadManSwitch = true;
}
setTimeout(checkNewImage, 10000);
};

var error = function(){
setTimeout(checkNewImage, 10000);
};

xmlhttp.addEventListener("load", load);
xmlhttp.addEventListener("error", error);

xmlhttp.open("GET", "current-picture-url", true);
xmlhttp.send();
};
Expand Down

0 comments on commit f780c8c

Please sign in to comment.