Added ajax request to projections.json for hot swapping projector rotation

This commit is contained in:
The Great & Powerful James Wernicke 2015-06-04 06:30:10 -06:00
parent c1dc1d7633
commit e2bfb9771d
2 changed files with 28 additions and 4 deletions

5
www/projections.json Normal file
View File

@ -0,0 +1,5 @@
[
"scoreboard.html",
"tanks.html",
"credits.html"
]

View File

@ -20,10 +20,20 @@
}
</style>
<script>
var urls = ["scoreboard.html", "credits.html", "tanks.html"];
var SECS = 1000;
var urls = ["scoreboard.html"];
var stack = [];
var secs = 1000;
var i = 0;
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
urls = JSON.parse(xmlhttp.responseText);
//console.log("new urls:", urls);
}
}
function reload() {
// alternate between scoreboard and other things
if (i%2){
@ -31,15 +41,24 @@ function reload() {
}
else {
if (stack.length === 0){
xmlhttp.open("GET", "projections.json", true);
xmlhttp.send();
if (urls.length > 1){
stack = urls.slice(1);
}
else {
stack = urls;
}
}
url = stack.pop();
}
console.log("loading " + url + " of " + urls);
document.getElementById("reloader").src = url;
i++;
}
function init() {
setInterval(reload, 60*secs);
setInterval(reload, 2*SECS);
}
window.addEventListener("load", init);