1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 19:42:20 +00:00

Count also the viewers that are streaming directly from their video player in the connected users stats

This commit is contained in:
Yohann D'ANELLO 2020-10-05 22:41:19 +02:00
parent 635081f269
commit 192c86f140
2 changed files with 9 additions and 2 deletions

View File

@ -46,6 +46,11 @@ func splitHostPort(hostport string) (string, uint16) {
return host, uint16(port64) return host, uint16(port64)
} }
// GetNumberConnectedSessions get the number of currently connected clients
func GetNumberConnectedSessions(streamID string) int {
return len(clientDataChannels[streamID])
}
// Serve SRT server // Serve SRT server
func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) { func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) {
// Start SRT in listening mode // Start SRT in listening mode

View File

@ -3,6 +3,7 @@ package web
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"gitlab.crans.org/nounous/ghostream/stream/srt"
"html/template" "html/template"
"log" "log"
"net" "net"
@ -133,11 +134,12 @@ func staticHandler() http.Handler {
} }
func statisticsHandler(w http.ResponseWriter, r *http.Request) { 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) enc := json.NewEncoder(w)
err := enc.Encode(struct { err := enc.Encode(struct {
ConnectedViewers int ConnectedViewers int
}{webrtc.GetNumberConnectedSessions(strings.Replace(r.URL.Path[7:], "/", "", -1))}) }{webrtc.GetNumberConnectedSessions(streamID) + srt.GetNumberConnectedSessions(streamID)})
if err != nil { if err != nil {
http.Error(w, "Failed to generate JSON.", http.StatusInternalServerError) http.Error(w, "Failed to generate JSON.", http.StatusInternalServerError)
log.Printf("Failed to generate JSON: %s", err) log.Printf("Failed to generate JSON: %s", err)