1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 23:12:20 +00:00

Use fetch API to fetch viewers count

This commit is contained in:
Alexandre Iooss 2020-09-30 15:56:24 +02:00
parent 9fe544b7bc
commit ac40d81e98
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02

View File

@ -1,17 +1,9 @@
// Refresh viewer count by pulling metric from server // Refresh viewer count by pulling metric from server
function refreshViewersCounter(period) { function refreshViewersCounter(period) {
let xhr = new XMLHttpRequest() fetch("/_stats/")
xhr.open("GET", "/_stats/", true) .then(response => response.json())
xhr.onload = function () { .then((data) => document.getElementById("connected-people").innerText = data.ConnectedViewers)
console.log(xhr.response) .catch(console.log)
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(() => { setTimeout(() => {
refreshViewersCounter(period) refreshViewersCounter(period)