diff --git a/stream/webrtc/webrtc.go b/stream/webrtc/webrtc.go index 6f2b0dd..4697560 100644 --- a/stream/webrtc/webrtc.go +++ b/stream/webrtc/webrtc.go @@ -38,8 +38,8 @@ func removeTrack(tracks []*webrtc.Track, track *webrtc.Track) []*webrtc.Track { } // GetNumberConnectedSessions get the number of currently connected clients -func GetNumberConnectedSessions() int { - return len(videoTracks) +func GetNumberConnectedSessions(streamID string) int { + return len(videoTracks[streamID]) } // newPeerHandler is called when server receive a new session description diff --git a/web/handler.go b/web/handler.go index 46f003d..b8282c4 100644 --- a/web/handler.go +++ b/web/handler.go @@ -137,7 +137,7 @@ func statisticsHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) err := enc.Encode(struct { ConnectedViewers int - }{webrtc.GetNumberConnectedSessions()}) + }{webrtc.GetNumberConnectedSessions(strings.Replace(r.URL.Path[7:], "/", "", -1))}) if err != nil { http.Error(w, "Failed to generate JSON.", http.StatusInternalServerError) log.Printf("Failed to generate JSON: %s", err) diff --git a/web/static/js/viewersCounter.js b/web/static/js/viewersCounter.js index 8d12798..2b0ba2b 100644 --- a/web/static/js/viewersCounter.js +++ b/web/static/js/viewersCounter.js @@ -1,6 +1,7 @@ // Refresh viewer count by pulling metric from server function refreshViewersCounter(period) { - fetch("/_stats/") + // Distinguish oneDomainPerStream mode + fetch("/_stats/" + (location.pathname === "/" ? location.host : location.pathname.substring(1))) .then(response => response.json()) .then((data) => document.getElementById("connected-people").innerText = data.ConnectedViewers) .catch(console.log)