Add new WebSocket command

This commit is contained in:
Ivan Danyliuk 2018-08-24 23:11:48 +03:00
parent 95f10be6a8
commit 65503ee846
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
1 changed files with 5 additions and 3 deletions

8
ws.go
View File

@ -31,8 +31,7 @@ func NewWSServer(layout *layout.Layout) *WSServer {
} }
type WSResponse struct { type WSResponse struct {
Type MsgType `json:"type"` Type MsgType `json:"type"`
//Positions []*position `json:"positions,omitempty"`
Positions map[string]*layout.Object `json:"positions,omitempty"` Positions map[string]*layout.Object `json:"positions,omitempty"`
Graph json.RawMessage `json:"graph,omitempty"` Graph json.RawMessage `json:"graph,omitempty"`
Propagation *PropagationLog `json:"propagation,omitempty"` Propagation *PropagationLog `json:"propagation,omitempty"`
@ -54,7 +53,8 @@ const (
// WebSocket commands // WebSocket commands
const ( const (
CmdInit WSCommand = "init" CmdInit WSCommand = "init"
CmdSendMessage WSCommand = "send_message"
) )
func (ws *WSServer) Handle(w http.ResponseWriter, r *http.Request) { func (ws *WSServer) Handle(w http.ResponseWriter, r *http.Request) {
@ -91,6 +91,8 @@ func (ws *WSServer) processRequest(c *websocket.Conn, mtype int, data []byte) {
ws.updatePositions() ws.updatePositions()
ws.sendPositions(c) ws.sendPositions(c)
ws.sendPropagationData(c) ws.sendPropagationData(c)
case CmdSendMessage:
ws.sendPropagationData(c)
} }
} }