diff --git a/stream/srt/srt.go b/stream/srt/srt.go index c05d15e..c9893c1 100644 --- a/stream/srt/srt.go +++ b/stream/srt/srt.go @@ -46,6 +46,11 @@ func splitHostPort(hostport string) (string, uint16) { return host, uint16(port64) } +// GetNumberConnectedSessions get the number of currently connected clients +func GetNumberConnectedSessions(streamID string) int { + return len(clientDataChannels[streamID]) +} + // Serve SRT server func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) { // Start SRT in listening mode diff --git a/web/handler.go b/web/handler.go index b8282c4..f27dd74 100644 --- a/web/handler.go +++ b/web/handler.go @@ -3,6 +3,7 @@ package web import ( "bytes" "encoding/json" + "gitlab.crans.org/nounous/ghostream/stream/srt" "html/template" "log" "net" @@ -133,11 +134,12 @@ func staticHandler() http.Handler { } func statisticsHandler(w http.ResponseWriter, r *http.Request) { - // Display connected users stats + // Display connected users stats, from WebRTC or streaming directly from a video player + streamID := strings.Replace(r.URL.Path[7:], "/", "", -1) enc := json.NewEncoder(w) err := enc.Encode(struct { ConnectedViewers int - }{webrtc.GetNumberConnectedSessions(strings.Replace(r.URL.Path[7:], "/", "", -1))}) + }{webrtc.GetNumberConnectedSessions(streamID) + srt.GetNumberConnectedSessions(streamID)}) if err != nil { http.Error(w, "Failed to generate JSON.", http.StatusInternalServerError) log.Printf("Failed to generate JSON: %s", err)