From 31ce7dfc19bca935c6d65467ae93eee6e9029270 Mon Sep 17 00:00:00 2001 From: lwch Date: Fri, 29 Oct 2021 19:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vnc=E7=9A=84ws=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/tunnel/vnc/core/capture_windows.go | 2 +- code/client/tunnel/vnc/h_ws.go | 23 +++++++++++++++++++ code/client/tunnel/vnc/vnc.go | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 code/client/tunnel/vnc/h_ws.go diff --git a/code/client/tunnel/vnc/core/capture_windows.go b/code/client/tunnel/vnc/core/capture_windows.go index 57dded6..edb3ef0 100644 --- a/code/client/tunnel/vnc/core/capture_windows.go +++ b/code/client/tunnel/vnc/core/capture_windows.go @@ -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 } diff --git a/code/client/tunnel/vnc/h_ws.go b/code/client/tunnel/vnc/h_ws.go new file mode 100644 index 0000000..23626fc --- /dev/null +++ b/code/client/tunnel/vnc/h_ws.go @@ -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()) + } +} diff --git a/code/client/tunnel/vnc/vnc.go b/code/client/tunnel/vnc/vnc.go index 5bfd3ed..f7b0a3b 100644 --- a/code/client/tunnel/vnc/vnc.go +++ b/code/client/tunnel/vnc/vnc.go @@ -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),