fix: ws订阅组消息发送客户端读取失败导致消息丢失
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -5,6 +5,6 @@ type IWSSend interface {
|
||||
// ByClientID 给已知客户端发消息
|
||||
ByClientID(clientID string, data any) error
|
||||
|
||||
// ByGroupID 给订阅组的用户发送消息
|
||||
// ByGroupID 给订阅组的客户端发送消息
|
||||
ByGroupID(gid string, data any) error
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user