Learn how to evaluate and integrate the VNC SDK

We're here if you need help.

Viewer

public final class Viewer

A VNC-compatible Viewer showing the screen of and controlling a remote computer.

Constructor Summary

  • Viewer()

    Creates and returns a new viewer.

Method Summary

Modifier and Type Method and Description
void

destroy()

Destroys the viewer.

void

disconnect()

Disconnects this viewer from the server.

void

enableAudio(boolean enable)

Enables receipt of audio from the Server by the Viewer.

AnnotationManager

getAnnotationManager()

Obtains the Viewer’s AnnotationManager for handling annotation operations.

ConnectionHandler

getConnectionHandler()

Returns the viewer’s ConnectionHandler for accepting connections.

ConnectionStatus

getConnectionStatus()

Returns the status of the viewer’s connection.

String

getDisconnectMessage()

Returns a human-readable message sent by the server for the last disconnection, or null if the last disconnection was not initiated by the server.

String

getDisconnectReason()

Returns a string ID representing the reason for the last viewer disconnection.

DisplayManager

getDisplayManager()

Obtains the Viewer’s DisplayManager, for managing the list of displays made available by the Server to the Viewer.

EncryptionLevel

getEncryptionLevel()

Returns the Viewer’s current encryption level.

MessagingManager

getMessagingManager()

Obtains the Viewer’s Messaging Manager for handling messaging

String

getPeerAddress()

Returns the address of the viewer’s server.

PictureQuality

getPictureQuality()

Returns the viewer’s current picture quality.

byte[]

getServerPointerFbData()

Gets the current mouse cursor image from the Server for rendering locally.

int

getServerPointerFbHeight()

Gets the height of the pointer framebuffer.

ImmutablePixelFormat

getServerPointerFbPixelFormat()

Gets the pixel format of the pointer framebuffer.

int

getServerPointerFbWidth()

Gets the width of the pointer framebuffer.

int

getServerPointerXOffset()

Gets the X offset of the “hotspot” of the pointer.

int

getServerPointerYOffset()

Gets the Y offset of the “hotspot” of the pointer.

byte[]

getViewerFbData(int x, int y, int w, int h)

Returns the viewer framebuffer data for the given rectangle.

void

getViewerFbData(int x, int y, int w, int h, Object bitmap, int targetX, int targetY)

Draw the framebuffer data into an Android Bitmap object.

int

getViewerFbHeight()

Gets the height of the viewer framebuffer.

ImmutablePixelFormat

getViewerFbPixelFormat()

Gets the pixel format of the viewer framebuffer.

int

getViewerFbStride()

Returns the stride of the viewer framebuffer data in pixels, that is, the number of pixels from the start of each row until the start of the next.

int

getViewerFbWidth()

Gets the width of the viewer framebuffer.

void

releaseAllKeys()

Send key up events for all currently pressed keys.

void

sendAuthenticationResponse(boolean ok, String user, String passwd)

Provides the SDK with the result of a username/password request.

void

sendClipboardText(String text)

Copies the given text to the server’s clipboard.

void

sendKeyDown(int keysym, int keyCode)

Sends a key down (press) event to the server.

void

sendKeyUp(int keyCode)

Sends a key up (release) event to the server.

void

sendPeerVerificationResponse(boolean ok)

Provides the SDK with the response to the Viewer.PeerVerificationCallback.verifyPeer() request.

void

sendPointerEvent(int x, int y, java.lang.Iterable<MouseButton> buttonState, boolean rel)

Sends a pointer event to the server.

void

sendScrollEvent(int delta, MouseWheel axis)

Sends a scroll wheel event to the server.

void

setAuthenticationCallback(Viewer.AuthenticationCallback callback)

Sets the callback to be called when a username and/or password is required.

void

setConnectionCallback(Viewer.ConnectionCallback callback)

Sets the callbacks for the Viewer to call when various events occur during its lifetime.

void

setEncryptionLevel(EncryptionLevel level)

Sets the desired encryption level of the session from the range of options enumerated by ENCRYPTION_LEVEL.

void

setFramebufferCallback(Viewer.FramebufferCallback callback)

Sets the framebuffer callback for this viewer.

void

setPeerVerificationCallback(Viewer.PeerVerificationCallback callback)

Sets the callbacks to be called to verify the identity of the peer (server).

void

setPictureQuality(PictureQuality quality)

Sets the desired picture quality of the session from the range of options enumerated by PICTURE_QUALITY.

void

setServerEventCallback(Viewer.ServerEventCallback callback)

Sets the server event callback for this viewer.

void

setServerPointerCallback(Viewer.ServerPointerCallback callback)

Sets the server pointer callback for this viewer.

void

setServerPointerFbPixelFormat(ImmutablePixelFormat pf)

