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