]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/playback-ui.js
b5fac90fcbbcee693af818065b9cb1222e4466c2
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 encoding
= VNC_frame_encoding
;
53 const notification = function (rfb
, mesg
, level
, options
) {
54 document
.getElementById('VNC_status').textContent
= mesg
;
57 function IterationPlayer (iterations
, frames
, encoding
) {
58 this._iterations
= iterations
;
60 this._iteration
= undefined;
61 this._player
= undefined;
63 this._start_time
= undefined;
65 this._frames
= frames
;
66 this._encoding
= encoding
;
68 this._state
= 'running';
70 this.onfinish = function() {};
71 this.oniterationfinish = function() {};
72 this.rfbdisconnected = function() {};
73 this.rfbnotification = function() {};
76 IterationPlayer
.prototype = {
77 start: function (mode
) {
79 this._start_time
= (new Date()).getTime();
81 this._realtime
= mode
.startsWith('realtime');
82 this._trafficMgmt
= !mode
.endsWith('-no-mgmt');
84 this._nextIteration();
87 _nextIteration: function () {
88 const player
= new RecordingPlayer(this._frames
, this._encoding
, this._disconnected
.bind(this), this._notification
.bind(this));
89 player
.onfinish
= this._iterationFinish
.bind(this);
91 if (this._state
!== 'running') { return; }
94 if (this._iteration
> this._iterations
) {
99 player
.run(this._realtime
, this._trafficMgmt
);
102 _finish: function () {
103 const endTime
= (new Date()).getTime();
104 const totalDuration
= endTime
- this._start_time
;
106 const evt
= new Event('finish');
107 evt
.duration
= totalDuration
;
108 evt
.iterations
= this._iterations
;
112 _iterationFinish: function (duration
) {
113 const evt
= new Event('iterationfinish');
114 evt
.duration
= duration
;
115 evt
.number
= this._iteration
;
116 this.oniterationfinish(evt
);
118 this._nextIteration();
121 _disconnected: function (rfb
, reason
, frame
) {
123 this._state
= 'failed';
126 var evt
= new Event('rfbdisconnected');
130 this.onrfbdisconnected(evt
);
133 _notification: function (rfb
, msg
, level
, options
) {
134 var evt
= new Event('rfbnotification');
137 evt
.options
= options
;
139 this.onrfbnotification(evt
);
144 document
.getElementById('startButton').value
= "Running";
145 document
.getElementById('startButton').disabled
= true;
147 const iterations
= document
.getElementById('iterations').value
;
151 if (document
.getElementById('mode1').checked
) {
152 message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
155 message(`Starting realtime playback [${iterations} iteration(s)]`);
159 const player
= new IterationPlayer(iterations
, frames
, encoding
);
160 player
.oniterationfinish = function (evt
) {
161 message(`Iteration ${evt.number} took ${evt.duration}ms`);
163 player
.onrfbdisconnected = function (evt
) {
165 message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`);
168 player
.onrfbnotification = function (evt
) {
169 document
.getElementById('VNC_status').textContent
= evt
.message
;
171 player
.onfinish = function (evt
) {
172 const iterTime
= parseInt(evt
.duration
/ evt
.iterations
, 10);
173 message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);
175 document
.getElementById('startButton').disabled
= false;
176 document
.getElementById('startButton').value
= "Start";
181 loadFile().then(enableUI
).catch(function (e
) { message("Error loading recording"); });