diff options
author | Christian Beier <dontmind@freeshell.org> | 2011-10-04 18:26:48 +0200 |
---|---|---|
committer | Christian Beier <dontmind@freeshell.org> | 2011-10-04 18:26:48 +0200 |
commit | edbd5ab8d4512a7adb089f3e4791e54523748253 (patch) | |
tree | b6dc74ec651e5a5173fe8d26d67392b35888c65d /classes/novnc/include/playback.js | |
parent | bffd9ee33bd141f5c75304b1430d2ea2725239b3 (diff) | |
download | libtdevnc-edbd5ab8d4512a7adb089f3e4791e54523748253.tar.gz libtdevnc-edbd5ab8d4512a7adb089f3e4791e54523748253.zip |
Add noVNC HTML5 client connect possibility to our http server.
Pure JavaScript, no Java plugin required anymore! (But a recent browser...)
Diffstat (limited to 'classes/novnc/include/playback.js')
-rw-r--r-- | classes/novnc/include/playback.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/classes/novnc/include/playback.js b/classes/novnc/include/playback.js new file mode 100644 index 0000000..22a00a3 --- /dev/null +++ b/classes/novnc/include/playback.js @@ -0,0 +1,90 @@ +/* + * noVNC: HTML5 VNC client + * Copyright (C) 2011 Joel Martin + * Licensed under LGPL-3 (see LICENSE.LGPL-3) + */ + +"use strict"; +/*jslint browser: true, white: false */ +/*global Util, VNC_frame_data, finish */ + +var rfb, mode, test_state, frame_idx, frame_length, + iteration, iterations, istart_time, + + // Pre-declarations for jslint + send_array, next_iteration, queue_next_packet, do_packet; + +// Override send_array +send_array = function (arr) { + // Stub out send_array +}; + +next_iteration = function () { + if (iteration === 0) { + frame_length = VNC_frame_data.length; + test_state = 'running'; + } else { + rfb.disconnect(); + } + + if (test_state !== 'running') { return; } + + iteration += 1; + if (iteration > iterations) { + finish(); + return; + } + + frame_idx = 0; + istart_time = (new Date()).getTime(); + rfb.connect('test', 0, "bogus"); + + queue_next_packet(); + +}; + +queue_next_packet = function () { + var frame, foffset, toffset, delay; + if (test_state !== 'running') { return; } + + frame = VNC_frame_data[frame_idx]; + while ((frame_idx < frame_length) && (frame.charAt(0) === "}")) { + //Util.Debug("Send frame " + frame_idx); + frame_idx += 1; + frame = VNC_frame_data[frame_idx]; + } + + if (frame === 'EOF') { + Util.Debug("Finished, found EOF"); + next_iteration(); + return; + } + if (frame_idx >= frame_length) { + Util.Debug("Finished, no more frames"); + next_iteration(); + return; + } + + if (mode === 'realtime') { + foffset = frame.slice(1, frame.indexOf('{', 1)); + toffset = (new Date()).getTime() - istart_time; + delay = foffset - toffset; + if (delay < 1) { + delay = 1; + } + + setTimeout(do_packet, delay); + } else { + setTimeout(do_packet, 1); + } +}; + +do_packet = function () { + //Util.Debug("Processing frame: " + frame_idx); + var frame = VNC_frame_data[frame_idx]; + rfb.recv_message({'data' : frame.slice(frame.indexOf('{', 1) + 1)}); + frame_idx += 1; + + queue_next_packet(); +}; + |