From 2b6a5d2ce26045ea0dd8cbabd24afffbe5ddaf46 Mon Sep 17 00:00:00 2001 From: lwch Date: Mon, 1 Nov 2021 15:34:01 +0800 Subject: [PATCH] WIP --- code/client/tunnel/vnc/h_ws.go | 37 ++++++++++++++++++++++++++++++++-- html/vnc/index.css | 0 html/vnc/index.html | 15 ++++++++++++++ html/vnc/index.js | 5 +++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 html/vnc/index.css create mode 100644 html/vnc/index.js diff --git a/code/client/tunnel/vnc/h_ws.go b/code/client/tunnel/vnc/h_ws.go index 3865d50..054f040 100644 --- a/code/client/tunnel/vnc/h_ws.go +++ b/code/client/tunnel/vnc/h_ws.go @@ -1,9 +1,18 @@ package vnc import ( + "bytes" + "errors" + "image" + "image/draw" + "image/jpeg" "natpass/code/client/pool" + "natpass/code/network" "net/http" "strings" + + "github.com/lwch/logging" + "github.com/lwch/runtime" ) func (v *VNC) WS(pool *pool.Pool, w http.ResponseWriter, r *http.Request) { @@ -14,9 +23,33 @@ func (v *VNC) WS(pool *pool.Pool, w http.ResponseWriter, r *http.Request) { return } ch := conn.ChanRead(id) + defer conn.SendDisconnect(v.link.target, v.link.targetIdx, v.link.id) for { msg := <-ch - // logging.Info("%s", msg.String()) - _ = msg + switch msg.GetXType() { + case network.Msg_vnc_image: + data, err := decodeImage(msg.GetVimg()) + runtime.Assert(err) + logging.Info("%d", len(data)) + } } } + +func decodeImage(data *network.VncImage) ([]byte, error) { + switch data.GetEncode() { + case network.VncImage_raw: + return data.GetData(), nil + case network.VncImage_jpeg: + img, err := jpeg.Decode(bytes.NewReader(data.GetData())) + if err != nil { + return nil, err + } + rect := img.Bounds() + raw := image.NewRGBA(rect) + draw.Draw(raw, rect, img, rect.Min, draw.Src) + return raw.Pix, nil + case network.VncImage_png: + // TODO + } + return nil, errors.New("unsupported") +} diff --git a/html/vnc/index.css b/html/vnc/index.css new file mode 100644 index 0000000..e69de29 diff --git a/html/vnc/index.html b/html/vnc/index.html index e69de29..d2f3ea7 100644 --- a/html/vnc/index.html +++ b/html/vnc/index.html @@ -0,0 +1,15 @@ + + + + + + vnc - [{{.Name}}] + + + + + + + + + \ No newline at end of file diff --git a/html/vnc/index.js b/html/vnc/index.js new file mode 100644 index 0000000..b74d66e --- /dev/null +++ b/html/vnc/index.js @@ -0,0 +1,5 @@ +var page = { + init: function() { + } +}; +$(document).ready(page.init); \ No newline at end of file