This commit is contained in:
laodaming 2023-09-22 10:41:38 +08:00
parent 1040f21ca6
commit bb645ce6f6
2 changed files with 21 additions and 9 deletions

View File

@ -192,7 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
userId: userInfo.UserId,
guestId: userInfo.GuestId,
extendRenderProperty: extendRenderProperty{
renderChan: make(chan []byte, renderChanLen),
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
},
}
//保存连接

View File

@ -30,16 +30,26 @@ type renderProcessor struct {
// 云渲染属性
type extendRenderProperty struct {
renderChan chan []byte //渲染消息入口的缓冲队列
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
colorSelectedIndex int //选择颜色索引
templateTag string //模板标签
}
// 处理分发到这里的数据
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
//logx.Info("开始处理渲染任务消息:", string(data))
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("invalid format of websocket render image message", err)
return
}
select {
case <-w.closeChan: //已经关闭
return
case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
w.extendRenderProperty.colorSelectedIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag
return
}
}
@ -51,26 +61,28 @@ func (w *wsConnectItem) consumeRenderImageData() {
logx.Error("func renderImage err:", err)
}
}()
var data []byte
for {
select {
case <-w.closeChan: //已关闭
return
case data = <-w.extendRenderProperty.renderChan: //消费数据
w.renderImage(data)
case data := <-w.extendRenderProperty.renderChan: //消费数据
//属性相同则发送渲染,不同则抛弃
if data.RenderData.TemplateTag == w.extendRenderProperty.templateTag && data.RenderData.TemplateTagColor.SelectedColorIndex == w.extendRenderProperty.colorSelectedIndex {
w.renderImage(data)
}
}
}
}
// 执行渲染任务
func (w *wsConnectItem) renderImage(data []byte) {
func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) {
//logx.Info("消费渲染数据:", string(data))
var renderImageData websocket_data.RenderImageReqMsg
/*var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("invalid format of websocket render image message", err)
return
}
}*/
if renderImageData.RenderData.Logo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return