gr
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user