add websockettype ping

This commit is contained in:
Martin/Geno 2018-08-24 23:44:26 +02:00
parent 832c30fa26
commit 3a887ec1c5
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 13 additions and 0 deletions

View File

@ -13,4 +13,6 @@ const (
MessageTypeNode = "node" MessageTypeNode = "node"
MessageTypeStats = "stats" MessageTypeStats = "stats"
MessageTypePing = "ping"
) )

View File

@ -15,3 +15,14 @@ func (ws *WebsocketServer) SendNode(node *runtime.Node) {
func (ws *WebsocketServer) SendStats(data *yanicRuntime.GlobalStats) { func (ws *WebsocketServer) SendStats(data *yanicRuntime.GlobalStats) {
ws.ws.SendAll(&wsLib.Message{Subject: MessageTypeStats, Body: data}) ws.ws.SendAll(&wsLib.Message{Subject: MessageTypeStats, Body: data})
} }
func (ws *WebsocketServer) SendPing(data interface{}) {
var sessions []*Session
msg := &wsLib.Message{Subject: MessageTypePing, Body: data}
ws.db.Find(&sessions)
for _, session := range sessions {
if session.Ping {
ws.ws.SendSession(session.SessionID, msg)
}
}
}