fix
This commit is contained in:
parent
57f3270af2
commit
669be27e0a
|
@ -72,13 +72,6 @@ var (
|
|||
websocketInChanLen = 2000
|
||||
//每个websocket连接出口缓冲队列长度默认值
|
||||
websocketOutChanLen = 2000
|
||||
//是否开启debug
|
||||
openDebug = true
|
||||
//允许跨域的origin
|
||||
mapAllowOrigin = map[string]struct{}{
|
||||
"https://www.fusen.3718.cn": struct{}{},
|
||||
"http://www.fusen.3718.cn": struct{}{},
|
||||
}
|
||||
)
|
||||
|
||||
// 用户标识的连接增删操作队列传输的值的结构
|
||||
|
@ -102,6 +95,7 @@ type wsConnectItem struct {
|
|||
inChan chan []byte //接受消息缓冲队列(基本属性)
|
||||
outChan chan []byte //要发送回客户端的消息缓冲队列(基本属性)
|
||||
mutex sync.Mutex //互斥锁(基本属性)
|
||||
openDebug bool //是否开启debug
|
||||
userId int64 //用户id(基本属性)
|
||||
guestId int64 //游客id(基本属性)
|
||||
extendRenderProperty extendRenderProperty //扩展云渲染属性(扩展属性)
|
||||
|
@ -109,20 +103,10 @@ type wsConnectItem struct {
|
|||
|
||||
// 请求建立连接,升级websocket协议
|
||||
func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.ResponseWriter, r *http.Request) {
|
||||
origin := r.Header.Get("Origin")
|
||||
//判断是不是允许的跨域
|
||||
if !openDebug {
|
||||
upgrader.CheckOrigin = func(r *http.Request) bool {
|
||||
if _, ok := mapAllowOrigin[origin]; !ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
//把子协议携带的token设置到标准token头信息中
|
||||
token := r.Header.Get("Sec-Websocket-Protocol")
|
||||
oldWid := req.Wid
|
||||
oldWid = strings.ReplaceAll(oldWid, " ", "+")
|
||||
oldWid = strings.Trim(oldWid, " ")
|
||||
//有token是正常用户,无则是白板用户,也可以连接
|
||||
if token != "" {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
|
@ -238,6 +222,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
|||
renderCtx: renderCtx,
|
||||
renderCtxCancelFunc: renderCtxCancelFunc,
|
||||
},
|
||||
openDebug: true, //默认都开debug
|
||||
}
|
||||
//保存连接
|
||||
mapConnPool.Store(uniqueId, ws)
|
||||
|
@ -254,10 +239,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
|||
|
||||
// 获取websocket发送到前端使用的数据传输类型(debug开启是文本,否则是二进制)
|
||||
func getWebsocketBaseTransferDataFormat() int {
|
||||
if openDebug {
|
||||
return websocket.TextMessage
|
||||
}
|
||||
return websocket.BinaryMessage
|
||||
return websocket.TextMessage
|
||||
}
|
||||
|
||||
// 获取唯一id
|
||||
|
|
|
@ -4,37 +4,41 @@ import "fusenapi/constants"
|
|||
|
||||
// 入口数据格式错误
|
||||
func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, data))
|
||||
if w.openDebug {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, data))
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染错误通知
|
||||
func (w *wsConnectItem) renderErrResponse(renderId, requestId, templateTag, taskId, description string, productId, userId, guestId, templateId, modelId, sizeId, elementModelId int64) {
|
||||
data := make(map[string]interface{})
|
||||
data["render_id"] = renderId
|
||||
data["request_id"] = requestId
|
||||
data["description"] = description
|
||||
data["template_tag"] = templateTag
|
||||
data["product_id"] = productId
|
||||
if taskId != "" {
|
||||
data["task_id"] = taskId
|
||||
if w.openDebug {
|
||||
data := make(map[string]interface{})
|
||||
data["render_id"] = renderId
|
||||
data["request_id"] = requestId
|
||||
data["description"] = description
|
||||
data["template_tag"] = templateTag
|
||||
data["product_id"] = productId
|
||||
if taskId != "" {
|
||||
data["task_id"] = taskId
|
||||
}
|
||||
/*if userId >= 0 {
|
||||
data["user_id"] = userId
|
||||
}
|
||||
if guestId >= 0 {
|
||||
data["guest_id"] = guestId
|
||||
}*/
|
||||
if templateId > 0 {
|
||||
data["template_id"] = templateId
|
||||
}
|
||||
if modelId > 0 {
|
||||
data["model_id"] = modelId
|
||||
}
|
||||
if sizeId > 0 {
|
||||
data["size_id"] = sizeId
|
||||
}
|
||||
if elementModelId > 0 {
|
||||
data["element_model_id"] = elementModelId
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, data))
|
||||
}
|
||||
/*if userId >= 0 {
|
||||
data["user_id"] = userId
|
||||
}
|
||||
if guestId >= 0 {
|
||||
data["guest_id"] = guestId
|
||||
}*/
|
||||
if templateId > 0 {
|
||||
data["template_id"] = templateId
|
||||
}
|
||||
if modelId > 0 {
|
||||
data["model_id"] = modelId
|
||||
}
|
||||
if sizeId > 0 {
|
||||
data["size_id"] = sizeId
|
||||
}
|
||||
if elementModelId > 0 {
|
||||
data["element_model_id"] = elementModelId
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, data))
|
||||
}
|
||||
|
|
|
@ -439,36 +439,42 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
|
|||
|
||||
// 发送合图完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId, combineTime, uploadTime int64) {
|
||||
combineTakesTime := "cache"
|
||||
uploadCombineImageTakesTime := "cache"
|
||||
if combineTime > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", combineTime)
|
||||
if w.openDebug {
|
||||
combineTakesTime := "cache"
|
||||
uploadCombineImageTakesTime := "cache"
|
||||
if combineTime > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", combineTime)
|
||||
}
|
||||
if uploadTime > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", uploadTime)
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
|
||||
RenderId: renderId,
|
||||
RequestId: requestId,
|
||||
CombineImage: combineImage,
|
||||
SizeId: sizeId,
|
||||
ModelId: modelId,
|
||||
TemplateId: templateId,
|
||||
CombineProcessTime: websocket_data.CombineProcessTime{
|
||||
CombineTakesTime: combineTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
},
|
||||
}))
|
||||
}
|
||||
if uploadTime > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", uploadTime)
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
|
||||
RenderId: renderId,
|
||||
RequestId: requestId,
|
||||
CombineImage: combineImage,
|
||||
SizeId: sizeId,
|
||||
ModelId: modelId,
|
||||
TemplateId: templateId,
|
||||
CombineProcessTime: websocket_data.CombineProcessTime{
|
||||
CombineTakesTime: combineTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
// 发送组装unity渲染数据完毕阶段通知消息
|
||||
// 发送组装unity需要的数据完毕消息
|
||||
func (w *wsConnectItem) sendAssembleRenderDataStepResponseMessage(renderId string, requestId string) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ASSEMBLE_RENDER_DATA, websocket_data.ToUnityRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
if w.openDebug {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ASSEMBLE_RENDER_DATA, websocket_data.ToUnityRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
}
|
||||
|
||||
// 发送组装unity渲染数据完毕阶段通知消息
|
||||
// 发送组装数据到unity完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendRenderDataToUnityStepResponseMessage(renderId string, requestId string) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.AssembleRenderDataRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
if w.openDebug {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.AssembleRenderDataRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
}
|
||||
|
||||
// 发送渲染最终结果数据到前端
|
||||
|
|
Loading…
Reference in New Issue
Block a user