]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/playback.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Licensed under MPL 2.0 (see LICENSE.txt)
8 /*jslint browser: true, white: false */
9 /*global Util, VNC_frame_data, finish */
11 var rfb
, mode
, test_state
, frame_idx
, frame_length
,
12 iteration
, iterations
, istart_time
,
14 // Pre-declarations for jslint
15 send_array
, next_iteration
, queue_next_packet
, do_packet
, enable_test_mode
;
17 // Override send_array
18 send_array = function (arr
) {
19 // Stub out send_array
22 enable_test_mode = function () {
23 rfb
._sock
._mode
= VNC_frame_encoding
;
24 rfb
._sock
.send
= send_array
;
25 rfb
._sock
.close = function () {};
26 rfb
._sock
.flush = function () {};
27 rfb
._checkEvents = function () {};
28 rfb
.connect = function (host
, port
, password
, path
) {
29 this._rfb_host
= host
;
30 this._rfb_port
= port
;
31 this._rfb_password
= (password
!== undefined) ? password
: "";
32 this._rfb_path
= (path
!== undefined) ? path
: "";
33 this._sock
.init('binary', 'ws');
34 this._updateState('ProtocolVersion', "Starting VNC handshake");
38 next_iteration = function () {
39 rfb
= new RFB({'target': document
.getElementById('VNC_canvas'),
40 'onUpdateState': updateState
});
43 if (iteration
=== 0) {
44 frame_length
= VNC_frame_data
.length
;
45 test_state
= 'running';
48 if (test_state
!== 'running') { return; }
51 if (iteration
> iterations
) {
57 istart_time
= (new Date()).getTime();
58 rfb
.connect('test', 0, "bogus");
64 queue_next_packet = function () {
65 var frame
, foffset
, toffset
, delay
;
66 if (test_state
!== 'running') { return; }
68 frame
= VNC_frame_data
[frame_idx
];
69 while ((frame_idx
< frame_length
) && (frame
.charAt(0) === "}")) {
70 //Util.Debug("Send frame " + frame_idx);
72 frame
= VNC_frame_data
[frame_idx
];
75 if (frame
=== 'EOF') {
76 Util
.Debug("Finished, found EOF");
80 if (frame_idx
>= frame_length
) {
81 Util
.Debug("Finished, no more frames");
86 if (mode
=== 'realtime') {
87 foffset
= frame
.slice(1, frame
.indexOf('{', 1));
88 toffset
= (new Date()).getTime() - istart_time
;
89 delay
= foffset
- toffset
;
94 setTimeout(do_packet
, delay
);
96 setTimeout(do_packet
, 1);
100 var bytes_processed
= 0;
102 do_packet = function () {
103 //Util.Debug("Processing frame: " + frame_idx);
104 var frame
= VNC_frame_data
[frame_idx
],
105 start
= frame
.indexOf('{', 1) + 1;
106 bytes_processed
+= frame
.length
- start
;
107 if (VNC_frame_encoding
=== 'binary') {
108 var u8
= new Uint8Array(frame
.length
- start
);
109 for (var i
= 0; i
< frame
.length
- start
; i
++) {
110 u8
[i
] = frame
.charCodeAt(start
+ i
);
112 rfb
._sock
._recv_message({'data' : u8
});
114 rfb
._sock
._recv_message({'data' : frame
.slice(start
)});