From 9f5cf89705e97f4c1cceef45cb56cbcd6ec75646 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Tue, 1 Dec 2015 19:23:35 -0500 Subject: [PATCH] Add /situation WS with 100ms update. --- main/managementinterface.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main/managementinterface.go b/main/managementinterface.go index 813062d9..6aab6cba 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -101,6 +101,21 @@ func handleStatusWS(conn *websocket.Conn) { } } +func handleSituationWS(conn *websocket.Conn) { + timer := time.NewTicker(100 * time.Millisecond) + for { + <-timer.C + situationJSON, _ := json.Marshal(&mySituation) + _, err := conn.Write(situationJSON) + + if err != nil { + break + } + + } + +} + // AJAX call - /getStatus. Responds with current global status // a webservice call for the same data available on the websocket but when only a single update is needed func handleStatusRequest(w http.ResponseWriter, r *http.Request) { @@ -225,6 +240,12 @@ func managementInterface() { Handler: websocket.Handler(handleStatusWS)} s.ServeHTTP(w, req) }) + http.HandleFunc("/situation", + func(w http.ResponseWriter, req *http.Request) { + s := websocket.Server{ + Handler: websocket.Handler(handleSituationWS)} + s.ServeHTTP(w, req) + }) http.HandleFunc("/weather", func(w http.ResponseWriter, req *http.Request) { s := websocket.Server{