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)
|
neInfo := neService.NewNeInfoImpl.SelectNeInfoByRmuid(cdrEvent.RmUID)
|
||||||
if neInfo.RmUID == cdrEvent.RmUID {
|
if neInfo.RmUID == cdrEvent.RmUID {
|
||||||
// 推送到ws订阅组
|
// 推送到ws订阅组
|
||||||
switch neType {
|
switch neInfo.NeType {
|
||||||
case "IMS":
|
case "IMS":
|
||||||
if v, ok := cdrEvent.CDR["recordType"]; ok && (v == "MOC" || v == "MTSM") {
|
if v, ok := cdrEvent.CDR["recordType"]; ok && (v == "MOC" || v == "MTSM") {
|
||||||
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_IMS_CDR+neInfo.NeId, cdrEvent)
|
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_IMS_CDR+neInfo.NeId, cdrEvent)
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ type IWSSend interface {
|
|||||||
// ByClientID 给已知客户端发消息
|
// ByClientID 给已知客户端发消息
|
||||||
ByClientID(clientID string, data any) error
|
ByClientID(clientID string, data any) error
|
||||||
|
|
||||||
// ByGroupID 给订阅组的用户发送消息
|
// ByGroupID 给订阅组的客户端发送消息
|
||||||
ByGroupID(gid string, data any) error
|
ByGroupID(gid string, data any) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,36 +55,28 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByGroupID 给订阅组的用户发送消息
|
// ByGroupID 给订阅组的客户端发送消息
|
||||||
func (s *WSSendImpl) ByGroupID(groupID string, data any) error {
|
func (s *WSSendImpl) ByGroupID(groupID string, data any) error {
|
||||||
uids, ok := wsGroup.Load(groupID)
|
clientIds, ok := wsGroup.Load(groupID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("no fount Group ID: %s", groupID)
|
return fmt.Errorf("no fount Group ID: %s", groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
groupUids := uids.(*[]string)
|
// 检查组内是否有客户端
|
||||||
// 群组中没有成员
|
ids := clientIds.(*[]string)
|
||||||
if len(*groupUids) == 0 {
|
if len(*ids) == 0 {
|
||||||
return fmt.Errorf("no members in the group")
|
return fmt.Errorf("no members in the group")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在群组中找到对应的 uid
|
// 遍历给客户端发消息
|
||||||
for _, uid := range *groupUids {
|
for _, clientId := range *ids {
|
||||||
clientIds, ok := wsUsers.Load(uid)
|
err := s.ByClientID(clientId, map[string]any{
|
||||||
if !ok {
|
"groupId": groupID,
|
||||||
|
"data": data,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
continue
|
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
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user