Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
Hiven 2023-08-10 15:23:35 +08:00
commit a2ee8327ac

View File

@ -87,14 +87,14 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
return return
} }
defer conn.Close() defer conn.Close()
//鉴权不成功10秒后断开 //鉴权不成功后断开
/*var ( var (
userInfo *auth.UserInfo userInfo *auth.UserInfo
isAuth bool isAuth bool
) )
isAuth, userInfo = l.checkAuth(svcCtx, r) isAuth, userInfo = l.checkAuth(svcCtx, r)
if !isAuth { if !isAuth {
time.Sleep(time.Second) //兼容下火狐 time.Sleep(time.Second * 4) //兼容下火狐
rsp := websocket_data.DataTransferData{ rsp := websocket_data.DataTransferData{
T: constants.WEBSOCKET_UNAUTH, T: constants.WEBSOCKET_UNAUTH,
D: nil, D: nil,
@ -105,10 +105,10 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
//发送关闭信息 //发送关闭信息
_ = conn.WriteMessage(websocket.CloseMessage, nil) _ = conn.WriteMessage(websocket.CloseMessage, nil)
return return
}*/ }
//测试的目前写死 39 //测试的目前写死 39
var userInfo auth.UserInfo /*var userInfo auth.UserInfo
userInfo.UserId = 39 userInfo.UserId = 39*/
//生成连接唯一标识 //生成连接唯一标识
uniqueId := websocketIdGenerator.Get() uniqueId := websocketIdGenerator.Get()
ws := wsConnectItem{ ws := wsConnectItem{
@ -130,10 +130,12 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
//保存连接 //保存连接
mapConnPool.Store(uniqueId, ws) mapConnPool.Store(uniqueId, ws)
defer ws.close() defer ws.close()
go func() {
//把连接成功消息发回去 //把连接成功消息发回去
time.Sleep(time.Second) //兼容下火狐 time.Sleep(time.Second * 4) //兼容下火狐
b := ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId) b := ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId)
_ = conn.WriteMessage(websocket.TextMessage, b) _ = conn.WriteMessage(websocket.TextMessage, b)
}()
//循环读客户端信息 //循环读客户端信息
go ws.readLoop() go ws.readLoop()
//循环把数据发送给客户端 //循环把数据发送给客户端