mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
send heartbeat with ping. (#16)
This commit is contained in:
parent
482476489e
commit
2cb64d15a0
@ -23,6 +23,16 @@ const pingPeriod = 10 * time.Second
|
||||
// period for sending inactive cursor messages
|
||||
const inactiveCursorsPeriod = 750 * time.Millisecond
|
||||
|
||||
// events that are not logged in debug mode
|
||||
var nologEvents = []string{
|
||||
// don't log twice
|
||||
event.SYSTEM_LOGS,
|
||||
// don't log heartbeat
|
||||
event.SYSTEM_HEARTBEAT,
|
||||
// don't log every cursor update
|
||||
event.SESSION_CURSORS,
|
||||
}
|
||||
|
||||
func New(
|
||||
sessions types.SessionManager,
|
||||
desktop types.DesktopManager,
|
||||
@ -301,7 +311,8 @@ func (manager *WebSocketManagerCtx) handle(connection *websocket.Conn, peer type
|
||||
break
|
||||
}
|
||||
|
||||
if data.Event != event.SYSTEM_LOGS {
|
||||
// log events if not ignored
|
||||
if ok, _ := utils.ArrayIn(data.Event, nologEvents); !ok {
|
||||
logger.Debug().
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Str("event", data.Event).
|
||||
|
@ -75,6 +75,13 @@ func (peer *WebSocketPeerCtx) Ping() error {
|
||||
return errors.New("peer connection not found")
|
||||
}
|
||||
|
||||
// application level heartbeat
|
||||
if err := peer.connection.WriteJSON(types.WebSocketMessage{
|
||||
Event: event.SYSTEM_HEARTBEAT,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return peer.connection.WriteMessage(websocket.PingMessage, nil)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ const (
|
||||
SYSTEM_SETTINGS = "system/settings"
|
||||
SYSTEM_LOGS = "system/logs"
|
||||
SYSTEM_DISCONNECT = "system/disconnect"
|
||||
SYSTEM_HEARTBEAT = "system/heartbeat"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
type WebSocketMessage struct {
|
||||
Event string `json:"event"`
|
||||
Payload json.RawMessage `json:"payload"`
|
||||
Payload json.RawMessage `json:"payload,omitempty"`
|
||||
}
|
||||
|
||||
type WebSocketHandler func(Session, WebSocketMessage) bool
|
||||
|
Loading…
Reference in New Issue
Block a user