]>
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 const notification = function (rfb
, mesg
, level
, options
) {
56 document
.getElementById('VNC_status').textContent
= mesg
;
59 function IterationPlayer (iterations
, frames
, encoding
) {
60 this._iterations
= iterations
;
62 this._iteration
= undefined;
63 this._player
= undefined;
65 this._start_time
= undefined;
67 this._frames
= frames
;
68 this._encoding
= encoding
;
70 this._state
= 'running';
72 this.onfinish = function() {};
73 this.oniterationfinish = function() {};
74 this.rfbdisconnected = function() {};
75 this.rfbnotification = function() {};
78 IterationPlayer
.prototype = {
79 start: function (mode
) {
81 this._start_time
= (new Date()).getTime();
83 this._realtime
= mode
.startsWith('realtime');
84 this._trafficMgmt
= !mode
.endsWith('-no-mgmt');
86 this._nextIteration();
89 _nextIteration: function () {
90 const player
= new RecordingPlayer(this._frames
, this._encoding
, this._disconnected
.bind(this), this._notification
.bind(this));
91 player
.onfinish
= this._iterationFinish
.bind(this);
93 if (this._state
!== 'running') { return; }
96 if (this._iteration
> this._iterations
) {
101 player
.run(this._realtime
, this._trafficMgmt
);
104 _finish: function () {
105 const endTime
= (new Date()).getTime();
106 const totalDuration
= endTime
- this._start_time
;
108 const evt
= new Event('finish');
109 evt
.duration
= totalDuration
;
110 evt
.iterations
= this._iterations
;
114 _iterationFinish: function (duration
) {
115 const evt
= new Event('iterationfinish');
116 evt
.duration
= duration
;
117 evt
.number
= this._iteration
;
118 this.oniterationfinish(evt
);
120 this._nextIteration();
123 _disconnected: function (rfb
, reason
, frame
) {
125 this._state
= 'failed';
128 var evt
= new Event('rfbdisconnected');
132 this.onrfbdisconnected(evt
);
135 _notification: function (rfb
, msg
, level
, options
) {
136 var evt
= new Event('rfbnotification');
139 evt
.options
= options
;
141 this.onrfbnotification(evt
);
146 document
.getElementById('startButton').value
= "Running";
147 document
.getElementById('startButton').disabled
= true;
149 const iterations
= document
.getElementById('iterations').value
;
153 if (document
.getElementById('mode1').checked
) {
154 message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
157 message(`Starting realtime playback [${iterations} iteration(s)]`);
161 const player
= new IterationPlayer(iterations
, frames
, encoding
);
162 player
.oniterationfinish = function (evt
) {
163 message(`Iteration ${evt.number} took ${evt.duration}ms`);
165 player
.onrfbdisconnected = function (evt
) {
167 message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`);
170 player
.onrfbnotification = function (evt
) {
171 document
.getElementById('VNC_status').textContent
= evt
.message
;
173 player
.onfinish = function (evt
) {
174 const iterTime
= parseInt(evt
.duration
/ evt
.iterations
, 10);
175 message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);
177 document
.getElementById('startButton').disabled
= false;
178 document
.getElementById('startButton').value
= "Start";
183 loadFile().then(enableUI
).catch(function (e
) { message("Error loading recording: " + e
); });