fix
This commit is contained in:
parent
44bcaf131e
commit
5a521c8a5f
|
@ -298,36 +298,6 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
|||
return true, userInfo
|
||||
}
|
||||
|
||||
// 鉴权失败通知
|
||||
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) {
|
||||
rsp := websocket_data.DataTransferData{
|
||||
T: constants.WEBSOCKET_UNAUTH,
|
||||
D: websocket_data.ConnectUnAuth{Message: errMessage},
|
||||
}
|
||||
b, _ := json.Marshal(rsp)
|
||||
if isFirefoxBrowser {
|
||||
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||
}
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
}
|
||||
|
||||
// 获取唯一标识失败通知
|
||||
func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) {
|
||||
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||
rsp := websocket_data.DataTransferData{
|
||||
T: constants.WEBSOCKET_CONNECT_ERR,
|
||||
D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "},
|
||||
}
|
||||
b, _ := json.Marshal(rsp)
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
}
|
||||
|
||||
// 心跳检测
|
||||
func (w *wsConnectItem) heartbeat() {
|
||||
tick := time.Tick(time.Second * 5)
|
||||
|
|
|
@ -1,8 +1,44 @@
|
|||
package logic
|
||||
|
||||
import "fusenapi/constants"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/gorilla/websocket"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 入口数据格式错误
|
||||
// 获取唯一标识失败通知
|
||||
func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) {
|
||||
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||
rsp := websocket_data.DataTransferData{
|
||||
T: constants.WEBSOCKET_CONNECT_ERR,
|
||||
D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "},
|
||||
}
|
||||
b, _ := json.Marshal(rsp)
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
}
|
||||
|
||||
// 鉴权失败通知
|
||||
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) {
|
||||
rsp := websocket_data.DataTransferData{
|
||||
T: constants.WEBSOCKET_UNAUTH,
|
||||
D: websocket_data.ConnectUnAuth{Message: errMessage},
|
||||
}
|
||||
b, _ := json.Marshal(rsp)
|
||||
if isFirefoxBrowser {
|
||||
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||
}
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
}
|
||||
|
||||
// 通用入口数据格式错误
|
||||
func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
|
|
59
server/websocket/internal/logic/ws_ok_response.go
Normal file
59
server/websocket/internal/logic/ws_ok_response.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/websocket_data"
|
||||
)
|
||||
|
||||
// *******************************合图相关begin******************************
|
||||
// 发送合图完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId int64, debugData *auth.DebugData) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
combineTakesTime := "cache"
|
||||
uploadCombineImageTakesTime := "cache"
|
||||
if debugData.DiffTimeLogoCombine > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine)
|
||||
}
|
||||
if debugData.DiffTimeUploadFile > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile)
|
||||
}
|
||||
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需要的数据完毕消息
|
||||
func (w *wsConnectItem) sendAssembleRenderDataStepResponseMessage(renderId string, requestId string) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ASSEMBLE_RENDER_DATA, websocket_data.ToUnityRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
|
||||
// 发送组装数据到unity完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendRenderDataToUnityStepResponseMessage(renderId string, requestId string) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.AssembleRenderDataRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
|
||||
// 发送渲染最终结果数据到前端
|
||||
func (w *wsConnectItem) sendRenderResultData(data websocket_data.RenderImageRspMsg) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data))
|
||||
}
|
||||
|
||||
// *******************************合图相关end******************************
|
|
@ -6,11 +6,8 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/curl"
|
||||
"fusenapi/utils/hash"
|
||||
"fusenapi/utils/websocket_data"
|
||||
|
@ -465,52 +462,3 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web
|
|||
}
|
||||
return hash.JsonHashKey(hashMap)
|
||||
}
|
||||
|
||||
// ****************************下面的发送消息的*********************************
|
||||
// 发送合图完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId int64, debugData *auth.DebugData) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
combineTakesTime := "cache"
|
||||
uploadCombineImageTakesTime := "cache"
|
||||
if debugData.DiffTimeLogoCombine > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine)
|
||||
}
|
||||
if debugData.DiffTimeUploadFile > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile)
|
||||
}
|
||||
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需要的数据完毕消息
|
||||
func (w *wsConnectItem) sendAssembleRenderDataStepResponseMessage(renderId string, requestId string) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ASSEMBLE_RENDER_DATA, websocket_data.ToUnityRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
|
||||
// 发送组装数据到unity完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendRenderDataToUnityStepResponseMessage(renderId string, requestId string) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.AssembleRenderDataRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
}
|
||||
|
||||
// 发送渲染最终结果数据到前端
|
||||
func (w *wsConnectItem) sendRenderResultData(data websocket_data.RenderImageRspMsg) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user