This commit is contained in:
Bel LaPointe
2024-02-20 11:35:11 -07:00
parent ce1c1e0205
commit 74830411d0
3 changed files with 60 additions and 7 deletions

View File

@@ -7,5 +7,48 @@
<h1>Hello World</h1>
</body>
<footer>
<script>
let g_questions = [];
let g_live_question = {};
function pollState() {
http("GET", "/api/v1/questions", (body) => {
g_questions = JSON.parse(body);
console.log("polled state:", body);
pollLiveAnswer();
pollLiveQuestion();
});
}
function pollLiveQuestion() {
let live_questions = g_questions.filter((q) => q.Live);
if (live_questions) {
g_live_question = live_questions[0];
}
}
function pollLiveAnswer() {
if (!g_live_question || !g_live_question.Closed) {
return;
}
}
function http(method, remote, callback, body) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
callback(xmlhttp.responseText, xmlhttp.status)
}
};
xmlhttp.open(method, remote, true);
if(typeof body == "undefined") {
body = null
}
xmlhttp.send(body);
}
pollState();
setInterval(() => { pollState(); }, 1000);
</script>
</footer>
</html>