fix: ws客户端读写保护/GroupID调整

This commit is contained in:
TsMask
2024-01-27 18:06:30 +08:00
parent 3a5c3edc70
commit 68f202d935
4 changed files with 17 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ func PostCDREventFromNF(w http.ResponseWriter, r *http.Request) {
}
// 推送到ws订阅组
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_CDR, cdrEvent)
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_IMS_CDR, cdrEvent)
services.ResponseStatusOK204NoContent(w)
}

View File

@@ -63,7 +63,7 @@ func PostUEEventFromAMF(c *gin.Context) {
}
// 推送到ws订阅组
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_UE, ueEvent)
wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_AMF_UE, ueEvent)
services.ResponseStatusOK204NoContent(c.Writer)
}

View File

@@ -14,12 +14,14 @@ import (
)
var (
// ws客户端读写互斥锁
mutex sync.Mutex
// ws客户端 [clientId: client]
WsClients = sync.Map{}
WsClients sync.Map
// ws用户对应的多个客户端id [uid:clientIds]
WsUsers = sync.Map{}
WsUsers sync.Map
// ws组对应的多个用户id [groupID:uids]
WsGroup = sync.Map{}
WsGroup sync.Map
)
// 实例化服务层 WSImpl 结构体
@@ -148,6 +150,7 @@ func (s *WSImpl) clientWrite(wsClient *model.WSClient) {
// CloseClient 客户端关闭
func (s *WSImpl) CloseClient(clientID string) {
mutex.Lock()
v, ok := WsClients.Load(clientID)
if !ok {
return
@@ -159,6 +162,7 @@ func (s *WSImpl) CloseClient(clientID string) {
client.Conn.Close()
client.StopChan <- struct{}{}
WsClients.Delete(clientID)
mutex.Unlock()
}()
// 客户端断线时自动踢出Uid绑定列表

View File

@@ -8,15 +8,18 @@ import (
"ems.agt/src/modules/ws/model"
)
// 订阅组指定编号为支持服务器向客户端主动推送数据
const (
// 组号-其他
GROUP_OTHER = "0"
// 组号-指标
GROUP_KPI = "1"
// 组号-CDR会话事件-IMS
GROUP_CDR = "1005"
// 组号-UE会话事件-AMF
GROUP_UE = "1010"
GROUP_KPI = "10"
// 组号-指标UPF
GROUP_KPI_UPF = "12"
// 组号-IMS_CDR会话事件
GROUP_IMS_CDR = "1005"
// 组号-AMF_UE会话事件
GROUP_AMF_UE = "1010"
)
// 实例化服务层 WSSendImpl 结构体