]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/playback-ui.js
1 import * as WebUtil
from '../app/webutil.js';
2 import RecordingPlayer
from './playback.js';
7 function message(str
) {
9 var cell
= document
.getElementById('messages');
10 cell
.textContent
+= str
+ "\n";
11 cell
.scrollTop
= cell
.scrollHeight
;
15 const fname
= WebUtil
.getQueryVar('data', null);
18 return Promise
.reject("Must specify data=FOO in query string.");
21 message("Loading " + fname
);
23 return new Promise(function (resolve
, reject
) {
24 var script
= document
.createElement("script");
25 script
.onload
= resolve
;
26 script
.onerror
= reject
;
27 document
.body
.appendChild(script
);
28 script
.src
= "../recordings/" + fname
;
33 var iterations
= WebUtil
.getQueryVar('iterations', 3);
34 document
.getElementById('iterations').value
= iterations
;
36 var mode
= WebUtil
.getQueryVar('mode', 3);
37 if (mode
=== 'realtime') {
38 document
.getElementById('mode2').checked
= true;
40 document
.getElementById('mode1').checked
= true;
43 message("VNC_frame_data.length: " + VNC_frame_data
.length
);
45 const startButton
= document
.getElementById('startButton');
46 startButton
.disabled
= false;
47 startButton
.addEventListener('click', start
);
49 frames
= VNC_frame_data
;
50 // Only present in older recordings
51 if (window
.VNC_frame_encoding
)
52 encoding
= VNC_frame_encoding
;
55 function IterationPlayer (iterations
, frames
, encoding
) {
56 this._iterations
= iterations
;
58 this._iteration
= undefined;
59 this._player
= undefined;
61 this._start_time
= undefined;
63 this._frames
= frames
;
64 this._encoding
= encoding
;
66 this._state
= 'running';
68 this.onfinish = function() {};
69 this.oniterationfinish = function() {};
70 this.rfbdisconnected = function() {};
73 IterationPlayer
.prototype = {
74 start: function (mode
) {
76 this._start_time
= (new Date()).getTime();
78 this._realtime
= mode
.startsWith('realtime');
79 this._trafficMgmt
= !mode
.endsWith('-no-mgmt');
81 this._nextIteration();
84 _nextIteration: function () {
85 const player
= new RecordingPlayer(this._frames
, this._encoding
, this._disconnected
.bind(this));
86 player
.onfinish
= this._iterationFinish
.bind(this);
88 if (this._state
!== 'running') { return; }
91 if (this._iteration
> this._iterations
) {
96 player
.run(this._realtime
, this._trafficMgmt
);
99 _finish: function () {
100 const endTime
= (new Date()).getTime();
101 const totalDuration
= endTime
- this._start_time
;
103 const evt
= new Event('finish');
104 evt
.duration
= totalDuration
;
105 evt
.iterations
= this._iterations
;
109 _iterationFinish: function (duration
) {
110 const evt
= new Event('iterationfinish');
111 evt
.duration
= duration
;
112 evt
.number
= this._iteration
;
113 this.oniterationfinish(evt
);
115 this._nextIteration();
118 _disconnected: function (rfb
, clean
, frame
) {
120 this._state
= 'failed';
123 var evt
= new Event('rfbdisconnected');
127 this.onrfbdisconnected(evt
);
132 document
.getElementById('startButton').value
= "Running";
133 document
.getElementById('startButton').disabled
= true;
135 const iterations
= document
.getElementById('iterations').value
;
139 if (document
.getElementById('mode1').checked
) {
140 message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
143 message(`Starting realtime playback [${iterations} iteration(s)]`);
147 const player
= new IterationPlayer(iterations
, frames
, encoding
);
148 player
.oniterationfinish = function (evt
) {
149 message(`Iteration ${evt.number} took ${evt.duration}ms`);
151 player
.onrfbdisconnected = function (evt
) {
153 message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`);
156 player
.onfinish = function (evt
) {
157 const iterTime
= parseInt(evt
.duration
/ evt
.iterations
, 10);
158 message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);
160 document
.getElementById('startButton').disabled
= false;
161 document
.getElementById('startButton').value
= "Start";
166 loadFile().then(enableUI
).catch(function (e
) { message("Error loading recording: " + e
); });