增加vnc的ws接口

This commit is contained in:
lwch
2021-10-29 19:04:57 +08:00
parent 318aa69c9a
commit 31ce7dfc19
3 changed files with 25 additions and 1 deletions
@@ -13,7 +13,7 @@ import (
func (worker *Worker) runCapture(conn *websocket.Conn) {
err := worker.capture()
if err != nil {
logging.Error(err.Error())
logging.Error("capture: %v", err.Error())
captureError(conn, err.Error())
return
}
+23
View File
@@ -0,0 +1,23 @@
package vnc
import (
"natpass/code/client/pool"
"net/http"
"strings"
"github.com/lwch/logging"
)
func (v *VNC) WS(pool *pool.Pool, w http.ResponseWriter, r *http.Request) {
id := strings.TrimPrefix(r.URL.Path, "/ws/")
conn := pool.Get(id)
if conn == nil {
http.NotFound(w, r)
return
}
ch := conn.ChanRead(id)
for {
msg := <-ch
logging.Info("%s", msg.String())
}
}
+1
View File
@@ -94,6 +94,7 @@ func (v *VNC) Handle(pl *pool.Pool) {
}
mux := http.NewServeMux()
mux.HandleFunc("/new", pf(v.New))
mux.HandleFunc("/ws/", pf(v.WS))
mux.HandleFunc("/", v.Render)
svr := &http.Server{
Addr: fmt.Sprintf("%s:%d", v.cfg.LocalAddr, v.cfg.LocalPort),