From 3deda93e7e715ab9b7c5757fdb20b1aea09cf58d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 26 Jul 2023 16:47:53 +0800 Subject: [PATCH] fix --- constants/websocket.go | 10 ++++++---- .../websocket/internal/logic/datatransferlogic.go | 3 ++- .../websocket/internal/logic/rendernotifylogic.go | 15 +++++++++------ .../internal/logic/ws_render_image_logic.go | 2 ++ server/websocket/internal/types/types.go | 4 ++-- server_api/websocket.api | 4 ++-- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index a9a6aa5d..71f1fc36 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -5,13 +5,15 @@ type websocket string // websocket消息类型 const ( //鉴权失败 - WEBSOCKET_UNAUTH = "unAuth" + WEBSOCKET_UNAUTH = "WEBSOCKET_UNAUTH" //ws连接成功 - WEBSOCKET_CONNECT_SUCCESS = "connect-success" + WEBSOCKET_CONNECT_SUCCESS = "WEBSOCKET_CONNECT_SUCCESS" //心跳信息 - WEBSOCKET_HEARTBEAT = "heartbeat" + WEBSOCKET_HEARTBEAT = "WEBSOCKET_HEARTBEAT" //图片渲染 - WEBSOCKET_RENDER_IMAGE = "render-image" + WEBSOCKET_RENDER_IMAGE = "WEBSOCKET_RENDER_IMAGE" + //数据格式错误 + WEBSOCKET_ERR_DATA_FORMAT = "WEBSOCKET_ERR_DATA_FORMAT" ) // 云渲染通知需要的签名字符串 diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index f2b31ab9..ec39e0d9 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -258,11 +258,12 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) { logx.Error("invalid format of websocket message") return } + d, _ := json.Marshal(parseInfo.D) //分消息类型给到不同逻辑处理,可扩展 switch parseInfo.T { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: - go w.SendToCloudRender([]byte(parseInfo.D)) + go w.SendToCloudRender(d) default: } diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 01f630de..064b459d 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -72,13 +72,16 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi if !ok { continue } - responseData := types.RenderImageRspMsg{ - ProductId: notifyItem.ProductId, - SizeId: notifyItem.SizeId, - TemplateId: notifyItem.TemplateId, - Source: "我是渲染资源", + rspData := types.DataTransferData{ + T: constants.WEBSOCKET_RENDER_IMAGE, + D: types.RenderImageRspMsg{ + ProductId: notifyItem.ProductId, + SizeId: notifyItem.SizeId, + TemplateId: notifyItem.TemplateId, + Source: "我是渲染资源", + }, } - b, _ := json.Marshal(responseData) + b, _ := json.Marshal(rspData) dataList = append(dataList, b) //删除对应的需要渲染的图片map ws.renderImageTaskCtlChan <- renderImageControlChanItem{ diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 8521ee91..c8b7f816 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -2,12 +2,14 @@ package logic import ( "encoding/json" + "fmt" "fusenapi/server/websocket/internal/types" "github.com/zeromicro/go-zero/core/logx" ) // 渲染请求数据处理发送云渲染服务处理 func (w *wsConnectItem) SendToCloudRender(data []byte) { + fmt.Println(string(data)) var renderImageData []types.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { logx.Error("invalid format of websocket render image message", err) diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 8178bcc6..d3336021 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -6,8 +6,8 @@ import ( ) type DataTransferData struct { - T string `json:"t"` //消息类型 - D string `json:"d"` //传递的消息 + T string `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 } type RenderImageReqMsg struct { diff --git a/server_api/websocket.api b/server_api/websocket.api index dadbd2ab..0d445c71 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -19,8 +19,8 @@ service websocket { //websocket数据交互 type DataTransferData { - T string `json:"t"` //消息类型 - D string `json:"d"` //传递的消息 + T string `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 } type RenderImageReqMsg { //websocket接受需要云渲染的图片 ProductId int64 `json:"product_id"`