This commit is contained in:
laodaming 2023-07-26 16:47:53 +08:00
parent 7dc9760d94
commit 3deda93e7e
6 changed files with 23 additions and 15 deletions

View File

@ -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"
)
// 云渲染通知需要的签名字符串

View File

@ -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:
}

View File

@ -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{

View File

@ -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)

View File

@ -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 {

View File

@ -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"`