This commit is contained in:
laodaming 2023-10-11 17:54:46 +08:00
parent a138cdbd01
commit c24ddb4af2

View File

@ -204,21 +204,25 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
//合成client后缀,不是同个后缀的不能复用 //合成client后缀,不是同个后缀的不能复用
userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent) userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent)
lenUserPart := len(userPart) lenUserPart := len(userPart)
canUseOldWid := true
//长度太短
if lendecryptionWid <= lenUserPart { if lendecryptionWid <= lenUserPart {
return wsConnectItem{}, errors.New("length of client id is too short") canUseOldWid = false
} }
//尾部不同不能复用 //尾部不同不能复用
if decryptionWid[lendecryptionWid-lenUserPart:] != userPart { if decryptionWid[lendecryptionWid-lenUserPart:] != userPart {
return wsConnectItem{}, errors.New("the client id is not belong to you before") canUseOldWid = false
} }
//存在是不能给他申请重新绑定 //存在是不能给他申请重新绑定
if _, ok := mapConnPool.Load(oldWid); ok { if _, ok := mapConnPool.Load(oldWid); ok {
return wsConnectItem{}, errors.New("the wid has bond by other connect") canUseOldWid = false
} }
//检测通过可以用旧的 //检测通过可以用旧的
if canUseOldWid {
logx.Info("====复用旧的ws连接成功====") logx.Info("====复用旧的ws连接成功====")
uniqueId = oldWid uniqueId = oldWid
} }
}
renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx) renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx)
ws := wsConnectItem{ ws := wsConnectItem{
conn: conn, conn: conn,