From 929738d30363dc1b4a79bcffd5d4c4301c19a111 Mon Sep 17 00:00:00 2001 From: asoseil Date: Sun, 15 Oct 2017 21:36:14 +0200 Subject: [PATCH] websocket communication fixed --- server.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index ad8f367..b504f4a 100644 --- a/server.go +++ b/server.go @@ -34,13 +34,13 @@ type Server struct { func (s *Server) projects(c echo.Context) error { websocket.Handler(func(ws *websocket.Conn) { defer ws.Close() - msg, _ := json.Marshal(s.parent.Schema) + msg, _ := json.Marshal(s.parent) err := websocket.Message.Send(ws, string(msg)) go func() { for { select { case <-s.parent.sync: - msg, _ := json.Marshal(s.parent.Schema) + msg, _ := json.Marshal(s.parent) err = websocket.Message.Send(ws, string(msg)) if err != nil { break @@ -52,12 +52,13 @@ func (s *Server) projects(c echo.Context) error { // Read text := "" err := websocket.Message.Receive(ws, &text) + fmt.Println("receive") if err != nil { break } else { - err := json.Unmarshal([]byte(text), &s.parent.Schema) - if err != nil { - s.parent.Settings.record(s.parent.Settings) + err := json.Unmarshal([]byte(text), &s.parent) + if err == nil { + s.parent.Settings.record(s.parent) break } } @@ -129,6 +130,7 @@ func (s *Server) start(p *cli.Context) (err error) { //websocket e.GET("/ws", s.projects) + e.HideBanner = true go e.Start(string(s.parent.Server.Host) + ":" + strconv.Itoa(s.parent.Server.Port)) _, err = s.openURL("http://" + string(s.parent.Server.Host) + ":" + strconv.Itoa(s.parent.Server.Port)) if err != nil {