1
This commit is contained in:
parent
bc3719065b
commit
6fe3c5148e
@ -285,28 +285,32 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
|
|||||||
panic("ConsumeUserConnPoolCtlChanData ctx deadline")
|
panic("ConsumeUserConnPoolCtlChanData ctx deadline")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
var (
|
||||||
|
data userConnPoolCtlChanItem
|
||||||
|
userKey string
|
||||||
|
)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case data := <-userConnPoolCtlChan:
|
case data = <-userConnPoolCtlChan:
|
||||||
key := getmapUserConnPoolUniqueId(data.userId, data.guestId)
|
userKey = getmapUserConnPoolUniqueId(data.userId, data.guestId)
|
||||||
switch data.option {
|
switch data.option {
|
||||||
case 2: //发送消息
|
case 2: //发送消息
|
||||||
logx.Info("通过用户id索引发送消息")
|
logx.Info("通过用户id索引发送消息")
|
||||||
mapUserUniqueId, ok := mapUserConnPool[key]
|
mapUserUniqueId, ok := mapUserConnPool[userKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", key)
|
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", userKey)
|
||||||
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)
|
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", userKey, " 原始uniqueId:", uniqueId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
originConn, ok := mapConnPoolVal.(wsConnectItem)
|
originConn, ok := mapConnPoolVal.(wsConnectItem)
|
||||||
if !ok {
|
if !ok {
|
||||||
logx.Error("通过用户id索引发送消息,断言原始连接失败,用户索引key:", key, " 原始uniqueId:", uniqueId)
|
logx.Error("通过用户id索引发送消息,断言原始连接失败,用户索引key:", userKey, " 原始uniqueId:", uniqueId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
originConn.sendToOutChan(data.message)
|
originConn.sendToOutChan(data.message)
|
||||||
@ -314,19 +318,17 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
|
|||||||
case 1: //添加
|
case 1: //添加
|
||||||
logx.Info("添加用户id索引标识:", data.uniqueId)
|
logx.Info("添加用户id索引标识:", data.uniqueId)
|
||||||
//存在这个用户的map池子
|
//存在这个用户的map池子
|
||||||
if mapUserUniqueId, ok := mapUserConnPool[key]; ok {
|
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
|
||||||
mapUserUniqueId[data.uniqueId] = struct{}{}
|
mapUserUniqueId[data.uniqueId] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
mapUserConnPool[key] = make(map[string]struct{})
|
mapUserConnPool[userKey] = make(map[string]struct{})
|
||||||
mapUserConnPool[key][data.uniqueId] = struct{}{}
|
mapUserConnPool[userKey][data.uniqueId] = struct{}{}
|
||||||
}
|
}
|
||||||
case 0: //删除
|
case 0: //删除
|
||||||
logx.Info("删除用户id索引标识:", data.uniqueId)
|
logx.Info("删除用户id索引标识:", data.uniqueId)
|
||||||
if mapUserUniqueId, ok := mapUserConnPool[key]; ok {
|
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
|
||||||
delete(mapUserUniqueId, data.uniqueId)
|
delete(mapUserUniqueId, data.uniqueId)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user