]>
Commit | Line | Data |
---|---|---|
d595e656 JM |
1 | /* |
2 | * noVNC: HTML5 VNC client | |
d58f8b51 | 3 | * Copyright (C) 2012 Joel Martin |
1d728ace | 4 | * Licensed under MPL 2.0 (see LICENSE.txt) |
d595e656 JM |
5 | */ |
6 | ||
7 | "use strict"; | |
8 | /*jslint browser: true, white: false */ | |
9 | /*global Util, VNC_frame_data, finish */ | |
10 | ||
b8bd88d0 | 11 | var rfb, mode, test_state, frame_idx, frame_length, |
d595e656 JM |
12 | iteration, iterations, istart_time, |
13 | ||
14 | // Pre-declarations for jslint | |
15 | send_array, next_iteration, queue_next_packet, do_packet; | |
b8bd88d0 JM |
16 | |
17 | // Override send_array | |
18 | send_array = function (arr) { | |
19 | // Stub out send_array | |
d595e656 | 20 | }; |
b8bd88d0 | 21 | |
d595e656 | 22 | next_iteration = function () { |
b8bd88d0 JM |
23 | if (iteration === 0) { |
24 | frame_length = VNC_frame_data.length; | |
25 | test_state = 'running'; | |
26 | } else { | |
27 | rfb.disconnect(); | |
28 | } | |
29 | ||
30 | if (test_state !== 'running') { return; } | |
31 | ||
d595e656 | 32 | iteration += 1; |
b8bd88d0 JM |
33 | if (iteration > iterations) { |
34 | finish(); | |
35 | return; | |
36 | } | |
37 | ||
38 | frame_idx = 0; | |
39 | istart_time = (new Date()).getTime(); | |
40 | rfb.connect('test', 0, "bogus"); | |
41 | ||
42 | queue_next_packet(); | |
43 | ||
d595e656 | 44 | }; |
b8bd88d0 | 45 | |
d595e656 JM |
46 | queue_next_packet = function () { |
47 | var frame, foffset, toffset, delay; | |
b8bd88d0 JM |
48 | if (test_state !== 'running') { return; } |
49 | ||
50 | frame = VNC_frame_data[frame_idx]; | |
51 | while ((frame_idx < frame_length) && (frame.charAt(0) === "}")) { | |
52 | //Util.Debug("Send frame " + frame_idx); | |
53 | frame_idx += 1; | |
54 | frame = VNC_frame_data[frame_idx]; | |
55 | } | |
56 | ||
57 | if (frame === 'EOF') { | |
58 | Util.Debug("Finished, found EOF"); | |
59 | next_iteration(); | |
60 | return; | |
61 | } | |
62 | if (frame_idx >= frame_length) { | |
63 | Util.Debug("Finished, no more frames"); | |
64 | next_iteration(); | |
65 | return; | |
66 | } | |
67 | ||
68 | if (mode === 'realtime') { | |
69 | foffset = frame.slice(1, frame.indexOf('{', 1)); | |
70 | toffset = (new Date()).getTime() - istart_time; | |
71 | delay = foffset - toffset; | |
72 | if (delay < 1) { | |
73 | delay = 1; | |
74 | } | |
75 | ||
76 | setTimeout(do_packet, delay); | |
77 | } else { | |
78 | setTimeout(do_packet, 1); | |
79 | } | |
d595e656 | 80 | }; |
b8bd88d0 | 81 | |
d595e656 | 82 | do_packet = function () { |
b8bd88d0 | 83 | //Util.Debug("Processing frame: " + frame_idx); |
d595e656 JM |
84 | var frame = VNC_frame_data[frame_idx]; |
85 | rfb.recv_message({'data' : frame.slice(frame.indexOf('{', 1) + 1)}); | |
b8bd88d0 JM |
86 | frame_idx += 1; |
87 | ||
88 | queue_next_packet(); | |
d595e656 | 89 | }; |
b8bd88d0 | 90 |