playback.js 2.1 KB

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