defaults = {};
}
- this._rfb_host = '';
- this._rfb_port = 5900;
+ // Connection details
+ this._url = '';
this._rfb_credentials = {};
- this._rfb_path = '';
+ // Internal state
this._rfb_connection_state = '';
this._rfb_init_state = '';
- this._rfb_version = 0;
- this._rfb_max_version = 3.8;
this._rfb_auth_scheme = '';
this._rfb_disconnect_reason = "";
+ // Server capabilities
+ this._rfb_version = 0;
+ this._rfb_max_version = 3.8;
this._rfb_tightvnc = false;
this._rfb_xvp_ver = 0;
+ this._fb_width = 0;
+ this._fb_height = 0;
+
+ this._fb_name = "";
+
this._capabilities = { power: false, resize: false };
- this._encHandlers = {};
- this._encStats = {};
+ this._supportsFence = false;
+ this._supportsContinuousUpdates = false;
+ this._enabledContinuousUpdates = false;
+
+ this._supportsSetDesktopSize = false;
+ this._screen_id = 0;
+ this._screen_flags = 0;
+
+ this._qemuExtKeyEventSupported = false;
+
+ // Internal objects
this._sock = null; // Websock object
this._display = null; // Display object
this._flushing = false; // Display flushing state
this._keyboard = null; // Keyboard input handler object
this._mouse = null; // Mouse input handler object
- this._disconnTimer = null; // disconnection timer
- this._supportsFence = false;
+ // Timers
+ this._disconnTimer = null; // disconnection timer
- this._supportsContinuousUpdates = false;
- this._enabledContinuousUpdates = false;
+ // Decoder states and stats
+ this._encHandlers = {};
+ this._encStats = {};
- // Frame buffer update state
this._FBU = {
rects: 0,
- subrects: 0, // RRE
+ subrects: 0, // RRE and HEXTILE
lines: 0, // RAW
tiles: 0, // HEXTILE
bytes: 0,
encoding: 0,
subencoding: -1,
background: null,
- zlib: [] // TIGHT zlib streams
+ zlibs: [] // TIGHT zlib streams
};
-
- this._fb_width = 0;
- this._fb_height = 0;
- this._fb_name = "";
+ for (var i = 0; i < 4; i++) {
+ this._FBU.zlibs[i] = new Inflator();
+ }
this._destBuff = null;
this._paletteBuff = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
pixels: 0
};
- this._supportsSetDesktopSize = false;
- this._screen_id = 0;
- this._screen_flags = 0;
-
// Mouse state
this._mouse_buttonMask = 0;
this._mouse_arr = [];
this._viewportDragPos = {};
this._viewportHasMoved = false;
- // QEMU Extended Key Event support - default to false
- this._qemuExtKeyEventSupported = false;
-
// set the default value on user-facing properties
set_defaults(this, defaults, {
'target': 'null', // VNC display rendering Canvas object
- 'encrypt': false, // Use TLS/SSL/wss encryption
'local_cursor': false, // Request locally rendered cursor
'shared': true, // Request shared mode
'view_only': false, // Disable client mouse/keyboard
Log.Error("Display exception: " + exc);
throw exc;
}
+ this._display.clear();
this._keyboard = new Keyboard({target: this._target,
onKeyEvent: this._handleKeyEvent.bind(this)});
Log.Warn("WebSocket on-error event");
});
- this._init_vars();
- this._cleanup();
-
var rmode = this._display.get_render_mode();
Log.Info("Using native WebSockets, render mode: " + rmode);
RFB.prototype = {
// Public methods
- connect: function (host, port, creds, path) {
- this._rfb_host = host;
- this._rfb_port = port;
+ connect: function (url, creds) {
+ this._url = url;
this._rfb_credentials = (creds !== undefined) ? creds : {};
- this._rfb_path = (path !== undefined) ? path : "";
- if (!this._rfb_host) {
- return this._fail(
- _("Must set host"));
+ if (!url) {
+ this._fail(_("Must specify URL"));
+ return;
}
this._rfb_init_state = '';
_connect: function () {
Log.Debug(">> RFB.connect");
- this._init_vars();
- var uri;
- if (typeof UsingSocketIO !== 'undefined') {
- uri = 'http';
- } else {
- uri = this._encrypt ? 'wss' : 'ws';
- }
-
- uri += '://' + this._rfb_host;
- if(this._rfb_port) {
- uri += ':' + this._rfb_port;
- }
- uri += '/' + this._rfb_path;
-
- Log.Info("connecting to " + uri);
+ Log.Info("connecting to " + this._url);
try {
// WebSocket.onopen transitions to the RFB init states
- this._sock.open(uri, this._wsProtocols);
+ this._sock.open(this._url, this._wsProtocols);
} catch (e) {
if (e.name === 'SyntaxError') {
this._fail("Invalid host or port value given", e);
Log.Debug("<< RFB.disconnect");
},
- _init_vars: function () {
- // reset state
- this._FBU.rects = 0;
- this._FBU.subrects = 0; // RRE and HEXTILE
- this._FBU.lines = 0; // RAW
- this._FBU.tiles = 0; // HEXTILE
- this._FBU.zlibs = []; // TIGHT zlib encoders
- this._mouse_buttonMask = 0;
- this._mouse_arr = [];
- this._rfb_tightvnc = false;
-
- // Clear the per connection encoding stats
- var stats = this._encStats;
- Object.keys(stats).forEach(function (key) {
- stats[key][0] = 0;
- });
-
- var i;
- for (i = 0; i < 4; i++) {
- this._FBU.zlibs[i] = new Inflator();
- }
- },
-
_print_stats: function () {
var stats = this._encStats;
if (!this._view_only) { this._mouse.ungrab(); }
this._display.defaultCursor();
if (Log.get_logging() !== 'debug') {
- // Show noVNC logo on load and when disconnected, unless in
+ // Show noVNC logo when disconnected, unless in
// debug mode
this._display.clear();
}
make_properties(RFB, [
['target', 'wo', 'dom'], // VNC display rendering Canvas object
- ['encrypt', 'rw', 'bool'], // Use TLS/SSL/wss encryption
['local_cursor', 'rw', 'bool'], // Request locally rendered cursor
['shared', 'rw', 'bool'], // Request shared mode
['view_only', 'rw', 'bool'], // Disable client mouse/keyboard