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 @@ + + +
+ + +