From 7510b363d6e985e9d8c85ffb7f270acf67eadc5e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 7 Aug 2023 12:31:31 +0800 Subject: [PATCH] fix --- .../render/consumer/assemble_render_data.go | 2 +- ...mageshandler.go => rendernotifyhandler.go} | 8 +- server/render/internal/handler/routes.go | 11 +-- .../render/internal/handler/tounityhandler.go | 35 -------- .../render/internal/logic/readimageslogic.go | 42 ---------- .../internal/logic/rendernotifylogic.go | 47 ++++------- server/render/internal/logic/tounitylogic.go | 42 ---------- server/render/internal/types/types.go | 11 +++ server/websocket/consumer/consumer.go | 12 --- .../internal/handler/rendernotifyhandler.go | 31 -------- server/websocket/internal/handler/routes.go | 10 --- .../handler/thirdpartyloginnotifyhandler.go | 35 -------- .../websocket/internal/logic/mq_consumer.go | 52 ++++++++++++ .../logic/thirdpartyloginnotifylogic.go | 79 ------------------- server/websocket/internal/types/types.go | 22 ------ server/websocket/websocket.go | 4 +- server_api/render.api | 20 +++-- server_api/websocket.api | 27 ------- utils/websocket_data/render_data.go | 12 ++- 19 files changed, 111 insertions(+), 391 deletions(-) rename server/render/internal/handler/{readimageshandler.go => rendernotifyhandler.go} (72%) delete mode 100644 server/render/internal/handler/tounityhandler.go delete mode 100644 server/render/internal/logic/readimageslogic.go rename server/{websocket => render}/internal/logic/rendernotifylogic.go (61%) delete mode 100644 server/render/internal/logic/tounitylogic.go delete mode 100644 server/websocket/consumer/consumer.go delete mode 100644 server/websocket/internal/handler/rendernotifyhandler.go delete mode 100644 server/websocket/internal/handler/thirdpartyloginnotifyhandler.go create mode 100644 server/websocket/internal/logic/mq_consumer.go delete mode 100644 server/websocket/internal/logic/thirdpartyloginnotifylogic.go diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 9f3b6187..78aa193e 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -7,6 +7,6 @@ type MqConsumerRenderAssemble struct { } func (m *MqConsumerRenderAssemble) Run(data []byte) error { - fmt.Println("收到消息:" + string(data)) + fmt.Println("收到需要组装的消息:" + string(data)) return nil } diff --git a/server/render/internal/handler/readimageshandler.go b/server/render/internal/handler/rendernotifyhandler.go similarity index 72% rename from server/render/internal/handler/readimageshandler.go rename to server/render/internal/handler/rendernotifyhandler.go index 4156ab0f..a8d01c9c 100644 --- a/server/render/internal/handler/readimageshandler.go +++ b/server/render/internal/handler/rendernotifyhandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/render/internal/types" ) -func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.RequestReadImages + var req types.RenderNotifyReq userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewReadImagesLogic(r.Context(), svcCtx) + l := logic.NewRenderNotifyLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.ReadImages(&req, userinfo) + resp := l.RenderNotify(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/render/internal/handler/routes.go b/server/render/internal/handler/routes.go index 46f97be9..0bbf0d3e 100644 --- a/server/render/internal/handler/routes.go +++ b/server/render/internal/handler/routes.go @@ -13,14 +13,9 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - Method: http.MethodGet, - Path: "/api/render/to-unity", - Handler: ToUnityHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/api/render/read-images", - Handler: ReadImagesHandler(serverCtx), + Method: http.MethodPost, + Path: "/api/render/render_notify", + Handler: RenderNotifyHandler(serverCtx), }, }, ) diff --git a/server/render/internal/handler/tounityhandler.go b/server/render/internal/handler/tounityhandler.go deleted file mode 100644 index 80191459..00000000 --- a/server/render/internal/handler/tounityhandler.go +++ /dev/null @@ -1,35 +0,0 @@ -package handler - -import ( - "net/http" - "reflect" - - "fusenapi/utils/basic" - - "fusenapi/server/render/internal/logic" - "fusenapi/server/render/internal/svc" - "fusenapi/server/render/internal/types" -) - -func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.RequestToUnity - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - - // 创建一个业务逻辑层实例 - l := logic.NewToUnityLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.ToUnity(&req, userinfo) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/render/internal/logic/readimageslogic.go b/server/render/internal/logic/readimageslogic.go deleted file mode 100644 index e7d36441..00000000 --- a/server/render/internal/logic/readimageslogic.go +++ /dev/null @@ -1,42 +0,0 @@ -package logic - -import ( - "fusenapi/utils/auth" - "fusenapi/utils/basic" - - "context" - - "fusenapi/server/render/internal/svc" - "fusenapi/server/render/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ReadImagesLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewReadImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadImagesLogic { - return &ReadImagesLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 处理进入前逻辑w,r -// func (l *ReadImagesLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { -// } - -// 处理逻辑后 w,r 如:重定向 -// func (l *ReadImagesLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// } - -func (l *ReadImagesLogic) ReadImages(req *types.RequestReadImages, userinfo *auth.UserInfo) (resp *basic.Response) { - // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) - // userinfo 传入值时, 一定不为null - - return resp.SetStatus(basic.CodeOK) -} diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/render/internal/logic/rendernotifylogic.go similarity index 61% rename from server/websocket/internal/logic/rendernotifylogic.go rename to server/render/internal/logic/rendernotifylogic.go index 27b2002d..aa735d6d 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/render/internal/logic/rendernotifylogic.go @@ -1,15 +1,17 @@ package logic import ( + "encoding/json" "fusenapi/constants" + "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/websocket_data" "time" "context" - "fusenapi/server/websocket/internal/svc" - "fusenapi/server/websocket/internal/types" + "fusenapi/server/render/internal/svc" + "fusenapi/server/render/internal/types" "github.com/zeromicro/go-zero/core/logx" ) @@ -37,7 +39,7 @@ func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Rend // // httpx.OkJsonCtx(r.Context(), w, resp) // } -func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basic.Response) { +func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { if time.Now().Unix()-120 > req.Time /*|| req.Time > time.Now().Unix() */ { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time") } @@ -51,35 +53,14 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi if req.Sign != sign { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign") }*/ - //遍历websocket链接把数据传进去 - mapConnPool.Range(func(key, value any) bool { - //断言连接 - ws, ok := value.(wsConnectItem) - if !ok { - return true - } - //关闭标识 - if ws.isClose { - return true - } - //查询有无该渲染任务 - renderId, ok := ws.renderProperty.renderImageTask[req.Info.TaskId] - if !ok { - return true - } - b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: renderId, - Image: req.Info.Image, - }) - //删除对应的需要渲染的图片map - ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ - Option: 0, //0删除 1添加 - TaskId: req.Info.TaskId, - RenderId: renderId, - } - //发送数据到out chan - ws.sendToOutChan(b) - return true - }) + data := websocket_data.RenderImageNotify{ + TaskId: req.Info.TaskId, + Image: req.Info.Image, + } + d, _ := json.Marshal(data) + if err := l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeServiceErr, "failed to send data") + } return resp.SetStatus(basic.CodeOK) } diff --git a/server/render/internal/logic/tounitylogic.go b/server/render/internal/logic/tounitylogic.go deleted file mode 100644 index bacf7b98..00000000 --- a/server/render/internal/logic/tounitylogic.go +++ /dev/null @@ -1,42 +0,0 @@ -package logic - -import ( - "fusenapi/utils/auth" - "fusenapi/utils/basic" - - "context" - - "fusenapi/server/render/internal/svc" - "fusenapi/server/render/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ToUnityLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewToUnityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToUnityLogic { - return &ToUnityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 处理进入前逻辑w,r -// func (l *ToUnityLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { -// } - -// 处理逻辑后 w,r 如:重定向 -// func (l *ToUnityLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// } - -func (l *ToUnityLogic) ToUnity(req *types.RequestToUnity, userinfo *auth.UserInfo) (resp *basic.Response) { - // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) - // userinfo 传入值时, 一定不为null - - return resp.SetStatus(basic.CodeOK) -} diff --git a/server/render/internal/types/types.go b/server/render/internal/types/types.go index e2847118..91d3407f 100644 --- a/server/render/internal/types/types.go +++ b/server/render/internal/types/types.go @@ -11,6 +11,17 @@ type RequestToUnity struct { type RequestReadImages struct { } +type RenderNotifyReq struct { + Sign string `json:"sign"` + Time int64 `json:"time"` + Info NotifyInfo `json:"info"` +} + +type NotifyInfo struct { + TaskId string `json:"task_id"` //任务id + Image string `json:"image"` +} + type Request struct { } diff --git a/server/websocket/consumer/consumer.go b/server/websocket/consumer/consumer.go deleted file mode 100644 index 16a7c8a9..00000000 --- a/server/websocket/consumer/consumer.go +++ /dev/null @@ -1,12 +0,0 @@ -package consumer - -import "fmt" - -// 消费渲染结果数据 -type MqConsumerRenderResult struct { -} - -func (m *MqConsumerRenderResult) Run(data []byte) error { - fmt.Println("收到消息:" + string(data)) - return nil -} diff --git a/server/websocket/internal/handler/rendernotifyhandler.go b/server/websocket/internal/handler/rendernotifyhandler.go deleted file mode 100644 index ab16cdad..00000000 --- a/server/websocket/internal/handler/rendernotifyhandler.go +++ /dev/null @@ -1,31 +0,0 @@ -package handler - -import ( - "fusenapi/server/websocket/internal/logic" - "fusenapi/server/websocket/internal/svc" - "fusenapi/server/websocket/internal/types" - "fusenapi/utils/basic" - "net/http" - "reflect" -) - -func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.RenderNotifyReq - _, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - // 创建一个业务逻辑层实例 - l := logic.NewRenderNotifyLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.RenderNotify(&req) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/websocket/internal/handler/routes.go b/server/websocket/internal/handler/routes.go index 6649e3c3..fd3200e4 100644 --- a/server/websocket/internal/handler/routes.go +++ b/server/websocket/internal/handler/routes.go @@ -17,16 +17,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/websocket/data_transfer", Handler: DataTransferHandler(serverCtx), }, - { - Method: http.MethodPost, - Path: "/api/websocket/render_notify", - Handler: RenderNotifyHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/api/websocket/third_party_login_notify", - Handler: ThirdPartyLoginNotifyHandler(serverCtx), - }, }, ) } diff --git a/server/websocket/internal/handler/thirdpartyloginnotifyhandler.go b/server/websocket/internal/handler/thirdpartyloginnotifyhandler.go deleted file mode 100644 index ae16b24c..00000000 --- a/server/websocket/internal/handler/thirdpartyloginnotifyhandler.go +++ /dev/null @@ -1,35 +0,0 @@ -package handler - -import ( - "net/http" - "reflect" - - "fusenapi/utils/basic" - - "fusenapi/server/websocket/internal/logic" - "fusenapi/server/websocket/internal/svc" - "fusenapi/server/websocket/internal/types" -) - -func ThirdPartyLoginNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.ThirdPartyLoginNotifyReq - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - - // 创建一个业务逻辑层实例 - l := logic.NewThirdPartyLoginNotifyLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.ThirdPartyLoginNotify(&req, userinfo) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/websocket/internal/logic/mq_consumer.go b/server/websocket/internal/logic/mq_consumer.go new file mode 100644 index 00000000..c28ff2d6 --- /dev/null +++ b/server/websocket/internal/logic/mq_consumer.go @@ -0,0 +1,52 @@ +package logic + +import ( + "encoding/json" + "fusenapi/constants" + "fusenapi/utils/websocket_data" + "github.com/zeromicro/go-zero/core/logx" +) + +// 消费渲染结果数据 +type MqConsumerRenderResult struct { +} + +func (m *MqConsumerRenderResult) Run(data []byte) error { + logx.Info("接收到MqConsumerRenderResult数据:", string(data)) + var parseInfo websocket_data.RenderImageNotify + if err := json.Unmarshal(data, &parseInfo); err != nil { + logx.Error("MqConsumerRenderResult data format err:", err) + return nil //不返回错误则就删掉该消息 + } + //遍历websocket链接把数据传进去 + mapConnPool.Range(func(key, value any) bool { + //断言连接 + ws, ok := value.(wsConnectItem) + if !ok { + return true + } + //关闭标识 + if ws.isClose { + return true + } + //查询有无该渲染任务 + renderId, ok := ws.renderProperty.renderImageTask[parseInfo.TaskId] + if !ok { + return true + } + b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ + RenderId: renderId, + Image: parseInfo.Image, + }) + //删除对应的需要渲染的图片map + ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ + Option: 0, //0删除 1添加 + TaskId: parseInfo.TaskId, + RenderId: renderId, + } + //发送数据到out chan + ws.sendToOutChan(b) + return true + }) + return nil +} diff --git a/server/websocket/internal/logic/thirdpartyloginnotifylogic.go b/server/websocket/internal/logic/thirdpartyloginnotifylogic.go deleted file mode 100644 index d3639a95..00000000 --- a/server/websocket/internal/logic/thirdpartyloginnotifylogic.go +++ /dev/null @@ -1,79 +0,0 @@ -package logic - -import ( - "fusenapi/constants" - "fusenapi/utils/auth" - "fusenapi/utils/basic" - "fusenapi/utils/websocket_data" - "time" - - "context" - - "fusenapi/server/websocket/internal/svc" - "fusenapi/server/websocket/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ThirdPartyLoginNotifyLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewThirdPartyLoginNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThirdPartyLoginNotifyLogic { - return &ThirdPartyLoginNotifyLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 处理进入前逻辑w,r -// func (l *ThirdPartyLoginNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { -// } - -// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *ThirdPartyLoginNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// // httpx.OkJsonCtx(r.Context(), w, resp) -// } - -func (l *ThirdPartyLoginNotifyLogic) ThirdPartyLoginNotify(req *types.ThirdPartyLoginNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { - if time.Now().Unix()-120 > req.Time /*|| req.Time > time.Now().Unix() */ { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param: time is invalid") - } - if req.Info.WebsocketId <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:websocket_id is required") - } - if req.Info.Token == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:token is required") - } - //验证签名 sha256 - /*notifyByte, _ := json.Marshal(req.Info) - h := sha256.New() - h.Write([]byte(fmt.Sprintf(constants.THIRD_PARTY_LOGIN_NOTIFY_SIGN_KEY, string(notifyByte), req.Time))) - signHex := h.Sum(nil) - sign := hex.EncodeToString(signHex) - //fmt.Println(sign) - if req.Sign != sign { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign") - }*/ - //查询对应websocket连接 - val, ok := mapConnPool.Load(req.Info.WebsocketId) - if !ok { - return resp.SetStatusWithMessage(basic.CodeOK, "success:websocket connection is not exists") - } - ws, ok := val.(wsConnectItem) - if !ok { - return resp.SetStatusWithMessage(basic.CodeServiceErr, "type of websocket connect object is err") - } - b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, websocket_data.ThirdPartyLoginRspMsg{ - Token: req.Info.Token, - }) - select { - case <-ws.closeChan: - return resp.SetStatusWithMessage(basic.CodeOK, "websocket connect object is closed") - case ws.outChan <- b: - return resp.SetStatusWithMessage(basic.CodeOK, "success") - } -} diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 67d38865..70ec268a 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -5,28 +5,6 @@ import ( "fusenapi/utils/basic" ) -type RenderNotifyReq struct { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info NotifyInfo `json:"info"` -} - -type NotifyInfo struct { - TaskId string `json:"task_id"` //任务id - Image string `json:"image"` -} - -type ThirdPartyLoginNotifyReq struct { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info ThirdPartyLoginNotify `json:"info"` -} - -type ThirdPartyLoginNotify struct { - WebsocketId uint64 `json:"websocket_id"` - Token string `json:"token"` -} - type Request struct { } diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go index 01a9efb8..202e57fd 100644 --- a/server/websocket/websocket.go +++ b/server/websocket/websocket.go @@ -5,7 +5,7 @@ import ( "flag" "fmt" "fusenapi/constants" - "fusenapi/server/websocket/consumer" + "fusenapi/server/websocket/internal/logic" "net/http" "fusenapi/utils/auth" @@ -34,7 +34,7 @@ func main() { ctx1 := context.Background() ctx2, cancel := context.WithCancel(ctx1) defer cancel() - go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &consumer.MqConsumerRenderResult{}) + go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &logic.MqConsumerRenderResult{}) handler.RegisterHandlers(server, ctx) fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) server.Start() diff --git a/server_api/render.api b/server_api/render.api index ba162b18..f25d6ab3 100644 --- a/server_api/render.api +++ b/server_api/render.api @@ -16,10 +16,18 @@ type RequestReadImages { } service render { - // 发送数据到unity渲染 - @handler ToUnityHandler - get /api/render/to-unity(RequestToUnity) returns (response); - // 读图像 - @handler ReadImagesHandler - get /api/render/read-images(RequestReadImages) returns (response); + //云渲染完了通知接口 + @handler RenderNotifyHandler + post /api/render/render_notify(RenderNotifyReq) returns (response); +} + +//渲染完了通知接口 +type RenderNotifyReq { + Sign string `json:"sign"` + Time int64 `json:"time"` + Info NotifyInfo `json:"info"` +} +type NotifyInfo { + TaskId string `json:"task_id"` //任务id + Image string `json:"image"` } \ No newline at end of file diff --git a/server_api/websocket.api b/server_api/websocket.api index 22104825..ef24d79f 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -12,31 +12,4 @@ service websocket { //websocket数据交互 @handler DataTransferHandler get /api/websocket/data_transfer(request) returns (response); - //云渲染完了通知接口 - @handler RenderNotifyHandler - post /api/websocket/render_notify(RenderNotifyReq) returns (response); - //第三方登录通知接口 - @handler ThirdPartyLoginNotifyHandler - post /api/websocket/third_party_login_notify(ThirdPartyLoginNotifyReq) returns (response); -} - -//渲染完了通知接口 -type RenderNotifyReq { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info NotifyInfo `json:"info"` -} -type NotifyInfo { - TaskId string `json:"task_id"` //任务id - Image string `json:"image"` -} -//第三方登录通知接口 -type ThirdPartyLoginNotifyReq { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info ThirdPartyLoginNotify `json:"info"` -} -type ThirdPartyLoginNotify { - WebsocketId uint64 `json:"websocket_id"` - Token string `json:"token"` } \ No newline at end of file diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 3ec0067a..1add9d87 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -5,16 +5,24 @@ type DataTransferData struct { T string `json:"t"` //消息类型 D interface{} `json:"d"` //传递的消息 } + +// websocket接受要云渲染处理的数据 type RenderImageReqMsg struct { - //websocket接受要云渲染处理的数据 RenderId string `json:"render_id"` //渲染id RenderData interface{} `json:"render_data"` //参数数据 } + +// websocket发送渲染完的数据 type RenderImageRspMsg struct { - //websocket发送渲染完的数据 RenderId string `json:"render_id"` //渲染id Image string `json:"image"` //渲染结果图片 } + +// 渲染服务器回调数据 +type RenderImageNotify struct { + TaskId string `json:"task_id"` + Image string `json:"image"` +} type ThirdPartyLoginRspMsg struct { //websocket三方登录的通知数据 Token string `json:"token"`