diff options
author | Juanjo Diaz <juanjo.diazmo@gmail.com> | 2018-07-05 21:31:56 +0200 |
---|---|---|
committer | Juanjo Diaz <juanjo.diazmo@gmail.com> | 2018-07-12 19:06:57 +0200 |
commit | 0e4808bf6f3165f7daa1282af445f6ea7e60de55 (patch) | |
tree | 956ae93dd7725a7f9ae92ed4d33a477402688378 /tests/fake.websocket.js | |
parent | 67fefcf184c1f291292027a785b333ba1a16f0c9 (diff) | |
download | novnc-0e4808bf6f3165f7daa1282af445f6ea7e60de55.tar.gz |
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: () => { ... } }`
Diffstat (limited to 'tests/fake.websocket.js')
-rw-r--r-- | tests/fake.websocket.js | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/tests/fake.websocket.js b/tests/fake.websocket.js index 2e28494..e0290ed 100644 --- a/tests/fake.websocket.js +++ b/tests/fake.websocket.js @@ -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._send_queue = new Uint8Array(20000); - this.readyState = FakeWebSocket.CONNECTING; - this.bufferedAmount = 0; + this.readyState = FakeWebSocket.CONNECTING; + this.bufferedAmount = 0; - this.__is_fake = true; -} + 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; |