diff --git a/src/modules/ws/service/ws.impl.go b/src/modules/ws/service/ws.impl.go index 447438b0..36409894 100644 --- a/src/modules/ws/service/ws.impl.go +++ b/src/modules/ws/service/ws.impl.go @@ -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) - *groupUIDs = append(*groupUIDs, uid) + // 避免同组内相同用户 + 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() } } diff --git a/src/modules/ws/service/ws_send.impl.go b/src/modules/ws/service/ws_send.impl.go index 62b7601a..8db8fcd9 100644 --- a/src/modules/ws/service/ws_send.impl.go +++ b/src/modules/ws/service/ws_send.impl.go @@ -41,6 +41,10 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error { } 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 return nil }