Commit d890e864 authored by Joel Martin's avatar Joel Martin

API changes/cleanup.

API changes:
    - include/canvas.js renamed to include/display.js
    - Display.rescale() method removed from API. Use Display.set_scale() instead.
    - Make logo configuration attribute of Display and display it when
      clear() is called if it is set.

API deprecations:
    - use RFB onUpdateState instead of updateState.
    - use RFB onClipboard instead of clipboardReceive.

See https://github.com/kanaka/noVNC/wiki/ModuleAPI for detailed noVNC
modules and API description.

Expand and normalize the event/callback interfaces. Standize on
"onEventName" form for callbacks.

    Callback Renames:
        - RFB updateState -> onUpdateState
        - RFB clipboardReceive -> onClipboard
        - Keyboard keyPress -> onKeyPress
        - Mouse mouseButton -> onMouseButton
        - Mouse mouseMove -> onMouseMove

    Callback Additions:
        - RFB onPasswordRequired
        - RFB onBell
        - RFB onFBUReceive
        - RFB onFBUComplete

Other:
- Add array type support to Util.conf_default()
- Removed a bunch of routines from the Display API that were just used
  internally and not actually by noVNC: flush, setFillColor,
  imageDataGet, imageDataCreate, rgbxImageData, rgbxImageFill,
  cmapImageData, cmapImageFill.
