mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Merge pull request #795 from jerson/patch-6
Websocket: added GetTotalConnections, GetConnections and GetConnection Former-commit-id: b4a90a3b9d0dbdfcc740b7d84a3725abe76d9ff2
This commit is contained in:
commit
7372cfe38d
|
@ -106,7 +106,7 @@ type (
|
||||||
config Config
|
config Config
|
||||||
connections connections
|
connections connections
|
||||||
rooms map[string][]string // by default a connection is joined to a room which has the connection id as its name
|
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
|
onConnectionListeners []ConnectionFunc
|
||||||
//connectionPool sync.Pool // sadly we can't make this because the websocket connection is live until is closed.
|
//connectionPool sync.Pool // sadly we can't make this because the websocket connection is live until is closed.
|
||||||
handler context.Handler
|
handler context.Handler
|
||||||
|
@ -305,6 +305,30 @@ func (s *Server) leave(roomName string, connID string) (left bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTotalConnections returns the number of total connections
|
||||||
|
func (s *Server) GetTotalConnections() int {
|
||||||
|
s.mu.RLock()
|
||||||
|
l := len(s.connections)
|
||||||
|
s.mu.RUnlock()
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConnections returns all connections
|
||||||
|
func (s *Server) GetConnections() []Connection {
|
||||||
|
s.mu.RLock()
|
||||||
|
conns := make([]Connection, len(s.connections), len(s.connections))
|
||||||
|
for i, c := range s.connections {
|
||||||
|
conns[i] = c.value
|
||||||
|
}
|
||||||
|
s.mu.RUnlock()
|
||||||
|
return conns
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConnection returns single connection
|
||||||
|
func (s *Server) GetConnection(key string) Connection {
|
||||||
|
return s.connections.get(key)
|
||||||
|
}
|
||||||
|
|
||||||
// GetConnectionsByRoom returns a list of Connection
|
// GetConnectionsByRoom returns a list of Connection
|
||||||
// which are joined to this room.
|
// which are joined to this room.
|
||||||
func (s *Server) GetConnectionsByRoom(roomName string) []Connection {
|
func (s *Server) GetConnectionsByRoom(roomName string) []Connection {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user