Separate statistics per stream
This commit is contained in:
parent
022f6fb098
commit
0a1329b929
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue