This commit is contained in:
laodaming 2023-09-04 15:17:30 +08:00
parent 4c62b941a0
commit 5b88e97307
2 changed files with 8 additions and 5 deletions

View File

@ -95,15 +95,15 @@ func ConsumeCommonCacheData(ctx context.Context) {
// }
func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
searchConnectType := "uniqueId"
searchConnectType := 1
if req.Wid == "" {
if req.UserId == 0 && req.GuestId == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "用户信息或者连接标识必须保证至少有其中一个")
}
searchConnectType = "userInfo"
searchConnectType = 2
}
switch searchConnectType {
case "uniqueId": //直接通过唯一标识发消息
case 1: //直接通过唯一标识发消息
//查询websocket连接
value, ok := mapConnPool.Load(req.Wid)
if !ok {
@ -124,7 +124,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误")
}
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, req.Data))
case "userInfo": //通过用户信息找连接发送
case 2: //通过用户信息找连接发送
sendToOutChanByUserIndex(req.UserId, req.GuestId, (&wsConnectItem{}).respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, req.Data))
}
return resp.SetStatusWithMessage(basic.CodeOK, "success")

View File

@ -274,19 +274,22 @@ func ConsumeUserPoolData(ctx context.Context) {
key := getmapUserConnPoolUniqueId(data.userId, data.guestId)
switch data.option {
case 2: //发送消息
logx.Info("通过用户id索引发送消息", data.uniqueId)
logx.Info("通过用户id索引发送消息")
mapUserUniqueId, ok := mapUserConnPool[key]
if !ok {
logx.Info("通过用户id索引发送消息,连接不存在用户索引key:", key)
continue
}
for uniqueId, _ := range mapUserUniqueId {
//根据uniqueId查询原始池中连接
mapConnPoolVal, ok := mapConnPool.Load(uniqueId)
if !ok {
logx.Info("通过用户id索引发送消息,连接不存在用户索引key:", key, " 原始uniqueId:", uniqueId)
continue
}
originConn, ok := mapConnPoolVal.(wsConnectItem)
if !ok {
logx.Error("通过用户id索引发送消息,断言原始连接失败用户索引key:", key, " 原始uniqueId:", uniqueId)
continue
}
originConn.sendToOutChan(data.message)