This commit is contained in:
laodaming
2023-07-28 17:15:37 +08:00
parent 5871da7b54
commit fef9f8d390
5 changed files with 101 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"fusenapi/constants"
"fusenapi/initalize"
"fusenapi/server/websocket/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/id_generator"
@@ -64,13 +65,14 @@ var (
// 每个连接的连接基本属性
type wsConnectItem struct {
conn *websocket.Conn //websocket的连接
closeChan chan struct{} //ws连接关闭chan
isClose bool //是否已经关闭
uniqueId uint64 //ws连接唯一标识
inChan chan []byte //接受消息缓冲通道
outChan chan []byte //发送回客户端的消息
mutex sync.Mutex //互斥锁
renderProperty renderProperty //扩展云渲染属性
rabbitMq *initalize.RabbitMqHandle
closeChan chan struct{} //ws连接关闭chan
isClose bool //是否已经关闭
uniqueId uint64 //ws连接唯一标识
inChan chan []byte //接受消息缓冲通道
outChan chan []byte //发送回客户端的消息
mutex sync.Mutex //互斥锁
renderProperty renderProperty //扩展云渲染属性
}
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) {
@@ -100,6 +102,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
uniqueId := websocketIdGenerator.Get()
ws := wsConnectItem{
conn: conn,
rabbitMq: l.svcCtx.RabbitMq,
uniqueId: uniqueId,
closeChan: make(chan struct{}, 1),
inChan: make(chan []byte, 1000),
@@ -272,7 +275,7 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
switch parseInfo.T {
//图片渲染
case constants.WEBSOCKET_RENDER_IMAGE:
go w.SendToCloudRender(d)
w.SendToCloudRender(d)
default:
}

View File

@@ -59,8 +59,12 @@ func (w *wsConnectItem) SendToCloudRender(data []byte) {
Option: 1, //0删除 1添加
Key: key,
}
// TODO 数据发送给云渲染服务器
if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, data); err != nil {
logx.Error(err)
continue
}
logx.Info("发送渲染数据到rabbitmq成功")
}
}
}

View File

@@ -18,6 +18,7 @@ type ServiceContext struct {
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
RabbitMq *initalize.RabbitMqHandle
}
func NewServiceContext(c config.Config) *ServiceContext {
@@ -26,6 +27,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
Config: c,
MysqlConn: initalize.InitMysql(c.SourceMysql),
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
}
}