- More keyboard/mouse logging when debug turned on.
- Some JSLinting
parent 2fb665ec
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
"use strict";
/*jslint white: false, bitwise: false, plusplus: false */ /*jslint white: false, bitwise: false, plusplus: false */
/*global console */ /*global console */
...@@ -52,6 +51,7 @@ toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+ ...@@ -52,6 +51,7 @@ toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+
base64Pad : '=', base64Pad : '=',
encode: function (data) { encode: function (data) {
"use strict";
var result = '', var result = '',
chrTable = Base64.toBase64Table.split(''), chrTable = Base64.toBase64Table.split(''),
pad = Base64.base64Pad, pad = Base64.base64Pad,
...@@ -95,6 +95,7 @@ toBinaryTable : [ ...@@ -95,6 +95,7 @@ toBinaryTable : [
], ],
decode: function (data, offset) { decode: function (data, offset) {
"use strict";
offset = typeof(offset) !== 'undefined' ? offset : 0; offset = typeof(offset) !== 'undefined' ? offset : 0;
var binTable = Base64.toBinaryTable, var binTable = Base64.toBinaryTable,
pad = Base64.base64Pad, pad = Base64.base64Pad,
......
This diff is collapsed.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// //
function Keyboard(conf) { function Keyboard(conf) {
"use strict"; "use strict";
conf = conf || {}; // Configuration conf = conf || {}; // Configuration
var that = {}, // Public API interface var that = {}, // Public API interface
...@@ -27,12 +27,12 @@ function cdef(v, type, defval, desc) { ...@@ -27,12 +27,12 @@ function cdef(v, type, defval, desc) {
Util.conf_default(conf, that, v, type, defval, desc); } Util.conf_default(conf, that, v, type, defval, desc); }
// Capability settings, default can be overridden // Capability settings, default can be overridden
cdef('target', 'dom', document, 'DOM element that grabs keyboard input'); cdef('target', 'dom', document, 'DOM element that captures keyboard input');
cdef('focused', 'bool', true, 'Capture and send key strokes'); cdef('focused', 'bool', true, 'Capture and send key events');
cdef('keyPress', 'func', null, 'Handler for key press/release'); cdef('onKeyPress', 'func', null, 'Handler for key press/release');
that.set_target = function () { throw("target cannot be changed"); } that.set_target = function() { throw("target cannot be changed"); };
// //
// Private functions // Private functions
...@@ -187,7 +187,7 @@ function getKeysym(evt) { ...@@ -187,7 +187,7 @@ function getKeysym(evt) {
} }
if ((keysym > 255) && (keysym < 0xFF00)) { if ((keysym > 255) && (keysym < 0xFF00)) {
msg = "Mapping keysym " + keysym; msg = "Mapping character code " + keysym;
// Map Unicode outside Latin 1 to X11 keysyms // Map Unicode outside Latin 1 to X11 keysyms
keysym = unicodeTable[keysym]; keysym = unicodeTable[keysym];
if (typeof(keysym) === 'undefined') { if (typeof(keysym) === 'undefined') {
...@@ -200,12 +200,13 @@ function getKeysym(evt) { ...@@ -200,12 +200,13 @@ function getKeysym(evt) {
} }
function show_keyDownList(kind) { function show_keyDownList(kind) {
var c;
var msg = "keyDownList (" + kind + "):\n"; var msg = "keyDownList (" + kind + "):\n";
for (var c = 0; c < keyDownList.length; c++) { for (c = 0; c < keyDownList.length; c++) {
msg = msg + " " + c + " - keyCode: " + keyDownList[c].keyCode + msg = msg + " " + c + " - keyCode: " + keyDownList[c].keyCode +
" - which: " + keyDownList[c].which + "\n"; " - which: " + keyDownList[c].which + "\n";
} }
//Util.Debug(msg); Util.Debug(msg);
} }
function copyKeyEvent(evt) { function copyKeyEvent(evt) {
...@@ -302,7 +303,7 @@ function onKeyDown(e) { ...@@ -302,7 +303,7 @@ function onKeyDown(e) {
} }
var fevt = null, evt = (e ? e : window.event), var fevt = null, evt = (e ? e : window.event),
keysym = null, suppress = false; keysym = null, suppress = false;
Util.Debug("onKeyDown kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which); //Util.Debug("onKeyDown kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which);
fevt = copyKeyEvent(evt); fevt = copyKeyEvent(evt);
...@@ -313,10 +314,11 @@ function onKeyDown(e) { ...@@ -313,10 +314,11 @@ function onKeyDown(e) {
// If it is a key or key combination that might trigger // If it is a key or key combination that might trigger
// browser behaviors or it has no corresponding keyPress // browser behaviors or it has no corresponding keyPress
// event, then send it immediately // event, then send it immediately
if (conf.keyPress && !ignoreKeyEvent(evt)) { if (conf.onKeyPress && !ignoreKeyEvent(evt)) {
Util.Debug("keyPress down 1, keysym: " + keysym + Util.Debug("onKeyPress down, keysym: " + keysym +
" (key: " + evt.keyCode + ", which: " + evt.which + ")"); " (onKeyDown key: " + evt.keyCode +
conf.keyPress(keysym, 1, evt); ", which: " + evt.which + ")");
conf.onKeyPress(keysym, 1, evt);
} }
suppress = true; suppress = true;
} }
...@@ -324,7 +326,7 @@ function onKeyDown(e) { ...@@ -324,7 +326,7 @@ function onKeyDown(e) {
if (! ignoreKeyEvent(evt)) { if (! ignoreKeyEvent(evt)) {
// Add it to the list of depressed keys // Add it to the list of depressed keys
pushKeyEvent(fevt); pushKeyEvent(fevt);
show_keyDownList('down'); //show_keyDownList('down');
} }
if (suppress) { if (suppress) {
...@@ -344,7 +346,7 @@ function onKeyPress(e) { ...@@ -344,7 +346,7 @@ function onKeyPress(e) {
} }
var evt = (e ? e : window.event), var evt = (e ? e : window.event),
kdlen = keyDownList.length, keysym = null; kdlen = keyDownList.length, keysym = null;
Util.Debug("onKeyPress kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which); //Util.Debug("onKeyPress kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which);
if (((evt.which !== "undefined") && (evt.which === 0)) || if (((evt.which !== "undefined") && (evt.which === 0)) ||
(getKeysymSpecial(evt))) { (getKeysymSpecial(evt))) {
...@@ -369,13 +371,14 @@ function onKeyPress(e) { ...@@ -369,13 +371,14 @@ function onKeyPress(e) {
Util.Warn("keyDownList empty when keyPress triggered"); Util.Warn("keyDownList empty when keyPress triggered");
} }
show_keyDownList('press'); //show_keyDownList('press');
// Send the translated keysym // Send the translated keysym
if (conf.keyPress && (keysym > 0)) { if (conf.onKeyPress && (keysym > 0)) {
Util.Debug("keyPress down 2, keysym: " + keysym + Util.Debug("onKeyPress down, keysym: " + keysym +
" (key: " + evt.keyCode + ", which: " + evt.which + ")"); " (onKeyPress key: " + evt.keyCode +
conf.keyPress(keysym, 1, evt); ", which: " + evt.which + ")");
conf.onKeyPress(keysym, 1, evt);
} }
// Stop keypress events just in case // Stop keypress events just in case
...@@ -387,8 +390,8 @@ function onKeyUp(e) { ...@@ -387,8 +390,8 @@ function onKeyUp(e) {
if (! conf.focused) { if (! conf.focused) {
return true; return true;
} }
var fevt = null, evt = (e ? e : window.event), i, keysym; var fevt = null, evt = (e ? e : window.event), keysym;
Util.Debug("onKeyUp kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which); //Util.Debug("onKeyUp kC:" + evt.keyCode + " cC:" + evt.charCode + " w:" + evt.which);
fevt = getKeyEvent(evt.keyCode, true); fevt = getKeyEvent(evt.keyCode, true);
...@@ -400,12 +403,15 @@ function onKeyUp(e) { ...@@ -400,12 +403,15 @@ function onKeyUp(e) {
keysym = 0; keysym = 0;
} }
show_keyDownList('up'); //show_keyDownList('up');
if (conf.keyPress && (keysym > 0)) { if (conf.onKeyPress && (keysym > 0)) {
Util.Debug("keyPress up, keysym: " + keysym + //Util.Debug("keyPress up, keysym: " + keysym +
" (key: " + evt.keyCode + ", which: " + evt.which + ")"); // " (key: " + evt.keyCode + ", which: " + evt.which + ")");
conf.keyPress(keysym, 0, evt); Util.Debug("onKeyPress up, keysym: " + keysym +
" (onKeyPress key: " + evt.keyCode +
", which: " + evt.which + ")");
conf.onKeyPress(keysym, 0, evt);
} }
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
...@@ -447,7 +453,7 @@ return that; // Return the public API interface ...@@ -447,7 +453,7 @@ return that; // Return the public API interface
// //
function Mouse(conf) { function Mouse(conf) {
"use strict"; "use strict";
conf = conf || {}; // Configuration conf = conf || {}; // Configuration
var that = {}; // Public API interface var that = {}; // Public API interface
...@@ -458,14 +464,14 @@ function cdef(v, type, defval, desc) { ...@@ -458,14 +464,14 @@ function cdef(v, type, defval, desc) {
Util.conf_default(conf, that, v, type, defval, desc); } Util.conf_default(conf, that, v, type, defval, desc); }
// Capability settings, default can be overridden // Capability settings, default can be overridden
cdef('target', 'dom', document, 'DOM element that grabs mouse input'); cdef('target', 'dom', document, 'DOM element that captures mouse input');
cdef('focused', 'bool', true, 'Capture and send mouse clicks/movement'); cdef('focused', 'bool', true, 'Capture and send mouse clicks/movement');
cdef('scale', 'float', 1.0, 'Viewport scale factor 0.0 - 1.0'); cdef('scale', 'float', 1.0, 'Viewport scale factor 0.0 - 1.0');
cdef('mouseButton', 'func', null, 'Handler for mouse button click/release'); cdef('onMouseButton', 'func', null, 'Handler for mouse button click/release');
cdef('mouseMove', 'func', null, 'Handler for mouse movement'); cdef('onMouseMove', 'func', null, 'Handler for mouse movement');
that.set_target = function () { throw("target cannot be changed"); } that.set_target = function() { throw("target cannot be changed"); };
// //
// Private functions // Private functions
...@@ -489,8 +495,10 @@ function onMouseButton(e, down) { ...@@ -489,8 +495,10 @@ function onMouseButton(e, down) {
} }
//Util.Debug("mouse " + pos.x + "," + pos.y + " down: " + down + //Util.Debug("mouse " + pos.x + "," + pos.y + " down: " + down +
// " bmask: " + bmask + "(evt.button: " + evt.button + ")"); // " bmask: " + bmask + "(evt.button: " + evt.button + ")");
if (conf.mouseButton) { if (conf.onMouseButton) {
conf.mouseButton(pos.x, pos.y, down, bmask); Util.Debug("onMouseButton " + (down ? "down" : "up") +
", x: " + pos.x + ", y: " + pos.y + ", bmask: " + bmask);
conf.onMouseButton(pos.x, pos.y, down, bmask);
} }
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
...@@ -518,9 +526,9 @@ function onMouseWheel(e) { ...@@ -518,9 +526,9 @@ function onMouseWheel(e) {
bmask = 1 << 4; bmask = 1 << 4;
} }
//Util.Debug('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y); //Util.Debug('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y);
if (conf.mouseButton) { if (conf.onMouseButton) {
conf.mouseButton(pos.x, pos.y, 1, bmask); conf.onMouseButton(pos.x, pos.y, 1, bmask);
conf.mouseButton(pos.x, pos.y, 0, bmask); conf.onMouseButton(pos.x, pos.y, 0, bmask);
} }
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
...@@ -534,8 +542,8 @@ function onMouseMove(e) { ...@@ -534,8 +542,8 @@ function onMouseMove(e) {
evt = (e ? e : window.event); evt = (e ? e : window.event);
pos = Util.getEventPosition(e, conf.target, conf.scale); pos = Util.getEventPosition(e, conf.target, conf.scale);
//Util.Debug('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y); //Util.Debug('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y);
if (conf.mouseMove) { if (conf.onMouseMove) {
conf.mouseMove(pos.x, pos.y); conf.onMouseMove(pos.x, pos.y);
} }
} }
...@@ -1862,5 +1870,5 @@ unicodeTable = { ...@@ -1862,5 +1870,5 @@ unicodeTable = {
0x28fc : 0x10028fc, 0x28fc : 0x10028fc,
0x28fd : 0x10028fd, 0x28fd : 0x10028fd,
0x28fe : 0x10028fe, 0x28fe : 0x10028fe,
0x28ff : 0x10028ff, 0x28ff : 0x10028ff
}; };
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"use strict"; "use strict";
/*jslint white: false, browser: true */ /*jslint white: false, browser: true */
/*global window, $D, Util, WebUtil, RFB, Canvas, Element, Fx */ /*global window, $D, Util, WebUtil, RFB, Display */
var UI = { var UI = {
...@@ -59,8 +59,8 @@ load: function(target) { ...@@ -59,8 +59,8 @@ load: function(target) {
html += ' id="menuButton"'; html += ' id="menuButton"';
html += ' onclick="UI.clickSettingsMenu();">'; html += ' onclick="UI.clickSettingsMenu();">';
html += ' <span id="VNC_settings_menu"'; html += ' <span id="VNC_settings_menu"';
html += ' onmouseover="UI.canvasBlur();"'; html += ' onmouseover="UI.displayBlur();"';
html += ' onmouseout="UI.canvasFocus();">'; html += ' onmouseout="UI.displayFocus();">';
html += ' <ul>'; html += ' <ul>';
html += ' <li><input id="VNC_encrypt"'; html += ' <li><input id="VNC_encrypt"';
html += ' type="checkbox"> Encrypt</li>'; html += ' type="checkbox"> Encrypt</li>';
...@@ -115,8 +115,8 @@ load: function(target) { ...@@ -115,8 +115,8 @@ load: function(target) {
html += ' onclick="UI.clipClear();">'; html += ' onclick="UI.clipClear();">';
html += ' <br>'; html += ' <br>';
html += ' <textarea id="VNC_clipboard_text" cols=80 rows=5'; html += ' <textarea id="VNC_clipboard_text" cols=80 rows=5';
html += ' onfocus="UI.canvasBlur();"'; html += ' onfocus="UI.displayBlur();"';
html += ' onblur="UI.canvasFocus();"'; html += ' onblur="UI.displayFocus();"';
html += ' onchange="UI.clipSend();"></textarea>'; html += ' onchange="UI.clipSend();"></textarea>';
html += '</div>'; html += '</div>';
target.innerHTML = html; target.innerHTML = html;
...@@ -140,8 +140,8 @@ load: function(target) { ...@@ -140,8 +140,8 @@ load: function(target) {
UI.initSetting('connectTimeout', 2); UI.initSetting('connectTimeout', 2);
UI.rfb = RFB({'target': $D('VNC_canvas'), UI.rfb = RFB({'target': $D('VNC_canvas'),
'updateState': UI.updateState, 'onUpdateState': UI.updateState,
'clipboardReceive': UI.clipReceive}); 'onClipboard': UI.clipReceive});
// Unfocus clipboard when over the VNC area // Unfocus clipboard when over the VNC area
$D('VNC_screen').onmousemove = function () { $D('VNC_screen').onmousemove = function () {
...@@ -233,7 +233,7 @@ clickSettingsMenu: function() { ...@@ -233,7 +233,7 @@ clickSettingsMenu: function() {
} else { } else {
UI.updateSetting('encrypt'); UI.updateSetting('encrypt');
UI.updateSetting('true_color'); UI.updateSetting('true_color');
if (UI.rfb.get_canvas().get_cursor_uri()) { if (UI.rfb.get_display().get_cursor_uri()) {
UI.updateSetting('cursor'); UI.updateSetting('cursor');
} else { } else {
UI.updateSetting('cursor', false); UI.updateSetting('cursor', false);
...@@ -265,7 +265,7 @@ settingsDisabled: function(disabled, rfb) { ...@@ -265,7 +265,7 @@ settingsDisabled: function(disabled, rfb) {
//Util.Debug(">> settingsDisabled"); //Util.Debug(">> settingsDisabled");
$D('VNC_encrypt').disabled = disabled; $D('VNC_encrypt').disabled = disabled;
$D('VNC_true_color').disabled = disabled; $D('VNC_true_color').disabled = disabled;
if (rfb && rfb.get_canvas() && rfb.get_canvas().get_cursor_uri()) { if (rfb && rfb.get_display() && rfb.get_display().get_cursor_uri()) {
$D('VNC_cursor').disabled = disabled; $D('VNC_cursor').disabled = disabled;
} else { } else {
UI.updateSetting('cursor', false); UI.updateSetting('cursor', false);
...@@ -281,7 +281,7 @@ settingsApply: function() { ...@@ -281,7 +281,7 @@ settingsApply: function() {
//Util.Debug(">> settingsApply"); //Util.Debug(">> settingsApply");
UI.saveSetting('encrypt'); UI.saveSetting('encrypt');
UI.saveSetting('true_color'); UI.saveSetting('true_color');
if (UI.rfb.get_canvas().get_cursor_uri()) { if (UI.rfb.get_display().get_cursor_uri()) {
UI.saveSetting('cursor'); UI.saveSetting('cursor');
} }
UI.saveSetting('shared'); UI.saveSetting('shared');
...@@ -398,12 +398,12 @@ disconnect: function() { ...@@ -398,12 +398,12 @@ disconnect: function() {
UI.rfb.disconnect(); UI.rfb.disconnect();
}, },
canvasBlur: function() { displayBlur: function() {
UI.rfb.get_keyboard().set_focused(false); UI.rfb.get_keyboard().set_focused(false);
UI.rfb.get_mouse().set_focused(false); UI.rfb.get_mouse().set_focused(false);
}, },
canvasFocus: function() { displayFocus: function() {
UI.rfb.get_keyboard().set_focused(true); UI.rfb.get_keyboard().set_focused(true);
UI.rfb.get_mouse().set_focused(true); UI.rfb.get_mouse().set_focused(true);
}, },
......
...@@ -89,13 +89,19 @@ Util.conf_default = function(cfg, api, v, type, defval, desc) { ...@@ -89,13 +89,19 @@ Util.conf_default = function(cfg, api, v, type, defval, desc) {
api['get_' + v + '_desc'] = desc; api['get_' + v + '_desc'] = desc;
// Default getter // Default getter
if (typeof api['get_' + v] === 'undefined') { if (typeof api['get_' + v] === 'undefined') {
api['get_' + v] = function () { api['get_' + v] = function (idx) {
if ((type in {'arr':1, 'array':1}) &&
(typeof idx !== 'undefined')) {
return cfg[v][idx];
} else {
return cfg[v]; return cfg[v];
}
}; };
} }
// Default setter // Default setter
if (typeof api['set_' + v] === 'undefined') { if (typeof api['set_' + v] === 'undefined') {
api['set_' + v] = function (val) { api['set_' + v] = function (val, idx) {
if (type in {'boolean':1, 'bool':1}) { if (type in {'boolean':1, 'bool':1}) {
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) { if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
val = false; val = false;
...@@ -109,12 +115,21 @@ Util.conf_default = function(cfg, api, v, type, defval, desc) { ...@@ -109,12 +115,21 @@ Util.conf_default = function(cfg, api, v, type, defval, desc) {
val = function () {}; val = function () {};
} }
} }
if (typeof idx !== 'undefined') {
cfg[v][idx] = val;
} else {
cfg[v] = val; cfg[v] = val;
}
}; };
} }
if (typeof cfg[v] === 'undefined') { if (typeof cfg[v] === 'undefined') {
// Set to default // Set to default
if (type in {'arr':1, 'array':1}) {
if (! (defval instanceof Array)) {
defval = [];
}
}
api['set_' + v](defval); api['set_' + v](defval);
} else { } else {
// Coerce existing setting to the right type // Coerce existing setting to the right type
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
* See README.md for usage and integration instructions. * See README.md for usage and integration instructions.
*/ */
"use strict";
/*jslint evil: true */ /*jslint evil: true */
/*global window, document, INCLUDE_URI */ /*global window, document, INCLUDE_URI */
...@@ -18,6 +17,8 @@ function get_INCLUDE_URI() { ...@@ -18,6 +17,8 @@ function get_INCLUDE_URI() {
} }
(function () { (function () {
"use strict";
var extra = "", start, end; var extra = "", start, end;
start = "<script src='" + get_INCLUDE_URI(); start = "<script src='" + get_INCLUDE_URI();
...@@ -34,7 +35,7 @@ function get_INCLUDE_URI() { ...@@ -34,7 +35,7 @@ function get_INCLUDE_URI() {
extra += start + "websock.js" + end; extra += start + "websock.js" + end;
extra += start + "des.js" + end; extra += start + "des.js" + end;
extra += start + "input.js" + end; extra += start + "input.js" + end;
extra += start + "canvas.js" + end; extra += start + "display.js" + end;
extra += start + "rfb.js" + end; extra += start + "rfb.js" + end;
document.write(extra); document.write(extra);
......
...@@ -45,6 +45,7 @@ if (window.WebSocket) { ...@@ -45,6 +45,7 @@ if (window.WebSocket) {
function Websock() { function Websock() {
"use strict";
var api = {}, // Public API var api = {}, // Public API
websocket = null, // WebSocket object websocket = null, // WebSocket object
...@@ -75,7 +76,7 @@ function get_rQ() { ...@@ -75,7 +76,7 @@ function get_rQ() {
function get_rQi() { function get_rQi() {
return rQi; return rQi;
} }
set_rQi = function(val) { function set_rQi(val) {
rQi = val; rQi = val;
}; };
...@@ -252,23 +253,28 @@ function init() { ...@@ -252,23 +253,28 @@ function init() {
function open(uri) { function open(uri) {
init(); init();
websocket = new WebSocket(uri); websocket = new WebSocket(uri, 'base64');
// TODO: future native binary support
//websocket = new WebSocket(uri, ['binary', 'base64']);
websocket.onmessage = recv_message; websocket.onmessage = recv_message;
websocket.onopen = function(e) { websocket.onopen = function() {
Util.Debug(">> WebSock.onopen"); Util.Debug(">> WebSock.onopen");
if (websocket.protocol) {
Util.Info("Server chose sub-protocol: " + websocket.protocol);
}
eventHandlers.open(); eventHandlers.open();
Util.Debug("<< WebSock.onopen"); Util.Debug("<< WebSock.onopen");
}; };
websocket.onclose = function(e) { websocket.onclose = function(e) {
Util.Debug(">> WebSock.onclose"); Util.Debug(">> WebSock.onclose");
eventHandlers.close(); eventHandlers.close(e);
Util.Debug("<< WebSock.onclose"); Util.Debug("<< WebSock.onclose");
}; };
websocket.onerror = function(e) { websocket.onerror = function(e) {
Util.Debug("<< WebSock.onerror: " + e); Util.Debug(">> WebSock.onerror: " + e);
eventHandlers.error(e); eventHandlers.error(e);
Util.Debug("<< WebSock.onerror: "); Util.Debug("<< WebSock.onerror");
}; };
} }
...@@ -309,7 +315,6 @@ function constructor() { ...@@ -309,7 +315,6 @@ function constructor() {
api.send = send; api.send = send;
api.send_string = send_string; api.send_string = send_string;
api.recv_message = recv_message;
api.on = on; api.on = on;
api.init = init; api.init = init;
api.open = open; api.open = open;
......
...@@ -42,6 +42,16 @@ ...@@ -42,6 +42,16 @@
var rfb; var rfb;
function passwordRequired(rfb) {
var msg;
msg = '<form onsubmit="return setPassword();"';
msg += ' style="margin-bottom: 0px">';
msg += 'Password Required: ';
msg += '<input type=password size=10 id="password_input" class="VNC_status">';
msg += '<\/form>';
$D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
$D('VNC_status').innerHTML = msg;
}
function setPassword() { function setPassword() {
rfb.sendPassword($D('password_input').value); rfb.sendPassword($D('password_input').value);
return false; return false;
...@@ -51,39 +61,24 @@ ...@@ -51,39 +61,24 @@
return false; return false;
} }
function updateState(rfb, state, oldstate, msg) { function updateState(rfb, state, oldstate, msg) {
var s, sb, cad, klass; var s, sb, cad, level;
s = $D('VNC_status'); s = $D('VNC_status');
sb = $D('VNC_status_bar'); sb = $D('VNC_status_bar');
cad = $D('sendCtrlAltDelButton'); cad = $D('sendCtrlAltDelButton');
switch (state) { switch (state) {
case 'failed': case 'failed': level = "error"; break;
case 'fatal': case 'fatal': level = "error"; break;
klass = "VNC_status_error"; case 'normal': level = "normal"; break;
break; case 'disconnected': level = "normal"; break;
case 'normal': case 'loaded': level = "normal"; break;
klass = "VNC_status_normal"; default: level = "warn"; break;
break;
case 'disconnected':
case 'loaded':
klass = "VNC_status_normal";
break;
case 'password':
msg = '<form onsubmit="return setPassword();"';
msg += ' style="margin-bottom: 0px">';
msg += 'Password Required: ';
msg += '<input type=password size=10 id="password_input" class="VNC_status">';
msg += '<\/form>';
klass = "VNC_status_warn";
break;
default:
klass = "VNC_status_warn";
} }
if (state === "normal") { cad.disabled = false; } if (state === "normal") { cad.disabled = false; }
else { cad.disabled = true; } else { cad.disabled = true; }
if (typeof(msg) !== 'undefined') { if (typeof(msg) !== 'undefined') {
sb.setAttribute("class", klass); sb.setAttribute("class", "VNC_status_" + level);
s.innerHTML = msg; s.innerHTML = msg;
} }
} }
...@@ -107,7 +102,8 @@ ...@@ -107,7 +102,8 @@
'true_color': WebUtil.getQueryVar('true_color', true), 'true_color': WebUtil.getQueryVar('true_color', true),
'local_cursor': WebUtil.getQueryVar('cursor', true), 'local_cursor': WebUtil.getQueryVar('cursor', true),
'shared': WebUtil.getQueryVar('shared', true), 'shared': WebUtil.getQueryVar('shared', true),
'updateState': updateState}); 'updateState': updateState,
'onPasswordRequired': passwordRequired});
rfb.connect(host, port, password); rfb.connect(host, port, password);
}; };
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment