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
56ec48be
Commit
56ec48be
authored
May 15, 2010
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move vars into RFB namespace. Extend array in util.js.
parent
c4164bda
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
151 deletions
+157
-151
util.js
include/util.js
+58
-0
vnc.js
vnc.js
+99
-151
No files found.
include/util.js
View file @
56ec48be
...
@@ -27,3 +27,61 @@ function dirObj(obj, depth, parent) {
...
@@ -27,3 +27,61 @@ function dirObj(obj, depth, parent) {
}
}
return
msg
;
return
msg
;
}
}
/*
* Make arrays quack
*/
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
()
{
return
(
this
.
shift
()
<<
24
)
+
(
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
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
);
};
vnc.js
View file @
56ec48be
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
/*global window, WebSocket, $, Browser, Canvas, Base64, DES */
/*global window, WebSocket, $, Browser, Canvas, Base64, DES */
// Globals defined here
// Globals defined here
var
VNC_native_ws
,
FBU
,
RFB
,
RQ
,
RQ_reorder
,
RQ_seq_num
,
SQ
;
var
VNC_native_ws
,
RFB
;
/*
/*
...
@@ -45,65 +45,23 @@ var VNC_native_ws, FBU, RFB, RQ, RQ_reorder, RQ_seq_num, SQ;
...
@@ -45,65 +45,23 @@ var VNC_native_ws, FBU, RFB, RQ, RQ_reorder, RQ_seq_num, SQ;
}());
}());
/*
/*
*
Make arrays quack
*
RFB namespace
*/
*/
Array
.
prototype
.
shift8
=
function
()
{
RFB
=
{
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
()
{
return
(
this
.
shift
()
<<
24
)
+
(
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
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
);
};
/*
ws
:
null
,
// Web Socket object
* Frame buffer update state
sendID
:
null
,
*/
use_seq
:
false
,
FBU
=
{
// Receive and send queues
RQ
:
[],
// Receive Queue
RQ_reorder
:
[],
// Receive Queue re-order list
RQ_seq_num
:
0
,
// Expected sequence number
SQ
:
""
,
// Send Queue
// Frame buffer update state
FBU
:
{
rects
:
0
,
rects
:
0
,
subrects
:
0
,
// RRE and HEXTILE
subrects
:
0
,
// RRE and HEXTILE
lines
:
0
,
// RAW
lines
:
0
,
// RAW
...
@@ -115,22 +73,8 @@ FBU = {
...
@@ -115,22 +73,8 @@ FBU = {
height
:
0
,
height
:
0
,
encoding
:
0
,
encoding
:
0
,
subencoding
:
-
1
,
subencoding
:
-
1
,
background
:
null
};
background
:
null
},
/*
* RFB namespace
*/
RQ
=
[];
// Receive Queue
RQ_reorder
=
[];
// Receive Queue re-order list
RQ_seq_num
=
0
;
// Expected sequence number
SQ
=
""
;
// Send Queue
RFB
=
{
ws
:
null
,
// Web Socket object
sendID
:
null
,
use_seq
:
false
,
// DOM objects
// DOM objects
statusLine
:
null
,
statusLine
:
null
,
...
@@ -180,12 +124,12 @@ mouse_arr : [],
...
@@ -180,12 +124,12 @@ mouse_arr : [],
/* RFB/VNC initialisation */
/* RFB/VNC initialisation */
init_msg
:
function
()
{
init_msg
:
function
()
{
console
.
log
(
">> init_msg [RFB.state '"
+
RFB
.
state
+
"']"
);
console
.
log
(
">> init_msg [RFB.state '"
+
RFB
.
state
+
"']"
);
//console.log("RQ (" + RQ.length + ") " + RQ);
var
verstr
,
strlen
,
reason
,
reason_len
,
server_versio
n
,
var
RQ
=
RFB
.
RQ
,
verstr
,
strlen
,
reason
,
reason_le
n
,
types
,
num_types
,
challenge
,
response
,
server_version
,
types
,
num_types
,
challenge
,
response
,
bpp
,
depth
,
big_endian
,
true_color
,
name_length
;
bpp
,
depth
,
big_endian
,
true_color
,
name_length
;
//console.log("RQ (" + RQ.length + ") " + RQ);
switch
(
RFB
.
state
)
{
switch
(
RFB
.
state
)
{
case
'ProtocolVersion'
:
case
'ProtocolVersion'
:
...
@@ -365,7 +309,9 @@ init_msg: function () {
...
@@ -365,7 +309,9 @@ init_msg: function () {
normal_msg
:
function
()
{
normal_msg
:
function
()
{
//console.log(">> normal_msg");
//console.log(">> normal_msg");
var
ret
=
true
,
msg_type
,
num_colours
,
msg
;
var
RQ
=
RFB
.
RQ
,
FBU
=
RFB
.
FBU
,
ret
=
true
,
msg_type
,
num_colours
,
msg
;
if
(
FBU
.
rects
>
0
)
{
if
(
FBU
.
rects
>
0
)
{
msg_type
=
0
;
msg_type
=
0
;
}
else
if
(
RFB
.
cuttext
!==
'none'
)
{
}
else
if
(
RFB
.
cuttext
!==
'none'
)
{
...
@@ -497,7 +443,7 @@ normal_msg: function () {
...
@@ -497,7 +443,7 @@ normal_msg: function () {
display_raw
:
function
()
{
display_raw
:
function
()
{
//console.log(">> display_raw");
//console.log(">> display_raw");
var
cur_y
,
cur_height
;
var
RQ
=
RFB
.
RQ
,
FBU
=
RFB
.
FBU
,
cur_y
,
cur_height
;
if
(
FBU
.
lines
===
0
)
{
if
(
FBU
.
lines
===
0
)
{
FBU
.
lines
=
FBU
.
height
;
FBU
.
lines
=
FBU
.
height
;
...
@@ -526,7 +472,7 @@ display_raw: function () {
...
@@ -526,7 +472,7 @@ display_raw: function () {
display_copy_rect
:
function
()
{
display_copy_rect
:
function
()
{
//console.log(">> display_copy_rect");
//console.log(">> display_copy_rect");
var
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 " +
//console.log(" waiting for " +
...
@@ -541,8 +487,8 @@ display_copy_rect: function () {
...
@@ -541,8 +487,8 @@ display_copy_rect: function () {
},
},
display_rre
:
function
()
{
display_rre
:
function
()
{
//console.log(">> display_rre (" + RQ.length + " bytes)");
//console.log(">> display_rre (" + R
FB.R
Q.length + " bytes)");
var
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 " +
//console.log(" waiting for " +
...
@@ -577,8 +523,9 @@ display_rre: function () {
...
@@ -577,8 +523,9 @@ display_rre: function () {
display_hextile
:
function
()
{
display_hextile
:
function
()
{
//console.log(">> display_hextile");
//console.log(">> display_hextile");
var
subencoding
,
subrects
,
cur_tile
,
tile_x
,
x
,
w
,
tile_y
,
y
,
h
,
var
RQ
=
RFB
.
RQ
,
FBU
=
RFB
.
FBU
,
idx
,
tile
,
xy
,
s
,
sx
,
sy
,
wh
,
sw
,
sh
,
color
;
subencoding
,
subrects
,
idx
,
tile
,
color
,
cur_tile
,
tile_x
,
x
,
w
,
tile_y
,
y
,
h
,
xy
,
s
,
sx
,
sy
,
wh
,
sw
,
sh
;
if
(
FBU
.
tiles
===
0
)
{
if
(
FBU
.
tiles
===
0
)
{
FBU
.
tiles_x
=
Math
.
ceil
(
FBU
.
width
/
16
);
FBU
.
tiles_x
=
Math
.
ceil
(
FBU
.
width
/
16
);
...
@@ -831,7 +778,7 @@ recv_message: function(e) {
...
@@ -831,7 +778,7 @@ recv_message: function(e) {
if
(
RFB
.
use_seq
)
{
if
(
RFB
.
use_seq
)
{
RFB
.
recv_message_reorder
(
e
);
RFB
.
recv_message_reorder
(
e
);
}
else
{
}
else
{
R
Q
=
RQ
.
concat
(
Base64
.
decode
(
e
.
data
,
0
));
R
FB
.
RQ
=
RFB
.
RQ
.
concat
(
Base64
.
decode
(
e
.
data
,
0
));
RFB
.
handle_message
();
RFB
.
handle_message
();
}
}
...
@@ -849,33 +796,34 @@ recv_message: function(e) {
...
@@ -849,33 +796,34 @@ recv_message: function(e) {
recv_message_reorder
:
function
(
e
)
{
recv_message_reorder
:
function
(
e
)
{
//console.log(">> recv_message_reorder");
//console.log(">> recv_message_reorder");
var
offset
,
seq_num
,
i
;
var
RQ_reorder
=
RFB
.
RQ_reorder
,
offset
,
seq_num
,
i
;
offset
=
e
.
data
.
indexOf
(
":"
)
+
1
;
offset
=
e
.
data
.
indexOf
(
":"
)
+
1
;
seq_num
=
parseInt
(
e
.
data
.
substr
(
0
,
offset
-
1
),
10
);
seq_num
=
parseInt
(
e
.
data
.
substr
(
0
,
offset
-
1
),
10
);
if
(
RQ_seq_num
===
seq_num
)
{
if
(
R
FB
.
R
Q_seq_num
===
seq_num
)
{
R
Q
=
RQ
.
concat
(
Base64
.
decode
(
e
.
data
,
offset
));
R
FB
.
RQ
=
RFB
.
RQ
.
concat
(
Base64
.
decode
(
e
.
data
,
offset
));
RQ_seq_num
++
;
R
FB
.
R
Q_seq_num
++
;
}
else
{
}
else
{
console
.
warn
(
"sequence number mismatch: expected "
+
console
.
warn
(
"sequence number mismatch: expected "
+
RQ_seq_num
+
", got "
+
seq_num
);
R
FB
.
R
Q_seq_num
+
", got "
+
seq_num
);
if
(
RQ_reorder
.
length
>
20
)
{
if
(
R
FB
.
R
Q_reorder
.
length
>
20
)
{
RFB
.
updateState
(
'failed'
,
"Re-order queue too long"
);
RFB
.
updateState
(
'failed'
,
"Re-order queue too long"
);
}
else
{
}
else
{
R
Q_reorder
=
RQ_reorder
.
concat
(
e
.
data
.
substr
(
0
));
R
FB
.
RQ_reorder
=
RFB
.
RQ_reorder
.
concat
(
e
.
data
.
substr
(
0
));
i
=
0
;
i
=
0
;
while
(
i
<
RQ_reorder
.
length
)
{
while
(
i
<
R
FB
.
R
Q_reorder
.
length
)
{
offset
=
RQ_reorder
[
i
].
indexOf
(
":"
)
+
1
;
offset
=
R
FB
.
R
Q_reorder
[
i
].
indexOf
(
":"
)
+
1
;
seq_num
=
parseInt
(
RQ_reorder
[
i
].
substr
(
0
,
offset
-
1
),
10
);
seq_num
=
parseInt
(
R
FB
.
R
Q_reorder
[
i
].
substr
(
0
,
offset
-
1
),
10
);
//console.log("Searching reorder list item " +
//console.log("Searching reorder list item " +
// i + ", seq_num " + seq_num);
// i + ", seq_num " + seq_num);
if
(
seq_num
===
RQ_seq_num
)
{
if
(
seq_num
===
R
FB
.
R
Q_seq_num
)
{
/* Remove it from reorder queue, decode it and
/* Remove it from reorder queue, decode it and
* add it to the receive queue */
* add it to the receive queue */
console
.
log
(
"Found re-ordered packet seq_num "
+
seq_num
);
console
.
log
(
"Found re-ordered packet seq_num "
+
seq_num
);
RQ
=
RQ
.
concat
(
Base64
.
decode
(
RQ_reorder
.
splice
(
i
,
1
)[
0
],
RFB
.
RQ
=
RFB
.
RQ
.
concat
(
Base64
.
decode
(
RFB
.
RQ_reorder
.
splice
(
i
,
1
)[
0
],
offset
));
offset
));
RQ_seq_num
++
;
R
FB
.
R
Q_seq_num
++
;
i
=
0
;
// Start search again for next one
i
=
0
;
// Start search again for next one
}
else
{
}
else
{
i
++
;
i
++
;
...
@@ -901,7 +849,7 @@ handle_message: function () {
...
@@ -901,7 +849,7 @@ handle_message: function () {
case
'normal'
:
case
'normal'
:
RFB
.
normal_msg
();
RFB
.
normal_msg
();
/*
/*
while (RQ.length > 0) {
while (R
FB.R
Q.length > 0) {
if (RFB.normal_msg() && RFB.state === 'normal') {
if (RFB.normal_msg() && RFB.state === 'normal') {
console.log("More to process");
console.log("More to process");
} else {
} else {
...
@@ -925,10 +873,10 @@ send_string: function (str) {
...
@@ -925,10 +873,10 @@ send_string: function (str) {
send_array
:
function
(
arr
)
{
send_array
:
function
(
arr
)
{
//console.log(">> send_array: " + arr);
//console.log(">> send_array: " + arr);
//console.log(">> send_array: " + Base64.encode(arr));
//console.log(">> send_array: " + Base64.encode(arr));
SQ
=
SQ
+
Base64
.
encode
(
arr
);
RFB
.
SQ
=
RFB
.
SQ
+
Base64
.
encode
(
arr
);
if
(
RFB
.
ws
.
bufferedAmount
===
0
)
{
if
(
RFB
.
ws
.
bufferedAmount
===
0
)
{
RFB
.
ws
.
send
(
SQ
);
RFB
.
ws
.
send
(
RFB
.
SQ
);
SQ
=
""
;
RFB
.
SQ
=
""
;
}
else
{
}
else
{
console
.
log
(
"Delaying send"
);
console
.
log
(
"Delaying send"
);
}
}
...
@@ -1129,9 +1077,9 @@ init_ws: function () {
...
@@ -1129,9 +1077,9 @@ init_ws: function () {
* or whatever slower rate the network can handle
* or whatever slower rate the network can handle
*/
*/
if
(
RFB
.
ws
.
bufferedAmount
===
0
)
{
if
(
RFB
.
ws
.
bufferedAmount
===
0
)
{
if
(
SQ
)
{
if
(
RFB
.
SQ
)
{
RFB
.
ws
.
send
(
SQ
);
RFB
.
ws
.
send
(
RFB
.
SQ
);
SQ
=
""
;
RFB
.
SQ
=
""
;
}
}
}
else
{
}
else
{
console
.
log
(
"Delaying send"
);
console
.
log
(
"Delaying send"
);
...
@@ -1158,14 +1106,14 @@ init_vars: function () {
...
@@ -1158,14 +1106,14 @@ init_vars: function () {
/* Reset state */
/* Reset state */
RFB
.
cuttext
=
'none'
;
RFB
.
cuttext
=
'none'
;
RFB
.
ct_length
=
0
;
RFB
.
ct_length
=
0
;
R
Q
=
[];
R
FB
.
RQ
=
[];
R
Q_reorder
=
[];
R
FB
.
RQ_reorder
=
[];
R
Q_seq_num
=
0
;
R
FB
.
RQ_seq_num
=
0
;
SQ
=
""
;
RFB
.
SQ
=
""
;
FBU
.
rects
=
0
;
RFB
.
FBU
.
rects
=
0
;
FBU
.
subrects
=
0
;
// RRE and HEXTILE
RFB
.
FBU
.
subrects
=
0
;
// RRE and HEXTILE
FBU
.
lines
=
0
;
// RAW
RFB
.
FBU
.
lines
=
0
;
// RAW
FBU
.
tiles
=
0
;
// HEXTILE
RFB
.
FBU
.
tiles
=
0
;
// HEXTILE
RFB
.
mouse_buttonmask
=
0
;
RFB
.
mouse_buttonmask
=
0
;
RFB
.
mouse_arr
=
[];
RFB
.
mouse_arr
=
[];
},
},
...
...
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