]>
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
);
22 return import(`../recordings/${fname}#nocache`);
25 function enableUI(recording
) {
26 var iterations
= WebUtil
.getQueryVar('iterations', 3);
27 document
.getElementById('iterations').value
= iterations
;
29 var mode
= WebUtil
.getQueryVar('mode', 3);
30 if (mode
=== 'realtime') {
31 document
.getElementById('mode2').checked
= true;
33 document
.getElementById('mode1').checked
= true;
36 message("VNC_frame_data.length: " + recording
.VNC_frame_data
.length
);
38 const startButton
= document
.getElementById('startButton');
39 startButton
.disabled
= false
40 startButton
.addEventListener('click', start
);
42 frames
= recording
.VNC_frame_data
;
43 encoding
= recording
.VNC_frame_encoding
;
46 const notification = function (rfb
, mesg
, level
, options
) {
47 document
.getElementById('VNC_status').textContent
= mesg
;
50 function IterationPlayer (iterations
, frames
, encoding
) {
51 this._iterations
= iterations
;
53 this._iteration
= undefined;
54 this._player
= undefined;
56 this._start_time
= undefined;
58 this._frames
= frames
;
59 this._encoding
= encoding
;
61 this._state
= 'running';
63 this.onfinish = function() {};
64 this.oniterationfinish = function() {};
65 this.rfbdisconnected = function() {};
66 this.rfbnotification = function() {};
69 IterationPlayer
.prototype = {
70 start: function (mode
) {
72 this._start_time
= (new Date()).getTime();
74 this._realtime
= mode
.startsWith('realtime');
75 this._trafficMgmt
= !mode
.endsWith('-no-mgmt');
77 this._nextIteration();
80 _nextIteration: function () {
81 const player
= new RecordingPlayer(this._frames
, this._encoding
, this._disconnected
.bind(this), this._notification
.bind(this));
82 player
.onfinish
= this._iterationFinish
.bind(this);
84 if (this._state
!== 'running') { return; }
87 if (this._iteration
> this._iterations
) {
92 player
.run(this._realtime
, this._trafficMgmt
);
95 _finish: function () {
96 const endTime
= (new Date()).getTime();
97 const totalDuration
= endTime
- this._start_time
;
99 const evt
= new Event('finish');
100 evt
.duration
= totalDuration
;
101 evt
.iterations
= this._iterations
;
105 _iterationFinish: function (duration
) {
106 const evt
= new Event('iterationfinish');
107 evt
.duration
= duration
;
108 evt
.number
= this._iteration
;
109 this.oniterationfinish(evt
);
111 this._nextIteration();
114 _disconnected: function (rfb
, reason
, frame
) {
116 this._state
= 'failed';
119 var evt
= new Event('rfbdisconnected');
123 this.onrfbdisconnected(evt
);
126 _notification: function (rfb
, msg
, level
, options
) {
127 var evt
= new Event('rfbnotification');
130 evt
.options
= options
;
132 this.onrfbnotification(evt
);
137 document
.getElementById('startButton').value
= "Running";
138 document
.getElementById('startButton').disabled
= true;
140 const iterations
= document
.getElementById('iterations').value
;
144 if (document
.getElementById('mode1').checked
) {
145 message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
148 message(`Starting realtime playback [${iterations} iteration(s)]`);
152 const player
= new IterationPlayer(iterations
, frames
, encoding
);
153 player
.oniterationfinish = function (evt
) {
154 message(`Iteration ${evt.number} took ${evt.duration}ms`);
156 player
.onrfbdisconnected = function (evt
) {
158 message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`);
161 player
.onrfbnotification = function (evt
) {
162 document
.getElementById('VNC_status').textContent
= evt
.message
;
164 player
.onfinish = function (evt
) {
165 const iterTime
= parseInt(evt
.duration
/ evt
.iterations
, 10);
166 message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);
168 document
.getElementById('startButton').disabled
= false;
169 document
.getElementById('startButton').value
= "Start";
174 loadFile().then(enableUI
).catch(message
);