This commit is contained in:
2024-01-30 18:12:39 +08:00
2 changed files with 16 additions and 1 deletions

View File

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

View File

@@ -41,6 +41,10 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error {
} }
client := v.(*model.WSClient) client := v.(*model.WSClient)
if len(client.MsgChan) > 90 {
NewWSImpl.CloseClient(client.ID)
return fmt.Errorf("msg chan over 90 will close client ID: %s", clientID)
}
client.MsgChan <- dataByte client.MsgChan <- dataByte
return nil return nil
} }