This commit is contained in:
laodaming
2023-08-23 15:08:45 +08:00
parent be6b6a5076
commit b91c8d75f0
36 changed files with 317 additions and 75 deletions

View File

@@ -1,5 +1,6 @@
package logic
//websocket连接
import (
"bytes"
"encoding/json"
@@ -323,7 +324,7 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
}
// 格式化为websocket标准返回格式
func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte {
func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte {
d := websocket_data.DataTransferData{
T: msgType,
D: data,

View File

@@ -0,0 +1,56 @@
package logic
//登录回调
import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/websocket/internal/svc"
"fusenapi/server/websocket/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type LoginNotifyLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewLoginNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginNotifyLogic {
return &LoginNotifyLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *LoginNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.Data.WebsocketConnId == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,连接标识不能为空")
}
value, ok := mapConnPool.Load(req.Data.WebsocketConnId)
if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
}
ws, ok := value.(wsConnectItem)
if !ok {
logx.Error("渲染回调断言websocket连接失败")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误")
}
//发送消息到出口缓冲池
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_LOGIN_NOTIFY, req.Data.Info))
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *LoginNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -0,0 +1,56 @@
package logic
//注册帐号回调
import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/websocket/internal/svc"
"fusenapi/server/websocket/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type RegisterAccountNotifyLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRegisterAccountNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterAccountNotifyLogic {
return &RegisterAccountNotifyLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *RegisterAccountNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAccountNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.Data.WebsocketConnId == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,连接标识不能为空")
}
value, ok := mapConnPool.Load(req.Data.WebsocketConnId)
if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
}
ws, ok := value.(wsConnectItem)
if !ok {
logx.Error("渲染回调断言websocket连接失败")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误")
}
//发送消息到出口缓冲池
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_REGISTER_NOTIFY, req.Data.Info))
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *RegisterAccountNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -1,5 +1,6 @@
package logic
//云渲染回调
import (
"context"
"fusenapi/server/websocket/internal/svc"

View File

@@ -1,5 +1,6 @@
package logic
//处理websocket云渲染任务数据
import (
"bytes"
"encoding/json"

View File

@@ -1,5 +1,6 @@
package logic
//复用websocket连接标识
import (
"encoding/json"
"fmt"