fix: ws同组多用户

This commit is contained in:
TsMask
2024-01-30 17:19:36 +08:00
parent 84641c532a
commit 3c67c5fd59

View File

@@ -85,7 +85,17 @@ func (s *WSImpl) NewClient(uid string, groupIDs []string, conn *websocket.Conn)
for _, groupID := range groupIDs {
if v, ok := WsGroup.Load(groupID); ok {
groupUIDs := v.(*[]string)
// 避免同组内相同用户
hasUid := false
for _, uidv := range *groupUIDs {
if uidv == uid {
hasUid = true
break
}
}
if !hasUid {
*groupUIDs = append(*groupUIDs, uid)
}
} else {
WsGroup.Store(groupID, &[]string{uid})
}
@@ -145,6 +155,7 @@ func (s *WSImpl) clientWrite(wsClient *model.WSClient) {
s.CloseClient(wsClient.ID)
return
}
wsClient.LastHeartbeat = time.Now().UnixMilli()
}
}