Sets the pixel format of the pointer framebuffer.

void

setServerPointerPosPeriod(int periodMs)

Sets the rate with which serverPointerPos callback will be called.

void

setViewerFb(java.nio.ByteBuffer pixels, ImmutablePixelFormat pf, int width, int height, int stride)

Sets the viewer framebuffer.

Constructors

public Viewer() throws Library.VncException

Creates and returns a new viewer.

For more information, see vnc_Viewer_create().

Methods

public void destroy()

Destroys the viewer.

For more information, see vnc_Viewer_destroy().

public void disconnect() throws Library.VncException

Disconnects this viewer from the server.

For more information, see vnc_Viewer_disconnect().

public void enableAudio(boolean enable) throws Library.VncException

Enables receipt of audio from the Server by the Viewer.

For more information, see vnc_Viewer_enableAudio().

public AnnotationManager getAnnotationManager() throws Library.VncException

Obtains the Viewer’s AnnotationManager for handling annotation operations.

public ConnectionHandler getConnectionHandler() throws Library.VncException

Returns the viewer’s ConnectionHandler for accepting connections.

public ConnectionStatus getConnectionStatus()

Returns the status of the viewer’s connection.

For more information, see vnc_Viewer_getConnectionStatus().

public String getDisconnectMessage()

Returns a human-readable message sent by the server for the last disconnection, or null if the last disconnection was not initiated by the server.

For more information, see vnc_Viewer_getDisconnectMessage().

public String getDisconnectReason()

Returns a string ID representing the reason for the last viewer disconnection.

For more information, see vnc_Viewer_getDisconnectReason().

public DisplayManager getDisplayManager() throws Library.VncException

Obtains the Viewer’s DisplayManager, for managing the list of displays made available by the Server to the Viewer.

public EncryptionLevel getEncryptionLevel()

Returns the Viewer’s current encryption level.

For more information, see vnc_Viewer_getEncryptionLevel().

public MessagingManager getMessagingManager() throws Library.VncException

Obtains the Viewer’s Messaging Manager for handling messaging

public String getPeerAddress() throws Library.VncException

Returns the address of the viewer’s server.

For more information, see vnc_Viewer_getPeerAddress().

public PictureQuality getPictureQuality()

Returns the viewer’s current picture quality.

For more information, see vnc_Viewer_getPictureQuality().

public byte[] getServerPointerFbData() throws Library.VncException

Gets the current mouse cursor image from the Server for rendering locally. The returned object is valid until the next call to getServerPointerFbData().

New in version 1.10.

public int getServerPointerFbHeight()

Gets the height of the pointer framebuffer.

For more information, see vnc_Viewer_getServerPointerFbHeight().

public ImmutablePixelFormat getServerPointerFbPixelFormat() throws Library.VncException

Gets the pixel format of the pointer framebuffer.

For more information, see vnc_Viewer_getServerPointerFbPixelFormat().

public int getServerPointerFbWidth()

Gets the width of the pointer framebuffer.

For more information, see vnc_Viewer_getServerPointerFbWidth().

public int getServerPointerXOffset()

Gets the X offset of the “hotspot” of the pointer.

For more information, see vnc_Viewer_getServerPointerXOffset().

public int getServerPointerYOffset()

Gets the Y offset of the “hotspot” of the pointer.

For more information, see vnc_Viewer_getServerPointerYOffset().

public byte[] getViewerFbData(int x, int y, int w, int h) throws Library.VncException

Returns the viewer framebuffer data for the given rectangle. This method is rarely useful, and is inefficient. Typically, efficient access to the framebuffer is implemented either by:

  1. using the setViewerFb method to pass a java.nio.ByteBuffer to the SDK, allowing the pixels to be accessed using the ByteBuffer‘s methods;
  2. or, on Android, using the getViewerFbData(int,int,int,int,Object,int,int) method to paint directly into an Android Bitmap.
public void getViewerFbData(int x, int y, int w, int h, Object bitmap, int targetX, int targetY) throws Library.VncException

Draw the framebuffer data into an Android Bitmap object. This method is only supported on Android. It provides improved performance over the standard methods provided by the Bitmap class, which are able to reinitialise the bitmap from a ByteBuffer, but do not provide efficient updating of subregions of the bitmap.

The rectangle described by (x, y, w, h) describes a region in the Viewer’s framebuffer which is to be painted into the Android Bitmap with the top-left of the rectangle at coordinates (targetX, targetY).

The Bitmap must use either the ARGB_8888 or RGB_565 pixel formats, and the Viewer’s framebuffer must have been previously configured using the SDK’s matching pixel format of PixelFormat.bgr888 or PixelFormat.rgb565 respectively. In the case of ARGB data, getViewerFbData does not fill in the alpha channel, so Bitmap.setHasAlpha(false) must be called.

