diff options
author | Pierre Ossman <ossman@cendio.se> | 2021-07-22 16:56:49 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2021-07-22 16:56:49 +0200 |
commit | 7485e82b72d4d1356d95ecca2d109cbf49908b9d (patch) | |
tree | 4484e2991e687ec09b92f32d7d47c05fb704272d /tests | |
parent | d44ddbe186e06c1c3e0cf899779f2e037f8da952 (diff) | |
download | novnc-7485e82b72d4d1356d95ecca2d109cbf49908b9d.tar.gz |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/playback.js | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/tests/playback.js b/tests/playback.js index 962307c..19ab2c3 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); } |