From e77638b0e1e4af8d698358af5f7d7459152d30ed Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 11 Oct 2023 18:06:40 +0800 Subject: [PATCH] fix --- .../internal/logic/datatransferlogic.go | 6 +++--- utils/websocket_data/base_data.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 utils/websocket_data/base_data.go diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index bd23c295..a870d52a 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -252,7 +252,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use if isFirefoxBrowser { time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) } - ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId)) + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId})) //发送累加统计连接书 increaseWebsocketConnectCount() return ws, nil @@ -306,7 +306,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool) { rsp := websocket_data.DataTransferData{ T: constants.WEBSOCKET_UNAUTH, - D: nil, + D: websocket_data.ConnectUnAuth{Message: "unAuth"}, } b, _ := json.Marshal(rsp) if isFirefoxBrowser { @@ -323,7 +323,7 @@ func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) { time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) rsp := websocket_data.DataTransferData{ T: constants.WEBSOCKET_CONNECT_ERR, - D: "err to gen unique id ", + D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "}, } b, _ := json.Marshal(rsp) //先发一条正常信息 diff --git a/utils/websocket_data/base_data.go b/utils/websocket_data/base_data.go new file mode 100644 index 00000000..c3799fa4 --- /dev/null +++ b/utils/websocket_data/base_data.go @@ -0,0 +1,16 @@ +package websocket_data + +// 基础连接成功返回 +type ConnectSuccessMsg struct { + Wid string `json:"wid"` +} + +// 连接失败 +type ConnectErrMsg struct { + Message string `json:"message"` +} + +// 未授权 +type ConnectUnAuth struct { + Message string `json:"message"` +}