Add /situation WS with 100ms update.

pull/145/head
Christopher Young 2015-12-01 19:23:35 -05:00
rodzic ab889fb116
commit 9f5cf89705
1 zmienionych plików z 21 dodań i 0 usunięć

Wyświetl plik

@ -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{