Archived
2
0

add members & host to stats.

This commit is contained in:
m1k1o 2021-03-19 22:06:40 +01:00
parent bbae073104
commit b96ba47224
4 changed files with 23 additions and 9 deletions

View File

@ -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=<your-password>` and it will be automatically used when logging in.
- Added `/stats?pwd=<admin>` endpoint to get total active connections.
- Added `/stats?pwd=<admin>` endpoint to get total active connections, host and members.
### Bugs
- Fixed minor gst pipeline bug.

View File

@ -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")
}
})

View File

@ -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)
}

View File

@ -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) {