1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-23 05:02:20 +00:00
ghostream/web/static/js/modules/viewerCounter.js
2020-10-21 22:38:36 +02:00

30 lines
720 B
JavaScript

/**
* ViewerCounter show the number of active viewers
*/
export class ViewerCounter {
/**
* @param {HTMLElement} element
* @param {String} streamName
*/
constructor(element, streamName) {
this.element = element;
this.url = "/_stats/" + streamName;
}
/**
* Regulary update counter
*
* @param {Number} updatePeriod
*/
regularUpdate(updatePeriod) {
setInterval(() => this.refreshViewersCounter(), updatePeriod);
}
refreshViewersCounter() {
fetch(this.url)
.then(response => response.json())
.then((data) => this.element.innerText = data.ConnectedViewers)
.catch(console.log);
}
}