diff --git a/web/static/js/main.js b/web/static/js/main.js index 3e7ec0b..48b3020 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -58,6 +58,7 @@ export function initViewerPage(stream, stunServers, viewersCounterRefreshPeriod) stream, ); viewerCounter.regularUpdate(viewersCounterRefreshPeriod); + viewerCounter.refreshViewersCounter(); // Side widget toggler const sideWidgetToggle = document.getElementById("sideWidgetToggle"); diff --git a/web/static/js/modules/viewerCounter.js b/web/static/js/modules/viewerCounter.js index 9c26d29..b95bf38 100644 --- a/web/static/js/modules/viewerCounter.js +++ b/web/static/js/modules/viewerCounter.js @@ -17,10 +17,10 @@ export class ViewerCounter { * @param {Number} updatePeriod */ regularUpdate(updatePeriod) { - setInterval(this._refreshViewersCounter, updatePeriod); + setInterval(() => this.refreshViewersCounter(), updatePeriod); } - _refreshViewersCounter() { + refreshViewersCounter() { fetch(this.url) .then(response => response.json()) .then((data) => this.element.innerText = data.ConnectedViewers) diff --git a/web/static/js/modules/webrtc.js b/web/static/js/modules/webrtc.js index b6e5366..fea8037 100644 --- a/web/static/js/modules/webrtc.js +++ b/web/static/js/modules/webrtc.js @@ -17,8 +17,8 @@ export class GsWebRTC { this.pc.addTransceiver("audio", { "direction": "sendrecv" }); // Configure events - this.pc.oniceconnectionstatechange = this._onConnectionStateChange; - this.pc.ontrack = this._onTrack; + this.pc.oniceconnectionstatechange = () => this._onConnectionStateChange(); + this.pc.ontrack = (e) => this._onTrack(e); } /** diff --git a/web/static/js/modules/websocket.js b/web/static/js/modules/websocket.js index 940cc96..0f33a84 100644 --- a/web/static/js/modules/websocket.js +++ b/web/static/js/modules/websocket.js @@ -23,11 +23,11 @@ export class GsWebSocket { }); this.socket.addEventListener("close", () => { console.log("WebSocket closed, retrying connection in 1s..."); - setTimeout(this._open, 1000); + setTimeout(() => this._open(), 1000); }); this.socket.addEventListener("error", () => { console.log("WebSocket errored, retrying connection in 1s..."); - setTimeout(this._open, 1000); + setTimeout(() => this._open(), 1000); }); }