mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Websocket: added GetTotalConnections, GetConnections and GetConnection
Former-commit-id: fddddcdebd2a72ca082223bd29638a13ae6c0343
This commit is contained in:
parent
dd5b293011
commit
6f1d1d2fea
|
@ -106,7 +106,7 @@ type (
|
|||
config Config
|
||||
connections connections
|
||||
rooms map[string][]string // by default a connection is joined to a room which has the connection id as its name
|
||||
mu sync.Mutex // for rooms
|
||||
mu sync.RWMutex // for rooms
|
||||
onConnectionListeners []ConnectionFunc
|
||||
//connectionPool sync.Pool // sadly we can't make this because the websocket connection is live until is closed.
|
||||
handler context.Handler
|
||||
|
@ -305,6 +305,31 @@ func (s *Server) leave(roomName string, connID string) (left bool) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetTotalConnections returns the number of total connections
|
||||
func (s *Server) GetTotalConnections() int {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return len(s.connections)
|
||||
}
|
||||
|
||||
// GetConnections returns all connections
|
||||
func (s *Server) GetConnections() []Connection {
|
||||
s.mu.Lock()
|
||||
var conns []Connection
|
||||
for _, conn := range s.connections {
|
||||
conns = append(conns, conn.value)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
return conns
|
||||
}
|
||||
|
||||
// GetConnection returns single connection
|
||||
func (s *Server) GetConnection(key string) Connection {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.connections.get(key)
|
||||
}
|
||||
|
||||
// GetConnectionsByRoom returns a list of Connection
|
||||
// which are joined to this room.
|
||||
func (s *Server) GetConnectionsByRoom(roomName string) []Connection {
|
||||
|
|
Loading…
Reference in New Issue
Block a user