2018-06-30 16:20:54 +02:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
2018-07-26 14:14:23 +02:00
|
|
|
wsLib "dev.sum7.eu/genofire/golang-lib/websocket"
|
2018-06-30 16:20:54 +02:00
|
|
|
|
|
|
|
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
|
2019-06-03 15:38:46 +02:00
|
|
|
"github.com/FreifunkBremen/freifunkmanager/data"
|
2019-06-05 12:00:11 +02:00
|
|
|
"github.com/FreifunkBremen/freifunkmanager/runtime"
|
2018-06-30 16:20:54 +02:00
|
|
|
)
|
|
|
|
|
2018-08-10 13:46:18 +02:00
|
|
|
func (ws *WebsocketServer) SendNode(node *runtime.Node) {
|
|
|
|
ws.ws.SendAll(&wsLib.Message{Subject: MessageTypeNode, Body: node})
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|