Isolate DOM references in load() and connect().

- Other misc cleanups.
This commit is contained in:
Joel Martin 2010-05-11 16:39:17 -05:00
parent ded9dfae10
commit db504ade0c
3 changed files with 36 additions and 24 deletions

View File

@ -131,7 +131,8 @@ decode: function (data, offset) {
// If there are any bits left, the base64 string was corrupted // If there are any bits left, the base64 string was corrupted
if (leftbits) if (leftbits)
throw Components.Exception('Corrupted base64 string'); throw {name: 'Base64-Error',
message: 'Corrupted base64 string'};
return result; return result;
} }

View File

@ -233,7 +233,6 @@ DES = {
DES.deskey(key, true, DES.encryptKeys); DES.deskey(key, true, DES.encryptKeys);
DES.deskey(key, false, DES.decryptKeys); DES.deskey(key, false, DES.decryptKeys);
console.log("DES.encryptKeys: " + DES.encryptKeys);
}, },
// Turn an 8-byte key into internal keys. // Turn an 8-byte key into internal keys.

56
vnc.js
View File

@ -122,10 +122,14 @@ SQ = ""; // Send Queue
RFB = { RFB = {
ws : null, // Web Socket object ws : null, // Web Socket object
scheme : "ws://",
sendID : null, sendID : null,
use_seq : false, use_seq : false,
// DOM objects
statusLine : null,
connectBtn : null,
clipboard : null,
max_version : 3.8, max_version : 3.8,
version : 0, version : 0,
auth_scheme : '', auth_scheme : '',
@ -942,26 +946,26 @@ mouseMove: function(e) {
clipboardCopyTo: function (text) { clipboardCopyTo: function (text) {
console.log(">> clipboardCopyTo: " + text.substr(0,40) + "..."); console.log(">> clipboardCopyTo: " + text.substr(0,40) + "...");
$('VNC_clipboard_text').value = text; RFB.clipboard.value = text;
console.log("<< clipboardCopyTo"); console.log("<< clipboardCopyTo");
}, },
clipboardPasteFrom: function () { clipboardPasteFrom: function () {
if (RFB.state != "normal") return; if (RFB.state != "normal") return;
var text = $('VNC_clipboard_text').value; var text = RFB.clipboard.value;
console.log(">> clipboardPasteFrom: " + text.substr(0,40) + "..."); console.log(">> clipboardPasteFrom: " + text.substr(0,40) + "...");
RFB.send_array(RFB.clientCutText(text)); RFB.send_array(RFB.clientCutText(text));
console.log("<< clipboardPasteFrom"); console.log("<< clipboardPasteFrom");
}, },
clipboardClear: function () { clipboardClear: function () {
$('VNC_clipboard_text').value = ''; RFB.clipboard.value = '';
RFB.clipboardPasteFrom(); RFB.clipboardPasteFrom();
}, },
updateState: function(state, statusMsg) { updateState: function(state, statusMsg) {
var s = $('VNC_status'); var s = RFB.statusLine;
var c = $('VNC_connect_button'); var c = RFB.connectBtn;
var func = function(msg) { console.log(msg) }; var func = function(msg) { console.log(msg) };
switch (state) { switch (state) {
case 'failed': case 'failed':
@ -977,7 +981,8 @@ updateState: function(state, statusMsg) {
break; break;
case 'disconnected': case 'disconnected':
c.value = "Connect"; c.value = "Connect";
c.onclick = RFB.connect; c.onclick = function () { RFB.connect(); },
c.disabled = false; c.disabled = false;
s.style.fontColor = "#000000"; s.style.fontColor = "#000000";
break; break;
@ -1003,7 +1008,13 @@ updateState: function(state, statusMsg) {
init_ws: function () { init_ws: function () {
console.log(">> init_ws"); console.log(">> init_ws");
var uri = RFB.scheme + RFB.host + ":" + RFB.port + "/?b64encode"; var uri = "";
if (RFB.encrypt) {
uri = "wss://";
} else {
uri = "ws://";
}
uri += RFB.host + ":" + RFB.port + "/?b64encode";
if (RFB.use_seq) { if (RFB.use_seq) {
uri += "&seq_num"; uri += "&seq_num";
} }
@ -1071,18 +1082,15 @@ init_vars: function () {
}, },
connect: function () { connect: function (host, port, password, encrypt) {
console.log(">> connect"); console.log(">> connect");
RFB.host = $('VNC_host').value; RFB.host = (host !== undefined) ? host : $('VNC_host').value;
RFB.port = $('VNC_port').value; console.log("RFB.host: " + RFB.host);
RFB.password = $('VNC_password').value; RFB.port = (port !== undefined) ? port : $('VNC_port').value;
if ($('VNC_encrypt').checked) { RFB.password = (password !== undefined) ? password : $('VNC_password').value;
RFB.scheme = "wss://"; RFB.encrypt = (encrypt !== undefined) ? encrypt : $('VNC_encrypt').checked;
} else {
RFB.scheme = "ws://";
}
if ((!RFB.host) || (!RFB.port)) { if ((!RFB.host) || (!RFB.port)) {
console.log("must set host and port"); alert("Must set host and port");
return; return;
} }
@ -1168,12 +1176,16 @@ load: function (target) {
} }
$('VNC_screen').innerHTML += html; $('VNC_screen').innerHTML += html;
/* DOM object references */
RFB.statusLine = $('VNC_status');
RFB.connectBtn = $('VNC_connect_button');
RFB.clipboard = $('VNC_clipboard_text');
/* Add handlers */ /* Add handlers */
$('VNC_clipboard_clear_button').onclick = RFB.clipboardClear; $('VNC_clipboard_clear_button').onclick = RFB.clipboardClear;
var clipt = $('VNC_clipboard_text') RFB.clipboard.onchange = RFB.clipboardPasteFrom;
clipt.onchange = RFB.clipboardPasteFrom; RFB.clipboard.onfocus = function () { RFB.clipboardFocus = true; };
clipt.onfocus = function () { RFB.clipboardFocus = true; }; RFB.clipboard.onblur = function () { RFB.clipboardFocus = false; };
clipt.onblur = function () { RFB.clipboardFocus = false; };
/* 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) {