freifunkmanager/websocket/send.go

30 lines
803 B
Go
Raw Permalink Normal View History

package websocket
import (
2018-07-26 14:14:23 +02:00
wsLib "dev.sum7.eu/genofire/golang-lib/websocket"
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
2019-06-03 15:38:46 +02:00
"github.com/FreifunkBremen/freifunkmanager/data"
"github.com/FreifunkBremen/freifunkmanager/runtime"
)
2018-08-10 13:46:18 +02:00
func (ws *WebsocketServer) SendNode(node *runtime.Node) {
ws.ws.SendAll(&wsLib.Message{Subject: MessageTypeNode, Body: node})
}
func (ws *WebsocketServer) SendStats(data *yanicRuntime.GlobalStats) {
ws.ws.SendAll(&wsLib.Message{Subject: MessageTypeStats, Body: data})
}
2019-06-03 15:38:46 +02:00
func (ws *WebsocketServer) SendPing(pResult *data.PingResult) {
2018-08-24 23:44:26 +02:00
var sessions []*Session
2019-06-03 15:38:46 +02:00
msg := &wsLib.Message{Subject: MessageTypePing, Body: pResult}
2018-08-24 23:44:26 +02:00
ws.db.Find(&sessions)
for _, session := range sessions {
if session.Ping {
ws.ws.SendSession(session.SessionID, msg)
}
}
}