2024-11-20 20:50:43 +00:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Check and remove stale clients
|
|
|
|
func RemoveStaleClients() {
|
|
|
|
ticker := time.NewTicker(30 * time.Second)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for range ticker.C {
|
|
|
|
mu.Lock()
|
|
|
|
for _, client := range Clients {
|
|
|
|
if client.IsStale() {
|
|
|
|
client.Conn.Close()
|
2024-11-20 21:01:56 +00:00
|
|
|
delete(Clients, client.Conn.LocalAddr())
|
2024-11-20 20:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mu.Unlock()
|
|
|
|
}
|
|
|
|
}
|