diff --git a/features/cdr/cdrevent.go b/features/cdr/cdrevent.go index 7214f179..9d73a265 100644 --- a/features/cdr/cdrevent.go +++ b/features/cdr/cdrevent.go @@ -59,7 +59,7 @@ func PostCDREventFrom(w http.ResponseWriter, r *http.Request) { neInfo := neService.NewNeInfoImpl.SelectNeInfoByRmuid(cdrEvent.RmUID) if neInfo.RmUID == cdrEvent.RmUID { // 推送到ws订阅组 - switch neType { + switch neInfo.NeType { case "IMS": if v, ok := cdrEvent.CDR["recordType"]; ok && (v == "MOC" || v == "MTSM") { wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_IMS_CDR+neInfo.NeId, cdrEvent) diff --git a/src/modules/ws/service/ws_send.go b/src/modules/ws/service/ws_send.go index 020d022a..91e48b14 100644 --- a/src/modules/ws/service/ws_send.go +++ b/src/modules/ws/service/ws_send.go @@ -5,6 +5,6 @@ type IWSSend interface { // ByClientID 给已知客户端发消息 ByClientID(clientID string, data any) error - // ByGroupID 给订阅组的用户发送消息 + // ByGroupID 给订阅组的客户端发送消息 ByGroupID(gid string, data any) error } diff --git a/src/modules/ws/service/ws_send.impl.go b/src/modules/ws/service/ws_send.impl.go index 88035523..cdf5b079 100644 --- a/src/modules/ws/service/ws_send.impl.go +++ b/src/modules/ws/service/ws_send.impl.go @@ -55,36 +55,28 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error { return nil } -// ByGroupID 给订阅组的用户发送消息 +// ByGroupID 给订阅组的客户端发送消息 func (s *WSSendImpl) ByGroupID(groupID string, data any) error { - uids, ok := wsGroup.Load(groupID) + clientIds, ok := wsGroup.Load(groupID) if !ok { return fmt.Errorf("no fount Group ID: %s", groupID) } - groupUids := uids.(*[]string) - // 群组中没有成员 - if len(*groupUids) == 0 { + // 检查组内是否有客户端 + ids := clientIds.(*[]string) + if len(*ids) == 0 { return fmt.Errorf("no members in the group") } - // 在群组中找到对应的 uid - for _, uid := range *groupUids { - clientIds, ok := wsUsers.Load(uid) - if !ok { + // 遍历给客户端发消息 + for _, clientId := range *ids { + err := s.ByClientID(clientId, map[string]any{ + "groupId": groupID, + "data": data, + }) + if err != nil { continue } - // 在用户中找到客户端并发送 - uidClientIds := clientIds.(*[]string) - for _, clientId := range *uidClientIds { - err := s.ByClientID(clientId, map[string]any{ - "groupId": groupID, - "data": data, - }) - if err != nil { - continue - } - } } return nil