Commit 81e5adaf authored by Joel Martin's avatar Joel Martin

Refactor console logging code.

Util.Debug, Util.Info, Util.Warn, Util.Error routines instead of
direct calls to console.*. Add "logging=XXX" query variable that sets
the logging level (default is "warn").

Logging values:
    debug: code debug logging (many calls in performance path are also
           commented for performance reasons).
    info: informative messages including timing information.
    warn: significant events
    error: something has gone wrong
parent 351a1da3
...@@ -111,7 +111,7 @@ decode: function (data, offset) { ...@@ -111,7 +111,7 @@ decode: function (data, offset) {
var padding = (data.charAt(i) == pad); var padding = (data.charAt(i) == pad);
// Skip illegal characters and whitespace // Skip illegal characters and whitespace
if (c == -1) { if (c == -1) {
console.log("Illegal character '" + data.charCodeAt(i) + "'"); console.error("Illegal character '" + data.charCodeAt(i) + "'");
continue; continue;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"use strict"; "use strict";
/*jslint white: false, bitwise: false */ /*jslint white: false, bitwise: false */
/*global window, console, $, Util */ /*global window, $, Util */
var Canvas, Canvas_native; var Canvas, Canvas_native;
...@@ -49,7 +49,7 @@ onMouseButton: function(e, down) { ...@@ -49,7 +49,7 @@ onMouseButton: function(e, down) {
evt = (e ? e : window.event); evt = (e ? e : window.event);
pos = Util.getEventPosition(e, $(Canvas.id)); pos = Util.getEventPosition(e, $(Canvas.id));
bmask = 1 << evt.button; bmask = 1 << evt.button;
//console.log('mouse ' + pos.x + "," + pos.y + " down: " + down + " bmask: " + bmask); //Util.Debug('mouse ' + pos.x + "," + pos.y + " down: " + down + " bmask: " + bmask);
if (Canvas.mouseButton) { if (Canvas.mouseButton) {
Canvas.mouseButton(pos.x, pos.y, down, bmask); Canvas.mouseButton(pos.x, pos.y, down, bmask);
} }
...@@ -75,7 +75,7 @@ onMouseWheel: function (e) { ...@@ -75,7 +75,7 @@ onMouseWheel: function (e) {
} else { } else {
bmask = 1 << 4; bmask = 1 << 4;
} }
//console.log('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y); //Util.Debug('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y);
if (Canvas.mouseButton) { if (Canvas.mouseButton) {
Canvas.mouseButton(pos.x, pos.y, 1, bmask); Canvas.mouseButton(pos.x, pos.y, 1, bmask);
Canvas.mouseButton(pos.x, pos.y, 0, bmask); Canvas.mouseButton(pos.x, pos.y, 0, bmask);
...@@ -89,14 +89,14 @@ onMouseMove: function (e) { ...@@ -89,14 +89,14 @@ onMouseMove: function (e) {
var evt, pos; var evt, pos;
evt = (e ? e : window.event); evt = (e ? e : window.event);
pos = Util.getEventPosition(e, $(Canvas.id)); pos = Util.getEventPosition(e, $(Canvas.id));
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y); //Util.Debug('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y);
if (Canvas.mouseMove) { if (Canvas.mouseMove) {
Canvas.mouseMove(pos.x, pos.y); Canvas.mouseMove(pos.x, pos.y);
} }
}, },
onKeyDown: function (e) { onKeyDown: function (e) {
//console.log("keydown: " + Canvas.getKeysym(e)); //Util.Debug("keydown: " + Canvas.getKeysym(e));
if (! Canvas.focused) { if (! Canvas.focused) {
return true; return true;
} }
...@@ -108,7 +108,7 @@ onKeyDown: function (e) { ...@@ -108,7 +108,7 @@ onKeyDown: function (e) {
}, },
onKeyUp : function (e) { onKeyUp : function (e) {
//console.log("keyup: " + Canvas.getKeysym(e)); //Util.Debug("keyup: " + Canvas.getKeysym(e));
if (! Canvas.focused) { if (! Canvas.focused) {
return true; return true;
} }
...@@ -128,27 +128,27 @@ onMouseDisable: function (e) { ...@@ -128,27 +128,27 @@ onMouseDisable: function (e) {
(evt.clientY >= pos.y) && (evt.clientY >= pos.y) &&
(evt.clientX < (pos.x + Canvas.c_wx)) && (evt.clientX < (pos.x + Canvas.c_wx)) &&
(evt.clientY < (pos.y + Canvas.c_wy))) { (evt.clientY < (pos.y + Canvas.c_wy))) {
//console.log("mouse event disabled"); //Util.Debug("mouse event disabled");
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
} }
//console.log("mouse event not disabled"); //Util.Debug("mouse event not disabled");
return true; return true;
}, },
init: function (id) { init: function (id) {
var c, imgTest, arora; var c, imgTest, arora;
console.log(">> Canvas.init"); Util.Debug(">> Canvas.init");
Canvas.id = id; Canvas.id = id;
c = $(Canvas.id); c = $(Canvas.id);
if (Canvas_native) { if (Canvas_native) {
console.log("Using native canvas"); Util.Info("Using native canvas");
// Use default Canvas functions // Use default Canvas functions
} else { } else {
console.warn("Using excanvas canvas emulation"); Util.Warn("Using excanvas canvas emulation");
//G_vmlCanvasManager.init(c); //G_vmlCanvasManager.init(c);
//G_vmlCanvasManager.initElement(c); //G_vmlCanvasManager.initElement(c);
} }
...@@ -176,22 +176,22 @@ init: function (id) { ...@@ -176,22 +176,22 @@ init: function (id) {
} catch (exc) {} } catch (exc) {}
if (Canvas.has_imageData) { if (Canvas.has_imageData) {
console.log("Canvas supports imageData"); Util.Info("Canvas supports imageData");
Canvas.force_canvas = false; Canvas.force_canvas = false;
if (Canvas.ctx.createImageData) { if (Canvas.ctx.createImageData) {
// If it's there, it's faster // If it's there, it's faster
console.log("Using Canvas createImageData"); Util.Info("Using Canvas createImageData");
Canvas._imageData = Canvas._imageDataCreate; Canvas._imageData = Canvas._imageDataCreate;
} else if (Canvas.ctx.getImageData) { } else if (Canvas.ctx.getImageData) {
console.log("Using Canvas getImageData"); Util.Info("Using Canvas getImageData");
Canvas._imageData = Canvas._imageDataGet; Canvas._imageData = Canvas._imageDataGet;
} }
console.log("Prefering javascript operations"); Util.Info("Prefering javascript operations");
Canvas.prefer_js = true; Canvas.prefer_js = true;
Canvas._rgbxImage = Canvas._rgbxImageData; Canvas._rgbxImage = Canvas._rgbxImageData;
Canvas._cmapImage = Canvas._cmapImageData; Canvas._cmapImage = Canvas._cmapImageData;
} else { } else {
console.log("Canvas lacks imageData, using fillRect (slow)"); Util.Warn("Canvas lacks imageData, using fillRect (slow)");
Canvas.force_canvas = true; Canvas.force_canvas = true;
Canvas.prefer_js = false; Canvas.prefer_js = false;
Canvas._rgbxImage = Canvas._rgbxImageFill; Canvas._rgbxImage = Canvas._rgbxImageFill;
...@@ -202,14 +202,14 @@ init: function (id) { ...@@ -202,14 +202,14 @@ init: function (id) {
Canvas.prevStyle = ""; Canvas.prevStyle = "";
Canvas.focused = true; Canvas.focused = true;
//console.log("<< Canvas.init"); Util.Debug("<< Canvas.init");
return true; return true;
}, },
start: function (keyPress, mouseButton, mouseMove) { start: function (keyPress, mouseButton, mouseMove) {
var c; var c;
console.log(">> Canvas.start"); Util.Debug(">> Canvas.start");
c = $(Canvas.id); c = $(Canvas.id);
Canvas.keyPress = keyPress || null; Canvas.keyPress = keyPress || null;
...@@ -228,7 +228,7 @@ start: function (keyPress, mouseButton, mouseMove) { ...@@ -228,7 +228,7 @@ start: function (keyPress, mouseButton, mouseMove) {
Util.addEvent(document, 'click', Canvas.onMouseDisable); Util.addEvent(document, 'click', Canvas.onMouseDisable);
Util.addEvent(document.body, 'contextmenu', Canvas.onMouseDisable); Util.addEvent(document.body, 'contextmenu', Canvas.onMouseDisable);
//console.log("<< Canvas.start"); Util.Debug("<< Canvas.start");
}, },
clear: function () { clear: function () {
...@@ -390,7 +390,6 @@ _cmapImageData: function(x, y, width, height, arr, offset) { ...@@ -390,7 +390,6 @@ _cmapImageData: function(x, y, width, height, arr, offset) {
_cmapImageFill: function(x, y, width, height, arr, offset) { _cmapImageFill: function(x, y, width, height, arr, offset) {
var sx = 0, sy = 0; var sx = 0, sy = 0;
cmap = Canvas.colourMap; cmap = Canvas.colourMap;
console.log("here1: arr[2]: " + arr[2] + ", cmap[arr[2]]: " + cmap[arr[2]]);
for (i=0, j=offset; i < (width * height); i+=1, j+=1) { for (i=0, j=offset; i < (width * height); i+=1, j+=1) {
Canvas.fillRect(x+sx, y+sy, 1, 1, [arr[j]]); Canvas.fillRect(x+sx, y+sy, 1, 1, [arr[j]]);
sx += 1; sx += 1;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* See README.md for usage and integration instructions. * See README.md for usage and integration instructions.
*/ */
"use strict"; "use strict";
/*global console, $, RFB, Canvas, VNC_uri_prefix, Element, Fx */ /*global $, RFB, Canvas, VNC_uri_prefix, Element, Fx */
// Load mootools // Load mootools
(function () { (function () {
...@@ -168,16 +168,16 @@ clipClear: function() { ...@@ -168,16 +168,16 @@ clipClear: function() {
}, },
clipReceive: function(text) { clipReceive: function(text) {
console.log(">> DefaultControls.clipReceive: " + text.substr(0,40) + "..."); Util.Debug(">> DefaultControls.clipReceive: " + text.substr(0,40) + "...");
$('VNC_clipboard_text').value = text; $('VNC_clipboard_text').value = text;
console.log("<< DefaultControls.clipReceive"); Util.Debug("<< DefaultControls.clipReceive");
}, },
clipSend: function() { clipSend: function() {
var text = $('VNC_clipboard_text').value; var text = $('VNC_clipboard_text').value;
console.log(">> DefaultControls.clipSend: " + text.substr(0,40) + "..."); Util.Debug(">> DefaultControls.clipSend: " + text.substr(0,40) + "...");
RFB.clipboardPasteFrom(text); RFB.clipboardPasteFrom(text);
console.log("<< DefaultControls.clipSend"); Util.Debug("<< DefaultControls.clipSend");
} }
}; };
...@@ -13,28 +13,37 @@ ...@@ -13,28 +13,37 @@
// Globals defined here // Globals defined here
var Util = {}, $; var Util = {}, $;
// Debug routines
// Logging/debug routines
if (typeof window.console === "undefined") { if (typeof window.console === "undefined") {
window.console = {
'log': function(m) {},
'warn': function(m) {},
'error': function(m) {}};
}
if (/__debug__$/i.test(document.location.href)) {
if (typeof window.opera !== "undefined") { if (typeof window.opera !== "undefined") {
window.console.log = window.opera.postError; window.console = {
window.console.warn = window.opera.postError; 'log' : window.opera.postError,
window.console.error = window.opera.postError; 'warn' : window.opera.postError,
'error': window.opera.postError };
} else {
window.console = {
'log' : function(m) {},
'warn' : function(m) {},
'error': function(m) {}};
} }
} else {
/*
// non-debug mode, an empty function
window.console.log = function (message) {};
window.console.warn = function (message) {};
window.console.error = function (message) {};
*/
} }
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
Util.logging = (document.location.href.match(
/logging=([A-Za-z0-9\._\-]*)/) || ['', 'warn'])[1];
switch (Util.logging) {
case 'debug': Util.Debug = function (msg) { console.log(msg); };
case 'info': Util.Info = function (msg) { console.log(msg); };
case 'warn': Util.Warn = function (msg) { console.warn(msg); };
case 'error': Util.Error = function (msg) { console.error(msg); };
break;
default:
throw("invalid logging type '" + Util.logging + "'");
}
// Simple DOM selector by ID // Simple DOM selector by ID
if (!window.$) { if (!window.$) {
$ = function (id) { $ = function (id) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"use strict"; "use strict";
/*jslint white: false, nomen: false, browser: true, bitwise: false */ /*jslint white: false, nomen: false, browser: true, bitwise: false */
/*global window, console, WebSocket, Util, Canvas, VNC_uri_prefix, Base64, DES */ /*global window, WebSocket, Util, Canvas, VNC_uri_prefix, Base64, DES */
// Globals defined here // Globals defined here
var VNC_native_ws, RFB; var VNC_native_ws, RFB;
...@@ -105,7 +105,7 @@ sendPassword: function(passwd) { ...@@ -105,7 +105,7 @@ sendPassword: function(passwd) {
sendCtrlAltDel: function() { sendCtrlAltDel: function() {
if (RFB.state !== "normal") { return false; } if (RFB.state !== "normal") { return false; }
console.log("Sending Ctrl-Alt-Del"); Util.Info("Sending Ctrl-Alt-Del");
var arr = []; var arr = [];
arr = arr.concat(RFB.keyEvent(0xFFE3, 1)); // Control arr = arr.concat(RFB.keyEvent(0xFFE3, 1)); // Control
arr = arr.concat(RFB.keyEvent(0xFFE9, 1)); // Alt arr = arr.concat(RFB.keyEvent(0xFFE9, 1)); // Alt
...@@ -119,14 +119,14 @@ sendCtrlAltDel: function() { ...@@ -119,14 +119,14 @@ sendCtrlAltDel: function() {
load: function () { load: function () {
var i; var i;
//console.log(">> load"); //Util.Debug(">> load");
/* Load web-socket-js if no builtin WebSocket support */ /* Load web-socket-js if no builtin WebSocket support */
if (VNC_native_ws) { if (VNC_native_ws) {
console.log("Using native WebSockets"); Util.Info("Using native WebSockets");
RFB.updateState('disconnected', 'Disconnected'); RFB.updateState('disconnected', 'Disconnected');
} else { } else {
console.warn("Using web-socket-js flash bridge"); Util.Warn("Using web-socket-js flash bridge");
if ((! Util.Flash) || if ((! Util.Flash) ||
(Util.Flash.version < 9)) { (Util.Flash.version < 9)) {
RFB.updateState('failed', "WebSockets or Adobe Flash is required"); RFB.updateState('failed', "WebSockets or Adobe Flash is required");
...@@ -150,11 +150,11 @@ load: function () { ...@@ -150,11 +150,11 @@ load: function () {
} }
RFB.encHandlers[0x07] = RFB.display_tight_png; RFB.encHandlers[0x07] = RFB.display_tight_png;
RFB.encNames[0x07] = 'TIGHT'; RFB.encNames[0x07] = 'TIGHT';
//console.log("<< load"); //Util.Debug("<< load");
}, },
connect: function (host, port, password, encrypt, true_color) { connect: function (host, port, password, encrypt, true_color) {
//console.log(">> connect"); //Util.Debug(">> connect");
RFB.host = host; RFB.host = host;
RFB.port = port; RFB.port = port;
...@@ -185,12 +185,12 @@ connect: function (host, port, password, encrypt, true_color) { ...@@ -185,12 +185,12 @@ connect: function (host, port, password, encrypt, true_color) {
RFB.init_ws(); RFB.init_ws();
RFB.updateState('ProtocolVersion'); RFB.updateState('ProtocolVersion');
//console.log("<< connect"); //Util.Debug("<< connect");
}, },
disconnect: function () { disconnect: function () {
//console.log(">> disconnect"); //Util.Debug(">> disconnect");
if ((RFB.ws) && (RFB.ws.readyState === WebSocket.OPEN)) { if ((RFB.ws) && (RFB.ws.readyState === WebSocket.OPEN)) {
RFB.ws.close(); RFB.ws.close();
RFB.updateState('closed'); RFB.updateState('closed');
...@@ -204,14 +204,14 @@ disconnect: function () { ...@@ -204,14 +204,14 @@ disconnect: function () {
} }
RFB.updateState('disconnected', 'Disconnected'); RFB.updateState('disconnected', 'Disconnected');
//console.log("<< disconnect"); //Util.Debug("<< disconnect");
}, },
clipboardPasteFrom: function (text) { clipboardPasteFrom: function (text) {
if (RFB.state !== "normal") { return; } if (RFB.state !== "normal") { return; }
//console.log(">> clipboardPasteFrom: " + text.substr(0,40) + "..."); //Util.Debug(">> clipboardPasteFrom: " + text.substr(0,40) + "...");
RFB.send_array(RFB.clientCutText(text)); RFB.send_array(RFB.clientCutText(text));
//console.log("<< clipboardPasteFrom"); //Util.Debug("<< clipboardPasteFrom");
}, },
...@@ -299,13 +299,13 @@ mouse_arr : [], ...@@ -299,13 +299,13 @@ mouse_arr : [],
/* RFB/VNC initialisation */ /* RFB/VNC initialisation */
init_msg: function () { init_msg: function () {
//console.log(">> init_msg [RFB.state '" + RFB.state + "']"); //Util.Debug(">> init_msg [RFB.state '" + RFB.state + "']");
var RQ = RFB.RQ, strlen, reason, reason_len, sversion, cversion, var RQ = RFB.RQ, strlen, reason, reason_len, sversion, cversion,
i, types, num_types, challenge, response, bpp, depth, i, types, num_types, challenge, response, bpp, depth,
big_endian, true_color, name_length; big_endian, true_color, name_length;
//console.log("RQ (" + RQ.length + ") " + RQ); //Util.Debug("RQ (" + RQ.length + ") " + RQ);
switch (RFB.state) { switch (RFB.state) {
case 'ProtocolVersion' : case 'ProtocolVersion' :
...@@ -315,7 +315,7 @@ init_msg: function () { ...@@ -315,7 +315,7 @@ init_msg: function () {
return; return;
} }
sversion = RQ.shiftStr(12).substr(4,7); sversion = RQ.shiftStr(12).substr(4,7);
console.log("Server ProtocolVersion: " + sversion); Util.Info("Server ProtocolVersion: " + sversion);
switch (sversion) { switch (sversion) {
case "003.003": RFB.version = 3.3; break; case "003.003": RFB.version = 3.3; break;
case "003.007": RFB.version = 3.7; break; case "003.007": RFB.version = 3.7; break;
...@@ -371,11 +371,11 @@ init_msg: function () { ...@@ -371,11 +371,11 @@ init_msg: function () {
// Fall through // Fall through
case 'Authentication' : case 'Authentication' :
//console.log("Security auth scheme: " + RFB.auth_scheme); //Util.Debug("Security auth scheme: " + RFB.auth_scheme);
switch (RFB.auth_scheme) { switch (RFB.auth_scheme) {
case 0: // connection failed case 0: // connection failed
if (RQ.length < 4) { if (RQ.length < 4) {
//console.log(" waiting for auth reason bytes"); //Util.Debug(" waiting for auth reason bytes");
return; return;
} }
strlen = RQ.shift32(); strlen = RQ.shift32();
...@@ -393,18 +393,18 @@ init_msg: function () { ...@@ -393,18 +393,18 @@ init_msg: function () {
return; return;
} }
if (RQ.length < 16) { if (RQ.length < 16) {
//console.log(" waiting for auth challenge bytes"); //Util.Debug(" waiting for auth challenge bytes");
return; return;
} }
challenge = RQ.shiftBytes(16); challenge = RQ.shiftBytes(16);
//console.log("Password: " + RFB.password); //Util.Debug("Password: " + RFB.password);
//console.log("Challenge: " + challenge + //Util.Debug("Challenge: " + challenge +
// " (" + challenge.length + ")"); // " (" + challenge.length + ")");
response = RFB.DES(RFB.password, challenge); response = RFB.DES(RFB.password, challenge);
//console.log("Response: " + response + //Util.Debug("Response: " + response +
// " (" + response.length + ")"); // " (" + response.length + ")");
//console.log("Sending DES encrypted auth response"); //Util.Debug("Sending DES encrypted auth response");
RFB.send_array(response); RFB.send_array(response);
RFB.updateState('SecurityResult'); RFB.updateState('SecurityResult');
break; break;
...@@ -458,10 +458,10 @@ init_msg: function () { ...@@ -458,10 +458,10 @@ init_msg: function () {
big_endian = RQ.shift8(); big_endian = RQ.shift8();
true_color = RQ.shift8(); true_color = RQ.shift8();
console.log("Screen: " + RFB.fb_width + "x" + RFB.fb_height + Util.Info("Screen: " + RFB.fb_width + "x" + RFB.fb_height +
", bpp: " + bpp + ", depth: " + depth + ", bpp: " + bpp + ", depth: " + depth +
", big_endian: " + big_endian + ", big_endian: " + big_endian +
", true_color: " + true_color); ", true_color: " + true_color);
/* Connection name/title */ /* Connection name/title */
RQ.shiftStr(12); RQ.shiftStr(12);
...@@ -494,13 +494,13 @@ init_msg: function () { ...@@ -494,13 +494,13 @@ init_msg: function () {
RFB.updateState('normal', "Connected to: " + RFB.fb_name); RFB.updateState('normal', "Connected to: " + RFB.fb_name);
break; break;
} }
//console.log("<< init_msg"); //Util.Debug("<< init_msg");
}, },
/* Normal RFB/VNC server messages */ /* Normal RFB/VNC server messages */
normal_msg: function () { normal_msg: function () {
//console.log(">> normal_msg"); //Util.Debug(">> normal_msg");
var RQ = RFB.RQ, ret = true, msg_type, var RQ = RFB.RQ, ret = true, msg_type,
c, first_colour, num_colours, red, green, blue; c, first_colour, num_colours, red, green, blue;
...@@ -517,34 +517,34 @@ normal_msg: function () { ...@@ -517,34 +517,34 @@ normal_msg: function () {
ret = RFB.framebufferUpdate(); ret = RFB.framebufferUpdate();
break; break;
case 1: // SetColourMapEntries case 1: // SetColourMapEntries
console.log("SetColourMapEntries"); Util.Debug("SetColourMapEntries");
RQ.shift8(); // Padding RQ.shift8(); // Padding
first_colour = RQ.shift16(); // First colour first_colour = RQ.shift16(); // First colour
num_colours = RQ.shift16(); num_colours = RQ.shift16();
for (c=0; c < num_colours; c+=1) { for (c=0; c < num_colours; c+=1) {
red = RQ.shift16(); red = RQ.shift16();
//console.log("red before: " + red); //Util.Debug("red before: " + red);
red = parseInt(red / 256, 10); red = parseInt(red / 256, 10);
//console.log("red after: " + red); //Util.Debug("red after: " + red);
green = parseInt(RQ.shift16() / 256, 10); green = parseInt(RQ.shift16() / 256, 10);
blue = parseInt(RQ.shift16() / 256, 10); blue = parseInt(RQ.shift16() / 256, 10);
Canvas.colourMap[first_colour + c] = [red, green, blue]; Canvas.colourMap[first_colour + c] = [red, green, blue];
} }
console.log("Registered " + num_colours + " colourMap entries"); Util.Info("Registered " + num_colours + " colourMap entries");
//console.log("colourMap: " + Canvas.colourMap); //Util.Debug("colourMap: " + Canvas.colourMap);
break; break;
case 2: // Bell case 2: // Bell
console.log("Bell (unsupported)"); Util.Warn("Bell (unsupported)");
break; break;
case 3: // ServerCutText case 3: // ServerCutText
console.log("ServerCutText"); Util.Debug("ServerCutText");
console.log("RQ:" + RQ.slice(0,20)); Util.Debug("RQ:" + RQ.slice(0,20));
if (RFB.cuttext === 'none') { if (RFB.cuttext === 'none') {
RFB.cuttext = 'header'; RFB.cuttext = 'header';
} }
if (RFB.cuttext === 'header') { if (RFB.cuttext === 'header') {
if (RQ.length < 7) { if (RQ.length < 7) {
//console.log("waiting for ServerCutText header"); //Util.Debug("waiting for ServerCutText header");
return false; return false;
} }
RQ.shiftBytes(3); // Padding RQ.shiftBytes(3); // Padding
...@@ -552,7 +552,7 @@ normal_msg: function () { ...@@ -552,7 +552,7 @@ normal_msg: function () {
} }
RFB.cuttext = 'bytes'; RFB.cuttext = 'bytes';
if (RQ.length < RFB.ct_length) { if (RQ.length < RFB.ct_length) {
//console.log("waiting for ServerCutText bytes"); //Util.Debug("waiting for ServerCutText bytes");
return false; return false;
} }
RFB.clipboardCopyTo(RQ.shiftStr(RFB.ct_length)); RFB.clipboardCopyTo(RQ.shiftStr(RFB.ct_length));
...@@ -561,10 +561,10 @@ normal_msg: function () { ...@@ -561,10 +561,10 @@ normal_msg: function () {
default: default:
RFB.updateState('failed', RFB.updateState('failed',
"Disconnected: illegal server message type " + msg_type); "Disconnected: illegal server message type " + msg_type);
console.log("RQ.slice(0,30):" + RQ.slice(0,30)); Util.Debug("RQ.slice(0,30):" + RQ.slice(0,30));
break; break;
} }
//console.log("<< normal_msg"); //Util.Debug("<< normal_msg");
return ret; return ret;
}, },
...@@ -576,25 +576,25 @@ framebufferUpdate: function() { ...@@ -576,25 +576,25 @@ framebufferUpdate: function() {
if (FBU.rects === 0) { if (FBU.rects === 0) {
if (RQ.length < 3) { if (RQ.length < 3) {
RQ.unshift(0); // FBU msg_type RQ.unshift(0); // FBU msg_type
//console.log(" waiting for FBU header bytes"); //Util.Debug(" waiting for FBU header bytes");
return false; return false;
} }
RQ.shift8(); RQ.shift8();
FBU.rects = RQ.shift16(); FBU.rects = RQ.shift16();
//console.log("FramebufferUpdate, rects:" + FBU.rects); //Util.Debug("FramebufferUpdate, rects:" + FBU.rects);
FBU.bytes = 0; FBU.bytes = 0;
timing.cur_fbu = 0; timing.cur_fbu = 0;
timing.h_fbus += 1; timing.h_fbus += 1;
if (timing.fbu_rt_start > 0) { if (timing.fbu_rt_start > 0) {
now = (new Date()).getTime(); now = (new Date()).getTime();
console.log("First FBU latency: " + (now - timing.fbu_rt_start)); Util.Info("First FBU latency: " + (now - timing.fbu_rt_start));
} }
} }
while ((FBU.rects > 0) && (RQ.length >= FBU.bytes)) { while ((FBU.rects > 0) && (RQ.length >= FBU.bytes)) {
if (FBU.bytes === 0) { if (FBU.bytes === 0) {
if (RQ.length < 12) { if (RQ.length < 12) {
//console.log(" waiting for rect header bytes"); //Util.Debug(" waiting for rect header bytes");
return false; return false;
} }
/* New FramebufferUpdate */ /* New FramebufferUpdate */
...@@ -612,7 +612,7 @@ framebufferUpdate: function() { ...@@ -612,7 +612,7 @@ framebufferUpdate: function() {
msg += " encoding:" + FBU.encoding; msg += " encoding:" + FBU.encoding;
msg += "(" + RFB.encNames[FBU.encoding] + ")"; msg += "(" + RFB.encNames[FBU.encoding] + ")";
msg += ", RQ.length: " + RQ.length; msg += ", RQ.length: " + RQ.length;
console.log(msg); Util.Debug(msg);
} else { } else {
RFB.updateState('failed', RFB.updateState('failed',
"Disconnected: unsupported encoding " + "Disconnected: unsupported encoding " +
...@@ -644,23 +644,23 @@ framebufferUpdate: function() { ...@@ -644,23 +644,23 @@ framebufferUpdate: function() {
(timing.fbu_rt_start > 0)) { (timing.fbu_rt_start > 0)) {
timing.full_fbu_total += timing.cur_fbu; timing.full_fbu_total += timing.cur_fbu;
timing.full_fbu_cnt += 1; timing.full_fbu_cnt += 1;
console.log("Timing of full FBU, cur: " + Util.Info("Timing of full FBU, cur: " +
timing.cur_fbu + ", total: " + timing.cur_fbu + ", total: " +
timing.full_fbu_total + ", cnt: " + timing.full_fbu_total + ", cnt: " +
timing.full_fbu_cnt + ", avg: " + timing.full_fbu_cnt + ", avg: " +
(timing.full_fbu_total / (timing.full_fbu_total /
timing.full_fbu_cnt)); timing.full_fbu_cnt));
} }
if (timing.fbu_rt_start > 0) { if (timing.fbu_rt_start > 0) {
fbu_rt_diff = now - timing.fbu_rt_start; fbu_rt_diff = now - timing.fbu_rt_start;
timing.fbu_rt_total += fbu_rt_diff; timing.fbu_rt_total += fbu_rt_diff;
timing.fbu_rt_cnt += 1; timing.fbu_rt_cnt += 1;
console.log("full FBU round-trip, cur: " + Util.Info("full FBU round-trip, cur: " +
fbu_rt_diff + ", total: " + fbu_rt_diff + ", total: " +
timing.fbu_rt_total + ", cnt: " + timing.fbu_rt_total + ", cnt: " +
timing.fbu_rt_cnt + ", avg: " + timing.fbu_rt_cnt + ", avg: " +
(timing.fbu_rt_total / (timing.fbu_rt_total /
timing.fbu_rt_cnt)); timing.fbu_rt_cnt));
timing.fbu_rt_start = 0; timing.fbu_rt_start = 0;
} }
} }
...@@ -675,7 +675,7 @@ framebufferUpdate: function() { ...@@ -675,7 +675,7 @@ framebufferUpdate: function() {
*/ */
display_raw: function () { display_raw: function () {
//console.log(">> display_raw"); //Util.Debug(">> display_raw");
var RQ = RFB.RQ, FBU = RFB.FBU, cur_y, cur_height; var RQ = RFB.RQ, FBU = RFB.FBU, cur_y, cur_height;
...@@ -684,8 +684,8 @@ display_raw: function () { ...@@ -684,8 +684,8 @@ display_raw: function () {
} }
FBU.bytes = FBU.width * RFB.fb_Bpp; // At least a line FBU.bytes = FBU.width * RFB.fb_Bpp; // At least a line
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for " + //Util.Debug(" waiting for " +
// (FBU.bytes - RQ.length) + " RAW bytes"); // (FBU.bytes - RQ.length) + " RAW bytes");
return; return;
} }
cur_y = FBU.y + (FBU.height - FBU.lines); cur_y = FBU.y + (FBU.height - FBU.lines);
...@@ -704,13 +704,13 @@ display_raw: function () { ...@@ -704,13 +704,13 @@ display_raw: function () {
}, },
display_copy_rect: function () { display_copy_rect: function () {
//console.log(">> display_copy_rect"); //Util.Debug(">> display_copy_rect");
var RQ = RFB.RQ, FBU = RFB.FBU, old_x, old_y; var RQ = RFB.RQ, FBU = RFB.FBU, old_x, old_y;
if (RQ.length < 4) { if (RQ.length < 4) {
//console.log(" waiting for " + //Util.Debug(" waiting for " +
// (FBU.bytes - RQ.length) + " COPYRECT bytes"); // (FBU.bytes - RQ.length) + " COPYRECT bytes");
return; return;
} }
old_x = RQ.shift16(); old_x = RQ.shift16();
...@@ -721,12 +721,12 @@ display_copy_rect: function () { ...@@ -721,12 +721,12 @@ display_copy_rect: function () {
}, },
display_rre: function () { display_rre: function () {
//console.log(">> display_rre (" + RFB.RQ.length + " bytes)"); //Util.Debug(">> display_rre (" + RFB.RQ.length + " bytes)");
var RQ = RFB.RQ, FBU = RFB.FBU, color, x, y, width, height, chunk; var RQ = RFB.RQ, FBU = RFB.FBU, color, x, y, width, height, chunk;
if (FBU.subrects === 0) { if (FBU.subrects === 0) {
if (RQ.length < 4 + RFB.fb_Bpp) { if (RQ.length < 4 + RFB.fb_Bpp) {
//console.log(" waiting for " + //Util.Debug(" waiting for " +
// (4 + RFB.fb_Bpp - RQ.length) + " RRE bytes"); // (4 + RFB.fb_Bpp - RQ.length) + " RRE bytes");
return; return;
} }
FBU.subrects = RQ.shift32(); FBU.subrects = RQ.shift32();
...@@ -742,8 +742,8 @@ display_rre: function () { ...@@ -742,8 +742,8 @@ display_rre: function () {
Canvas.fillRect(FBU.x + x, FBU.y + y, width, height, color); Canvas.fillRect(FBU.x + x, FBU.y + y, width, height, color);
FBU.subrects -= 1; FBU.subrects -= 1;
} }
//console.log(" display_rre: rects: " + FBU.rects + //Util.Debug(" display_rre: rects: " + FBU.rects +
// ", FBU.subrects: " + FBU.subrects); // ", FBU.subrects: " + FBU.subrects);
if (FBU.subrects > 0) { if (FBU.subrects > 0) {
chunk = Math.min(RFB.rre_chunk, FBU.subrects); chunk = Math.min(RFB.rre_chunk, FBU.subrects);
...@@ -752,11 +752,11 @@ display_rre: function () { ...@@ -752,11 +752,11 @@ display_rre: function () {
FBU.rects -= 1; FBU.rects -= 1;
FBU.bytes = 0; FBU.bytes = 0;
} }
//console.log("<< display_rre, FBU.bytes: " + FBU.bytes); //Util.Debug("<< display_rre, FBU.bytes: " + FBU.bytes);
}, },
display_hextile: function() { display_hextile: function() {
//console.log(">> display_hextile"); //Util.Debug(">> display_hextile");
var RQ = RFB.RQ, FBU = RFB.FBU, var RQ = RFB.RQ, FBU = RFB.FBU,
subencoding, subrects, idx, tile, color, cur_tile, subencoding, subrects, idx, tile, color, cur_tile,
tile_x, x, w, tile_y, y, h, xy, s, sx, sy, wh, sw, sh; tile_x, x, w, tile_y, y, h, xy, s, sx, sy, wh, sw, sh;
...@@ -772,14 +772,14 @@ display_hextile: function() { ...@@ -772,14 +772,14 @@ display_hextile: function() {
while (FBU.tiles > 0) { while (FBU.tiles > 0) {
FBU.bytes = 1; FBU.bytes = 1;
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for HEXTILE subencoding byte"); //Util.Debug(" waiting for HEXTILE subencoding byte");
return; return;
} }
subencoding = RQ[0]; // Peek subencoding = RQ[0]; // Peek
if (subencoding > 30) { // Raw if (subencoding > 30) { // Raw
RFB.updateState('failed', RFB.updateState('failed',
"Disconnected: illegal hextile subencoding " + subencoding); "Disconnected: illegal hextile subencoding " + subencoding);
console.log("RQ.slice(0,30):" + RQ.slice(0,30)); Util.Debug("RQ.slice(0,30):" + RQ.slice(0,30));
return; return;
} }
subrects = 0; subrects = 0;
...@@ -793,7 +793,7 @@ display_hextile: function() { ...@@ -793,7 +793,7 @@ display_hextile: function() {
/* Figure out how much we are expecting */ /* Figure out how much we are expecting */
if (subencoding & 0x01) { // Raw if (subencoding & 0x01) { // Raw
//console.log(" Raw subencoding"); //Util.Debug(" Raw subencoding");
FBU.bytes += w * h * RFB.fb_Bpp; FBU.bytes += w * h * RFB.fb_Bpp;
} else { } else {
if (subencoding & 0x02) { // Background if (subencoding & 0x02) { // Background
...@@ -806,7 +806,7 @@ display_hextile: function() { ...@@ -806,7 +806,7 @@ display_hextile: function() {
FBU.bytes += 1; // Since we aren't shifting it off FBU.bytes += 1; // Since we aren't shifting it off
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
/* Wait for subrects byte */ /* Wait for subrects byte */
//console.log(" waiting for hextile subrects header byte"); //Util.Debug(" waiting for hextile subrects header byte");
return; return;
} }
subrects = RQ[FBU.bytes-1]; // Peek subrects = RQ[FBU.bytes-1]; // Peek
...@@ -818,17 +818,17 @@ display_hextile: function() { ...@@ -818,17 +818,17 @@ display_hextile: function() {
} }
} }
//console.log(" tile:" + cur_tile + "/" + (FBU.total_tiles - 1) + //Util.Debug(" tile:" + cur_tile + "/" + (FBU.total_tiles - 1) +
// ", subencoding:" + subencoding + // ", subencoding:" + subencoding +
// "(last: " + FBU.lastsubencoding + "), subrects:" + // "(last: " + FBU.lastsubencoding + "), subrects:" +
// subrects + ", tile:" + tile_x + "," + tile_y + // subrects + ", tile:" + tile_x + "," + tile_y +
// " [" + x + "," + y + "]@" + w + "x" + h + // " [" + x + "," + y + "]@" + w + "x" + h +
// ", d.length:" + RQ.length + ", bytes:" + FBU.bytes + // ", d.length:" + RQ.length + ", bytes:" + FBU.bytes +
// " last:" + RQ.slice(FBU.bytes-10, FBU.bytes) + // " last:" + RQ.slice(FBU.bytes-10, FBU.bytes) +
// " next:" + RQ.slice(FBU.bytes-1, FBU.bytes+10)); // " next:" + RQ.slice(FBU.bytes-1, FBU.bytes+10));
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for " + //Util.Debug(" waiting for " +
// (FBU.bytes - RQ.length) + " hextile bytes"); // (FBU.bytes - RQ.length) + " hextile bytes");
return; return;
} }
...@@ -838,7 +838,7 @@ display_hextile: function() { ...@@ -838,7 +838,7 @@ display_hextile: function() {
if (FBU.subencoding === 0) { if (FBU.subencoding === 0) {
if (FBU.lastsubencoding & 0x01) { if (FBU.lastsubencoding & 0x01) {
/* Weird: ignore blanks after RAW */ /* Weird: ignore blanks after RAW */
console.log(" Ignoring blank after RAW"); Util.Debug(" Ignoring blank after RAW");
} else { } else {
Canvas.fillRect(x, y, w, h, FBU.background); Canvas.fillRect(x, y, w, h, FBU.background);
} }
...@@ -890,22 +890,22 @@ display_hextile: function() { ...@@ -890,22 +890,22 @@ display_hextile: function() {
FBU.rects -= 1; FBU.rects -= 1;
} }
//console.log("<< display_hextile"); //Util.Debug("<< display_hextile");
}, },
display_tight_png: function() { display_tight_png: function() {
//console.log(">> display_tight_png"); //Util.Debug(">> display_tight_png");
var RQ = RFB.RQ, FBU = RFB.FBU, var RQ = RFB.RQ, FBU = RFB.FBU,
ctl, cmode, clength, getCLength, color, img; ctl, cmode, clength, getCLength, color, img;
//console.log(" FBU.rects: " + FBU.rects); //Util.Debug(" FBU.rects: " + FBU.rects);
//console.log(" RQ.length: " + RQ.length); //Util.Debug(" RQ.length: " + RQ.length);
//console.log(" RQ.slice(0,20): " + RQ.slice(0,20)); //Util.Debug(" RQ.slice(0,20): " + RQ.slice(0,20));
FBU.bytes = 1; // compression-control byte FBU.bytes = 1; // compression-control byte
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for TIGHT compression-control byte"); //Util.Debug(" waiting for TIGHT compression-control byte");
return; return;
} }
...@@ -939,12 +939,12 @@ display_tight_png: function() { ...@@ -939,12 +939,12 @@ display_tight_png: function() {
} }
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for TIGHT " + cmode + " bytes"); //Util.Debug(" waiting for TIGHT " + cmode + " bytes");
return; return;
} }
//console.log(" RQ.slice(0,20): " + RFB.RQ.slice(0,20) + " (" + RFB.RQ.length + ")"); //Util.Debug(" RQ.slice(0,20): " + RFB.RQ.slice(0,20) + " (" + RFB.RQ.length + ")");
//console.log(" cmode: " + cmode); //Util.Debug(" cmode: " + cmode);
// Determine FBU.bytes // Determine FBU.bytes
switch (cmode) { switch (cmode) {
...@@ -958,12 +958,12 @@ display_tight_png: function() { ...@@ -958,12 +958,12 @@ display_tight_png: function() {
clength = getCLength(RQ, 1); clength = getCLength(RQ, 1);
FBU.bytes = 1 + clength[0] + clength[1]; // ctl + clength size + jpeg-data FBU.bytes = 1 + clength[0] + clength[1]; // ctl + clength size + jpeg-data
if (RQ.length < FBU.bytes) { if (RQ.length < FBU.bytes) {
//console.log(" waiting for TIGHT " + cmode + " bytes"); //Util.Debug(" waiting for TIGHT " + cmode + " bytes");
return; return;
} }
// We have everything, render it // We have everything, render it
//console.log(" png, RQ.length: " + RQ.length + ", clength[0]: " + clength[0] + ", clength[1]: " + clength[1]); //Util.Debug(" png, RQ.length: " + RQ.length + ", clength[0]: " + clength[0] + ", clength[1]: " + clength[1]);
RQ.shiftBytes(1 + clength[0]); // shift off ctl + compact length RQ.shiftBytes(1 + clength[0]); // shift off ctl + compact length
img = new Image(); img = new Image();
img.onload = RFB.scan_tight_imgs; img.onload = RFB.scan_tight_imgs;
...@@ -975,8 +975,9 @@ display_tight_png: function() { ...@@ -975,8 +975,9 @@ display_tight_png: function() {
} }
FBU.bytes = 0; FBU.bytes = 0;
FBU.rects -= 1; FBU.rects -= 1;
//console.log(" ending RQ.length: " + RQ.length); //Util.Debug(" ending RQ.length: " + RQ.length);
//console.log(" ending RQ.slice(0,20): " + RQ.slice(0,20)); //Util.Debug(" ending RQ.slice(0,20): " + RQ.slice(0,20));
//Util.Debug("<< display_tight_png");
}, },
extract_data_uri : function (arr) { extract_data_uri : function (arr) {
...@@ -1001,7 +1002,7 @@ scan_tight_imgs : function () { ...@@ -1001,7 +1002,7 @@ scan_tight_imgs : function () {
}, },
set_desktopsize : function () { set_desktopsize : function () {
console.log(">> set_desktopsize"); Util.Debug(">> set_desktopsize");
RFB.fb_width = RFB.FBU.width; RFB.fb_width = RFB.FBU.width;
RFB.fb_height = RFB.FBU.height; RFB.fb_height = RFB.FBU.height;
Canvas.clear(); Canvas.clear();
...@@ -1009,17 +1010,17 @@ set_desktopsize : function () { ...@@ -1009,17 +1010,17 @@ set_desktopsize : function () {
RFB.timing.fbu_rt_start = (new Date()).getTime(); RFB.timing.fbu_rt_start = (new Date()).getTime();
// Send a new non-incremental request // Send a new non-incremental request
RFB.send_array(RFB.fbUpdateRequest(0)); RFB.send_array(RFB.fbUpdateRequest(0));
console.log("<< set_desktopsize"); Util.Debug("<< set_desktopsize");
RFB.FBU.bytes = 0; RFB.FBU.bytes = 0;
RFB.FBU.rects -= 1; RFB.FBU.rects -= 1;
}, },
set_jpeg_quality : function () { set_jpeg_quality : function () {
console.log(">> set_jpeg_quality"); Util.Debug(">> set_jpeg_quality");
}, },
set_compress_level: function () { set_compress_level: function () {
console.log(">> set_compress_level"); Util.Debug(">> set_compress_level");
}, },
/* /*
...@@ -1027,7 +1028,7 @@ set_compress_level: function () { ...@@ -1027,7 +1028,7 @@ set_compress_level: function () {
*/ */
pixelFormat: function () { pixelFormat: function () {
//console.log(">> pixelFormat"); //Util.Debug(">> pixelFormat");
var arr; var arr;
arr = [0]; // msg-type arr = [0]; // msg-type
arr.push8(0); // padding arr.push8(0); // padding
...@@ -1049,7 +1050,7 @@ pixelFormat: function () { ...@@ -1049,7 +1050,7 @@ pixelFormat: function () {
arr.push8(0); // padding arr.push8(0); // padding
arr.push8(0); // padding arr.push8(0); // padding
arr.push8(0); // padding arr.push8(0); // padding
//console.log("<< pixelFormat"); //Util.Debug("<< pixelFormat");
return arr; return arr;
}, },
...@@ -1057,7 +1058,7 @@ fixColourMapEntries: function () { ...@@ -1057,7 +1058,7 @@ fixColourMapEntries: function () {
}, },
clientEncodings: function () { clientEncodings: function () {
//console.log(">> clientEncodings"); //Util.Debug(">> clientEncodings");
var arr, i; var arr, i;
arr = [2]; // msg-type arr = [2]; // msg-type
arr.push8(0); // padding arr.push8(0); // padding
...@@ -1067,12 +1068,12 @@ clientEncodings: function () { ...@@ -1067,12 +1068,12 @@ clientEncodings: function () {
for (i=0; i<RFB.encodings.length; i += 1) { for (i=0; i<RFB.encodings.length; i += 1) {
arr.push32(RFB.encodings[i][1]); arr.push32(RFB.encodings[i][1]);
} }
//console.log("<< clientEncodings: " + arr); //Util.Debug("<< clientEncodings: " + arr);
return arr; return arr;
}, },
fbUpdateRequest: function (incremental, x, y, xw, yw) { fbUpdateRequest: function (incremental, x, y, xw, yw) {
//console.log(">> fbUpdateRequest"); //Util.Debug(">> fbUpdateRequest");
if (!x) { x = 0; } if (!x) { x = 0; }
if (!y) { y = 0; } if (!y) { y = 0; }
if (!xw) { xw = RFB.fb_width; } if (!xw) { xw = RFB.fb_width; }
...@@ -1084,35 +1085,35 @@ fbUpdateRequest: function (incremental, x, y, xw, yw) { ...@@ -1084,35 +1085,35 @@ fbUpdateRequest: function (incremental, x, y, xw, yw) {
arr.push16(y); arr.push16(y);
arr.push16(xw); arr.push16(xw);
arr.push16(yw); arr.push16(yw);
//console.log("<< fbUpdateRequest"); //Util.Debug("<< fbUpdateRequest");
return arr; return arr;
}, },
keyEvent: function (keysym, down) { keyEvent: function (keysym, down) {
//console.log(">> keyEvent, keysym: " + keysym + ", down: " + down); //Util.Debug(">> keyEvent, keysym: " + keysym + ", down: " + down);
var arr; var arr;
arr = [4]; // msg-type arr = [4]; // msg-type
arr.push8(down); arr.push8(down);
arr.push16(0); arr.push16(0);
arr.push32(keysym); arr.push32(keysym);
//console.log("<< keyEvent"); //Util.Debug("<< keyEvent");
return arr; return arr;
}, },
pointerEvent: function (x, y) { pointerEvent: function (x, y) {
//console.log(">> pointerEvent, x,y: " + x + "," + y + //Util.Debug(">> pointerEvent, x,y: " + x + "," + y +
// " , mask: " + RFB.mouse_buttonMask); // " , mask: " + RFB.mouse_buttonMask);
var arr; var arr;
arr = [5]; // msg-type arr = [5]; // msg-type
arr.push8(RFB.mouse_buttonMask); arr.push8(RFB.mouse_buttonMask);
arr.push16(x); arr.push16(x);
arr.push16(y); arr.push16(y);
//console.log("<< pointerEvent"); //Util.Debug("<< pointerEvent");
return arr; return arr;
}, },
clientCutText: function (text) { clientCutText: function (text) {
//console.log(">> clientCutText"); //Util.Debug(">> clientCutText");
var arr; var arr;
arr = [6]; // msg-type arr = [6]; // msg-type
arr.push8(0); // padding arr.push8(0); // padding
...@@ -1120,7 +1121,7 @@ clientCutText: function (text) { ...@@ -1120,7 +1121,7 @@ clientCutText: function (text) {
arr.push8(0); // padding arr.push8(0); // padding
arr.push32(text.length); arr.push32(text.length);
arr.pushStr(text); arr.pushStr(text);
//console.log("<< clientCutText:" + arr); //Util.Debug("<< clientCutText:" + arr);
return arr; return arr;
}, },
...@@ -1139,7 +1140,7 @@ encode_message: function(arr) { ...@@ -1139,7 +1140,7 @@ encode_message: function(arr) {
}, },
decode_message: function(data, offset) { decode_message: function(data, offset) {
//console.log(">> decode_message: " + data); //Util.Debug(">> decode_message: " + data);
if (RFB.b64encode) { if (RFB.b64encode) {
RFB.RQ = RFB.RQ.concat(Base64.decode(data, offset)); RFB.RQ = RFB.RQ.concat(Base64.decode(data, offset));
} else { } else {
...@@ -1149,22 +1150,22 @@ decode_message: function(data, offset) { ...@@ -1149,22 +1150,22 @@ decode_message: function(data, offset) {
RQ.push(data.charCodeAt(i) % 256); RQ.push(data.charCodeAt(i) % 256);
} }
} }
//console.log(">> decode_message, RQ: " + RFB.RQ); //Util.Debug(">> decode_message, RQ: " + RFB.RQ);
}, },
recv_message: function(e) { recv_message: function(e) {
//console.log(">> recv_message"); //Util.Debug(">> recv_message");
try { try {
RFB.decode_message(e.data, 0); RFB.decode_message(e.data, 0);
RFB.handle_message(); RFB.handle_message();
} catch (exc) { } catch (exc) {
if (typeof exc.stack !== 'undefined') { if (typeof exc.stack !== 'undefined') {
console.log("recv_message, caught exception: " + exc.stack); Util.Warn("recv_message, caught exception: " + exc.stack);
} else if (typeof exc.description !== 'undefined') { } else if (typeof exc.description !== 'undefined') {
console.log("recv_message, caught exception: " + exc.description); Util.Warn("recv_message, caught exception: " + exc.description);
} else { } else {
console.log("recv_message, caught exception:" + exc); Util.Warn("recv_message, caught exception:" + exc);
} }
if (typeof exc.name !== 'undefined') { if (typeof exc.name !== 'undefined') {
RFB.updateState('failed', exc.name + ": " + exc.message); RFB.updateState('failed', exc.name + ": " + exc.message);
...@@ -1172,17 +1173,17 @@ recv_message: function(e) { ...@@ -1172,17 +1173,17 @@ recv_message: function(e) {
RFB.updateState('failed', exc); RFB.updateState('failed', exc);
} }
} }
//console.log("<< recv_message"); //Util.Debug("<< recv_message");
}, },
handle_message: function () { handle_message: function () {
//console.log("RQ.slice(0,20): " + RFB.RQ.slice(0,20) + " (" + RFB.RQ.length + ")"); //Util.Debug("RQ.slice(0,20): " + RFB.RQ.slice(0,20) + " (" + RFB.RQ.length + ")");
switch (RFB.state) { switch (RFB.state) {
case 'disconnected': case 'disconnected':
console.error("Got data while disconnected"); Util.Error("Got data while disconnected");
break; break;
case 'failed': case 'failed':
console.log("Giving up!"); Util.Warn("Giving up!");
RFB.disconnect(); RFB.disconnect();
break; break;
case 'normal': case 'normal':
...@@ -1190,7 +1191,7 @@ handle_message: function () { ...@@ -1190,7 +1191,7 @@ handle_message: function () {
/* /*
while (RFB.RQ.length > 0) { while (RFB.RQ.length > 0) {
if (RFB.normal_msg() && RFB.state === 'normal') { if (RFB.normal_msg() && RFB.state === 'normal') {
console.log("More to process"); Util.Debug("More to process");
} else { } else {
break; break;
} }
...@@ -1204,19 +1205,19 @@ handle_message: function () { ...@@ -1204,19 +1205,19 @@ handle_message: function () {
}, },
send_string: function (str) { send_string: function (str) {
//console.log(">> send_string: " + str); //Util.Debug(">> send_string: " + str);
RFB.send_array(str.split('').map( RFB.send_array(str.split('').map(
function (chr) { return chr.charCodeAt(0); } ) ); function (chr) { return chr.charCodeAt(0); } ) );
}, },
send_array: function (arr) { send_array: function (arr) {
//console.log(">> send_array: " + arr); //Util.Debug(">> send_array: " + arr);
RFB.encode_message(arr); RFB.encode_message(arr);
if (RFB.ws.bufferedAmount === 0) { if (RFB.ws.bufferedAmount === 0) {
RFB.ws.send(RFB.SQ); RFB.ws.send(RFB.SQ);
RFB.SQ = ""; RFB.SQ = "";
} else { } else {
console.log("Delaying send"); Util.Debug("Delaying send");
} }
}, },
...@@ -1281,26 +1282,26 @@ mouseButton: function(x, y, down, bmask) { ...@@ -1281,26 +1282,26 @@ mouseButton: function(x, y, down, bmask) {
}, },
mouseMove: function(x, y) { mouseMove: function(x, y) {
//console.log('>> mouseMove ' + x + "," + y); //Util.Debug('>> mouseMove ' + x + "," + y);
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) ); RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
}, },
clipboardCopyTo: function (text) { clipboardCopyTo: function (text) {
console.log(">> clipboardCopyTo stub"); Util.Debug(">> clipboardCopyTo stub");
// Stub // Stub
}, },
externalUpdateState: function(state, msg) { externalUpdateState: function(state, msg) {
console.log(">> externalUpdateState stub"); Util.Debug(">> externalUpdateState stub");
// Stub // Stub
}, },
updateState: function(state, statusMsg) { updateState: function(state, statusMsg) {
var func, cmsg; var func, cmsg;
if (state === 'failed') { if (state === 'failed') {
func = function(msg) { console.error(msg); }; func = Util.Error;
} else { } else {
func = function(msg) { console.warn(msg); }; func = Util.Warn;
} }
cmsg = typeof(statusMsg) !== 'undefined' ? (" Msg: " + statusMsg) : ""; cmsg = typeof(statusMsg) !== 'undefined' ? (" Msg: " + statusMsg) : "";
...@@ -1348,7 +1349,7 @@ show_timings: function() { ...@@ -1348,7 +1349,7 @@ show_timings: function() {
delta, tot_time = 0, tot_fbus = 0, tot_rects = 0, delta, tot_time = 0, tot_fbus = 0, tot_rects = 0,
tot_bytes = 0, tot_pixels = 0; tot_bytes = 0, tot_pixels = 0;
if (timing.history_start === 0) { return; } if (timing.history_start === 0) { return; }
console.log(">> show_timings"); //Util.Debug(">> show_timings");
RFB.update_timings(); // Final accumulate RFB.update_timings(); // Final accumulate
msg = "\nTimings\n"; msg = "\nTimings\n";
msg += " time: fbus,rects,bytes,pixels\n"; msg += " time: fbus,rects,bytes,pixels\n";
...@@ -1369,7 +1370,8 @@ show_timings: function() { ...@@ -1369,7 +1370,8 @@ show_timings: function() {
msg += " " + tot_time.toFixed(3); msg += " " + tot_time.toFixed(3);
msg += ": " + tot_fbus + "," + tot_rects; msg += ": " + tot_fbus + "," + tot_rects;
msg += "," + tot_bytes + "," + tot_pixels; msg += "," + tot_bytes + "," + tot_pixels;
console.log(msg); Util.Info(msg);
//Util.Debug("<< show_timings");
}, },
/* /*
...@@ -1377,7 +1379,7 @@ show_timings: function() { ...@@ -1377,7 +1379,7 @@ show_timings: function() {
*/ */
init_ws: function () { init_ws: function () {
//console.log(">> init_ws"); //Util.Debug(">> init_ws");
var uri = "", vars = []; var uri = "", vars = [];
if (RFB.encrypt) { if (RFB.encrypt) {
...@@ -1392,12 +1394,12 @@ init_ws: function () { ...@@ -1392,12 +1394,12 @@ init_ws: function () {
if (vars.length > 0) { if (vars.length > 0) {
uri += "?" + vars.join("&"); uri += "?" + vars.join("&");
} }
console.log("connecting to " + uri); Util.Info("connecting to " + uri);
RFB.ws = new WebSocket(uri); RFB.ws = new WebSocket(uri);
RFB.ws.onmessage = RFB.recv_message; RFB.ws.onmessage = RFB.recv_message;
RFB.ws.onopen = function(e) { RFB.ws.onopen = function(e) {
//console.log(">> WebSocket.onopen"); Util.Debug(">> WebSocket.onopen");
RFB.updateState('ProtocolVersion', "Starting VNC handshake"); RFB.updateState('ProtocolVersion', "Starting VNC handshake");
RFB.sendID = setInterval(function() { RFB.sendID = setInterval(function() {
/* /*
...@@ -1410,21 +1412,21 @@ init_ws: function () { ...@@ -1410,21 +1412,21 @@ init_ws: function () {
RFB.SQ = ""; RFB.SQ = "";
} }
} else { } else {
console.log("Delaying send"); Util.Debug("Delaying send");
} }
}, 50); }, 50);
//console.log("<< WebSocket.onopen"); Util.Debug("<< WebSocket.onopen");
}; };
RFB.ws.onclose = function(e) { RFB.ws.onclose = function(e) {
//console.log(">> WebSocket.onclose"); Util.Debug(">> WebSocket.onclose");
clearInterval(RFB.sendID); clearInterval(RFB.sendID);
RFB.updateState('disconnected', 'VNC disconnected'); RFB.updateState('disconnected', 'VNC disconnected');
//console.log("<< WebSocket.onclose"); Util.Debug("<< WebSocket.onclose");
}; };
RFB.ws.onerror = function(e) { RFB.ws.onerror = function(e) {
console.error(">> WebSocket.onerror"); Util.Debug(">> WebSocket.onerror");
RFB.updateState('failed', "WebSocket error"); RFB.updateState('failed', "WebSocket error");
console.error("<< WebSocket.onerror"); Util.Debug("<< WebSocket.onerror");
}; };
setTimeout(function () { setTimeout(function () {
...@@ -1434,7 +1436,7 @@ init_ws: function () { ...@@ -1434,7 +1436,7 @@ init_ws: function () {
} }
}, RFB.connectTimeout); }, RFB.connectTimeout);
//console.log("<< init_ws"); //Util.Debug("<< init_ws");
}, },
init_vars: function () { init_vars: function () {
......
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