fix
This commit is contained in:
parent
1a1903c826
commit
1b091892a4
|
@ -195,12 +195,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||||
mapConnPool.Store(uniqueId, ws)
|
mapConnPool.Store(uniqueId, ws)
|
||||||
//非白板用户,需要为这个用户建立map索引便于通过用户查询
|
//非白板用户,需要为这个用户建立map索引便于通过用户查询
|
||||||
if userInfo.IsUser() || userInfo.IsGuest() {
|
if userInfo.IsUser() || userInfo.IsGuest() {
|
||||||
createUserConnPoolElement(userConnPoolChanItem{
|
createUserConnPoolElement(userInfo.UserId, userInfo.GuestId, uniqueId)
|
||||||
userId: userInfo.UserId,
|
|
||||||
guestId: userInfo.GuestId,
|
|
||||||
uniqueId: uniqueId,
|
|
||||||
option: 1,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if isFirefoxBrowser {
|
if isFirefoxBrowser {
|
||||||
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||||
|
@ -210,37 +205,54 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加用户索引池ws连接
|
// 添加用户索引池ws连接
|
||||||
func createUserConnPoolElement(data userConnPoolChanItem) {
|
func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
||||||
data.option = 1
|
data := userConnPoolChanItem{
|
||||||
|
userId: userId,
|
||||||
|
guestId: guestId,
|
||||||
|
uniqueId: uniqueId,
|
||||||
|
message: nil,
|
||||||
|
messageType: "",
|
||||||
|
option: 1,
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case mapUserConnPoolCtlChan <- data:
|
case mapUserConnPoolCtlChan <- data:
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("向用户索引池中连接任务放入增加操作超时失败")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从用户索引池删除ws连接
|
// 从用户索引池删除ws连接
|
||||||
func deleteUserConnPoolElement(data userConnPoolChanItem) {
|
func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
||||||
data.option = 0
|
data := userConnPoolChanItem{
|
||||||
|
userId: userId,
|
||||||
|
guestId: guestId,
|
||||||
|
uniqueId: uniqueId,
|
||||||
|
message: nil,
|
||||||
|
messageType: "",
|
||||||
|
option: 0,
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case mapUserConnPoolCtlChan <- data:
|
case mapUserConnPoolCtlChan <- data:
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("向用户索引池中连接任务放入删除操作超时失败")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据用户索引发现链接并发送消息到出口队列
|
// 根据用户索引发现链接并发送消息到出口队列
|
||||||
func sendToOutChanByUserIndex(data userConnPoolChanItem) {
|
func sendToOutChanByUserIndex(userId, guestId int64, uniqueId string, message []byte) {
|
||||||
data.option = 0
|
data := userConnPoolChanItem{
|
||||||
|
userId: userId,
|
||||||
|
guestId: guestId,
|
||||||
|
uniqueId: uniqueId,
|
||||||
|
message: message,
|
||||||
|
option: 2,
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case mapUserConnPoolCtlChan <- data:
|
case mapUserConnPoolCtlChan <- data:
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("通过用户索引找连接发送消息失败")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -398,12 +410,7 @@ func (w *wsConnectItem) close() {
|
||||||
w.isClose = true
|
w.isClose = true
|
||||||
close(w.closeChan)
|
close(w.closeChan)
|
||||||
//删除用户级索引
|
//删除用户级索引
|
||||||
deleteUserConnPoolElement(userConnPoolChanItem{
|
deleteUserConnPoolElement(w.userId, w.guestId, w.uniqueId)
|
||||||
userId: w.userId,
|
|
||||||
guestId: w.guestId,
|
|
||||||
uniqueId: w.uniqueId,
|
|
||||||
option: 0,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
logx.Info("###websocket:", w.uniqueId, " uid:", w.userId, " gid:", w.guestId, " is closed")
|
logx.Info("###websocket:", w.uniqueId, " uid:", w.userId, " gid:", w.guestId, " is closed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,7 @@ func (r *reuseConnProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||||
w.uniqueId = wid
|
w.uniqueId = wid
|
||||||
mapConnPool.Store(wid, *w)
|
mapConnPool.Store(wid, *w)
|
||||||
//添加用户id级别索引
|
//添加用户id级别索引
|
||||||
createUserConnPoolElement(userConnPoolChanItem{
|
createUserConnPoolElement(w.userId, w.guestId, wid)
|
||||||
userId: w.userId,
|
|
||||||
guestId: w.guestId,
|
|
||||||
uniqueId: wid,
|
|
||||||
option: 1,
|
|
||||||
})
|
|
||||||
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid)
|
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid)
|
||||||
w.sendToOutChan(rsp)
|
w.sendToOutChan(rsp)
|
||||||
logx.Info("重新绑定websocket连接标识成功")
|
logx.Info("重新绑定websocket连接标识成功")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user