]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/rfb.js
Switch to URL for connect()
[mirror_novnc.git] / core / rfb.js
index 7eb1c417aac3e24057141d41a1bb0c6fa1cbcc03..ec413a84f74140eaae7691bf036a121e4d6184f5 100644 (file)
@@ -34,42 +34,57 @@ export default function RFB(defaults) {
         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,
@@ -80,12 +95,11 @@ export default function RFB(defaults) {
         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)
@@ -105,10 +119,6 @@ export default function RFB(defaults) {
         pixels: 0
     };
 
-    this._supportsSetDesktopSize = false;
-    this._screen_id = 0;
-    this._screen_flags = 0;
-
     // Mouse state
     this._mouse_buttonMask = 0;
     this._mouse_arr = [];
@@ -116,13 +126,9 @@ export default function RFB(defaults) {
     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
@@ -173,6 +179,7 @@ export default function RFB(defaults) {
         Log.Error("Display exception: " + exc);
         throw exc;
     }
+    this._display.clear();
 
     this._keyboard = new Keyboard({target: this._target,
                                    onKeyEvent: this._handleKeyEvent.bind(this)});
@@ -229,9 +236,6 @@ export default function RFB(defaults) {
         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);
 
@@ -240,15 +244,13 @@ export default function RFB(defaults) {
 
 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 = '';
@@ -368,26 +370,12 @@ RFB.prototype = {
 
     _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);
@@ -413,29 +401,6 @@ RFB.prototype = {
         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;
 
@@ -459,7 +424,7 @@ RFB.prototype = {
         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();
         }
@@ -1481,7 +1446,6 @@ RFB.prototype = {
 
 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