From ecd06fc837dde312c66c14c53580a81a61594961 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 17:39:31 +0800 Subject: [PATCH] fix --- .../websocket/internal/logic/datatransferlogic.go | 7 ++++--- server/websocket/internal/logic/ws_err_response.go | 13 ++++++++----- utils/websocket_data/base_data.go | 12 ++++++++++-- utils/websocket_data/render_data.go | 8 -------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index eaa9e9bc..6594b632 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -185,7 +185,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use if isFirefoxBrowser { time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) } - l.sendGetUniqueIdErrResponse(conn) + l.sendGetUniqueIdErrResponse(conn, userInfo.Debug) return wsConnectItem{}, err } //传入绑定的wid判断是否可重用 @@ -442,8 +442,9 @@ func (w *wsConnectItem) sendToInChan(data []byte) { // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ - T: msgType, - D: data, + T: msgType, + D: data, + Debug: w.debug != nil, } b, _ := json.Marshal(d) return b diff --git a/server/websocket/internal/logic/ws_err_response.go b/server/websocket/internal/logic/ws_err_response.go index 3b01c758..0e966684 100644 --- a/server/websocket/internal/logic/ws_err_response.go +++ b/server/websocket/internal/logic/ws_err_response.go @@ -3,16 +3,18 @@ package logic import ( "encoding/json" "fusenapi/constants" + "fusenapi/utils/auth" "fusenapi/utils/websocket_data" "github.com/gorilla/websocket" "time" ) // 获取唯一标识失败通知 -func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) { +func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn, debug *auth.Debug) { rsp := websocket_data.DataTransferData{ - T: constants.WEBSOCKET_CONNECT_ERR, - D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "}, + T: constants.WEBSOCKET_CONNECT_ERR, + D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "}, + Debug: debug != nil, } b, _ := json.Marshal(rsp) //先发一条正常信息 @@ -24,8 +26,9 @@ func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) { // 鉴权失败通知 func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) { rsp := websocket_data.DataTransferData{ - T: constants.WEBSOCKET_UNAUTH, - D: websocket_data.ConnectUnAuth{Message: errMessage}, + T: constants.WEBSOCKET_UNAUTH, + D: websocket_data.ConnectUnAuth{Message: errMessage}, + Debug: false, } b, _ := json.Marshal(rsp) if isFirefoxBrowser { diff --git a/utils/websocket_data/base_data.go b/utils/websocket_data/base_data.go index 2951c394..d9d4476d 100644 --- a/utils/websocket_data/base_data.go +++ b/utils/websocket_data/base_data.go @@ -1,9 +1,17 @@ package websocket_data +import "fusenapi/constants" + +// websocket数据交互基本数据类型 +type DataTransferData struct { + T constants.Websocket `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 + Debug bool `json:"debug"` //是否开启debug +} + // 基础连接成功返回 type ConnectSuccessMsg struct { - Wid string `json:"wid"` //websocket连接唯一标识 - Debug bool `json:"debug"` //是否开启debug + Wid string `json:"wid"` //websocket连接唯一标识 } // 连接失败 diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index bcca7309..fb97e0a6 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -1,13 +1,5 @@ package websocket_data -import "fusenapi/constants" - -// websocket数据交互基本数据类型 -type DataTransferData struct { - T constants.Websocket `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 -} - // websocket接受要云渲染处理的数据 type RenderImageReqMsg struct { RenderId string `json:"render_id"` //渲染id