Remove stale client purging. Use sockets to count clients. #323
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/core"
|
"github.com/owncast/owncast/core"
|
||||||
"github.com/owncast/owncast/models"
|
|
||||||
"github.com/owncast/owncast/router/middleware"
|
"github.com/owncast/owncast/router/middleware"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
)
|
)
|
||||||
@@ -47,9 +46,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if path.Ext(r.URL.Path) == ".m3u8" {
|
if path.Ext(r.URL.Path) == ".m3u8" {
|
||||||
middleware.DisableCache(w)
|
middleware.DisableCache(w)
|
||||||
|
|
||||||
client := models.GenerateClientFromRequest(r)
|
|
||||||
core.SetClientActive(client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a cache control max-age header
|
// Set a cache control max-age header
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ func NewClient(ws *websocket.Conn) *Client {
|
|||||||
|
|
||||||
ipAddress := utils.GetIPAddressFromRequest(ws.Request())
|
ipAddress := utils.GetIPAddressFromRequest(ws.Request())
|
||||||
userAgent := ws.Request().UserAgent()
|
userAgent := ws.Request().UserAgent()
|
||||||
clientID := utils.GenerateClientIDFromRequest(ws.Request())
|
|
||||||
socketID, _ := shortid.Generate()
|
socketID, _ := shortid.Generate()
|
||||||
|
clientID := socketID
|
||||||
|
|
||||||
return &Client{time.Now(), 0, userAgent, ipAddress, nil, clientID, nil, socketID, ws, ch, pingch, usernameChangeChannel, doneCh}
|
return &Client{time.Now(), 0, userAgent, ipAddress, nil, clientID, nil, socketID, ws, ch, pingch, usernameChangeChannel, doneCh}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (s *server) Listen() {
|
|||||||
// remove a client
|
// remove a client
|
||||||
case c := <-s.delCh:
|
case c := <-s.delCh:
|
||||||
delete(s.Clients, c.socketID)
|
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
|
// message was recieved from a client and should be sanitized, validated
|
||||||
// and distributed to other clients.
|
// and distributed to other clients.
|
||||||
|
|||||||
@@ -43,32 +43,9 @@ func setupStats() error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
staleViewerPurgeTimer := time.NewTicker(3 * time.Second)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-staleViewerPurgeTimer.C:
|
|
||||||
purgeStaleViewers()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
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
|
//IsStreamConnected checks if the stream is connected or not
|
||||||
func IsStreamConnected() bool {
|
func IsStreamConnected() bool {
|
||||||
if !_stats.StreamConnected {
|
if !_stats.StreamConnected {
|
||||||
|
|||||||
Reference in New Issue
Block a user