fix
This commit is contained in:
parent
6a9bfa0ef0
commit
6c341590ee
@ -9,9 +9,6 @@ const (
|
|||||||
WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单向通信)
|
WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单向通信)
|
||||||
)
|
)
|
||||||
|
|
||||||
// 心跳
|
|
||||||
const WEBSOCKET_HEARTBEAT Websocket = "WEBSOCKET_HEARTBEAT"
|
|
||||||
|
|
||||||
// websocket消息类型(通用通知类别)
|
// websocket消息类型(通用通知类别)
|
||||||
const (
|
const (
|
||||||
WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知(1级消息,单向通信)
|
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",
|
Path: "/api/websocket/close_websocket",
|
||||||
Handler: CloseWebsocketHandler(serverCtx),
|
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() {
|
if w.debug != nil && w.debug.Exp != nil && *w.debug.Exp < time.Now().UTC().Unix() {
|
||||||
w.debug = nil
|
w.debug = nil
|
||||||
}
|
}
|
||||||
//发送心跳信息
|
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != 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 {
|
|
||||||
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
|
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
|
||||||
w.close()
|
w.close()
|
||||||
return
|
return
|
||||||
|
@ -29,6 +29,15 @@ type CloseWebsocketReq struct {
|
|||||||
Wid string `json:"wid"`
|
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 {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ service websocket {
|
|||||||
//关闭某个连接
|
//关闭某个连接
|
||||||
@handler CloseWebsocketHandler
|
@handler CloseWebsocketHandler
|
||||||
post /api/websocket/close_websocket(CloseWebsocketReq) returns (response);
|
post /api/websocket/close_websocket(CloseWebsocketReq) returns (response);
|
||||||
|
//获取ws统计信息
|
||||||
|
@handler GetStatHandler
|
||||||
|
post /api/websocket/get_stat(GetStatReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//websocket数据交互[
|
//websocket数据交互[
|
||||||
@ -47,3 +50,11 @@ type CommonNotifyReq {
|
|||||||
type CloseWebsocketReq {
|
type CloseWebsocketReq {
|
||||||
Wid string `json:"wid"`
|
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 {
|
type ConnectUnAuth struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 心跳数据
|
|
||||||
type HeartBeatMsg struct {
|
|
||||||
WsCount int `json:"ws_count"`
|
|
||||||
CombineCount int `json:"combine_count"`
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user