Skip to content

Commit

Permalink
Create RFB object on connect
Browse files Browse the repository at this point in the history
In e543525, we switched to creating
a new RFB object on disconnect.  This caused issues, however, since
any errors were only displayed briefly before the new "loaded" text
was displayed instead.

Now, we create the RFB object on connect.  This essentially removes
the usefulness of the "loaded" state, but prevents the aforementioned
problem.

To facilitate this, the code which does detection of cursor URI support
was moved from this Display constructor (which now calls the new
function) into its own function, `Util.browserSupportsCursorURIs()`.

Fixes #467
  • Loading branch information
DirectXMan12 committed Mar 24, 2015
1 parent 16b3ef7 commit 5712666
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
26 changes: 3 additions & 23 deletions include/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,9 @@ var Display;
}

// Determine browser support for setting the cursor via data URI scheme
var curDat = [];
for (var i = 0; i < 8 * 8 * 4; i++) {
curDat.push(255);
}
try {
var curSave = this._target.style.cursor;
Display.changeCursor(this._target, curDat, curDat, 2, 2, 8, 8);
if (this._target.style.cursor) {
if (this._cursor_uri === null || this._cursor_uri === undefined) {
this._cursor_uri = true;
}
Util.Info("Data URI scheme cursor supported");
this._target.style.cursor = curSave;
} else {
if (this._cursor_uri === null || this._cursor_uri === undefined) {
this._cursor_uri = false;
}
Util.Warn("Data URI scheme cursor not supported");
this._target.style.cursor = "none";
}
} catch (exc) {
Util.Error("Data URI scheme cursor test exception: " + exc);
this._cursor_uri = false;
if (this._cursor_uri || this._cursor_uri === null ||
this._cursor_uri === undefined) {
this._cursor_uri = Util.browserSupportsCursorURIs(this._target);
}

Util.Debug("<< Display.constructor");
Expand Down
36 changes: 17 additions & 19 deletions include/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ var UI;
UI.initSetting('path', 'websockify');
UI.initSetting('repeaterID', '');

UI.initRFB();

var autoconnect = WebUtil.getQueryVar('autoconnect', false);
if (autoconnect === 'true' || autoconnect == '1') {
autoconnect = true;
Expand Down Expand Up @@ -136,7 +134,7 @@ var UI;
Util.addEvent(window, 'load', UI.keyboardinputReset);

Util.addEvent(window, 'beforeunload', function () {
if (UI.rfb_state === 'normal') {
if (UI.rfb && UI.rfb_state === 'normal') {
return "You are currently connected.";
}
} );
Expand Down Expand Up @@ -213,12 +211,14 @@ var UI;
$D("noVNC_connect_button").onclick = UI.connect;

$D("noVNC_resize").onchange = function () {
var connected = UI.rfb_state === 'normal' ? true : false;
var connected = UI.rfb && UI.rfb_state === 'normal';
UI.enableDisableClip(connected);
};
},

onresize: function (callback) {
if (!UI.rfb) return;

var size = UI.getCanvasLimit();

if (size && UI.rfb_state === 'normal' && UI.rfb.get_display()) {
Expand Down Expand Up @@ -480,7 +480,7 @@ var UI;
} else {
UI.updateSetting('encrypt');
UI.updateSetting('true_color');
if (UI.rfb.get_display().get_cursor_uri()) {
if (Util.browserSupportsCursorURIs()) {
UI.updateSetting('cursor');
} else {
UI.updateSetting('cursor', !UI.isTouchDevice);
Expand Down Expand Up @@ -536,7 +536,7 @@ var UI;
//Util.Debug(">> settingsApply");
UI.saveSetting('encrypt');
UI.saveSetting('true_color');
if (UI.rfb.get_display().get_cursor_uri()) {
if (Util.browserSupportsCursorURIs()) {
UI.saveSetting('cursor');
}

Expand All @@ -558,7 +558,7 @@ var UI;
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
WebUtil.init_logging(UI.getSetting('logging'));
UI.setViewClip();
UI.setViewDrag(UI.rfb.get_viewportDrag());
UI.setViewDrag(UI.rfb && UI.rfb.get_viewportDrag());
//Util.Debug("<< settingsApply");
},

Expand Down Expand Up @@ -642,13 +642,6 @@ var UI;
break;
}

switch (state) {
case 'fatal':
case 'failed':
case 'disconnected':
UI.initRFB();
}

if (typeof(msg) !== 'undefined') {
$D('noVNC-control-bar').setAttribute("class", klass);
$D('noVNC_status').innerHTML = msg;
Expand All @@ -659,13 +652,12 @@ var UI;

// Disable/enable controls depending on connection state
updateVisualState: function() {
var connected = UI.rfb_state === 'normal' ? true : false;
var connected = UI.rfb && UI.rfb_state === 'normal';

//Util.Debug(">> updateVisualState");
$D('noVNC_encrypt').disabled = connected;
$D('noVNC_true_color').disabled = connected;
if (UI.rfb && UI.rfb.get_display() &&
UI.rfb.get_display().get_cursor_uri()) {
if (Util.browserSupportsCursorURIs()) {
$D('noVNC_cursor').disabled = connected;
} else {
UI.updateSetting('cursor', !UI.isTouchDevice);
Expand Down Expand Up @@ -780,6 +772,8 @@ var UI;
throw new Error("Must set host and port");
}

UI.initRFB();

UI.rfb.set_encrypt(UI.getSetting('encrypt'));
UI.rfb.set_true_color(UI.getSetting('true_color'));
UI.rfb.set_local_cursor(UI.getSetting('cursor'));
Expand Down Expand Up @@ -809,11 +803,15 @@ var UI;
},

displayBlur: function() {
if (!UI.rfb) return;

UI.rfb.get_keyboard().set_focused(false);
UI.rfb.get_mouse().set_focused(false);
},

displayFocus: function() {
if (!UI.rfb) return;

UI.rfb.get_keyboard().set_focused(true);
UI.rfb.get_mouse().set_focused(true);
},
Expand Down Expand Up @@ -882,7 +880,7 @@ var UI;

// Toggle/set/unset the viewport drag/move button
setViewDrag: function(drag) {
if (!UI.rfb) { return; }
if (!UI.rfb) return;

UI.updateViewDragButton();

Expand Down Expand Up @@ -953,7 +951,7 @@ var UI;
// sending keyCodes in the normal keyboard events when using on screen keyboards.
keyInput: function(event) {

if (!UI.rfb) { return; }
if (!UI.rfb) return;

var newValue = event.target.value;

Expand Down
23 changes: 23 additions & 0 deletions include/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,29 @@ Util.stopEvent = function (e) {
else { e.returnValue = false; }
};

Util._cursor_uris_supported = null;

Util.browserSupportsCursorURIs = function () {
if (Util._cursor_uris_supported === null) {
try {
var target = document.createElement('canvas');
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';

if (target.style.cursor) {
Util.Info("Data URI scheme cursor supported");
Util._cursor_uris_supported = true;
} else {
Util.Warn("Data URI scheme cursor not supported");
Util._cursor_uris_supported = false;
}
} catch (exc) {
Util.Error("Data URI scheme cursor test exception: " + exc);
Util._cursor_uris_supported = false;
}
}

return Util._cursor_uris_supported;
};

// Set browser engine versions. Based on mootools.
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
Expand Down
2 changes: 1 addition & 1 deletion vnc.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</div>
</div>

<div id="noVNC_status">Loading</div>
<div id="noVNC_status" class="noVNC_status_normal"></div>

<!--noVNC Buttons-->
<div class="noVNC-buttons-right">
Expand Down

0 comments on commit 5712666

Please sign in to comment.