Support Query online devices

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2018-01-17 23:55:12 +08:00
parent b8c9e36059
commit b0212d4b00
+11
View File
@@ -240,6 +240,16 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
go wsConn.wsWriteLoop()
}
func handlerList(w http.ResponseWriter, r *http.Request) {
devs := make([]string, 0)
for k, _ := range dev2wsConnection {
devs = append(devs, k)
}
js, _ := json.Marshal(devs)
fmt.Fprintf(w, "%s", js)
}
func main() {
port := flag.Int("port", 5912, "http service port")
flag.Parse()
@@ -254,6 +264,7 @@ func main() {
http.HandleFunc("/ws/device", serveWs)
http.HandleFunc("/ws/browser", serveWs)
http.HandleFunc("/list", handlerList)
http.Handle("/", http.FileServer(statikFS))
log.Fatal(http.ListenAndServe(":" + strconv.Itoa(*port), nil))
}