mirror of https://github.com/1Panel-dev/1Panel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
710 B
39 lines
710 B
package websocket
|
|
|
|
import "sync"
|
|
|
|
type Manager struct {
|
|
Group map[string]*Client
|
|
Lock sync.Mutex
|
|
Register, UnRegister chan *Client
|
|
ClientCount uint
|
|
}
|
|
|
|
func (m *Manager) Start() {
|
|
for {
|
|
select {
|
|
case client := <-m.Register:
|
|
m.Lock.Lock()
|
|
m.Group[client.ID] = client
|
|
m.ClientCount++
|
|
m.Lock.Unlock()
|
|
case client := <-m.UnRegister:
|
|
m.Lock.Lock()
|
|
if _, ok := m.Group[client.ID]; ok {
|
|
close(client.Msg)
|
|
delete(m.Group, client.ID)
|
|
m.ClientCount--
|
|
}
|
|
m.Lock.Unlock()
|
|
}
|
|
}
|
|
}
|
|
|
|
func (m *Manager) RegisterClient(client *Client) {
|
|
m.Register <- client
|
|
}
|
|
|
|
func (m *Manager) UnRegisterClient(client *Client) {
|
|
m.UnRegister <- client
|
|
}
|