fix
This commit is contained in:
parent
6a9bfa0ef0
commit
6c341590ee
|
@ -9,9 +9,6 @@ const (
|
|||
WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单向通信)
|
||||
)
|
||||
|
||||
// 心跳
|
||||
const WEBSOCKET_HEARTBEAT Websocket = "WEBSOCKET_HEARTBEAT"
|
||||
|
||||
// websocket消息类型(通用通知类别)
|
||||
const (
|
||||
WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知(1级消息,单向通信)
|
||||
|
|
|
@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/websocket/close_websocket",
|
||||
Handler: CloseWebsocketHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/websocket/get_stat",
|
||||
Handler: GetStatHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -321,15 +321,7 @@ func (w *wsConnectItem) heartbeat() {
|
|||
if w.debug != nil && w.debug.Exp != nil && *w.debug.Exp < time.Now().UTC().Unix() {
|
||||
w.debug = nil
|
||||
}
|
||||
//发送心跳信息
|
||||
var d interface{}
|
||||
if w.debug != nil {
|
||||
d = websocket_data.HeartBeatMsg{
|
||||
WsCount: currentWebsocketConnectCount,
|
||||
CombineCount: currentRequestCombineApiCount,
|
||||
}
|
||||
}
|
||||
if err := w.conn.WriteMessage(websocket.PongMessage, w.respondDataFormat(constants.WEBSOCKET_HEARTBEAT, d)); err != nil {
|
||||
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
|
||||
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
|
||||
w.close()
|
||||
return
|
||||
|
|
|
@ -29,6 +29,15 @@ type CloseWebsocketReq struct {
|
|||
Wid string `json:"wid"`
|
||||
}
|
||||
|
||||
type GetStatReq struct {
|
||||
Password string `form:"password"`
|
||||
}
|
||||
|
||||
type GetStatRsp struct {
|
||||
WsTotalCount int `json:"ws_total_count"` //ws连接数
|
||||
CurRequestCombineCount int `json:"cur_request_combine_count"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ service websocket {
|
|||
//关闭某个连接
|
||||
@handler CloseWebsocketHandler
|
||||
post /api/websocket/close_websocket(CloseWebsocketReq) returns (response);
|
||||
//获取ws统计信息
|
||||
@handler GetStatHandler
|
||||
post /api/websocket/get_stat(GetStatReq) returns (response);
|
||||
}
|
||||
|
||||
//websocket数据交互[
|
||||
|
@ -46,4 +49,12 @@ type CommonNotifyReq {
|
|||
//关闭连接
|
||||
type CloseWebsocketReq {
|
||||
Wid string `json:"wid"`
|
||||
}
|
||||
//获取ws统计信息
|
||||
type GetStatReq {
|
||||
Password string `form:"password"`
|
||||
}
|
||||
type GetStatRsp {
|
||||
WsTotalCount int `json:"ws_total_count"` //ws连接数
|
||||
CurRequestCombineCount int `json:"cur_request_combine_count"`
|
||||
}
|
|
@ -23,9 +23,3 @@ type ConnectErrMsg struct {
|
|||
type ConnectUnAuth struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// 心跳数据
|
||||
type HeartBeatMsg struct {
|
||||
WsCount int `json:"ws_count"`
|
||||
CombineCount int `json:"combine_count"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user