From 3a887ec1c5a970a057cd94db33f3bd950c2cca27 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Fri, 24 Aug 2018 23:44:26 +0200 Subject: [PATCH] add websockettype ping --- websocket/msg.go | 2 ++ websocket/send.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/websocket/msg.go b/websocket/msg.go index f11a4a9..1a6c0fd 100644 --- a/websocket/msg.go +++ b/websocket/msg.go @@ -13,4 +13,6 @@ const ( MessageTypeNode = "node" MessageTypeStats = "stats" + + MessageTypePing = "ping" ) diff --git a/websocket/send.go b/websocket/send.go index 3f6f7f7..65f694e 100644 --- a/websocket/send.go +++ b/websocket/send.go @@ -15,3 +15,14 @@ func (ws *WebsocketServer) SendNode(node *runtime.Node) { func (ws *WebsocketServer) SendStats(data *yanicRuntime.GlobalStats) { 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) + } + } +}