fix
This commit is contained in:
parent
4c62b941a0
commit
5b88e97307
@ -95,15 +95,15 @@ func ConsumeCommonCacheData(ctx context.Context) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
searchConnectType := "uniqueId"
|
searchConnectType := 1
|
||||||
if req.Wid == "" {
|
if req.Wid == "" {
|
||||||
if req.UserId == 0 && req.GuestId == 0 {
|
if req.UserId == 0 && req.GuestId == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "用户信息或者连接标识必须保证至少有其中一个")
|
return resp.SetStatusWithMessage(basic.CodeOK, "用户信息或者连接标识必须保证至少有其中一个")
|
||||||
}
|
}
|
||||||
searchConnectType = "userInfo"
|
searchConnectType = 2
|
||||||
}
|
}
|
||||||
switch searchConnectType {
|
switch searchConnectType {
|
||||||
case "uniqueId": //直接通过唯一标识发消息
|
case 1: //直接通过唯一标识发消息
|
||||||
//查询websocket连接
|
//查询websocket连接
|
||||||
value, ok := mapConnPool.Load(req.Wid)
|
value, ok := mapConnPool.Load(req.Wid)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -124,7 +124,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a
|
|||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误")
|
||||||
}
|
}
|
||||||
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, req.Data))
|
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))
|
sendToOutChanByUserIndex(req.UserId, req.GuestId, (&wsConnectItem{}).respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, req.Data))
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||||
|
@ -274,19 +274,22 @@ func ConsumeUserPoolData(ctx context.Context) {
|
|||||||
key := getmapUserConnPoolUniqueId(data.userId, data.guestId)
|
key := getmapUserConnPoolUniqueId(data.userId, data.guestId)
|
||||||
switch data.option {
|
switch data.option {
|
||||||
case 2: //发送消息
|
case 2: //发送消息
|
||||||
logx.Info("通过用户id索引发送消息:", data.uniqueId)
|
logx.Info("通过用户id索引发送消息")
|
||||||
mapUserUniqueId, ok := mapUserConnPool[key]
|
mapUserUniqueId, ok := mapUserConnPool[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", key)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for uniqueId, _ := range mapUserUniqueId {
|
for uniqueId, _ := range mapUserUniqueId {
|
||||||
//根据uniqueId查询原始池中连接
|
//根据uniqueId查询原始池中连接
|
||||||
mapConnPoolVal, ok := mapConnPool.Load(uniqueId)
|
mapConnPoolVal, ok := mapConnPool.Load(uniqueId)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", key, " 原始uniqueId:", uniqueId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
originConn, ok := mapConnPoolVal.(wsConnectItem)
|
originConn, ok := mapConnPoolVal.(wsConnectItem)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
logx.Error("通过用户id索引发送消息,断言原始连接失败,用户索引key:", key, " 原始uniqueId:", uniqueId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
originConn.sendToOutChan(data.message)
|
originConn.sendToOutChan(data.message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user