From 7485e82b72d4d1356d95ecca2d109cbf49908b9d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 22 Jul 2021 16:56:49 +0200 Subject: [PATCH] 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. --- tests/playback.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/tests/playback.js b/tests/playback.js index 962307c0..19ab2c34 100644 --- a/tests/playback.js +++ b/tests/playback.js @@ -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 { constructor(frames, disconnected) { this._frames = frames; @@ -63,13 +81,13 @@ export default class RecordingPlayer { run(realtime, trafficManagement) { // 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.addEventListener("disconnect", this._handleDisconnect.bind(this)); this._rfb.addEventListener("credentialsrequired", this._handleCredentials.bind(this)); - this._enablePlaybackMode(); // reset the frame index and timer this._frameIndex = 0; @@ -79,19 +97,7 @@ export default class RecordingPlayer { this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement; this._running = true; - } - - // _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(); - }; + this._queueNextPacket(); } _queueNextPacket() { @@ -136,7 +142,7 @@ export default class RecordingPlayer { const frame = this._frames[this._frameIndex]; - this._rfb._sock._recvMessage({'data': frame.data}); + this._ws.onmessage({'data': frame.data}); this._frameIndex++; this._queueNextPacket(); @@ -153,7 +159,7 @@ export default class RecordingPlayer { this._rfb._display.flush(); } else { this._running = false; - this._rfb._sock._eventHandlers.close({code: 1000, reason: ""}); + this._ws.onclose({code: 1000, reason: ""}); delete this._rfb; this.onfinish((new Date()).getTime() - this._startTime); }