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 9817a68a1b
commit 92dd35fd59
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> </style>
<script> <script>
var urls = ["scoreboard.html", "credits.html", "tanks.html"]; var SECS = 1000;
var urls = ["scoreboard.html"];
var stack = []; var stack = [];
var secs = 1000;
var i = 0; 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() { function reload() {
// alternate between scoreboard and other things // alternate between scoreboard and other things
if (i%2){ if (i%2){
@ -31,15 +41,24 @@ function reload() {
} }
else { else {
if (stack.length === 0){ if (stack.length === 0){
stack = urls.slice(1); xmlhttp.open("GET", "projections.json", true);
xmlhttp.send();
if (urls.length > 1){
stack = urls.slice(1);
}
else {
stack = urls;
}
} }
url = stack.pop(); url = stack.pop();
} }
console.log("loading " + url + " of " + urls);
document.getElementById("reloader").src = url; document.getElementById("reloader").src = url;
i++;
} }
function init() { function init() {
setInterval(reload, 60*secs); setInterval(reload, 2*SECS);
} }
window.addEventListener("load", init); window.addEventListener("load", init);