Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
c4164bda
Commit
c4164bda
authored
May 15, 2010
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JSLint and "use strict".
parent
753bde8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
345 additions
and
247 deletions
+345
-247
canvas.js
canvas.js
+57
-34
vnc.js
vnc.js
+288
-213
No files found.
canvas.js
View file @
c4164bda
Canvas
=
{
/*
* noVNC: HTML5 VNC client
*
* Licensed under AGPL-3 (see LICENSE.AGPL-3)
*
* See README.md for usage and integration instructions.
*/
"use strict"
;
/*global window, $, Browser */
// Everything namespaced inside Canvas
var
Canvas
=
{
c_x
:
0
,
c_y
:
0
,
...
...
@@ -40,26 +52,29 @@ keyUp : function (e) {
},
ctxDisable
:
function
(
e
)
{
evt
=
e
.
event
||
window
.
event
;
var
evt
=
e
.
event
||
window
.
event
;
/* Stop propagation if inside canvas area */
if
((
evt
.
clientX
>=
Canvas
.
c_x
)
&&
(
evt
.
clientX
<
(
Canvas
.
c_x
+
Canvas
.
c_wx
))
&&
(
evt
.
clientY
>=
Canvas
.
c_y
)
&&
(
evt
.
clientY
<
(
Canvas
.
c_y
+
Canvas
.
c_wy
)))
{
if
((
evt
.
clientX
>=
Canvas
.
c_x
)
&&
(
evt
.
clientY
>=
Canvas
.
c_y
)
&&
(
evt
.
clientX
<
(
Canvas
.
c_x
+
Canvas
.
c_wx
))
&&
(
evt
.
clientY
<
(
Canvas
.
c_y
+
Canvas
.
c_wy
)))
{
e
.
stop
();
return
false
;
}
;
}
},
init
:
function
(
id
,
width
,
height
,
keyDown
,
keyUp
,
mouseDown
,
mouseUp
,
mouseMove
)
{
init
:
function
(
id
,
width
,
height
,
keyDown
,
keyUp
,
mouseDown
,
mouseUp
,
mouseMove
)
{
console
.
log
(
">> Canvas.init"
);
Canvas
.
id
=
id
;
if
(
!
keyDown
)
keyDown
=
Canvas
.
keyDown
;
if
(
!
keyUp
)
keyUp
=
Canvas
.
keyUp
;
if
(
!
mouseDown
)
mouseDown
=
Canvas
.
mouseDown
;
if
(
!
mouseUp
)
mouseUp
=
Canvas
.
mouseUp
;
if
(
!
mouseMove
)
mouseMove
=
Canvas
.
mouseMove
;
if
(
!
keyDown
)
{
keyDown
=
Canvas
.
keyDown
;
}
if
(
!
keyUp
)
{
keyUp
=
Canvas
.
keyUp
;
}
if
(
!
mouseDown
)
{
mouseDown
=
Canvas
.
mouseDown
;
}
if
(
!
mouseUp
)
{
mouseUp
=
Canvas
.
mouseUp
;
}
if
(
!
mouseMove
)
{
mouseMove
=
Canvas
.
mouseMove
;
}
var
c
=
$
(
Canvas
.
id
);
document
.
addEvent
(
'keydown'
,
keyDown
);
...
...
@@ -79,7 +94,7 @@ init: function (id, width, height, keyDown, keyUp, mouseDown, mouseUp, mouseMove
Canvas
.
c_wx
=
c
.
getSize
().
x
;
Canvas
.
c_wy
=
c
.
getSize
().
y
;
if
(
!
c
.
getContext
)
return
;
if
(
!
c
.
getContext
)
{
return
;
}
Canvas
.
ctx
=
c
.
getContext
(
'2d'
);
Canvas
.
prevStyle
=
""
;
...
...
@@ -108,6 +123,7 @@ stop: function () {
},
draw
:
function
()
{
var
img
,
x
,
y
;
/* Border */
Canvas
.
ctx
.
stroke
();
Canvas
.
ctx
.
rect
(
0
,
0
,
Canvas
.
c_wx
,
Canvas
.
c_wy
);
...
...
@@ -121,13 +137,13 @@ draw: function () {
*/
/* Test array image data */
//
var
img = Canvas.ctx.createImageData(50, 50);
var
img
=
Canvas
.
ctx
.
getImageData
(
0
,
0
,
50
,
50
);
//img = Canvas.ctx.createImageData(50, 50);
img
=
Canvas
.
ctx
.
getImageData
(
0
,
0
,
50
,
50
);
for
(
y
=
0
;
y
<
50
;
y
++
)
{
for
(
x
=
0
;
x
<
50
;
x
++
)
{
img
.
data
[(
y
*
50
+
x
)
*
4
+
0
]
=
255
-
parseInt
((
255
/
50
)
*
y
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
1
]
=
parseInt
((
255
/
50
)
*
y
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
2
]
=
parseInt
((
255
/
50
)
*
x
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
0
]
=
255
-
parseInt
((
255
/
50
)
*
y
,
10
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
1
]
=
parseInt
((
255
/
50
)
*
y
,
10
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
2
]
=
parseInt
((
255
/
50
)
*
x
,
10
);
img
.
data
[(
y
*
50
+
x
)
*
4
+
3
]
=
255
;
}
}
...
...
@@ -143,13 +159,15 @@ draw: function () {
* gecko, Javascript array handling is much slower.
*/
getTile
:
function
(
x
,
y
,
width
,
height
,
color
)
{
var
img
=
{
'x'
:
x
,
'y'
:
y
,
'width'
:
width
,
'height'
:
height
,
'data'
:
[]};
var
img
,
p
,
red
,
green
,
blue
,
j
,
i
;
img
=
{
'x'
:
x
,
'y'
:
y
,
'width'
:
width
,
'height'
:
height
,
'data'
:
[]};
if
(
Browser
.
Engine
.
webkit
)
{
var
p
,
red
=
color
[
0
],
green
=
color
[
1
],
blue
=
color
[
2
];
var
width
=
img
.
width
,
height
=
img
.
height
;
for
(
var
j
=
0
;
j
<
height
;
j
++
)
{
for
(
var
i
=
0
;
i
<
width
;
i
++
)
{
red
=
color
[
0
];
green
=
color
[
1
];
blue
=
color
[
2
];
for
(
j
=
0
;
j
<
height
;
j
++
)
{
for
(
i
=
0
;
i
<
width
;
i
++
)
{
p
=
(
i
+
(
j
*
width
)
)
*
4
;
img
.
data
[
p
+
0
]
=
red
;
img
.
data
[
p
+
1
]
=
green
;
...
...
@@ -164,11 +182,14 @@ getTile: function(x, y, width, height, color) {
},
setTile
:
function
(
img
,
x
,
y
,
w
,
h
,
color
)
{
var
p
,
red
,
green
,
blue
,
width
,
j
,
i
;
if
(
Browser
.
Engine
.
webkit
)
{
var
p
,
red
=
color
[
0
],
green
=
color
[
1
],
blue
=
color
[
2
];
var
width
=
img
.
width
;
for
(
var
j
=
0
;
j
<
h
;
j
++
)
{
for
(
var
i
=
0
;
i
<
w
;
i
++
)
{
width
=
img
.
width
;
red
=
color
[
0
];
green
=
color
[
1
];
blue
=
color
[
2
];
for
(
j
=
0
;
j
<
h
;
j
++
)
{
for
(
i
=
0
;
i
<
w
;
i
++
)
{
p
=
(
x
+
i
+
((
y
+
j
)
*
width
)
)
*
4
;
img
.
data
[
p
+
0
]
=
red
;
img
.
data
[
p
+
1
]
=
green
;
...
...
@@ -192,9 +213,10 @@ putTile: function(img) {
rgbxImage
:
function
(
x
,
y
,
width
,
height
,
arr
)
{
var
img
,
i
;
/* Old firefox and Opera don't support createImageData */
var
img
=
Canvas
.
ctx
.
getImageData
(
0
,
0
,
width
,
height
);
for
(
var
i
=
0
;
i
<
(
width
*
height
);
i
++
)
{
img
=
Canvas
.
ctx
.
getImageData
(
0
,
0
,
width
,
height
);
for
(
i
=
0
;
i
<
(
width
*
height
);
i
++
)
{
img
.
data
[
i
*
4
+
0
]
=
arr
[
i
*
4
+
0
];
img
.
data
[
i
*
4
+
1
]
=
arr
[
i
*
4
+
1
];
img
.
data
[
i
*
4
+
2
]
=
arr
[
i
*
4
+
2
];
...
...
@@ -206,9 +228,9 @@ rgbxImage: function(x, y, width, height, arr) {
fillRect
:
function
(
x
,
y
,
width
,
height
,
color
)
{
var
newStyle
=
"rgb("
+
color
[
0
]
+
","
+
color
[
1
]
+
","
+
color
[
2
]
+
")"
;
if
(
newStyle
!=
Canvas
.
prevStyle
)
{
if
(
newStyle
!=
=
Canvas
.
prevStyle
)
{
Canvas
.
ctx
.
fillStyle
=
newStyle
;
prevStyle
=
newStyle
;
Canvas
.
prevStyle
=
newStyle
;
}
Canvas
.
ctx
.
fillRect
(
x
,
y
,
width
,
height
);
},
...
...
@@ -220,8 +242,8 @@ copyImage: function(old_x, old_y, new_x, new_y, width, height) {
/* Translate DOM key event to keysym value */
getKeysym
:
function
(
e
)
{
var
evt
,
keysym
;
evt
=
e
.
event
||
window
.
event
;
var
keysym
;
/* Remap modifier and special keys */
switch
(
evt
.
keyCode
)
{
...
...
@@ -263,8 +285,9 @@ getKeysym: function(e) {
case
187
:
keysym
=
61
;
break
;
// = (IE)
case
188
:
keysym
=
44
;
break
;
// , (Mozilla, IE)
case
109
:
// - (Mozilla)
if
(
Browser
.
Engine
.
gecko
)
keysym
=
45
;
break
;
if
(
Browser
.
Engine
.
gecko
)
{
keysym
=
45
;
}
break
;
case
189
:
keysym
=
45
;
break
;
// - (IE)
case
190
:
keysym
=
46
;
break
;
// . (Mozilla, IE)
case
191
:
keysym
=
47
;
break
;
// / (Mozilla, IE)
...
...
vnc.js
View file @
c4164bda
...
...
@@ -4,38 +4,45 @@
* Licensed under AGPL-3 (see LICENSE.AGPL-3)
*
* See README.md for usage and integration instructions.
*
* This script defines the following globals:
* VNC_scripts, VNC_native_ws, FBU, RFB,
* RQ, RQ_reorder, RQ_seq_num, SQ
*/
"use strict"
;
/*global window, WebSocket, $, Browser, Canvas, Base64, DES */
// Globals defined here
var
VNC_native_ws
,
FBU
,
RFB
,
RQ
,
RQ_reorder
,
RQ_seq_num
,
SQ
;
/*
* Load supporting scripts
*/
VNC_scripts
=
""
;
// Uncomment to activate firebug lite
//VNC_scripts += "<script src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'><\/script>";
VNC_scripts
+=
"<script src='include/mootools.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='include/base64.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='include/des.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='include/util.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='canvas.js'><
\
/script>"
;
/* If no builtin websockets then load web_socket.js */
if
(
window
.
WebSocket
)
{
VNC_native_ws
=
true
;
}
else
{
VNC_native_ws
=
false
;
VNC_scripts
+=
"<script src='include/web-socket-js/swfobject.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='include/web-socket-js/FABridge.js'><
\
/script>"
;
VNC_scripts
+=
"<script src='include/web-socket-js/web_socket.js'><
\
/script>"
;
}
document
.
write
(
VNC_scripts
);
(
function
()
{
var
extra
,
start
,
end
;
extra
=
""
;
start
=
"<script src='"
;
end
=
"'><
\
/script>"
;
// Uncomment to activate firebug lite
//extra += start + "http://getfirebug.com/releases/lite/1.2/" +
// firebug-lite-compressed.js" + end;
extra
+=
start
+
"include/mootools.js"
+
end
;
extra
+=
start
+
"include/base64.js"
+
end
;
extra
+=
start
+
"include/des.js"
+
end
;
extra
+=
start
+
"include/util.js"
+
end
;
extra
+=
start
+
"canvas.js"
+
end
;
/* If no builtin websockets then load web_socket.js */
if
(
window
.
WebSocket
)
{
VNC_native_ws
=
true
;
}
else
{
VNC_native_ws
=
false
;
extra
+=
start
+
"include/web-socket-js/swfobject.js"
+
end
;
extra
+=
start
+
"include/web-socket-js/FABridge.js"
+
end
;
extra
+=
start
+
"include/web-socket-js/web_socket.js"
+
end
;
}
document
.
write
(
extra
);
}());
/*
* Make arrays quack
...
...
@@ -43,19 +50,19 @@ document.write(VNC_scripts);
Array
.
prototype
.
shift8
=
function
()
{
return
this
.
shift
();
}
}
;
Array
.
prototype
.
push8
=
function
(
num
)
{
this
.
push
(
num
&
0xFF
);
}
}
;
Array
.
prototype
.
shift16
=
function
()
{
return
(
this
.
shift
()
<<
8
)
+
(
this
.
shift
()
);
}
}
;
Array
.
prototype
.
push16
=
function
(
num
)
{
this
.
push
((
num
>>
8
)
&
0xFF
,
(
num
)
&
0xFF
);
}
}
;
Array
.
prototype
.
shift32
=
function
()
{
...
...
@@ -63,35 +70,35 @@ Array.prototype.shift32 = function () {
(
this
.
shift
()
<<
16
)
+
(
this
.
shift
()
<<
8
)
+
(
this
.
shift
()
);
}
}
;
Array
.
prototype
.
get32
=
function
(
off
)
{
return
(
this
[
off
]
<<
24
)
+
(
this
[
off
+
1
]
<<
16
)
+
(
this
[
off
+
2
]
<<
8
)
+
(
this
[
off
+
3
]
);
}
}
;
Array
.
prototype
.
push32
=
function
(
num
)
{
this
.
push
((
num
>>
24
)
&
0xFF
,
(
num
>>
16
)
&
0xFF
,
(
num
>>
8
)
&
0xFF
,
(
num
)
&
0xFF
);
}
}
;
Array
.
prototype
.
shiftStr
=
function
(
len
)
{
var
arr
=
this
.
splice
(
0
,
len
);
return
arr
.
map
(
function
(
num
)
{
return
String
.
fromCharCode
(
num
);
}
).
join
(
''
);
}
}
;
Array
.
prototype
.
pushStr
=
function
(
str
)
{
var
n
=
str
.
length
;
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
i
,
n
=
str
.
length
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
this
.
push
(
str
.
charCodeAt
(
i
));
}
}
}
;
Array
.
prototype
.
shiftBytes
=
function
(
len
)
{
return
this
.
splice
(
0
,
len
);
}
}
;
/*
* Frame buffer update state
...
...
@@ -173,64 +180,72 @@ mouse_arr : [],
/* RFB/VNC initialisation */
init_msg
:
function
()
{
console
.
log
(
">> init_msg [RFB.state '"
+
RFB
.
state
+
"']"
);
//console.log("RQ (" + RQ.length + ") " + RQ);
var
verstr
,
strlen
,
reason
,
reason_len
,
server_version
,
types
,
num_types
,
challenge
,
response
,
bpp
,
depth
,
big_endian
,
true_color
,
name_length
;
switch
(
RFB
.
state
)
{
case
'ProtocolVersion'
:
if
(
RQ
.
length
<
12
)
{
RFB
.
updateState
(
'failed'
,
"Disconnected: invalid RFB protocol version received"
);
RFB
.
updateState
(
'failed'
,
"Disconnected: incomplete protocol version"
);
return
;
}
var
server_version
=
RQ
.
shiftStr
(
12
).
substr
(
0
,
11
);
server_version
=
RQ
.
shiftStr
(
12
).
substr
(
0
,
11
);
console
.
log
(
"Server ProtocolVersion: "
+
server_version
);
if
((
server_version
==
"RFB 003.003"
)
||
(
RFB
.
max_version
==
3.3
))
{
if
((
server_version
==
=
"RFB 003.003"
)
||
(
RFB
.
max_version
=
==
3.3
))
{
RFB
.
version
=
3.3
;
v
ar
v
erstr
=
"RFB 003.003"
;
verstr
=
"RFB 003.003"
;
RFB
.
send_string
(
verstr
+
"
\n
"
);
RFB
.
updateState
(
'Security'
,
"Sent ProtocolVersion: "
+
verstr
);
}
else
if
(
server_version
==
"RFB 003.008"
)
{
}
else
if
(
server_version
==
=
"RFB 003.008"
)
{
RFB
.
version
=
3.8
;
v
ar
v
erstr
=
"RFB 003.008"
;
verstr
=
"RFB 003.008"
;
RFB
.
send_string
(
verstr
+
"
\n
"
);
RFB
.
updateState
(
'Security'
,
"Sent ProtocolVersion: "
+
verstr
);
}
else
{
RFB
.
updateState
(
'failed'
,
"Invalid server version "
+
server_version
);
RFB
.
updateState
(
'failed'
,
"Invalid server version "
+
server_version
);
return
;
}
break
;
case
'Security'
:
if
(
RFB
.
version
==
3.8
)
{
var
num_types
=
RQ
.
shift8
();
if
(
num_types
==
0
)
{
var
strlen
=
RQ
.
shift32
();
var
reason
=
RQ
.
shiftStr
(
strlen
);
RFB
.
updateState
(
'failed'
,
"Disconnected: security failure: "
+
reason
);
if
(
RFB
.
version
===
3.8
)
{
num_types
=
RQ
.
shift8
();
if
(
num_types
===
0
)
{
strlen
=
RQ
.
shift32
();
reason
=
RQ
.
shiftStr
(
strlen
);
RFB
.
updateState
(
'failed'
,
"Disconnected: security failure: "
+
reason
);
return
;
}
var
types
=
RQ
.
shiftBytes
(
num_types
);
types
=
RQ
.
shiftBytes
(
num_types
);
if
((
types
[
0
]
!=
1
)
&&
(
types
[
0
]
!=
2
))
{
RFB
.
updateState
(
'failed'
,
"Disconnected: invalid security types list: "
+
types
);
if
((
types
[
0
]
!==
1
)
&&
(
types
[
0
]
!==
2
))
{
RFB
.
updateState
(
'failed'
,
"Disconnected: invalid security types list: "
+
types
);
return
;
}
if
(
RFB
.
password
.
length
==
0
)
{
if
(
RFB
.
password
.
length
==
=
0
)
{
RFB
.
auth_scheme
=
1
;
}
else
{
RFB
.
auth_scheme
=
types
[
0
];
}
RFB
.
send_array
([
RFB
.
auth_scheme
]);
}
else
if
(
RFB
.
version
==
3.3
)
{
}
else
if
(
RFB
.
version
==
=
3.3
)
{
if
(
RQ
.
length
<
4
)
{
RFB
.
updateState
(
'failed'
,
"Invalid security frame"
);
return
;
}
RFB
.
auth_scheme
=
RQ
.
shift32
();
}
RFB
.
updateState
(
'Authentication'
,
"Authenticating using scheme: "
+
RFB
.
auth_scheme
);
RFB
.
updateState
(
'Authentication'
,
"Authenticating using scheme: "
+
RFB
.
auth_scheme
);
// Fall through
case
'Authentication'
:
...
...
@@ -241,9 +256,10 @@ init_msg: function () {
console
.
log
(
" waiting for auth reason bytes"
);
return
;
}
var
strlen
=
RQ
.
shift32
();
var
reason
=
RQ
.
shiftStr
(
strlen
);
RFB
.
updateState
(
'failed'
,
"Disconnected: auth failure: "
+
reason
);
strlen
=
RQ
.
shift32
();
reason
=
RQ
.
shiftStr
(
strlen
);
RFB
.
updateState
(
'failed'
,
"Disconnected: auth failure: "
+
reason
);
return
;
case
1
:
// no authentication
// RFB.send_array([RFB.shared]); // ClientInitialisation
...
...
@@ -254,18 +270,22 @@ init_msg: function () {
console
.
log
(
" waiting for auth challenge bytes"
);
return
;
}
var
challenge
=
RQ
.
shiftBytes
(
16
);
challenge
=
RQ
.
shiftBytes
(
16
);
//console.log("Password: " + RFB.password);
//console.log("Challenge: " + challenge + " (" + challenge.length + ")");
var
response
=
RFB
.
DES
(
RFB
.
password
,
challenge
);
//console.log("Response: " + response + " (" + response.length + ")");
//console.log("Challenge: " + challenge +
// " (" + challenge.length + ")");
response
=
RFB
.
DES
(
RFB
.
password
,
challenge
);
//console.log("Response: " + response +
// " (" + response.length + ")");
console
.
log
(
"Sending DES encrypted auth response"
);
RFB
.
send_array
(
response
);
RFB
.
updateState
(
'SecurityResult'
);
break
;
default
:
RFB
.
updateState
(
'failed'
,
"Disconnected: unsupported auth scheme: "
+
RFB
.
auth_scheme
);
RFB
.
updateState
(
'failed'
,
"Disconnected: unsupported auth scheme: "
+
RFB
.
auth_scheme
);
return
;
}
break
;
...
...
@@ -275,22 +295,22 @@ init_msg: function () {
RFB
.
updateState
(
'failed'
,
"Invalid VNC auth response"
);
return
;
}
var
resp
=
RQ
.
shift32
();
switch
(
resp
)
{
switch
(
RQ
.
shift32
())
{
case
0
:
// OK
RFB
.
updateState
(
'ServerInitialisation'
,
"Authentication OK"
);
break
;
case
1
:
// failed
if
(
RFB
.
version
==
3.8
)
{
var
reason_len
=
RQ
.
shift32
();
var
reason
=
RQ
.
shiftStr
(
reason_len
);
if
(
RFB
.
version
==
=
3.8
)
{
reason_len
=
RQ
.
shift32
();
reason
=
RQ
.
shiftStr
(
reason_len
);
RFB
.
updateState
(
'failed'
,
reason
);
}
else
if
(
RFB
.
version
==
3.3
)
{
}
else
if
(
RFB
.
version
==
=
3.3
)
{
RFB
.
updateState
(
'failed'
,
"Authentication failed"
);
}
return
;
case
2
:
// too-many
RFB
.
updateState
(
'failed'
,
"Disconnected: too many auth attempts"
);
RFB
.
updateState
(
'failed'
,
"Disconnected: too many auth attempts"
);
return
;
}
RFB
.
send_array
([
RFB
.
shared
]);
// ClientInitialisation
...
...
@@ -307,10 +327,10 @@ init_msg: function () {
RFB
.
fb_height
=
RQ
.
shift16
();
/* PIXEL_FORMAT */
var
bpp
=
RQ
.
shift8
();
var
depth
=
RQ
.
shift8
();
var
big_endian
=
RQ
.
shift8
();
var
true_color
=
RQ
.
shift8
();
bpp
=
RQ
.
shift8
();
depth
=
RQ
.
shift8
();
big_endian
=
RQ
.
shift8
();
true_color
=
RQ
.
shift8
();
console
.
log
(
"Screen: "
+
RFB
.
fb_width
+
"x"
+
RFB
.
fb_height
+
", bpp: "
+
bpp
+
", depth: "
+
depth
+
...
...
@@ -319,18 +339,17 @@ init_msg: function () {
/* Connection name/title */
RQ
.
shiftStr
(
12
);
var
name_length
=
RQ
.
shift32
();
name_length
=
RQ
.
shift32
();
RFB
.
fb_name
=
RQ
.
shiftStr
(
name_length
);
Canvas
.
init
(
'VNC_canvas'
,
RFB
.
fb_width
,
RFB
.
fb_height
,
RFB
.
keyDown
,
RFB
.
keyUp
,
RFB
.
mouseDown
,
RFB
.
mouseUp
,
RFB
.
mouseMove
);
var
init
=
[];
init
=
init
.
concat
(
RFB
.
pixelFormat
());
init
=
init
.
concat
(
RFB
.
encodings
());
init
=
init
.
concat
(
RFB
.
fbUpdateRequest
(
0
));
RFB
.
send_array
(
init
);
response
=
RFB
.
pixelFormat
();
response
=
response
.
concat
(
RFB
.
encodings
());
response
=
response
.
concat
(
RFB
.
fbUpdateRequest
(
0
));
RFB
.
send_array
(
response
);
/* Start pushing/polling */
RFB
.
checkEvents
.
delay
(
RFB
.
check_rate
);
...
...
@@ -345,17 +364,18 @@ init_msg: function () {
/* Normal RFB/VNC server messages */
normal_msg
:
function
()
{
//console.log(">> normal_msg");
var
ret
=
true
;
var
ret
=
true
,
msg_type
,
num_colours
,
msg
;
if
(
FBU
.
rects
>
0
)
{
var
msg_type
=
0
;
}
else
if
(
RFB
.
cuttext
!=
'none'
)
{
var
msg_type
=
3
;
msg_type
=
0
;
}
else
if
(
RFB
.
cuttext
!=
=
'none'
)
{
msg_type
=
3
;
}
else
{
var
msg_type
=
RQ
.
shift8
();
msg_type
=
RQ
.
shift8
();
}
switch
(
msg_type
)
{
case
0
:
// FramebufferUpdate
if
(
FBU
.
rects
==
0
)
{
if
(
FBU
.
rects
==
=
0
)
{
if
(
RQ
.
length
<
3
)
{
RQ
.
unshift
(
msg_type
);
console
.
log
(
" waiting for FBU header bytes"
);
...
...
@@ -369,7 +389,7 @@ normal_msg: function () {
}
while
((
FBU
.
rects
>
0
)
&&
(
RQ
.
length
>=
FBU
.
bytes
))
{
if
(
FBU
.
bytes
==
0
)
{
if
(
FBU
.
bytes
==
=
0
)
{
if
(
RQ
.
length
<
12
)
{
console
.
log
(
" waiting for rect header bytes"
);
return
false
;
...
...
@@ -383,14 +403,17 @@ normal_msg: function () {
// Debug:
/*
var msg = "FramebufferUpdate rects:" + FBU.rects + " encoding:" + FBU.encoding
msg = "FramebufferUpdate rects:" + FBU.rects +
" encoding:" + FBU.encoding
switch (FBU.encoding) {
case 0: msg += "(RAW)"; break;
case 1: msg += "(COPY-RECT)"; break;
case 2: msg += "(RRE)"; break;
case 5: msg += "(HEXTILE " + FBU.tiles + " tiles)"; break;
default:
RFB.updateState('failed', "Disconnected: unsupported encoding " + FBU.encoding);
RFB.updateState('failed',
"Disconnected: unsupported encoding " +
FBU.encoding);
return false;
}
msg += ", RQ.length: " + RQ.length
...
...
@@ -398,22 +421,29 @@ normal_msg: function () {
*/
}
RFB
.
timing
.
last_fbu
=
(
new
Date
).
getTime
();
RFB
.
timing
.
last_fbu
=
(
new
Date
()
).
getTime
();
switch
(
FBU
.
encoding
)
{
case
0
:
ret
=
RFB
.
display_raw
();
break
;
// Raw
case
1
:
ret
=
RFB
.
display_copy_rect
();
break
;
// Copy-Rect
case
2
:
ret
=
RFB
.
display_rre
();
break
;
// RRE
case
5
:
ret
=
RFB
.
display_hextile
();
break
;
// hextile
}
RFB
.
timing
.
cur_fbu
+=
((
new
Date
).
getTime
()
-
RFB
.
timing
.
last_fbu
);
if
(
FBU
.
rects
==
0
)
{
if
((
FBU
.
width
===
RFB
.
fb_width
)
&&
(
FBU
.
height
===
RFB
.
fb_height
))
{
RFB
.
timing
.
cur_fbu
+=
((
new
Date
()).
getTime
()
-
RFB
.
timing
.
last_fbu
);
if
(
FBU
.
rects
===
0
)
{
if
((
FBU
.
width
===
RFB
.
fb_width
)
&&
(
FBU
.
height
===
RFB
.
fb_height
))
{
RFB
.
timing
.
full_fbu_total
+=
RFB
.
timing
.
cur_fbu
;
RFB
.
timing
.
full_fbu_cnt
+=
1
;
console
.
log
(
"Timing of full FBU, cur: "
+
RFB
.
timing
.
cur_fbu
+
", total: "
+
RFB
.
timing
.
full_fbu_total
+
", cnt: "
+
RFB
.
timing
.
full_fbu_cnt
+
", avg: "
+
(
RFB
.
timing
.
full_fbu_total
/
RFB
.
timing
.
full_fbu_cnt
));
console
.
log
(
"Timing of full FBU, cur: "
+
RFB
.
timing
.
cur_fbu
+
", total: "
+
RFB
.
timing
.
full_fbu_total
+
", cnt: "
+
RFB
.
timing
.
full_fbu_cnt
+
", avg: "
+
(
RFB
.
timing
.
full_fbu_total
/
RFB
.
timing
.
full_fbu_cnt
));
}
}
if
(
RFB
.
state
!=
"normal"
)
return
true
;
if
(
RFB
.
state
!=
=
"normal"
)
{
return
true
;
}
}
break
;
...
...
@@ -421,7 +451,7 @@ normal_msg: function () {
console
.
log
(
"SetColourMapEntries (unsupported)"
);
RQ
.
shift8
();
// Padding
RQ
.
shift16
();
// First colour
var
num_colours
=
RQ
.
shift16
();
num_colours
=
RQ
.
shift16
();
RQ
.
shiftBytes
(
num_colours
*
6
);
break
;
case
2
:
// Bell
...
...
@@ -430,10 +460,10 @@ normal_msg: function () {
case
3
:
// ServerCutText
console
.
log
(
"ServerCutText"
);
console
.
log
(
"RQ:"
+
RQ
.
slice
(
0
,
20
));
if
(
RFB
.
cuttext
==
'none'
)
{
if
(
RFB
.
cuttext
==
=
'none'
)
{
RFB
.
cuttext
=
'header'
;
}
if
(
RFB
.
cuttext
==
'header'
)
{
if
(
RFB
.
cuttext
==
=
'header'
)
{
if
(
RQ
.
length
<
7
)
{
console
.
log
(
"waiting for ServerCutText header"
);
return
false
;
...
...
@@ -450,7 +480,8 @@ normal_msg: function () {
RFB
.
cuttext
=
'none'
;
break
;
default
:
RFB
.
updateState
(
'failed'
,
"Disconnected: illegal server message type "
+
msg_type
);
RFB
.
updateState
(
'failed'
,
"Disconnected: illegal server message type "
+
msg_type
);
console
.
log
(
"RQ.slice(0,30):"
+
RQ
.
slice
(
0
,
30
));
break
;
}
...
...
@@ -465,16 +496,21 @@ normal_msg: function () {
display_raw
:
function
()
{
//console.log(">> display_raw");
if
(
FBU
.
lines
==
0
)
{
var
cur_y
,
cur_height
;
if
(
FBU
.
lines
===
0
)
{
FBU
.
lines
=
FBU
.
height
;
}
FBU
.
bytes
=
FBU
.
width
*
RFB
.
fb_Bpp
;
// At least a line
if
(
RQ
.
length
<
FBU
.
bytes
)
{
//console.log(" waiting for " + (FBU.bytes - RQ.length) + " RAW bytes");
//console.log(" waiting for " +
// (FBU.bytes - RQ.length) + " RAW bytes");
return
;
}
var
cur_y
=
FBU
.
y
+
(
FBU
.
height
-
FBU
.
lines
);
var
cur_height
=
Math
.
min
(
FBU
.
lines
,
Math
.
floor
(
RQ
.
length
/
(
FBU
.
width
*
RFB
.
fb_Bpp
)));
cur_y
=
FBU
.
y
+
(
FBU
.
height
-
FBU
.
lines
);
cur_height
=
Math
.
min
(
FBU
.
lines
,
Math
.
floor
(
RQ
.
length
/
(
FBU
.
width
*
RFB
.
fb_Bpp
)));
Canvas
.
rgbxImage
(
FBU
.
x
,
cur_y
,
FBU
.
width
,
cur_height
,
RQ
);
RQ
.
shiftBytes
(
FBU
.
width
*
cur_height
*
RFB
.
fb_Bpp
);
FBU
.
lines
-=
cur_height
;
...
...
@@ -489,12 +525,16 @@ display_raw: function () {
display_copy_rect
:
function
()
{
//console.log(">> display_copy_rect");
var
old_x
,
old_y
;
if
(
RQ
.
length
<
4
)
{
//console.log(" waiting for " + (FBU.bytes - RQ.length) + " COPY-RECT bytes");
//console.log(" waiting for " +
// (FBU.bytes - RQ.length) + " COPY-RECT bytes");
return
;
}
var
old_x
=
RQ
.
shift16
();
var
old_y
=
RQ
.
shift16
();
old_x
=
RQ
.
shift16
();
old_y
=
RQ
.
shift16
();
Canvas
.
copyImage
(
old_x
,
old_y
,
FBU
.
x
,
FBU
.
y
,
FBU
.
width
,
FBU
.
height
);
FBU
.
rects
--
;
FBU
.
bytes
=
0
;
...
...
@@ -502,29 +542,31 @@ display_copy_rect: function () {
display_rre
:
function
()
{
//console.log(">> display_rre (" + RQ.length + " bytes)");
if
(
FBU
.
subrects
==
0
)
{
;
var
color
,
x
,
y
,
width
,
height
,
chunk
;
if
(
FBU
.
subrects
===
0
)
{
if
(
RQ
.
length
<
4
+
RFB
.
fb_Bpp
)
{
//console.log(" waiting for " + (4 + RFB.fb_Bpp - RQ.length) + " RRE bytes");
//console.log(" waiting for " +
// (4 + RFB.fb_Bpp - RQ.length) + " RRE bytes");
return
;
}
FBU
.
subrects
=
RQ
.
shift32
();
var
color
=
RQ
.
shiftBytes
(
RFB
.
fb_Bpp
);
// Background
color
=
RQ
.
shiftBytes
(
RFB
.
fb_Bpp
);
// Background
Canvas
.
fillRect
(
FBU
.
x
,
FBU
.
y
,
FBU
.
width
,
FBU
.
height
,
color
);
}
while
((
FBU
.
subrects
>
0
)
&&
(
RQ
.
length
>=
(
RFB
.
fb_Bpp
+
8
)))
{
var
color
=
RQ
.
shiftBytes
(
RFB
.
fb_Bpp
);
var
x
=
RQ
.
shift16
();
var
y
=
RQ
.
shift16
();
var
width
=
RQ
.
shift16
();
var
height
=
RQ
.
shift16
();
color
=
RQ
.
shiftBytes
(
RFB
.
fb_Bpp
);
x
=
RQ
.
shift16
();
y
=
RQ
.
shift16
();
width
=
RQ
.
shift16
();
height
=
RQ
.
shift16
();
Canvas
.
fillRect
(
FBU
.
x
+
x
,
FBU
.
y
+
y
,
width
,
height
,
color
);
FBU
.
subrects
--
;
}
//console.log(" display_rre: rects: " + FBU.rects + ", FBU.subrects: " + FBU.subrects);
//console.log(" display_rre: rects: " + FBU.rects +
// ", FBU.subrects: " + FBU.subrects);
if
(
FBU
.
subrects
>
0
)
{
var
chunk
=
Math
.
min
(
RFB
.
rre_chunk
,
FBU
.
subrects
);
chunk
=
Math
.
min
(
RFB
.
rre_chunk
,
FBU
.
subrects
);
FBU
.
bytes
=
(
RFB
.
fb_Bpp
+
8
)
*
chunk
;
}
else
{
FBU
.
rects
--
;
...
...
@@ -535,9 +577,10 @@ display_rre: function () {
display_hextile
:
function
()
{
//console.log(">> display_hextile");
var
subencoding
,
subrects
,
cur_tile
,
tile_x
,
x
,
w
,
tile_y
,
y
,
h
;
var
subencoding
,
subrects
,
cur_tile
,
tile_x
,
x
,
w
,
tile_y
,
y
,
h
,
idx
,
tile
,
xy
,
s
,
sx
,
sy
,
wh
,
sw
,
sh
,
color
;
if
(
FBU
.
tiles
==
0
)
{
if
(
FBU
.
tiles
==
=
0
)
{
FBU
.
tiles_x
=
Math
.
ceil
(
FBU
.
width
/
16
);
FBU
.
tiles_y
=
Math
.
ceil
(
FBU
.
height
/
16
);
FBU
.
total_tiles
=
FBU
.
tiles_x
*
FBU
.
tiles_y
;
...
...
@@ -553,7 +596,8 @@ display_hextile: function() {
}
subencoding
=
RQ
[
0
];
// Peek
if
(
subencoding
>
30
)
{
// Raw
RFB
.
updateState
(
'failed'
,
"Disconnected: illegal hextile subencoding "
+
subencoding
);
RFB
.
updateState
(
'failed'
,
"Disconnected: illegal hextile subencoding "
+
subencoding
);
console
.
log
(
"RQ.slice(0,30):"
+
RQ
.
slice
(
0
,
30
));
return
;
}
...
...
@@ -563,8 +607,8 @@ display_hextile: function() {
tile_y
=
Math
.
floor
(
cur_tile
/
FBU
.
tiles_x
);
x
=
FBU
.
x
+
tile_x
*
16
;
y
=
FBU
.
y
+
tile_y
*
16
;
w
=
Math
.
min
(
16
,
(
FBU
.
x
+
FBU
.
width
)
-
x
)
h
=
Math
.
min
(
16
,
(
FBU
.
y
+
FBU
.
height
)
-
y
)
w
=
Math
.
min
(
16
,
(
FBU
.
x
+
FBU
.
width
)
-
x
)
;
h
=
Math
.
min
(
16
,
(
FBU
.
y
+
FBU
.
height
)
-
y
)
;
/* Figure out how much we are expecting */
if
(
subencoding
&
0x01
)
{
// Raw
...
...
@@ -593,16 +637,24 @@ display_hextile: function() {
}
}
//console.log(" tile:" + cur_tile + "/" + (FBU.total_tiles - 1) + ", subencoding:" + subencoding + "(last: " + FBU.lastsubencoding + "), subrects:" + subrects + ", tile:" + tile_x + "," + tile_y + " [" + x + "," + y + "]@" + w + "x" + h + ", d.length:" + RQ.length + ", bytes:" + FBU.bytes + " last:" + RQ.slice(FBU.bytes-10, FBU.bytes) + " next:" + RQ.slice(FBU.bytes-1, FBU.bytes+10));
//console.log(" tile:" + cur_tile + "/" + (FBU.total_tiles - 1) +
// ", subencoding:" + subencoding +
// "(last: " + FBU.lastsubencoding + "), subrects:" +
// subrects + ", tile:" + tile_x + "," + tile_y +
// " [" + x + "," + y + "]@" + w + "x" + h +
// ", d.length:" + RQ.length + ", bytes:" + FBU.bytes +
// " last:" + RQ.slice(FBU.bytes-10, FBU.bytes) +
// " next:" + RQ.slice(FBU.bytes-1, FBU.bytes+10));
if
(
RQ
.
length
<
FBU
.
bytes
)
{
//console.log(" waiting for " + (FBU.bytes - RQ.length) + " hextile bytes");
//console.log(" waiting for " +
// (FBU.bytes - RQ.length) + " hextile bytes");
return
;
}
/* We know the encoding and have a whole tile */
FBU
.
subencoding
=
RQ
.
shift8
();
FBU
.
bytes
--
;
if
(
FBU
.
subencoding
==
0
)
{
if
(
FBU
.
subencoding
==
=
0
)
{
if
(
FBU
.
lastsubencoding
&
0x01
)
{
/* Weird: ignore blanks after RAW */
console
.
log
(
" Ignoring blank after RAW"
);
...
...
@@ -612,7 +664,7 @@ display_hextile: function() {
}
else
if
(
FBU
.
subencoding
&
0x01
)
{
// Raw
Canvas
.
rgbxImage
(
x
,
y
,
w
,
h
,
RQ
);
}
else
{
var
idx
=
0
;
idx
=
0
;
if
(
FBU
.
subencoding
&
0x02
)
{
// Background
FBU
.
background
=
RQ
.
slice
(
idx
,
idx
+
RFB
.
fb_Bpp
);
idx
+=
RFB
.
fb_Bpp
;
...
...
@@ -622,12 +674,11 @@ display_hextile: function() {
idx
+=
RFB
.
fb_Bpp
;
}
var
tile
=
Canvas
.
getTile
(
x
,
y
,
w
,
h
,
FBU
.
background
);
tile
=
Canvas
.
getTile
(
x
,
y
,
w
,
h
,
FBU
.
background
);
if
(
FBU
.
subencoding
&
0x08
)
{
// AnySubrects
subrects
=
RQ
[
idx
];
idx
++
;
var
xy
,
sx
,
sy
,
wh
,
sw
,
sh
;
for
(
var
s
=
0
;
s
<
subrects
;
s
++
)
{
for
(
s
=
0
;
s
<
subrects
;
s
++
)
{
if
(
FBU
.
subencoding
&
0x10
)
{
// SubrectsColoured
color
=
RQ
.
slice
(
idx
,
idx
+
RFB
.
fb_Bpp
);
idx
+=
RFB
.
fb_Bpp
;
...
...
@@ -655,7 +706,7 @@ display_hextile: function() {
FBU
.
tiles
--
;
}
if
(
FBU
.
tiles
==
0
)
{
if
(
FBU
.
tiles
==
=
0
)
{
FBU
.
rects
--
;
}
...
...
@@ -717,10 +768,10 @@ encodings: function () {
fbUpdateRequest
:
function
(
incremental
,
x
,
y
,
xw
,
yw
)
{
//console.log(">> fbUpdateRequest");
if
(
!
x
)
x
=
0
;
if
(
!
y
)
y
=
0
;
if
(
!
xw
)
xw
=
RFB
.
fb_width
;
if
(
!
yw
)
yw
=
RFB
.
fb_height
;
if
(
!
x
)
{
x
=
0
;
}
if
(
!
y
)
{
y
=
0
;
}
if
(
!
xw
)
{
xw
=
RFB
.
fb_width
;
}
if
(
!
yw
)
{
yw
=
RFB
.
fb_height
;
}
var
arr
;
arr
=
[
3
];
// msg-type
arr
.
push8
(
incremental
);
...
...
@@ -744,7 +795,8 @@ keyEvent: function (keysym, down) {
},
pointerEvent
:
function
(
x
,
y
)
{
//console.log(">> pointerEvent, x,y: " + x + "," + y + " , mask: " + RFB.mouse_buttonMask);
//console.log(">> pointerEvent, x,y: " + x + "," + y +
// " , mask: " + RFB.mouse_buttonMask);
var
arr
;
arr
=
[
5
];
// msg-type
arr
.
push8
(
RFB
.
mouse_buttonMask
);
...
...
@@ -783,12 +835,12 @@ recv_message: function(e) {
RFB
.
handle_message
();
}
}
catch
(
e
)
{
console
.
log
(
"recv_message, caught exception: "
+
e
);
if
(
typeof
e
.
name
!==
'undefined'
)
{
RFB
.
updateState
(
'failed'
,
e
.
name
+
": "
+
e
.
message
);
}
catch
(
e
xc
)
{
console
.
log
(
"recv_message, caught exception: "
+
e
xc
);
if
(
typeof
e
xc
.
name
!==
'undefined'
)
{
RFB
.
updateState
(
'failed'
,
e
xc
.
name
+
": "
+
exc
.
message
);
}
else
{
RFB
.
updateState
(
'failed'
,
e
);
RFB
.
updateState
(
'failed'
,
e
xc
);
}
}
//console.log("<< recv_message");
...
...
@@ -797,27 +849,32 @@ recv_message: function(e) {
recv_message_reorder
:
function
(
e
)
{
//console.log(">> recv_message_reorder");
var
offset
=
e
.
data
.
indexOf
(
":"
)
+
1
;
var
seq_num
=
parseInt
(
e
.
data
.
substr
(
0
,
offset
-
1
));
if
(
RQ_seq_num
==
seq_num
)
{
var
offset
,
seq_num
,
i
;
offset
=
e
.
data
.
indexOf
(
":"
)
+
1
;
seq_num
=
parseInt
(
e
.
data
.
substr
(
0
,
offset
-
1
),
10
);
if
(
RQ_seq_num
===
seq_num
)
{
RQ
=
RQ
.
concat
(
Base64
.
decode
(
e
.
data
,
offset
));
RQ_seq_num
++
;
}
else
{
console
.
warn
(
"sequence number mismatch: expected "
+
RQ_seq_num
+
", got "
+
seq_num
);
console
.
warn
(
"sequence number mismatch: expected "
+
RQ_seq_num
+
", got "
+
seq_num
);
if
(
RQ_reorder
.
length
>
20
)
{
RFB
.
updateState
(
'failed'
,
"Re-order queue too long"
);
}
else
{
RQ_reorder
=
RQ_reorder
.
concat
(
e
.
data
.
substr
(
0
));
var
i
=
0
;
i
=
0
;
while
(
i
<
RQ_reorder
.
length
)
{
var
offset
=
RQ_reorder
[
i
].
indexOf
(
":"
)
+
1
;
var
seq_num
=
parseInt
(
RQ_reorder
[
i
].
substr
(
0
,
offset
-
1
));
//console.log("Searching reorder list item " + i + ", seq_num " + seq_num);
if
(
seq_num
==
RQ_seq_num
)
{
offset
=
RQ_reorder
[
i
].
indexOf
(
":"
)
+
1
;
seq_num
=
parseInt
(
RQ_reorder
[
i
].
substr
(
0
,
offset
-
1
),
10
);
//console.log("Searching reorder list item " +
// i + ", seq_num " + seq_num);
if
(
seq_num
===
RQ_seq_num
)
{
/* Remove it from reorder queue, decode it and
* add it to the receive queue */
console
.
log
(
"Found re-ordered packet seq_num "
+
seq_num
);
RQ
=
RQ
.
concat
(
Base64
.
decode
(
RQ_reorder
.
splice
(
i
,
1
)[
0
],
offset
));
RQ
=
RQ
.
concat
(
Base64
.
decode
(
RQ_reorder
.
splice
(
i
,
1
)[
0
],
offset
));
RQ_seq_num
++
;
i
=
0
;
// Start search again for next one
}
else
{
...
...
@@ -845,7 +902,7 @@ handle_message: function () {
RFB
.
normal_msg
();
/*
while (RQ.length > 0) {
if (RFB.normal_msg() && RFB.state == 'normal') {
if (RFB.normal_msg() && RFB.state ==
=
'normal') {
console.log("More to process");
} else {
break;
...
...
@@ -862,25 +919,26 @@ handle_message: function () {
send_string
:
function
(
str
)
{
//console.log(">> send_string: " + str);
RFB
.
send_array
(
str
.
split
(
''
).
map
(
function
(
chr
)
{
return
chr
.
charCodeAt
(
0
)
}
)
);
function
(
chr
)
{
return
chr
.
charCodeAt
(
0
)
;
}
)
);
},
send_array
:
function
(
arr
)
{
//console.log(">> send_array: " + arr);
//console.log(">> send_array: " + Base64.encode(arr));
SQ
=
SQ
+
Base64
.
encode
(
arr
);
if
(
RFB
.
ws
.
bufferedAmount
==
0
)
{
if
(
RFB
.
ws
.
bufferedAmount
==
=
0
)
{
RFB
.
ws
.
send
(
SQ
);
SQ
=
""
SQ
=
""
;
}
else
{
console
.
log
(
"Delaying send"
);
}
},
DES
:
function
(
password
,
challenge
)
{
var
passwd
=
[];
var
response
=
challenge
.
slice
();
for
(
var
i
=
0
;
i
<
password
.
length
;
i
++
)
{
var
i
,
passwd
,
response
;
passwd
=
[];
response
=
challenge
.
slice
();
for
(
i
=
0
;
i
<
password
.
length
;
i
++
)
{
passwd
.
push
(
password
.
charCodeAt
(
i
));
}
...
...
@@ -891,10 +949,9 @@ DES: function (password, challenge) {
},
flushClient
:
function
()
{
var
arr
=
[];
if
(
RFB
.
mouse_arr
.
length
>
0
)
{
//RFB.send_array(RFB.mouse_arr.concat(RFB.fbUpdateRequest(1)));
RFB
.
send_array
(
RFB
.
mouse_arr
)
RFB
.
send_array
(
RFB
.
mouse_arr
)
;
setTimeout
(
function
()
{
RFB
.
send_array
(
RFB
.
fbUpdateRequest
(
1
));
},
50
);
...
...
@@ -907,9 +964,10 @@ flushClient: function () {
},
checkEvents
:
function
()
{
if
(
RFB
.
state
==
'normal'
)
{
var
now
;
if
(
RFB
.
state
===
'normal'
)
{
if
(
!
RFB
.
flushClient
())
{
var
now
=
new
Date
().
getTime
();
now
=
new
Date
().
getTime
();
if
(
now
>
RFB
.
last_req
+
RFB
.
req_rate
)
{
RFB
.
last_req
=
now
;
RFB
.
send_array
(
RFB
.
fbUpdateRequest
(
1
));
...
...
@@ -919,32 +977,34 @@ checkEvents: function () {
RFB
.
checkEvents
.
delay
(
RFB
.
check_rate
);
},
_keyX
:
function
(
e
,
down
)
{
keyX
:
function
(
e
,
down
)
{
var
arr
;
if
(
RFB
.
clipboardFocus
)
{
return
true
;
}
e
.
stop
();
var
arr
=
RFB
.
keyEvent
(
Canvas
.
getKeysym
(
e
),
down
);
arr
=
RFB
.
keyEvent
(
Canvas
.
getKeysym
(
e
),
down
);
arr
=
arr
.
concat
(
RFB
.
fbUpdateRequest
(
1
));
RFB
.
send_array
(
arr
);
},
keyDown
:
function
(
e
)
{
//console.log(">> keyDown: " + Canvas.getKeysym(e));
RFB
.
_
keyX
(
e
,
1
);
RFB
.
keyX
(
e
,
1
);
},
keyUp
:
function
(
e
)
{
//console.log(">> keyUp: " + Canvas.getKeysym(e));
RFB
.
_
keyX
(
e
,
0
);
RFB
.
keyX
(
e
,
0
);
},
mouseDown
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
var
x
,
y
;
var
evt
,
x
,
y
;
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
c_x
);
y
=
(
evt
.
clientY
-
Canvas
.
c_y
);
//console.log('>> mouseDown ' + evt.which + '/' + evt.button + " " + x + "," + y);
//console.log(">> mouseDown " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB
.
mouse_buttonMask
|=
1
<<
evt
.
button
;
RFB
.
mouse_arr
=
RFB
.
mouse_arr
.
concat
(
RFB
.
pointerEvent
(
x
,
y
)
);
...
...
@@ -952,11 +1012,12 @@ mouseDown: function(e) {
},
mouseUp
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
var
x
,
y
;
var
evt
,
x
,
y
;
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
c_x
);
y
=
(
evt
.
clientY
-
Canvas
.
c_y
);
//console.log('>> mouseUp ' + evt.which + '/' + evt.button + " " + x + "," + y);
//console.log(">> mouseUp " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB
.
mouse_buttonMask
^=
1
<<
evt
.
button
;
RFB
.
mouse_arr
=
RFB
.
mouse_arr
.
concat
(
RFB
.
pointerEvent
(
x
,
y
)
);
...
...
@@ -964,8 +1025,8 @@ mouseUp: function(e) {
},
mouseMove
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
var
x
,
y
;
var
evt
,
x
,
y
;
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
c_x
);
y
=
(
evt
.
clientY
-
Canvas
.
c_y
);
//console.log('>> mouseMove ' + x + "," + y);
...
...
@@ -979,8 +1040,9 @@ clipboardCopyTo: function (text) {
},
clipboardPasteFrom
:
function
()
{
if
(
RFB
.
state
!=
"normal"
)
return
;
var
text
=
RFB
.
clipboard
.
value
;
var
text
;
if
(
RFB
.
state
!==
"normal"
)
{
return
;
}
text
=
RFB
.
clipboard
.
value
;
console
.
log
(
">> clipboardPasteFrom: "
+
text
.
substr
(
0
,
40
)
+
"..."
);
RFB
.
send_array
(
RFB
.
clientCutText
(
text
));
console
.
log
(
"<< clipboardPasteFrom"
);
...
...
@@ -992,13 +1054,13 @@ clipboardClear: function () {
},
updateState
:
function
(
state
,
statusMsg
)
{
var
s
=
RFB
.
statusLine
;
var
c
=
RFB
.
connectBtn
;
var
func
=
function
(
msg
)
{
console
.
log
(
msg
)
}
;
var
color
;
var
s
,
c
,
func
,
color
,
cmsg
;
s
=
RFB
.
statusLine
;
c
=
RFB
.
connectBtn
;
func
=
function
(
msg
)
{
console
.
log
(
msg
);
}
;
switch
(
state
)
{
case
'failed'
:
func
=
function
(
msg
)
{
console
.
error
(
msg
)
};
func
=
function
(
msg
)
{
console
.
error
(
msg
)
;
};
c
.
disabled
=
true
;
color
=
"#880000"
;
break
;
...
...
@@ -1010,13 +1072,13 @@ updateState: function(state, statusMsg) {
break
;
case
'disconnected'
:
c
.
value
=
"Connect"
;
c
.
onclick
=
function
()
{
RFB
.
connect
();
}
,
c
.
onclick
=
function
()
{
RFB
.
connect
();
}
;
c
.
disabled
=
false
;
color
=
"#000000"
;
break
;
default
:
func
=
function
(
msg
)
{
console
.
warn
(
msg
)
};
func
=
function
(
msg
)
{
console
.
warn
(
msg
)
;
};
c
.
disabled
=
true
;
color
=
"#444400"
;
break
;
...
...
@@ -1030,9 +1092,9 @@ updateState: function(state, statusMsg) {
RFB
.
state
=
state
;
s
.
style
.
color
=
color
;
var
cmsg
=
typeof
(
statusMsg
)
!
=
'undefined'
?
(
" Msg: "
+
statusMsg
)
:
""
;
cmsg
=
typeof
(
statusMsg
)
!=
=
'undefined'
?
(
" Msg: "
+
statusMsg
)
:
""
;
func
(
"New state '"
+
state
+
"'."
+
cmsg
);
if
(
typeof
(
statusMsg
)
!=
'undefined'
)
{
if
(
typeof
(
statusMsg
)
!=
=
'undefined'
)
{
s
.
innerHTML
=
statusMsg
;
}
},
...
...
@@ -1042,8 +1104,8 @@ updateState: function(state, statusMsg) {
*/
init_ws
:
function
()
{
console
.
log
(
">> init_ws"
);
var
uri
=
""
;
if
(
RFB
.
encrypt
)
{
uri
=
"wss://"
;
...
...
@@ -1066,7 +1128,7 @@ init_ws: function () {
* Send updates either at a rate of one update every 50ms,
* or whatever slower rate the network can handle
*/
if
(
RFB
.
ws
.
bufferedAmount
==
0
)
{
if
(
RFB
.
ws
.
bufferedAmount
==
=
0
)
{
if
(
SQ
)
{
RFB
.
ws
.
send
(
SQ
);
SQ
=
""
;
...
...
@@ -1102,8 +1164,8 @@ init_vars: function () {
SQ
=
""
;
FBU
.
rects
=
0
;
FBU
.
subrects
=
0
;
// RRE and HEXTILE
FBU
.
lines
=
0
,
// RAW
FBU
.
tiles
=
0
,
// HEXTILE
FBU
.
lines
=
0
;
// RAW
FBU
.
tiles
=
0
;
// HEXTILE
RFB
.
mouse_buttonmask
=
0
;
RFB
.
mouse_arr
=
[];
},
...
...
@@ -1112,10 +1174,14 @@ init_vars: function () {
connect
:
function
(
host
,
port
,
password
,
encrypt
)
{
console
.
log
(
">> connect"
);
RFB
.
host
=
(
host
!==
undefined
)
?
host
:
$
(
'VNC_host'
).
value
;
RFB
.
port
=
(
port
!==
undefined
)
?
port
:
$
(
'VNC_port'
).
value
;
RFB
.
password
=
(
password
!==
undefined
)
?
password
:
$
(
'VNC_password'
).
value
;
RFB
.
encrypt
=
(
encrypt
!==
undefined
)
?
encrypt
:
$
(
'VNC_encrypt'
).
checked
;
RFB
.
host
=
(
host
!==
undefined
)
?
host
:
$
(
'VNC_host'
).
value
;
RFB
.
port
=
(
port
!==
undefined
)
?
port
:
$
(
'VNC_port'
).
value
;
RFB
.
password
=
(
password
!==
undefined
)
?
password
:
$
(
'VNC_password'
).
value
;
RFB
.
encrypt
=
(
encrypt
!==
undefined
)
?
encrypt
:
$
(
'VNC_encrypt'
).
checked
;
if
((
!
RFB
.
host
)
||
(
!
RFB
.
port
))
{
alert
(
"Must set host and port"
);
return
;
...
...
@@ -1123,7 +1189,7 @@ connect: function (host, port, password, encrypt) {
RFB
.
init_vars
();
if
((
RFB
.
ws
)
&&
(
RFB
.
ws
.
readyState
==
WebSocket
.
OPEN
))
{
if
((
RFB
.
ws
)
&&
(
RFB
.
ws
.
readyState
==
=
WebSocket
.
OPEN
))
{
RFB
.
ws
.
close
();
}
RFB
.
init_ws
();
...
...
@@ -1135,9 +1201,9 @@ connect: function (host, port, password, encrypt) {
disconnect
:
function
()
{
console
.
log
(
">> disconnect"
);
if
((
RFB
.
ws
)
&&
(
RFB
.
ws
.
readyState
==
WebSocket
.
OPEN
))
{
if
((
RFB
.
ws
)
&&
(
RFB
.
ws
.
readyState
==
=
WebSocket
.
OPEN
))
{
RFB
.
updateState
(
'closed'
);
RFB
.
ws
.
onmessage
=
function
(
e
)
{
return
;
}
RFB
.
ws
.
onmessage
=
function
(
e
)
{
return
;
}
;
RFB
.
ws
.
close
();
}
if
(
Canvas
.
ctx
)
{
...
...
@@ -1156,20 +1222,23 @@ disconnect: function () {
*/
load
:
function
(
target
)
{
//console.log(">> load");
var
html
,
url
;
if
(
!
target
)
{
target
=
'vnc'
};
if
(
!
target
)
{
target
=
'vnc'
;
}
/* Populate the 'vnc' div */
var
html
=
""
;
html
=
""
;
if
(
$
(
'VNC_controls'
)
===
null
)
{
html
+=
'<div id="VNC_controls">'
;
html
+=
' <ul>'
;
html
+=
' <li>Host: <input id="VNC_host"></li>'
;
html
+=
' <li>Port: <input id="VNC_port"></li>'
;
html
+=
' <li>Password: <input id="VNC_password" type="password"></li>'
;
html
+=
' <li>Encrypt: <input id="VNC_encrypt" type="checkbox"></li>'
;
html
+=
' <li>Password: <input id="VNC_password"'
;
html
+=
' type="password"></li>'
;
html
+=
' <li>Encrypt: <input id="VNC_encrypt"'
;
html
+=
' type="checkbox"></li>'
;
html
+=
' <li><input id="VNC_connect_button" type="button"'
;
html
+=
'
value="Loading" disabled></li>'
;
html
+=
' value="Loading" disabled></li>'
;
html
+=
' </ul>'
;
html
+=
'</div>'
;
}
...
...
@@ -1181,7 +1250,8 @@ load: function (target) {
html
+=
'<br><br>'
;
html
+=
'<div id="VNC_clipboard">'
;
html
+=
' VNC Clipboard:'
;
html
+=
' <input id="VNC_clipboard_clear_button" type="button" value="Clear">'
;
html
+=
' <input id="VNC_clipboard_clear_button"'
;
html
+=
' type="button" value="Clear">'
;
html
+=
' <br>'
;
html
+=
' <textarea id="VNC_clipboard_text" cols=80 rows=5>'
;
html
+=
' </textarea>'
;
...
...
@@ -1220,8 +1290,9 @@ load: function (target) {
if
((
!
Browser
.
Plugins
.
Flash
)
||
(
Browser
.
Plugins
.
Flash
.
version
<
9
))
{
RFB
.
updateState
(
'failed'
,
"WebSockets or Adobe Flash is required"
);
}
else
if
(
location
.
href
.
substr
(
0
,
7
)
==
"file://"
)
{
RFB
.
updateState
(
'failed'
,
"'file://' URL is incompatible with Adobe Flash"
);
}
else
if
(
location
.
href
.
substr
(
0
,
7
)
===
"file://"
)
{
RFB
.
updateState
(
'failed'
,
"'file://' URL is incompatible with Adobe Flash"
);
}
else
{
WebSocket
.
__swfLocation
=
"include/web-socket-js/WebSocketMain.swf"
;
RFB
.
use_seq
=
true
;
...
...
@@ -1230,15 +1301,19 @@ load: function (target) {
}
/* Populate the controls if defaults are provided in the URL */
if
(
RFB
.
state
==
'disconnected'
)
{
var
url
=
document
.
location
.
href
;
$
(
'VNC_host'
).
value
=
(
url
.
match
(
/host=
([^
&#
]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_port'
).
value
=
(
url
.
match
(
/port=
([^
&#
]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_password'
).
value
=
(
url
.
match
(
/password=
([^
&#
]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_encrypt'
).
checked
=
(
url
.
match
(
/encrypt=
([^
&#
]
*
)
/
)
||
[
''
,
''
])[
1
];
if
(
RFB
.
state
===
'disconnected'
)
{
url
=
document
.
location
.
href
;
$
(
'VNC_host'
).
value
=
(
url
.
match
(
/host=
([
A-Za-z0-9.
\-]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_port'
).
value
=
(
url
.
match
(
/port=
([
0-9
]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_password'
).
value
=
(
url
.
match
(
/password=
([^
&#
]
*
)
/
)
||
[
''
,
''
])[
1
];
$
(
'VNC_encrypt'
).
checked
=
(
url
.
match
(
/encrypt=
([
A-Za-z0-9
]
*
)
/
)
||
[
''
,
''
])[
1
];
}
//console.log("<< load");
}
,
}
};
/* End of RFB */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment