Use ES6 classes
Always use the shorthand notation if the function is a method of an object or class `{ foo() { ... } }` or `class bar { foo() { ... } }`
unless it's a callback in which case you a fat arrow function should be used `{ cb: () => { ... } }`
This commit is contained in:
+7
-7
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"globals": {
|
||||
"chai": true
|
||||
}
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"globals": {
|
||||
"chai": true
|
||||
}
|
||||
}
|
||||
+27
-27
@@ -12,34 +12,34 @@ function make_event(name, props) {
|
||||
return evt;
|
||||
}
|
||||
|
||||
export default function FakeWebSocket (uri, protocols) {
|
||||
this.url = uri;
|
||||
this.binaryType = "arraybuffer";
|
||||
this.extensions = "";
|
||||
export default class FakeWebSocket {
|
||||
constructor(uri, protocols) {
|
||||
this.url = uri;
|
||||
this.binaryType = "arraybuffer";
|
||||
this.extensions = "";
|
||||
|
||||
if (!protocols || typeof protocols === 'string') {
|
||||
this.protocol = protocols;
|
||||
} else {
|
||||
this.protocol = protocols[0];
|
||||
if (!protocols || typeof protocols === 'string') {
|
||||
this.protocol = protocols;
|
||||
} else {
|
||||
this.protocol = protocols[0];
|
||||
}
|
||||
|
||||
this._send_queue = new Uint8Array(20000);
|
||||
|
||||
this.readyState = FakeWebSocket.CONNECTING;
|
||||
this.bufferedAmount = 0;
|
||||
|
||||
this.__is_fake = true;
|
||||
}
|
||||
|
||||
this._send_queue = new Uint8Array(20000);
|
||||
|
||||
this.readyState = FakeWebSocket.CONNECTING;
|
||||
this.bufferedAmount = 0;
|
||||
|
||||
this.__is_fake = true;
|
||||
}
|
||||
|
||||
FakeWebSocket.prototype = {
|
||||
close: function (code, reason) {
|
||||
close(code, reason) {
|
||||
this.readyState = FakeWebSocket.CLOSED;
|
||||
if (this.onclose) {
|
||||
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
send: function (data) {
|
||||
send(data) {
|
||||
if (this.protocol == 'base64') {
|
||||
data = Base64.decode(data);
|
||||
} else {
|
||||
@@ -47,25 +47,25 @@ FakeWebSocket.prototype = {
|
||||
}
|
||||
this._send_queue.set(data, this.bufferedAmount);
|
||||
this.bufferedAmount += data.length;
|
||||
},
|
||||
}
|
||||
|
||||
_get_sent_data: function () {
|
||||
_get_sent_data() {
|
||||
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
||||
this.bufferedAmount = 0;
|
||||
return res;
|
||||
},
|
||||
}
|
||||
|
||||
_open: function (data) {
|
||||
_open() {
|
||||
this.readyState = FakeWebSocket.OPEN;
|
||||
if (this.onopen) {
|
||||
this.onopen(make_event('open'));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_receive_data: function (data) {
|
||||
_receive_data(data) {
|
||||
this.onmessage(make_event("message", { 'data': data }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
FakeWebSocket.OPEN = WebSocket.OPEN;
|
||||
FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
|
||||
|
||||
+21
-21
@@ -53,26 +53,26 @@ function enableUI() {
|
||||
encoding = VNC_frame_encoding;
|
||||
}
|
||||
|
||||
function IterationPlayer (iterations, frames, encoding) {
|
||||
this._iterations = iterations;
|
||||
class IterationPlayer {
|
||||
constructor(iterations, frames, encoding) {
|
||||
this._iterations = iterations;
|
||||
|
||||
this._iteration = undefined;
|
||||
this._player = undefined;
|
||||
this._iteration = undefined;
|
||||
this._player = undefined;
|
||||
|
||||
this._start_time = undefined;
|
||||
this._start_time = undefined;
|
||||
|
||||
this._frames = frames;
|
||||
this._encoding = encoding;
|
||||
this._frames = frames;
|
||||
this._encoding = encoding;
|
||||
|
||||
this._state = 'running';
|
||||
this._state = 'running';
|
||||
|
||||
this.onfinish = function() {};
|
||||
this.oniterationfinish = function() {};
|
||||
this.rfbdisconnected = function() {};
|
||||
}
|
||||
}
|
||||
|
||||
IterationPlayer.prototype = {
|
||||
start: function (mode) {
|
||||
start(mode) {
|
||||
this._iteration = 0;
|
||||
this._start_time = (new Date()).getTime();
|
||||
|
||||
@@ -80,9 +80,9 @@ IterationPlayer.prototype = {
|
||||
this._trafficMgmt = !mode.endsWith('-no-mgmt');
|
||||
|
||||
this._nextIteration();
|
||||
},
|
||||
}
|
||||
|
||||
_nextIteration: function () {
|
||||
_nextIteration() {
|
||||
const player = new RecordingPlayer(this._frames, this._encoding, this._disconnected.bind(this));
|
||||
player.onfinish = this._iterationFinish.bind(this);
|
||||
|
||||
@@ -95,9 +95,9 @@ IterationPlayer.prototype = {
|
||||
}
|
||||
|
||||
player.run(this._realtime, this._trafficMgmt);
|
||||
},
|
||||
}
|
||||
|
||||
_finish: function () {
|
||||
_finish() {
|
||||
const endTime = (new Date()).getTime();
|
||||
const totalDuration = endTime - this._start_time;
|
||||
|
||||
@@ -105,18 +105,18 @@ IterationPlayer.prototype = {
|
||||
evt.duration = totalDuration;
|
||||
evt.iterations = this._iterations;
|
||||
this.onfinish(evt);
|
||||
},
|
||||
}
|
||||
|
||||
_iterationFinish: function (duration) {
|
||||
_iterationFinish(duration) {
|
||||
const evt = new Event('iterationfinish');
|
||||
evt.duration = duration;
|
||||
evt.number = this._iteration;
|
||||
this.oniterationfinish(evt);
|
||||
|
||||
this._nextIteration();
|
||||
},
|
||||
}
|
||||
|
||||
_disconnected: function (clean, frame) {
|
||||
_disconnected(clean, frame) {
|
||||
if (!clean) {
|
||||
this._state = 'failed';
|
||||
}
|
||||
@@ -127,8 +127,8 @@ IterationPlayer.prototype = {
|
||||
evt.iteration = this._iteration;
|
||||
|
||||
this.onrfbdisconnected(evt);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
document.getElementById('startButton').value = "Running";
|
||||
|
||||
+29
-29
@@ -44,37 +44,37 @@ if (window.setImmediate === undefined) {
|
||||
window.addEventListener("message", _onMessage);
|
||||
}
|
||||
|
||||
export default function RecordingPlayer (frames, encoding, disconnected) {
|
||||
this._frames = frames;
|
||||
this._encoding = encoding;
|
||||
export default class RecordingPlayer {
|
||||
constructor(frames, encoding, disconnected) {
|
||||
this._frames = frames;
|
||||
this._encoding = encoding;
|
||||
|
||||
this._disconnected = disconnected;
|
||||
this._disconnected = disconnected;
|
||||
|
||||
if (this._encoding === undefined) {
|
||||
if (this._encoding === undefined) {
|
||||
const frame = this._frames[0];
|
||||
const start = frame.indexOf('{', 1) + 1;
|
||||
if (frame.slice(start).startsWith('UkZC')) {
|
||||
this._encoding = 'base64';
|
||||
} else {
|
||||
this._encoding = 'binary';
|
||||
if (frame.slice(start).startsWith('UkZC')) {
|
||||
this._encoding = 'base64';
|
||||
} else {
|
||||
this._encoding = 'binary';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._rfb = undefined;
|
||||
this._frame_length = this._frames.length;
|
||||
this._rfb = undefined;
|
||||
this._frame_length = this._frames.length;
|
||||
|
||||
this._frame_index = 0;
|
||||
this._start_time = undefined;
|
||||
this._realtime = true;
|
||||
this._trafficManagement = true;
|
||||
this._frame_index = 0;
|
||||
this._start_time = undefined;
|
||||
this._realtime = true;
|
||||
this._trafficManagement = true;
|
||||
|
||||
this._running = false;
|
||||
this._running = false;
|
||||
|
||||
this.onfinish = function () {};
|
||||
}
|
||||
}
|
||||
|
||||
RecordingPlayer.prototype = {
|
||||
run: function (realtime, trafficManagement) {
|
||||
run(realtime, trafficManagement) {
|
||||
// initialize a new RFB
|
||||
this._rfb = new RFB(document.getElementById('VNC_screen'), 'wss://test');
|
||||
this._rfb.viewOnly = true;
|
||||
@@ -92,10 +92,10 @@ RecordingPlayer.prototype = {
|
||||
this._running = true;
|
||||
|
||||
this._queueNextPacket();
|
||||
},
|
||||
}
|
||||
|
||||
// _enablePlaybackMode mocks out things not required for running playback
|
||||
_enablePlaybackMode: function () {
|
||||
_enablePlaybackMode() {
|
||||
this._rfb._sock.send = function (arr) {};
|
||||
this._rfb._sock.close = function () {};
|
||||
this._rfb._sock.flush = function () {};
|
||||
@@ -103,9 +103,9 @@ RecordingPlayer.prototype = {
|
||||
this.init();
|
||||
this._eventHandlers.open();
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
_queueNextPacket: function () {
|
||||
_queueNextPacket() {
|
||||
if (!this._running) { return; }
|
||||
|
||||
let frame = this._frames[this._frame_index];
|
||||
@@ -138,9 +138,9 @@ RecordingPlayer.prototype = {
|
||||
} else {
|
||||
setImmediate(this._doPacket.bind(this));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_doPacket: function () {
|
||||
_doPacket() {
|
||||
// Avoid having excessive queue buildup in non-realtime mode
|
||||
if (this._trafficManagement && this._rfb._flushing) {
|
||||
const player = this;
|
||||
@@ -170,7 +170,7 @@ RecordingPlayer.prototype = {
|
||||
this._frame_index++;
|
||||
|
||||
this._queueNextPacket();
|
||||
},
|
||||
}
|
||||
|
||||
_finish() {
|
||||
if (this._rfb._display.pending()) {
|
||||
@@ -188,10 +188,10 @@ RecordingPlayer.prototype = {
|
||||
delete this._rfb;
|
||||
this.onfinish((new Date()).getTime() - this._start_time);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_handleDisconnect(evt) {
|
||||
this._running = false;
|
||||
this._disconnected(evt.detail.clean, this._frame_index);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+18
-18
@@ -194,7 +194,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
describe('#sendCtrlAlDel', function () {
|
||||
it('should sent ctrl[down]-alt[down]-del[down] then del[up]-alt[up]-ctrl[up]', function () {
|
||||
const expected = {_sQ: new Uint8Array(48), _sQlen: 0, flush: function () {}};
|
||||
const expected = {_sQ: new Uint8Array(48), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.keyEvent(expected, 0xFFE3, 1);
|
||||
RFB.messages.keyEvent(expected, 0xFFE9, 1);
|
||||
RFB.messages.keyEvent(expected, 0xFFFF, 1);
|
||||
@@ -223,14 +223,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
describe('#sendKey', function () {
|
||||
it('should send a single key with the given code and state (down = true)', function () {
|
||||
const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
|
||||
const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.keyEvent(expected, 123, 1);
|
||||
client.sendKey(123, 'Key123', true);
|
||||
expect(client._sock).to.have.sent(expected._sQ);
|
||||
});
|
||||
|
||||
it('should send both a down and up event if the state is not specified', function () {
|
||||
const expected = {_sQ: new Uint8Array(16), _sQlen: 0, flush: function () {}};
|
||||
const expected = {_sQ: new Uint8Array(16), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.keyEvent(expected, 123, 1);
|
||||
RFB.messages.keyEvent(expected, 123, 0);
|
||||
client.sendKey(123, 'Key123');
|
||||
@@ -253,7 +253,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should send QEMU extended events if supported', function () {
|
||||
client._qemuExtKeyEventSupported = true;
|
||||
const expected = {_sQ: new Uint8Array(12), _sQlen: 0, flush: function () {}};
|
||||
const expected = {_sQ: new Uint8Array(12), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.QEMUExtendedKeyEvent(expected, 0x20, true, 0x0039);
|
||||
client.sendKey(0x20, 'Space', true);
|
||||
expect(client._sock).to.have.sent(expected._sQ);
|
||||
@@ -261,7 +261,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should not send QEMU extended events if unknown key code', function () {
|
||||
client._qemuExtKeyEventSupported = true;
|
||||
const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
|
||||
const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.keyEvent(expected, 123, 1);
|
||||
client.sendKey(123, 'FooBar', true);
|
||||
expect(client._sock).to.have.sent(expected._sQ);
|
||||
@@ -287,7 +287,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
describe('#clipboardPasteFrom', function () {
|
||||
it('should send the given text in a paste event', function () {
|
||||
const expected = {_sQ: new Uint8Array(11), _sQlen: 0,
|
||||
_sQbufferSize: 11, flush: function () {}};
|
||||
_sQbufferSize: 11, flush: () => {}};
|
||||
RFB.messages.clientCutText(expected, 'abc');
|
||||
client.clipboardPasteFrom('abc');
|
||||
expect(client._sock).to.have.sent(expected._sQ);
|
||||
@@ -1615,7 +1615,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
}
|
||||
|
||||
it('should send an update request if there is sufficient data', function () {
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
||||
|
||||
client._framebufferUpdate = function () { return true; };
|
||||
@@ -1630,7 +1630,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should resume receiving an update if we previously did not have enough data', function () {
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
||||
|
||||
// just enough to set FBU.rects
|
||||
@@ -2040,8 +2040,8 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should respond correctly to ServerFence', function () {
|
||||
const expected_msg = {_sQ: new Uint8Array(16), _sQlen: 0, flush: function() {}};
|
||||
const incoming_msg = {_sQ: new Uint8Array(16), _sQlen: 0, flush: function() {}};
|
||||
const expected_msg = {_sQ: new Uint8Array(16), _sQlen: 0, flush: () => {}};
|
||||
const incoming_msg = {_sQ: new Uint8Array(16), _sQlen: 0, flush: () => {}};
|
||||
|
||||
const payload = "foo\x00ab9";
|
||||
|
||||
@@ -2065,7 +2065,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should enable continuous updates on first EndOfContinousUpdates', function () {
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: () => {}};
|
||||
|
||||
RFB.messages.enableContinuousUpdates(expected_msg, true, 0, 0, 640, 20);
|
||||
|
||||
@@ -2087,7 +2087,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should update continuous updates on resize', function () {
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
|
||||
const expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.enableContinuousUpdates(expected_msg, true, 0, 0, 90, 700);
|
||||
|
||||
client._resize(450, 160);
|
||||
@@ -2131,14 +2131,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should send a pointer event on mouse button presses', function () {
|
||||
client._handleMouseButton(10, 12, 1, 0x001);
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
|
||||
it('should send a mask of 1 on mousedown', function () {
|
||||
client._handleMouseButton(10, 12, 1, 0x001);
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
@@ -2146,14 +2146,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
it('should send a mask of 0 on mouseup', function () {
|
||||
client._mouse_buttonMask = 0x001;
|
||||
client._handleMouseButton(10, 12, 0, 0x001);
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
|
||||
it('should send a pointer event on mouse movement', function () {
|
||||
client._handleMouseMove(10, 12);
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
@@ -2161,7 +2161,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
it('should set the button mask so that future mouse movements use it', function () {
|
||||
client._handleMouseButton(10, 12, 1, 0x010);
|
||||
client._handleMouseMove(13, 9);
|
||||
const pointer_msg = {_sQ: new Uint8Array(12), _sQlen: 0, flush: function () {}};
|
||||
const pointer_msg = {_sQ: new Uint8Array(12), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x010);
|
||||
RFB.messages.pointerEvent(pointer_msg, 13, 9, 0x010);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
@@ -2171,7 +2171,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
describe('Keyboard Event Handlers', function () {
|
||||
it('should send a key message on a key press', function () {
|
||||
client._handleKeyEvent(0x41, 'KeyA', true);
|
||||
const key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
|
||||
const key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}};
|
||||
RFB.messages.keyEvent(key_msg, 0x41, 1);
|
||||
expect(client._sock).to.have.sent(key_msg._sQ);
|
||||
});
|
||||
|
||||
@@ -117,9 +117,9 @@ describe('WebUtil', function() {
|
||||
window.chrome = {
|
||||
storage: {
|
||||
sync: {
|
||||
get: function(cb){ cb(settings); },
|
||||
set: function(){},
|
||||
remove: function() {}
|
||||
get(cb){ cb(settings); },
|
||||
set(){},
|
||||
remove() {}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user