This commit is contained in:
laodaming 2023-08-07 11:25:06 +08:00
parent 8e4e1c1cfd
commit 36efad44df
7 changed files with 30 additions and 42 deletions

View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"fusenapi/constants"
"fusenapi/initalize"
"fusenapi/server/websocket/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/id_generator"
"fusenapi/utils/websocket_data"
"github.com/gorilla/websocket"
"net/http"
"sync"
@ -251,7 +251,7 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
// 格式化返回数据
func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte {
d := types.DataTransferData{
d := websocket_data.DataTransferData{
T: msgType,
D: data,
}
@ -261,7 +261,7 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by
// 处理接受到的数据
func (w *wsConnectItem) dealwithReciveData(data []byte) {
var parseInfo types.DataTransferData
var parseInfo websocket_data.DataTransferData
if err := json.Unmarshal(data, &parseInfo); err != nil {
logx.Error("invalid format of websocket message")
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data))

View File

@ -3,6 +3,7 @@ package logic
import (
"fusenapi/constants"
"fusenapi/utils/basic"
"fusenapi/utils/websocket_data"
"time"
"context"
@ -66,7 +67,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
if !ok {
return true
}
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, types.RenderImageRspMsg{
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: renderId,
Image: req.Info.Image,
})

View File

@ -4,6 +4,7 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/websocket_data"
"time"
"context"
@ -66,7 +67,7 @@ func (l *ThirdPartyLoginNotifyLogic) ThirdPartyLoginNotify(req *types.ThirdParty
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "type of websocket connect object is err")
}
b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, types.ThirdPartyLoginRspMsg{
b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, websocket_data.ThirdPartyLoginRspMsg{
Token: req.Info.Token,
})
select {

View File

@ -3,8 +3,8 @@ package logic
import (
"encoding/json"
"fusenapi/constants"
"fusenapi/server/websocket/internal/types"
"fusenapi/utils/hash"
"fusenapi/utils/websocket_data"
"github.com/zeromicro/go-zero/core/logx"
)
@ -28,7 +28,7 @@ type assembleRenderData struct {
}
func (w *wsConnectItem) assembleRenderData(data []byte) {
var renderImageData types.RenderImageReqMsg
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
logx.Error("invalid format of websocket render image message", err)

View File

@ -5,25 +5,6 @@ import (
"fusenapi/utils/basic"
)
type DataTransferData struct {
T string `json:"t"` //消息类型
D interface{} `json:"d"` //传递的消息
}
type RenderImageReqMsg struct {
RenderId string `json:"render_id"` //渲染id
RenderData interface{} `json:"render_data"` //参数数据
}
type RenderImageRspMsg struct {
RenderId string `json:"render_id"` //渲染id
Image string `json:"image"` //渲染结果图片
}
type ThirdPartyLoginRspMsg struct {
Token string `json:"token"`
}
type RenderNotifyReq struct {
Sign string `json:"sign"`
Time int64 `json:"time"`

View File

@ -20,22 +20,6 @@ service websocket {
post /api/websocket/third_party_login_notify(ThirdPartyLoginNotifyReq) returns (response);
}
//websocket数据交互
type DataTransferData {
T string `json:"t"` //消息类型
D interface{} `json:"d"` //传递的消息
}
type RenderImageReqMsg { //websocket接受要云渲染处理的数据
RenderId string `json:"render_id"` //渲染id
RenderData interface{} `json:"render_data"` //参数数据
}
type RenderImageRspMsg { //websocket发送渲染完的数据
RenderId string `json:"render_id"` //渲染id
Image string `json:"image"` //渲染结果图片
}
type ThirdPartyLoginRspMsg { //websocket三方登录的通知数据
Token string `json:"token"`
}
//渲染完了通知接口
type RenderNotifyReq {
Sign string `json:"sign"`

View File

@ -0,0 +1,21 @@
package websocket_data
// websocket数据交互
type DataTransferData struct {
T string `json:"t"` //消息类型
D interface{} `json:"d"` //传递的消息
}
type RenderImageReqMsg struct {
//websocket接受要云渲染处理的数据
RenderId string `json:"render_id"` //渲染id
RenderData interface{} `json:"render_data"` //参数数据
}
type RenderImageRspMsg struct {
//websocket发送渲染完的数据
RenderId string `json:"render_id"` //渲染id
Image string `json:"image"` //渲染结果图片
}
type ThirdPartyLoginRspMsg struct {
//websocket三方登录的通知数据
Token string `json:"token"`
}