Update playback test to use new API

Hooking in to the underlying WebSocket after it has been created no
longer works, so clean things up and use the new method of passing an
existing object to the RFB constructor.
This commit is contained in:
Pierre Ossman 2021-07-22 16:56:49 +02:00
parent d44ddbe186
commit 7485e82b72
1 changed files with 23 additions and 17 deletions

View File

@ -42,6 +42,24 @@ if (window.setImmediate === undefined) {
}); });
} }
class FakeWebSocket {
constructor() {
this.binaryType = "arraybuffer";
this.protocol = "";
this.readyState = "open";
this.onerror = () => {};
this.onmessage = () => {};
this.onopen = () => {};
}
send() {
}
close() {
}
}
export default class RecordingPlayer { export default class RecordingPlayer {
constructor(frames, disconnected) { constructor(frames, disconnected) {
this._frames = frames; this._frames = frames;
@ -63,13 +81,13 @@ export default class RecordingPlayer {
run(realtime, trafficManagement) { run(realtime, trafficManagement) {
// initialize a new RFB // initialize a new RFB
this._rfb = new RFB(document.getElementById('VNC_screen'), 'wss://test'); this._ws = new FakeWebSocket();
this._rfb = new RFB(document.getElementById('VNC_screen'), this._ws);
this._rfb.viewOnly = true; this._rfb.viewOnly = true;
this._rfb.addEventListener("disconnect", this._rfb.addEventListener("disconnect",
this._handleDisconnect.bind(this)); this._handleDisconnect.bind(this));
this._rfb.addEventListener("credentialsrequired", this._rfb.addEventListener("credentialsrequired",
this._handleCredentials.bind(this)); this._handleCredentials.bind(this));
this._enablePlaybackMode();
// reset the frame index and timer // reset the frame index and timer
this._frameIndex = 0; this._frameIndex = 0;
@ -79,19 +97,7 @@ export default class RecordingPlayer {
this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement; this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement;
this._running = true; this._running = true;
} this._queueNextPacket();
// _enablePlaybackMode mocks out things not required for running playback
_enablePlaybackMode() {
const self = this;
this._rfb._sock.send = () => {};
this._rfb._sock.close = () => {};
this._rfb._sock.flush = () => {};
this._rfb._sock.open = function () {
this.init();
this._eventHandlers.open();
self._queueNextPacket();
};
} }
_queueNextPacket() { _queueNextPacket() {
@ -136,7 +142,7 @@ export default class RecordingPlayer {
const frame = this._frames[this._frameIndex]; const frame = this._frames[this._frameIndex];
this._rfb._sock._recvMessage({'data': frame.data}); this._ws.onmessage({'data': frame.data});
this._frameIndex++; this._frameIndex++;
this._queueNextPacket(); this._queueNextPacket();
@ -153,7 +159,7 @@ export default class RecordingPlayer {
this._rfb._display.flush(); this._rfb._display.flush();
} else { } else {
this._running = false; this._running = false;
this._rfb._sock._eventHandlers.close({code: 1000, reason: ""}); this._ws.onclose({code: 1000, reason: ""});
delete this._rfb; delete this._rfb;
this.onfinish((new Date()).getTime() - this._startTime); this.onfinish((new Date()).getTime() - this._startTime);
} }