diff --git a/README.md b/README.md index b6f4d7ac..13d762a7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ For n.eko room management software visit https://github.com/m1k1o/neko-rooms. - Added `VIDEO_BITRATE` and `AUDIO_BITRATE` in kbit/s to control stream quality (in collaboration with @mbattista). - Added `MAX_FPS`, where you can specify max WebRTC frame rate. When set to `0`, frame rate won't be capped and you can enjoy your real `60fps` experience. Originally, it was constant at `25fps`. - Invite links. You can invite people and they don't need to enter passwords by themselves (and get confused about user accounts that do not exits). You can put your password in URL using `?pwd=` and it will be automatically used when logging in. -- Added `/stats?pwd=` endpoint to get total active connections. +- Added `/stats?pwd=` endpoint to get total active connections, host and members. ### Bugs - Fixed minor gst pipeline bug. diff --git a/server/internal/http/http.go b/server/internal/http/http.go index 5e4be6de..810dddd8 100644 --- a/server/internal/http/http.go +++ b/server/internal/http/http.go @@ -51,11 +51,9 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server { } w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(struct{ - Connections uint32 `json:"connections"` - }{ - Connections: webSocketHandler.TotalConns(), - }); err != nil { + + stats := webSocketHandler.Stats() + if err := json.NewEncoder(w).Encode(stats); err != nil { logger.Warn().Err(err).Msg("failed writing json error response") } }) diff --git a/server/internal/types/webscoket.go b/server/internal/types/webscoket.go index e15967b9..c884c771 100644 --- a/server/internal/types/webscoket.go +++ b/server/internal/types/webscoket.go @@ -2,6 +2,12 @@ package types import "net/http" +type Stats struct { + Connections uint32 `json:"connections"` + Host string `json:"host"` + Members []*Member `json:"members"` +} + type WebSocket interface { Address() string Send(v interface{}) error @@ -12,6 +18,6 @@ type WebSocketHandler interface { Start() error Shutdown() error Upgrade(w http.ResponseWriter, r *http.Request) error - TotalConns() uint32 + Stats() Stats IsAdmin(password string) (bool, error) } diff --git a/server/internal/websocket/websocket.go b/server/internal/websocket/websocket.go index 526b84c6..a93045ee 100644 --- a/server/internal/websocket/websocket.go +++ b/server/internal/websocket/websocket.go @@ -198,8 +198,18 @@ func (ws *WebSocketHandler) Upgrade(w http.ResponseWriter, r *http.Request) erro return nil } -func (ws *WebSocketHandler) TotalConns() uint32 { - return atomic.LoadUint32(&ws.conns) +func (ws *WebSocketHandler) Stats() types.Stats { + host := "" + session, ok := ws.sessions.GetHost() + if ok { + host = session.ID() + } + + return types.Stats{ + Connections: atomic.LoadUint32(&ws.conns), + Host: host, + Members: ws.sessions.Members(), + } } func (ws *WebSocketHandler) IsAdmin(password string) (bool, error) {