aa
This commit is contained in:
@@ -37,7 +37,6 @@ const (
|
||||
type WSClient struct {
|
||||
Clients map[int]map[string]*websocket.Conn
|
||||
ClientsHeart map[string]*websocket.Conn
|
||||
s *sync.RWMutex
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -45,7 +44,6 @@ func init() {
|
||||
clientsHeart := make(map[string]*websocket.Conn)
|
||||
wsClient.Clients = clients
|
||||
wsClient.ClientsHeart = clientsHeart
|
||||
wsClient.s = new(sync.RWMutex)
|
||||
|
||||
go handleMessages()
|
||||
}
|
||||
@@ -101,7 +99,6 @@ func ImMessage(userID string, ws *websocket.Conn) (err error) {
|
||||
if len(messageGroups) == 0 {
|
||||
return
|
||||
}
|
||||
wsClient.s.Lock()
|
||||
clientUser[userID] = ws
|
||||
wsClient.ClientsHeart[userID] = ws
|
||||
for _, v := range messageGroups {
|
||||
@@ -111,7 +108,6 @@ func ImMessage(userID string, ws *websocket.Conn) (err error) {
|
||||
wsClient.Clients[v.GroupID] = clientUser
|
||||
}
|
||||
}
|
||||
wsClient.s.Unlock()
|
||||
globals.SugarLogger.Debugf("userID :%v ,clients :%v", userID, utils.Format4Output(wsClient.Clients, false))
|
||||
|
||||
var s *model.ImMessageRecord
|
||||
@@ -174,9 +170,10 @@ func ImMessage(userID string, ws *websocket.Conn) (err error) {
|
||||
}
|
||||
|
||||
func GetOnlineUserCount() (count int) {
|
||||
wsClient.s.RLock()
|
||||
defer wsClient.s.RUnlock()
|
||||
s := new(sync.RWMutex)
|
||||
s.Lock()
|
||||
count = len(wsClient.ClientsHeart)
|
||||
s.Unlock()
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -709,9 +706,7 @@ func SendSysMessage(ctx *jxcontext.Context, imMessageRecord *model.ImMessageReco
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wsClient.s.RLock()
|
||||
client := wsClient.Clients[groupID][userID]
|
||||
wsClient.s.RUnlock()
|
||||
globals.SugarLogger.Debugf("msg %v", utils.Format4Output(imMessageRecord, false))
|
||||
if client == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user