From 4de2841659f5539c2f1b32f6946811bc0e5b97be Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Thu, 5 Nov 2020 00:14:51 -0800 Subject: [PATCH] Remove stale client purging. Use sockets to count clients. #323 --- controllers/index.go | 4 ---- core/chat/client.go | 2 +- core/chat/server.go | 2 +- core/stats.go | 23 ----------------------- 4 files changed, 2 insertions(+), 29 deletions(-) diff --git a/controllers/index.go b/controllers/index.go index f83a6b059..7f11ea4d9 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -13,7 +13,6 @@ import ( "github.com/owncast/owncast/config" "github.com/owncast/owncast/core" - "github.com/owncast/owncast/models" "github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/utils" ) @@ -47,9 +46,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { if path.Ext(r.URL.Path) == ".m3u8" { middleware.DisableCache(w) - - client := models.GenerateClientFromRequest(r) - core.SetClientActive(client) } // Set a cache control max-age header diff --git a/core/chat/client.go b/core/chat/client.go index cd7018cdf..361d788e7 100644 --- a/core/chat/client.go +++ b/core/chat/client.go @@ -57,8 +57,8 @@ func NewClient(ws *websocket.Conn) *Client { ipAddress := utils.GetIPAddressFromRequest(ws.Request()) userAgent := ws.Request().UserAgent() - clientID := utils.GenerateClientIDFromRequest(ws.Request()) socketID, _ := shortid.Generate() + clientID := socketID return &Client{time.Now(), 0, userAgent, ipAddress, nil, clientID, nil, socketID, ws, ch, pingch, usernameChangeChannel, doneCh} } diff --git a/core/chat/server.go b/core/chat/server.go index 15c6a37c2..096c743bd 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -108,7 +108,7 @@ func (s *server) Listen() { // remove a client case c := <-s.delCh: delete(s.Clients, c.socketID) - s.listener.ClientRemoved(c.ClientID) + s.listener.ClientRemoved(c.socketID) // message was recieved from a client and should be sanitized, validated // and distributed to other clients. diff --git a/core/stats.go b/core/stats.go index 30d7e6fad..2d180db62 100644 --- a/core/stats.go +++ b/core/stats.go @@ -43,32 +43,9 @@ func setupStats() error { } }() - staleViewerPurgeTimer := time.NewTicker(3 * time.Second) - go func() { - for { - select { - case <-staleViewerPurgeTimer.C: - purgeStaleViewers() - } - } - }() - return nil } -func purgeStaleViewers() { - for clientID, client := range _stats.Clients { - if client.LastSeen.IsZero() { - continue - } - - timeSinceLastActive := time.Since(client.LastSeen).Minutes() - if timeSinceLastActive > 1 { - RemoveClient(clientID) - } - } -} - //IsStreamConnected checks if the stream is connected or not func IsStreamConnected() bool { if !_stats.StreamConnected {