Parameters:
  • bitmap – An android.graphics.Bitmap object.

See also: android.graphics.Bitmap documentation

public int getViewerFbHeight()

Gets the height of the viewer framebuffer.

For more information, see vnc_Viewer_getViewerFbHeight().

public ImmutablePixelFormat getViewerFbPixelFormat() throws Library.VncException

Gets the pixel format of the viewer framebuffer.

For more information, see vnc_Viewer_getViewerFbPixelFormat().

public int getViewerFbStride()

Returns the stride of the viewer framebuffer data in pixels, that is, the number of pixels from the start of each row until the start of the next.

For more information, see vnc_Viewer_getViewerFbStride().

public int getViewerFbWidth()

Gets the width of the viewer framebuffer.

For more information, see vnc_Viewer_getViewerFbWidth().

public void releaseAllKeys() throws Library.VncException

Send key up events for all currently pressed keys.

For more information, see vnc_Viewer_releaseAllKeys().

public void sendAuthenticationResponse(boolean ok, String user, String passwd) throws Library.VncException

Provides the SDK with the result of a username/password request.

For more information, see vnc_Viewer_sendAuthenticationResponse().

public void sendClipboardText(String text) throws Library.VncException

Copies the given text to the server’s clipboard.

For more information, see vnc_Viewer_sendClipboardText().

public void sendKeyDown(int keysym, int keyCode) throws Library.VncException

Sends a key down (press) event to the server.

For more information, see vnc_Viewer_sendKeyDown().

public void sendKeyUp(int keyCode) throws Library.VncException

Sends a key up (release) event to the server.

For more information, see vnc_Viewer_sendKeyUp().

public void sendPeerVerificationResponse(boolean ok) throws Library.VncException

Provides the SDK with the response to the Viewer.PeerVerificationCallback.verifyPeer() request.

For more information, see vnc_Viewer_sendPeerVerificationResponse().

public void sendPointerEvent(int x, int y, java.lang.Iterable<MouseButton> buttonState, boolean rel) throws Library.VncException

Sends a pointer event to the server.

For more information, see vnc_Viewer_sendPointerEvent().

public void sendScrollEvent(int delta, MouseWheel axis) throws Library.VncException

Sends a scroll wheel event to the server.

For more information, see vnc_Viewer_sendScrollEvent().

public void setAuthenticationCallback(Viewer.AuthenticationCallback callback) throws Library.VncException

Sets the callback to be called when a username and/or password is required.

For more information, see vnc_Viewer_setAuthenticationCallback().

public void setConnectionCallback(Viewer.ConnectionCallback callback) throws Library.VncException

Sets the callbacks for the Viewer to call when various events occur during its lifetime.

For more information, see vnc_Viewer_setConnectionCallback().

public void setEncryptionLevel(EncryptionLevel level) throws Library.VncException

Sets the desired encryption level of the session from the range of options enumerated by ENCRYPTION_LEVEL.

For more information, see vnc_Viewer_setEncryptionLevel().

public void setFramebufferCallback(Viewer.FramebufferCallback callback) throws Library.VncException

Sets the framebuffer callback for this viewer.

For more information, see vnc_Viewer_setFramebufferCallback().

public void setPeerVerificationCallback(Viewer.PeerVerificationCallback callback) throws Library.VncException

Sets the callbacks to be called to verify the identity of the peer (server).

For more information, see vnc_Viewer_setPeerVerificationCallback().

public void setPictureQuality(PictureQuality quality) throws Library.VncException

Sets the desired picture quality of the session from the range of options enumerated by PICTURE_QUALITY.

For more information, see vnc_Viewer_setPictureQuality().

public void setServerEventCallback(Viewer.ServerEventCallback callback) throws Library.VncException

Sets the server event callback for this viewer.

For more information, see vnc_Viewer_setServerEventCallback().

public void setServerPointerCallback(Viewer.ServerPointerCallback callback) throws Library.VncException

Sets the server pointer callback for this viewer.

For more information, see vnc_Viewer_setServerPointerCallback().

public void setServerPointerFbPixelFormat(ImmutablePixelFormat pf)

Sets the pixel format of the pointer framebuffer.

For more information, see vnc_Viewer_setServerPointerFbPixelFormat().

public void setServerPointerPosPeriod(int periodMs)

Sets the rate with which serverPointerPos callback will be called.

For more information, see vnc_Viewer_setServerPointerPosPeriod().

public void setViewerFb(java.nio.ByteBuffer pixels, ImmutablePixelFormat pf, int width, int height, int stride) throws Library.VncException

Sets the viewer framebuffer.

For more information, see vnc_Viewer_setViewerFb().

×