mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-07-04 21:54:04 +02:00
viewerCounter and websocket JS modules
This commit is contained in:
29
web/static/js/modules/viewerCounter.js
Normal file
29
web/static/js/modules/viewerCounter.js
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user