Connected clients admin API (#217)
* Add support for ending the inbound stream. Closes #191 * Add a simple success response to API requests * Connected clients API with geo details * Post-rebase cleanup * Make setting and reading geo details separate operations to unblock and speed up * Rename file * Fire geoip api call behind goroutine * Add comment * Post-rebase fixes * Add support for the MaxMind GeoLite2 GeoIP database
This commit is contained in:
@@ -79,7 +79,7 @@ func (s *server) onConnection(ws *websocket.Conn) {
|
||||
client := NewClient(ws)
|
||||
|
||||
defer func() {
|
||||
log.Tracef("The client was connected for %s and sent %d messages (%s)", time.Since(client.ConnectedAt), client.MessageCount, client.clientID)
|
||||
log.Tracef("The client was connected for %s and sent %d messages (%s)", time.Since(client.ConnectedAt), client.MessageCount, client.ClientID)
|
||||
|
||||
if err := ws.Close(); err != nil {
|
||||
s.errCh <- err
|
||||
@@ -102,13 +102,13 @@ func (s *server) Listen() {
|
||||
// add new a client
|
||||
case c := <-s.addCh:
|
||||
s.Clients[c.socketID] = c
|
||||
s.listener.ClientAdded(c.clientID)
|
||||
s.listener.ClientAdded(c.GetViewerClientFromChatClient())
|
||||
s.sendWelcomeMessageToClient(c)
|
||||
|
||||
// remove a client
|
||||
case c := <-s.delCh:
|
||||
delete(s.Clients, c.socketID)
|
||||
s.listener.ClientRemoved(c.clientID)
|
||||
s.listener.ClientRemoved(c.ClientID)
|
||||
|
||||
// broadcast a message to all clients
|
||||
case msg := <-s.sendAllCh:
|
||||
@@ -138,3 +138,13 @@ func (s *server) sendWelcomeMessageToClient(c *Client) {
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
func (s *server) getClientForClientID(clientID string) *Client {
|
||||
for _, client := range s.Clients {
|
||||
if client.ClientID == clientID {
|
||||
return client
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user