kopia lustrzana https://github.com/cyoung/stratux
commit
34eec10b5a
|
@ -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
|
// 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
|
// 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) {
|
func handleStatusRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -225,6 +240,12 @@ func managementInterface() {
|
||||||
Handler: websocket.Handler(handleStatusWS)}
|
Handler: websocket.Handler(handleStatusWS)}
|
||||||
s.ServeHTTP(w, req)
|
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",
|
http.HandleFunc("/weather",
|
||||||
func(w http.ResponseWriter, req *http.Request) {
|
func(w http.ResponseWriter, req *http.Request) {
|
||||||
s := websocket.Server{
|
s := websocket.Server{
|
||||||
|
|
Ładowanie…
Reference in New Issue