1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 19:12:07 +02:00

Refresh viewer counter every 20 seconds

This commit is contained in:
Yohann D'ANELLO
2020-09-29 18:25:38 +02:00
parent f8aa587d0e
commit 881c78f576
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,18 @@
function refreshViewersCounter() {
let xhr = new XMLHttpRequest()
xhr.open("GET", "/_stats/", true)
xhr.onload = function () {
console.log(xhr.response)
if (xhr.status === 200) {
let data = JSON.parse(xhr.response)
document.getElementById("connected-people").innerText = data.ConnectedViewers
}
else
console.log("WARNING: status code " + xhr.status + " was returned while fetching connected viewers.")
}
xhr.send()
setTimeout(refreshViewersCounter, 20000)
}
refreshViewersCounter()