Documentation
¶
Overview ¶
client.go
Package client implements the RDP client, and carries the RFB (VNC) client this fork inherited from upstream alongside it.
The VNC client (VncClient) is exercised against a real server by scripts/vnc-dev.sh, which starts TigerVNC's Xtigervnc and runs the live tests in protocol/rfb. Its clipboard is implemented in both directions: text the server cuts arrives as the "clipboard-text" event, and SetClipboardText publishes with ClientCutText.
For an RDP session the pixels are read from Framebuffer, whichever drawing path the server chose. The RFB client keeps its own framebuffer inside protocol/rfb instead, because an RFB server picks the pixel format per connection rather than sending BGRA.
Index ¶
- Constants
- Variables
- func Bpp(bp uint16) int
- func MergeDirty(dirty []image.Rectangle, r, bounds image.Rectangle) []image.Rectangle
- type Bitmap
- type Client
- func (c *Client) Close()
- func (c *Client) Files() *cliprdr.CliprdrClient
- func (c *Client) Framebuffer() *Framebuffer
- func (c *Client) KeyDown(sc int, name string)
- func (c *Client) KeyUp(sc int, name string)
- func (c *Client) Login() error
- func (c *Client) LoginContext(ctx context.Context) error
- func (c *Client) MouseDown(button, x, y int)
- func (c *Client) MouseMove(x, y int)
- func (c *Client) MouseUp(button, x, y int)
- func (c *Client) MouseWheel(scroll, x, y int)
- func (c *Client) OnBitmap(f func([]Bitmap))deprecated
- func (c *Client) OnClipboardText(f func(text string))
- func (c *Client) OnClose(f func())
- func (c *Client) OnCursor(f func(cur *Cursor))
- func (c *Client) OnCursorPos(f func(x, y int))
- func (c *Client) OnError(f func(e error))
- func (c *Client) OnFrame(f func(dirty []image.Rectangle))
- func (c *Client) OnOrdersFrame(f func(dirty image.Rectangle))deprecated
- func (c *Client) OnPointer(f func(p *pdu.PointerDataPDU))
- func (c *Client) OnPointerPosition(f func(x, y int))
- func (c *Client) OnReady(f func())
- func (c *Client) OnResize(f func(w, h int))
- func (c *Client) OnSuccess(f func())
- func (c *Client) OnSurfaceFrame(f func(frameID uint32, surfaces []*rdpgfx.Surface))
- func (c *Client) OnSurfaceReset(f func(width, height int))
- func (c *Client) RequestClipboardText() error
- func (c *Client) RequestResize(w, h int) error
- func (c *Client) Screen() *orders.Screendeprecated
- func (c *Client) SetClipboardText(text string) error
- func (c *Client) TypeText(s string, hold time.Duration) error
- func (c *Client) UnicodeKeyDown(r rune)
- func (c *Client) UnicodeKeyUp(r rune)
- type Control
- type Cursor
- type Framebuffer
- type RdpClient
- func (c *RdpClient) Close()
- func (c *RdpClient) KeyDown(sc int, name string)
- func (c *RdpClient) KeyUp(sc int, name string)
- func (c *RdpClient) Login(host, user, pwd string, width, height int) error
- func (c *RdpClient) MouseDown(button int, x, y int)
- func (c *RdpClient) MouseMove(x, y int)
- func (c *RdpClient) MouseUp(button int, x, y int)
- func (c *RdpClient) MouseWheel(scroll, x, y int)
- func (c *RdpClient) On(event string, f interface{})
- func (c *RdpClient) RequestClipboardText() error
- func (c *RdpClient) SetClipboardText(text string) error
- func (c *RdpClient) UnicodeKeyDown(r rune)
- func (c *RdpClient) UnicodeKeyUp(r rune)
- type Setting
- type VncClient
- func (c *VncClient) Close()
- func (c *VncClient) KeyDown(sc int, name string)
- func (c *VncClient) KeyUp(sc int, name string)
- func (c *VncClient) Login(host, user, pwd string, width, height int) error
- func (c *VncClient) MouseDown(button int, x, y int)
- func (c *VncClient) MouseMove(x, y int)
- func (c *VncClient) MouseUp(button int, x, y int)
- func (c *VncClient) MouseWheel(scroll, x, y int)
- func (c *VncClient) On(event string, f interface{})
- func (c *VncClient) RequestClipboardText() error
- func (c *VncClient) SetClipboardText(text string) error
- func (c *VncClient) UnicodeKeyDown(r rune)
- func (c *VncClient) UnicodeKeyUp(r rune)
Constants ¶
const ( CLIP_OFF = 0 CLIP_IN = 0x1 CLIP_OUT = 0x2 )
Clipboard directions accepted by the (currently inert) Setting.SetClipboard.
const ( TC_RDP = 0 TC_VNC = 1 )
Transport kinds accepted by NewClient: TC_RDP for RDP, TC_VNC for VNC (RFB).
const DefaultLoginTimeout = 30 * time.Second
DefaultLoginTimeout bounds how long Login waits for the RDP session to become ready after the transport handshake succeeds.
Variables ¶
var ErrAuthenticationFailed = errors.New("client: the server did not accept the credentials")
ErrAuthenticationFailed reports that the CredSSP exchange did not complete, so the credentials were not accepted.
It is the distinction an operator needs and cannot get from the message alone: a wrong password against an NLA server surfaces as a TLS alert, because Windows drops the connection rather than answering with an NTLM status, and that reads like a certificate problem. Errors from Login wrap this one when the failure happened after TLS was established, which is where the authentication exchange runs.
It is not proof that the password was wrong. A server that disappeared in the middle of the exchange looks the same, which is why the name is about the exchange rather than about the password. What it does rule out is TLS itself: a certificate problem fails before this point and does not wrap it.
var ErrNoUnicodeInput = errors.New("client: this protocol has no Unicode key event; an RFB server takes scancodes only")
ErrNoUnicodeInput is returned by TypeText on a session whose protocol has no Unicode keyboard event.
var ErrSessionEndedByServer = errors.New("client: the server ended the session, which usually means another connection took it over")
ErrSessionEndedByServer reports that the server sent a disconnect ultimatum: it ended this session, most often because the same account connected from somewhere else and took it over.
A gateway has to tell this from a dropped connection, because the two look alike and only one is a fault. The session is not lost: it is still on the server, detached, and connecting again gets it back. An operator told "connection lost" goes looking for a network problem that does not exist.
It says the server ended the session, and no more than that. Whether the cause was a takeover or a logoff is not on the wire in any form this library could decode, so it is not claimed; see tpkt's DisconnectError for the byte that would have to be read to say, and why it was not read.
Functions ¶
func Bpp ¶
Bpp converts a bit depth to a byte count by dividing by eight: 16 to 2, 32 to 4. It truncates, so 15 bpp gives 1 rather than 2.
func MergeDirty ¶ added in v0.7.0
MergeDirty adds r to a list of changed rectangles, merging it with anything it overlaps or shares an edge with and collapsing to the whole of bounds once the result covers most of it.
It is what the dirty regions OnFrame reports were built with, exported for a caller that accumulates them across frames: a gateway pacing its encoding on a timer has to fold each frame's regions into what it has not sent yet, and doing that by simply appending would send the same overlapping rectangles again and again.
Types ¶
type Bitmap ¶
type Bitmap struct {
DestLeft int `json:"destLeft"`
DestTop int `json:"destTop"`
DestRight int `json:"destRight"`
DestBottom int `json:"destBottom"`
Width int `json:"width"`
Height int `json:"height"`
BitsPerPixel int `json:"bitsPerPixel"`
IsCompress bool `json:"isCompress"`
Data []byte `json:"data"`
}
Bitmap is one decoded rectangle of the remote screen.
The rectangle is [DestLeft, DestRight) x [DestTop, DestBottom) on the desktop; Width and Height are the size of the source data and are usually equal to the destination size. Data is top-down BGRA (B first) at BitsPerPixel/8 bytes per pixel when IsCompress is false, which is how OnBitmap delivers RDP updates.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one session with an RDP or VNC server. It picks a protocol-specific implementation from the type given to NewClient (RdpClient or VncClient) and exposes one API for input, events, the clipboard and the framebuffer.
A Client is safe for concurrent use. Build one with NewClient; the zero value is not usable. Nothing is sent until Login is called.
func NewClient ¶
NewClient returns an unconnected session for host, which must be "address:port". t selects the transport: TC_RDP for RDP, TC_VNC for VNC. A nil s is replaced by NewSetting, so the common call is NewClient(host, user, pass, TC_RDP, nil).
No connection is made here. Call Login to connect, and Close when done.
func (*Client) Close ¶
func (c *Client) Close()
Close ends the session and closes the underlying connection. It is safe to call more than once and on a client that never connected, and it is safe to call concurrently with input methods, which become no-ops once the connection is gone.
func (*Client) Files ¶ added in v0.7.0
func (c *Client) Files() *cliprdr.CliprdrClient
Files returns the clipboard's file transfer surface, or nil when the clipboard channel is not enabled or the session is not RDP.
It is how the application supplies the files it shares (SetFileProvider) and receives the files the server offers (OnRemoteFiles, ReadRemoteFile, ClearRemoteFiles). A file transfer is not text: the protocol hands the application a manifest and then asks it for ranges of bytes, so the application decides where the bytes come from and go, and the library never touches a path the remote end named. Nothing file shaped is advertised on the clipboard until a provider is set, because a format the client cannot produce data for leaves the pasting side waiting.
func (*Client) Framebuffer ¶ added in v0.7.0
func (c *Client) Framebuffer() *Framebuffer
Framebuffer returns the buffer every decoded frame lands in, or nil before Login has been called.
It is the one place to read pixels from, whichever way the server is drawing: bitmap updates, drawing orders and graphics channel surface bits all composite into it. Use OnFrame to learn what changed rather than assuming the whole buffer did.
This is the RDP path. The VNC client does not composite into a framebuffer, because an RFB server chooses the pixel format per connection and the buffer here is defined as BGRA; a VNC session therefore returns nil and has to be driven from OnBitmap instead.
func (*Client) KeyDown ¶
KeyDown presses the key whose PC set 1 scancode is sc, with the same extended key handling as KeyUp. name is ignored.
func (*Client) KeyUp ¶
KeyUp releases the key whose PC set 1 scancode is sc. A value in 0xE000..0xE0FF is sent as an extended key: the low byte is the scancode and the 0xE0 prefix becomes the extended flag. name is accepted for source compatibility and ignored; the scancode is what reaches the server.
func (*Client) LoginContext ¶
LoginContext is Login with an explicit context. It returns only once the server has completed the connection sequence and the session is ready, or when the handshake fails, the connection is closed, or ctx expires.
func (*Client) MouseDown ¶
MouseDown presses button 0 (left), 1 (middle) or 2 (right) at (x, y), with the same numbering as MouseUp.
func (*Client) MouseMove ¶
MouseMove moves the pointer to (x, y) in screen pixels from the top left.
func (*Client) MouseUp ¶
MouseUp releases button 0 (left), 1 (middle) or 2 (right) at (x, y). Any other value only moves the pointer. The numbering is the sender's, not the protocol's.
func (*Client) MouseWheel ¶
MouseWheel turns the wheel by scroll notches at (x, y); positive is up (away from the user) and the magnitude is clamped to the protocol's 9 bit field.
func (*Client) OnBitmap
deprecated
OnBitmap registers f to be called with each bitmap update, already expanded and converted to BGRA at 32 bpp where the source was compressed. f may see the same underlying data reused by the next update, so copy anything it keeps. For VNC the Bitmap rectangles carry the VNC pixel format instead.
Deprecated: use OnFrame and Framebuffer, whose pixels survive the callback. This remains for callers that want the raw update, and it is still what an RFB session has to use.
func (*Client) OnClipboardText ¶
OnClipboardText reports text the server has put on the clipboard. It only fires when the clipboard channel is enabled.
func (*Client) OnClose ¶
func (c *Client) OnClose(f func())
OnClose registers f to be called when the connection to the server is gone. Like the other handlers it may be registered before Login.
func (*Client) OnCursor ¶ added in v0.7.0
OnCursor registers f to be called when the pointer's shape changes, or when the server names a system pointer instead.
It does not fire for a position change: a pointer that moves keeps its shape, and a gateway re-encoding the shape on every mouse move would be doing work for nothing. Use OnCursorPos for that. The cursor is only valid for the duration of the call.
func (*Client) OnCursorPos ¶ added in v0.7.0
OnCursorPos registers f to be called with the server's pointer position, in desktop pixels from the top left. It is the counterpart of OnCursor: the shape says what to draw and this says where.
This is a different event from OnPointerPosition, which reports the raw fast-path update; both end up here, so a caller that only wants to place the pointer does not have to follow two of them.
func (*Client) OnError ¶
OnError registers f to be called with a handshake or transport error. Handlers may be registered before Login; they are kept and delivered once the session layers exist.
func (*Client) OnFrame ¶ added in v0.7.0
OnFrame registers f to be called once per batch of updates, after every rectangle in the batch has been composited, with the areas that changed.
The rectangles have already been merged and clipped to Framebuffer().Bounds(), so f can encode exactly those regions without checking them. Neighbouring and overlapping rectangles arrive as one, and when the merged area covers most of the frame it arrives as the whole frame. The slice is only valid for the duration of the call.
f runs on the goroutine that decodes the session's data, so anything that can block belongs on another one. The pixels it reads from Framebuffer().Pix() stay as they are until the next call.
func (*Client) OnOrdersFrame
deprecated
added in
v0.3.0
OnOrdersFrame reports that a batch of drawing orders changed the screen, giving the area that changed, merged into a single rectangle.
Deprecated: use OnFrame, which reports every drawing path and does not have to merge a batch into one rectangle to fit the signature.
func (*Client) OnPointer ¶
func (c *Client) OnPointer(f func(p *pdu.PointerDataPDU))
OnPointer reports slow-path pointer updates (PDUTYPE2_POINTER), which carry either a new position or a pointer shape.
func (*Client) OnPointerPosition ¶
OnPointerPosition reports the server-side pointer position (fast-path FASTPATH_UPDATETYPE_PTR_POSITION). It is useful to confirm that mouse input reached the remote session.
func (*Client) OnReady ¶
func (c *Client) OnReady(f func())
OnReady registers f to be called once the session is negotiated and the server is about to send its first update. It fires before any bitmap or order callback.
func (*Client) OnResize ¶ added in v0.7.0
OnResize registers f to be called when the desktop size changes.
It is driven by what the server draws, not by what was asked for: the server decides whether a resize is allowed and when to apply it, and the first update at a new size is the confirmation. A shrink is not reported this way on the bitmap path, because nothing in a bitmap update says the desktop got smaller; the graphics channel does say so, and resizes both ways.
func (*Client) OnSuccess ¶
func (c *Client) OnSuccess(f func())
OnSuccess registers f to be called when the server accepts the credentials, before the session is ready to draw.
func (*Client) OnSurfaceFrame ¶
OnSurfaceFrame reports each completed EGFX frame and the surfaces it touched. The pixel data lives on the surfaces, so callers that need it should copy what they need before returning.
func (*Client) OnSurfaceReset ¶
OnSurfaceReset reports the desktop size an EGFX server will composite into, which also means any previously known surfaces are gone.
func (*Client) RequestClipboardText ¶
RequestClipboardText asks the server for the clipboard text it last announced. OnClipboardText normally triggers this by itself, but a server can announce a format before it is able to serve it, in which case an explicit request made later is what gets the data.
func (*Client) RequestResize ¶ added in v0.7.0
RequestResize asks the server to change the desktop to w by h pixels.
It reports an error when the session cannot do it: the Display Control channel has to be opened at connect time, with Setting.EnableDisplayControl, because opening a dynamic channel changes the connect sequence. It also reports an error for a size the server will not accept, rather than clamping it, so that a caller is not told its request succeeded when the size was changed.
The server applies the change on its own schedule, so the size is not changed by the time this returns. OnResize says when it has, and Framebuffer follows.
func (*Client) Screen
deprecated
added in
v0.3.0
Screen returns the raw framebuffer that drawing orders are rendered into, or nil when Setting.EnableOrders was not set.
Deprecated: use Framebuffer, which exists whether or not orders are enabled and is the only supported way to read pixels. This remains for callers that need the orders-specific machinery (the caches and Unsupported counts).
func (*Client) SetClipboardText ¶
SetClipboardText publishes text on the shared clipboard, so a paste on the server pastes it. It only does anything when the clipboard channel is enabled.
func (*Client) TypeText ¶ added in v0.7.0
TypeText types s one character at a time, holding each key for hold before releasing it. A hold of zero sends the release immediately, with no delay at all, which is what a server that reads the event stream rather than a keyboard queue needs; a small hold is what a server that has to synthesise keystrokes from them needs, and is the difference between the text arriving and the server dropping all but the first character.
It returns an error if the session's protocol has no Unicode key event, or if s is not valid UTF-8 and so cannot be turned into characters.
func (*Client) UnicodeKeyDown ¶ added in v0.7.0
UnicodeKeyDown presses the key that produces r.
A scancode says which key was pressed; this says which character was meant, and it is the only way to send what an input method produced. That is what it exists for in RDP: a Chinese, Japanese or Korean IME composes several keystrokes into one character, and the composed character has no scancode. Latin text can be sent this way too, and then the server does not need to know the client's keyboard layout.
Use TypeText for a string, since it pairs the presses with releases.
func (*Client) UnicodeKeyUp ¶ added in v0.7.0
UnicodeKeyUp releases the key that UnicodeKeyDown pressed for r.
type Control ¶
type Control interface {
Login(host, user, passwd string, width, height int) error
KeyUp(sc int, name string)
KeyDown(sc int, name string)
UnicodeKeyDown(r rune)
UnicodeKeyUp(r rune)
MouseMove(x, y int)
MouseWheel(scroll, x, y int)
MouseUp(button int, x, y int)
MouseDown(button int, x, y int)
On(event string, msg interface{})
SetClipboardText(text string) error
RequestClipboardText() error
Close()
}
Control is the small surface both clients implement, so that Client can hold either one. Callers normally use Client rather than this.
type Cursor ¶ added in v0.7.0
type Cursor struct {
// Image is the shape with the AND and XOR masks already applied, so that
// alpha is what decides what shows through. It is nil for a system cursor,
// which has no pixels.
Image *image.RGBA
// Width and Height are the shape's size, and are 0 for a system cursor.
Width int
Height int
// Hotspot is the point within the image that sits on the position
// reported by OnCursorPos. It is always inside the image for a decoded
// shape.
Hotspot image.Point
// System is true when the server named one of its built in cursors rather
// than sending pixels. Image is then nil, and the caller is expected to
// substitute its own artwork for SystemType. A system cursor is reported
// rather than skipped because a caller that never hears about it keeps
// drawing the last shape it was given, which is how a pointer ends up
// looking like an hourglass forever.
System bool
// SystemType is the raw systemPointerType. SYSPTR_NULL means the pointer
// should be hidden. Other values are passed through unnamed: the
// specification's table lists only the two below, and inventing names for
// the rest would be a guess about a value a caller is better placed to
// interpret.
SystemType uint32
// XorBpp is the bytes per pixel the shape was decoded at: three for a
// 24bpp pointer, four for a 32bpp one, and one for a two colour pointer,
// where it means one bit per pixel rather than one byte. It is what a
// caller needs in order to read Xor for itself.
XorBpp int
// Xor and And are the masks the Image was built from, in the layout they
// arrived in, so that a caller which wants to composite the pointer its
// own way does not have to decode the image back into them. Most callers
// want Image.
Xor []byte
And []byte
}
Cursor is the pointer as the server wants it drawn.
A gateway needs this because the pointer is not part of the desktop image: it is drawn over it, at a position the server sends separately, and a browser cannot be told to draw it out of a bitmap update. So the two halves arrive here rather than in Framebuffer.
type Framebuffer ¶ added in v0.7.0
type Framebuffer struct {
// contains filtered or unexported fields
}
Framebuffer is where decoded pixels land, whichever way the server chose to draw them.
It exists so that a caller does not have to care whether the session is running on bitmap updates, drawing orders or the graphics channel: the pixels end up here either way, and OnFrame says what changed. A framebuffer exists for every session, whether or not Setting.EnableOrders was set, because the bitmap path composites into it too. It is reachable from Client.Framebuffer once Login has been called.
The pixels are BGRA, top down, with a stride of four bytes per pixel and no padding between rows, so the byte at offset y*Stride()+x*4 is the blue channel of the pixel at (x, y). The alpha byte is 255 everywhere: RDP does not carry per-pixel alpha for the desktop.
func (*Framebuffer) Bounds ¶ added in v0.7.0
func (f *Framebuffer) Bounds() image.Rectangle
Bounds is the whole framebuffer, which is the desktop size. A zero rectangle means there is no framebuffer yet.
func (*Framebuffer) Pix ¶ added in v0.7.0
func (f *Framebuffer) Pix() []byte
Pix returns the pixel buffer itself, not a copy, so that handing a frame to an encoder costs nothing. It stays valid, with the frame as drawn, until the next OnFrame callback, and it is only safe to read from the callback's own goroutine while the session is running. Copy it if it is needed for longer.
Callers must not write to it.
func (*Framebuffer) Size ¶ added in v0.7.0
func (f *Framebuffer) Size() (w, h int)
Size is Bounds().Dx() and Bounds().Dy().
func (*Framebuffer) Stride ¶ added in v0.7.0
func (f *Framebuffer) Stride() int
Stride is the number of bytes between the start of one row and the next.
type RdpClient ¶
type RdpClient struct {
// contains filtered or unexported fields
}
RdpClient is the RDP implementation of Control. NewClient builds one (stored unexported) for TC_RDP; callers interact with it through Client, which forwards input, events and the clipboard to it.
func (*RdpClient) Close ¶
func (c *RdpClient) Close()
Close closes the underlying transport. It is safe on a partially built client and more than once; input methods become no-ops afterwards.
func (*RdpClient) KeyDown ¶
KeyDown presses sc. See Client.KeyUp for the scancode and extended key conventions. name is ignored.
func (*RdpClient) KeyUp ¶
KeyUp releases sc. See Client.KeyUp for the scancode and extended key conventions. name is ignored.
func (*RdpClient) Login ¶
Login dials host, builds the protocol stack (TPKT/X.224/MCS/security/PDU) and starts the connection. user may be "user", "DOMAIN\user" or "domain/user": the domain is split off and sent separately.
Login returns once the connection has been established, which is before the session is usable. The session becomes ready asynchronously and is reported on the "ready" event; errors and closure arrive on "error" and "close". Use Client.Login or Client.LoginContext to connect and wait for readiness in one call.
func (*RdpClient) MouseMove ¶
MouseMove moves the pointer to (x, y) in screen pixels from the top left.
func (*RdpClient) MouseWheel ¶
MouseWheel turns the wheel by scroll notches at (x, y); positive is up.
func (*RdpClient) On ¶
On registers a handler for an event. It may be called before Login, in which case handlers are buffered and replayed once the layer that produces them exists; this ordering is what lets a caller register handlers and then call Login without losing the "ready" event.
Event names: "ready", "success", "error" (error), "close", "bitmap" ([]pdu.BitmapData), "surface-bits" (*pdu.SurfaceBitsCommand), "orders" ([]pdu.OrderPdu), "orders-frame" (image.Rectangle), "pointer" (*pdu.PointerDataPDU), "pointer-position" (*pdu.FastPathPointerPositionPDU), "clipboard-text" (string), and "gfx-frame"/"gfx-reset" from the graphics channel. f must have the type the event carries or the receive will panic.
func (*RdpClient) RequestClipboardText ¶
RequestClipboardText asks the server for its clipboard text.
func (*RdpClient) SetClipboardText ¶
SetClipboardText publishes text on the shared clipboard.
func (*RdpClient) UnicodeKeyDown ¶ added in v0.7.0
UnicodeKeyDown presses the key that produces r. See Client.UnicodeKeyDown.
func (*RdpClient) UnicodeKeyUp ¶ added in v0.7.0
UnicodeKeyUp releases it.
type Setting ¶
type Setting struct {
// Width and Height are the desktop size requested from the server, in
// pixels. They are sent in the MCS connect sequence and must be positive;
// NewSetting uses 1024x768.
Width int
Height int
// Protocol selects the security path: "tls" (the default) or "ssl" for
// TLS, "nla", "hybrid" or "credssp" for CredSSP, and "rdp" or "standard"
// for Standard RDP Security with no TLS. The empty string means TLS, and an
// unrecognised value falls back to TLS with a warning rather than failing.
Protocol string
// Timeout bounds the whole of Login, from dial to ready. Zero or negative
// means DefaultLoginTimeout (30s).
Timeout time.Duration
// LogLevel is applied to the package-global glog logger by NewClient. The
// default is glog.INFO; glog.NONE silences the library.
LogLevel glog.LEVEL
// NoFastPathInput forces keyboard/mouse input over the slow path even
// when the server advertised fast-path input. Useful for debugging.
NoFastPathInput bool
// EnableEGFX opens the dynamic virtual channel needed for the RDP
// Graphics Pipeline Extension, so the server can composite surfaces and
// send them as compressed bitmaps instead of bitmap updates.
//
// This is off by default: it has not been exercised against a server that
// speaks EGFX, and enabling it changes how the server draws the session.
EnableEGFX bool
// EnableClipboard opens the clipboard channel so text can be exchanged
// with the server. Use Client.OnClipboardText and Client.SetClipboardText
// to bridge it to the local clipboard.
EnableClipboard bool
// EnableDisplayControl opens the Display Control dynamic virtual channel, so
// that RequestResize can ask the server to change the desktop size while the
// session runs. It is off by default for the same reason as EGFX: opening a
// dynamic channel changes the connect sequence, and a caller that is not
// going to resize anything should not have its negotiation altered.
EnableDisplayControl bool
// EnableOrders advertises support for the MEMBLT drawing order and renders
// the drawing orders that follow, into a framebuffer reachable through
// Client.Screen.
//
// It is off by default because it changes how the server draws the session
// and it cannot mix: once MEMBLT is advertised the server stops sending
// bitmap updates and puts everything through the bitmap cache instead. With
// it off the session is drawn from bitmap updates, which is correct, just
// larger on the wire.
EnableOrders bool
}
Setting configures a session. NewSetting returns one with usable defaults; the fields below are only read when Login is called, so they may be changed until then.
func NewSetting ¶
func NewSetting() *Setting
NewSetting returns a Setting with the default desktop size (1024x768), the default login timeout and INFO logging.
func (*Setting) SetClipboard ¶
SetClipboard is inert: it does nothing. Use Setting.EnableClipboard to open the clipboard channel.
func (*Setting) SetLogLevel ¶
func (s *Setting) SetLogLevel()
SetLogLevel pushes LogLevel into the package-global glog logger. NewClient already does this, so it only needs calling if the level is changed after the client is built.
func (*Setting) SetRequestedProtocol ¶
SetRequestedProtocol is inert: it does nothing. Set Setting.Protocol instead, which is read when Login negotiates the security path.
type VncClient ¶
type VncClient struct {
// contains filtered or unexported fields
}
VncClient is the RFB (VNC) client. It is exercised against a real server by scripts/vnc-dev.sh, which starts TigerVNC and runs the live tests: a frame is received and parsed, and the clipboard works in both directions. Raw, CopyRect and Hextile encodings are implemented and advertised, and the live tests have seen the server choose Hextile for ordinary rectangles and CopyRect for a real scroll. RequestClipboardText is not implemented, which a test records.
Login blocks until the handshake completes, fails, or the configured timeout expires, so it is safe to register handlers and drive input afterwards; before it returns those calls do nothing rather than panic.
func (*VncClient) Close ¶
func (c *VncClient) Close()
Close implements the Control interface. It does nothing until Login has completed.
func (*VncClient) KeyDown ¶
KeyDown implements the Control interface. It does nothing until Login has completed.
func (*VncClient) KeyUp ¶
KeyUp implements the Control interface. It does nothing until Login has completed.
func (*VncClient) Login ¶
Login dials the server and returns only once the RFB handshake has completed, the handshake has failed, or the timeout expires. The handshake is event driven, so it is driven to a result the caller can see instead of returning while it is still running. scripts/vnc-dev.sh runs this against a real server.
func (*VncClient) MouseDown ¶
MouseDown implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseMove ¶
MouseMove implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseUp ¶
MouseUp implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseWheel ¶
MouseWheel implements the Control interface. It does nothing until Login has completed.
func (*VncClient) On ¶
On registers a listener. A listener registered before Login is held until there is a connection to attach it to, so a caller that registers before connecting still receives events.
func (*VncClient) RequestClipboardText ¶
RequestClipboardText is not supported by RFB and says so. Unlike the RDP clipboard channel, RFB has no client message that asks for the server's cut text: the server sends ServerCutText whenever its clipboard changes, and the only client-to-server message, ClientCutText, publishes rather than requests. Text therefore arrives through OnClipboardText with no request behind it.
func (*VncClient) SetClipboardText ¶
SetClipboardText publishes text on the server's clipboard. RFB carries it as one ClientCutText message. There is no acknowledgement, so a nil error only means the bytes were written to the socket.
func (*VncClient) UnicodeKeyDown ¶ added in v0.7.0
UnicodeKeyDown implements the Control interface. RFB has no Unicode key event: a KeyEvent carries an X11 keysym or a scancode and nothing else, so there is no way to say which character an input method produced. The call is accepted and logged rather than silently ignored, and Client.TypeText returns an error on a VNC session instead of reaching here.
func (*VncClient) UnicodeKeyUp ¶ added in v0.7.0
UnicodeKeyUp implements the Control interface, and is the counterpart of UnicodeKeyDown: there is nothing to release.