diff --git a/.eslintrc b/.eslintrc index 900a7186..4b50d2ff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -44,5 +44,6 @@ "named": "never", "asyncArrow": "always" }], "switch-colon-spacing": ["error"], + "camelcase": ["error", { allow: ["^XK_", "^XF86XK_"] }], } } diff --git a/app/ui.js b/app/ui.js index 7207b2ff..a039e94b 100644 --- a/app/ui.js +++ b/app/ui.js @@ -37,9 +37,9 @@ const UI = { lastKeyboardinput: null, defaultKeyboardinputLen: 100, - inhibit_reconnect: true, - reconnect_callback: null, - reconnect_password: null, + inhibitReconnect: true, + reconnectCallback: null, + reconnectPassword: null, prime() { return WebUtil.initSettings().then(() => { @@ -394,25 +394,25 @@ const UI = { document.documentElement.classList.remove("noVNC_disconnecting"); document.documentElement.classList.remove("noVNC_reconnecting"); - const transition_elem = document.getElementById("noVNC_transition_text"); + const transitionElem = document.getElementById("noVNC_transition_text"); switch (state) { case 'init': break; case 'connecting': - transition_elem.textContent = _("Connecting..."); + transitionElem.textContent = _("Connecting..."); document.documentElement.classList.add("noVNC_connecting"); break; case 'connected': document.documentElement.classList.add("noVNC_connected"); break; case 'disconnecting': - transition_elem.textContent = _("Disconnecting..."); + transitionElem.textContent = _("Disconnecting..."); document.documentElement.classList.add("noVNC_disconnecting"); break; case 'disconnected': break; case 'reconnecting': - transition_elem.textContent = _("Reconnecting..."); + transitionElem.textContent = _("Reconnecting..."); document.documentElement.classList.add("noVNC_reconnecting"); break; default: @@ -452,11 +452,11 @@ const UI = { .classList.remove('noVNC_open'); }, - showStatus(text, status_type, time) { + showStatus(text, statusType, time) { const statusElem = document.getElementById('noVNC_status'); - if (typeof status_type === 'undefined') { - status_type = 'normal'; + if (typeof statusType === 'undefined') { + statusType = 'normal'; } // Don't overwrite more severe visible statuses and never @@ -466,14 +466,14 @@ const UI = { return; } if (statusElem.classList.contains("noVNC_status_warn") && - status_type === 'normal') { + statusType === 'normal') { return; } } clearTimeout(UI.statusTimeout); - switch (status_type) { + switch (statusType) { case 'error': statusElem.classList.remove("noVNC_status_warn"); statusElem.classList.remove("noVNC_status_normal"); @@ -503,7 +503,7 @@ const UI = { } // Error messages do not timeout - if (status_type !== 'error') { + if (statusType !== 'error') { UI.statusTimeout = window.setTimeout(UI.hideStatus, time); } }, @@ -1003,7 +1003,7 @@ const UI = { if (typeof password === 'undefined') { password = WebUtil.getConfigVar('password'); - UI.reconnect_password = password; + UI.reconnectPassword = password; } if (password === null) { @@ -1060,7 +1060,7 @@ const UI = { UI.connected = false; // Disable automatic reconnecting - UI.inhibit_reconnect = true; + UI.inhibitReconnect = true; UI.updateVisualState('disconnecting'); @@ -1068,20 +1068,20 @@ const UI = { }, reconnect() { - UI.reconnect_callback = null; + UI.reconnectCallback = null; // if reconnect has been disabled in the meantime, do nothing. - if (UI.inhibit_reconnect) { + if (UI.inhibitReconnect) { return; } - UI.connect(null, UI.reconnect_password); + UI.connect(null, UI.reconnectPassword); }, cancelReconnect() { - if (UI.reconnect_callback !== null) { - clearTimeout(UI.reconnect_callback); - UI.reconnect_callback = null; + if (UI.reconnectCallback !== null) { + clearTimeout(UI.reconnectCallback); + UI.reconnectCallback = null; } UI.updateVisualState('disconnected'); @@ -1092,7 +1092,7 @@ const UI = { connectFinished(e) { UI.connected = true; - UI.inhibit_reconnect = false; + UI.inhibitReconnect = false; let msg; if (UI.getSetting('encrypt')) { @@ -1126,11 +1126,11 @@ const UI = { } else { UI.showStatus(_("Failed to connect to server"), 'error'); } - } else if (UI.getSetting('reconnect', false) === true && !UI.inhibit_reconnect) { + } else if (UI.getSetting('reconnect', false) === true && !UI.inhibitReconnect) { UI.updateVisualState('reconnecting'); const delay = parseInt(UI.getSetting('reconnect_delay')); - UI.reconnect_callback = setTimeout(UI.reconnect, delay); + UI.reconnectCallback = setTimeout(UI.reconnect, delay); return; } else { UI.updateVisualState('disconnected'); @@ -1203,7 +1203,7 @@ const UI = { inputElemPassword.value = ""; UI.rfb.sendCredentials({ username: username, password: password }); - UI.reconnect_password = password; + UI.reconnectPassword = password; document.getElementById('noVNC_credentials_dlg') .classList.remove('noVNC_open'); }, @@ -1634,8 +1634,8 @@ const UI = { * ------v------*/ setMouseButton(num) { - const view_only = UI.rfb.viewOnly; - if (UI.rfb && !view_only) { + const viewOnly = UI.rfb.viewOnly; + if (UI.rfb && !viewOnly) { UI.rfb.touchButton = num; } @@ -1643,7 +1643,7 @@ const UI = { for (let b = 0; b < blist.length; b++) { const button = document.getElementById('noVNC_mouse_button' + blist[b]); - if (blist[b] === num && !view_only) { + if (blist[b] === num && !viewOnly) { button.classList.remove("noVNC_hidden"); } else { button.classList.add("noVNC_hidden"); @@ -1683,7 +1683,7 @@ const UI = { }, updateLogging() { - WebUtil.init_logging(UI.getSetting('logging')); + WebUtil.initLogging(UI.getSetting('logging')); }, updateDesktopName(e) { diff --git a/app/webutil.js b/app/webutil.js index e552d421..a099f9d7 100644 --- a/app/webutil.js +++ b/app/webutil.js @@ -6,16 +6,16 @@ * See README.md for usage and integration instructions. */ -import { init_logging as main_init_logging } from '../core/util/logging.js'; +import { initLogging as mainInitLogging } from '../core/util/logging.js'; // init log level reading the logging HTTP param -export function init_logging(level) { +export function initLogging(level) { "use strict"; if (typeof level !== "undefined") { - main_init_logging(level); + mainInitLogging(level); } else { const param = document.location.href.match(/logging=([A-Za-z0-9._-]*)/); - main_init_logging(param || undefined); + mainInitLogging(param || undefined); } } @@ -184,7 +184,7 @@ export function injectParamIfMissing(path, param, value) { const elem = document.createElement('a'); elem.href = path; - const param_eq = encodeURIComponent(param) + "="; + const paramEq = encodeURIComponent(param) + "="; let query; if (elem.search) { query = elem.search.slice(1).split('&'); @@ -192,8 +192,8 @@ export function injectParamIfMissing(path, param, value) { query = []; } - if (!query.some(v => v.startsWith(param_eq))) { - query.push(param_eq + encodeURIComponent(value)); + if (!query.some(v => v.startsWith(paramEq))) { + query.push(paramEq + encodeURIComponent(value)); elem.search = "?" + query.join("&"); } diff --git a/core/base64.js b/core/base64.js index 88e74546..db572c2d 100644 --- a/core/base64.js +++ b/core/base64.js @@ -57,12 +57,12 @@ export default { /* eslint-enable comma-spacing */ decode(data, offset = 0) { - let data_length = data.indexOf('=') - offset; - if (data_length < 0) { data_length = data.length - offset; } + let dataLength = data.indexOf('=') - offset; + if (dataLength < 0) { dataLength = data.length - offset; } /* Every four characters is 3 resulting numbers */ - const result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5); - const result = new Array(result_length); + const resultLength = (dataLength >> 2) * 3 + Math.floor((dataLength % 4) / 1.5); + const result = new Array(resultLength); // Convert one by one. diff --git a/core/decoders/hextile.js b/core/decoders/hextile.js index b762060d..8dbe8092 100644 --- a/core/decoders/hextile.js +++ b/core/decoders/hextile.js @@ -17,10 +17,10 @@ export default class HextileDecoder { decodeRect(x, y, width, height, sock, display, depth) { if (this._tiles === 0) { - this._tiles_x = Math.ceil(width / 16); - this._tiles_y = Math.ceil(height / 16); - this._total_tiles = this._tiles_x * this._tiles_y; - this._tiles = this._total_tiles; + this._tilesX = Math.ceil(width / 16); + this._tilesY = Math.ceil(height / 16); + this._totalTiles = this._tilesX * this._tilesY; + this._tiles = this._totalTiles; } while (this._tiles > 0) { @@ -39,11 +39,11 @@ export default class HextileDecoder { subencoding + ")"); } - const curr_tile = this._total_tiles - this._tiles; - const tile_x = curr_tile % this._tiles_x; - const tile_y = Math.floor(curr_tile / this._tiles_x); - const tx = x + tile_x * 16; - const ty = y + tile_y * 16; + const currTile = this._totalTiles - this._tiles; + const tileX = currTile % this._tilesX; + const tileY = Math.floor(currTile / this._tilesX); + const tx = x + tileX * 16; + const ty = y + tileY * 16; const tw = Math.min(16, (x + width) - tx); const th = Math.min(16, (y + height) - ty); diff --git a/core/decoders/raw.js b/core/decoders/raw.js index 0e806d3c..4d84d7d1 100644 --- a/core/decoders/raw.js +++ b/core/decoders/raw.js @@ -24,15 +24,15 @@ export default class RawDecoder { return false; } - const cur_y = y + (height - this._lines); - const curr_height = Math.min(this._lines, - Math.floor(sock.rQlen / bytesPerLine)); + const curY = y + (height - this._lines); + const currHeight = Math.min(this._lines, + Math.floor(sock.rQlen / bytesPerLine)); let data = sock.rQ; let index = sock.rQi; // Convert data if needed if (depth == 8) { - const pixels = width * curr_height; + const pixels = width * currHeight; const newdata = new Uint8Array(pixels * 4); for (let i = 0; i < pixels; i++) { newdata[i * 4 + 0] = ((data[index + i] >> 0) & 0x3) * 255 / 3; @@ -44,9 +44,9 @@ export default class RawDecoder { index = 0; } - display.blitImage(x, cur_y, width, curr_height, data, index); - sock.rQskipBytes(curr_height * bytesPerLine); - this._lines -= curr_height; + display.blitImage(x, curY, width, currHeight, data, index); + sock.rQskipBytes(currHeight * bytesPerLine); + this._lines -= currHeight; if (this._lines > 0) { return false; } diff --git a/core/deflator.js b/core/deflator.js index ad3d0fb7..fe2a8f70 100644 --- a/core/deflator.js +++ b/core/deflator.js @@ -21,12 +21,14 @@ export default class Deflator { } deflate(inData) { + /* eslint-disable camelcase */ this.strm.input = inData; this.strm.avail_in = this.strm.input.length; this.strm.next_in = 0; this.strm.output = this.outputBuffer; this.strm.avail_out = this.chunkSize; this.strm.next_out = 0; + /* eslint-enable camelcase */ let lastRet = deflate(this.strm, Z_FULL_FLUSH); let outData = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); @@ -41,9 +43,11 @@ export default class Deflator { let chunks = [outData]; let totalLen = outData.length; do { + /* eslint-disable camelcase */ this.strm.output = new Uint8Array(this.chunkSize); this.strm.next_out = 0; this.strm.avail_out = this.chunkSize; + /* eslint-enable camelcase */ lastRet = deflate(this.strm, Z_FULL_FLUSH); @@ -69,9 +73,11 @@ export default class Deflator { outData = newData; } + /* eslint-disable camelcase */ this.strm.input = null; this.strm.avail_in = 0; this.strm.next_in = 0; + /* eslint-enable camelcase */ return outData; } diff --git a/core/display.js b/core/display.js index 3dd5fcea..7b7f5363 100644 --- a/core/display.js +++ b/core/display.js @@ -13,20 +13,19 @@ import { supportsImageMetadata } from './util/browser.js'; export default class Display { constructor(target) { this._drawCtx = null; - this._c_forceCanvas = false; this._renderQ = []; // queue drawing actions for in-oder rendering this._flushing = false; // the full frame buffer (logical canvas) size - this._fb_width = 0; - this._fb_height = 0; + this._fbWidth = 0; + this._fbHeight = 0; this._prevDrawStyle = ""; this._tile = null; this._tile16x16 = null; - this._tile_x = 0; - this._tile_y = 0; + this._tileX = 0; + this._tileY = 0; Log.Debug(">> Display.constructor"); @@ -95,11 +94,11 @@ export default class Display { } get width() { - return this._fb_width; + return this._fbWidth; } get height() { - return this._fb_height; + return this._fbHeight; } // ===== PUBLIC METHODS ===== @@ -122,15 +121,15 @@ export default class Display { if (deltaX < 0 && vp.x + deltaX < 0) { deltaX = -vp.x; } - if (vx2 + deltaX >= this._fb_width) { - deltaX -= vx2 + deltaX - this._fb_width + 1; + if (vx2 + deltaX >= this._fbWidth) { + deltaX -= vx2 + deltaX - this._fbWidth + 1; } if (vp.y + deltaY < 0) { deltaY = -vp.y; } - if (vy2 + deltaY >= this._fb_height) { - deltaY -= (vy2 + deltaY - this._fb_height + 1); + if (vy2 + deltaY >= this._fbHeight) { + deltaY -= (vy2 + deltaY - this._fbHeight + 1); } if (deltaX === 0 && deltaY === 0) { @@ -153,18 +152,18 @@ export default class Display { typeof(height) === "undefined") { Log.Debug("Setting viewport to full display region"); - width = this._fb_width; - height = this._fb_height; + width = this._fbWidth; + height = this._fbHeight; } width = Math.floor(width); height = Math.floor(height); - if (width > this._fb_width) { - width = this._fb_width; + if (width > this._fbWidth) { + width = this._fbWidth; } - if (height > this._fb_height) { - height = this._fb_height; + if (height > this._fbHeight) { + height = this._fbHeight; } const vp = this._viewportLoc; @@ -204,8 +203,8 @@ export default class Display { resize(width, height) { this._prevDrawStyle = ""; - this._fb_width = width; - this._fb_height = height; + this._fbWidth = width; + this._fbHeight = height; const canvas = this._backbuffer; if (canvas.width !== width || canvas.height !== height) { @@ -253,9 +252,9 @@ export default class Display { // Update the visible canvas with the contents of the // rendering canvas - flip(from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { - this._renderQ_push({ + flip(fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { + this._renderQPush({ 'type': 'flip' }); } else { @@ -311,9 +310,9 @@ export default class Display { } } - fillRect(x, y, width, height, color, from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { - this._renderQ_push({ + fillRect(x, y, width, height, color, fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { + this._renderQPush({ 'type': 'fill', 'x': x, 'y': y, @@ -328,14 +327,14 @@ export default class Display { } } - copyImage(old_x, old_y, new_x, new_y, w, h, from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { - this._renderQ_push({ + copyImage(oldX, oldY, newX, newY, w, h, fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { + this._renderQPush({ 'type': 'copy', - 'old_x': old_x, - 'old_y': old_y, - 'x': new_x, - 'y': new_y, + 'oldX': oldX, + 'oldY': oldY, + 'x': newX, + 'y': newY, 'width': w, 'height': h, }); @@ -353,9 +352,9 @@ export default class Display { this._drawCtx.imageSmoothingEnabled = false; this._drawCtx.drawImage(this._backbuffer, - old_x, old_y, w, h, - new_x, new_y, w, h); - this._damage(new_x, new_y, w, h); + oldX, oldY, w, h, + newX, newY, w, h); + this._damage(newX, newY, w, h); } } @@ -368,7 +367,7 @@ export default class Display { const img = new Image(); img.src = "data: " + mime + ";base64," + Base64.encode(arr); - this._renderQ_push({ + this._renderQPush({ 'type': 'img', 'img': img, 'x': x, @@ -380,8 +379,8 @@ export default class Display { // start updating a tile startTile(x, y, width, height, color) { - this._tile_x = x; - this._tile_y = y; + this._tileX = x; + this._tileY = y; if (width === 16 && height === 16) { this._tile = this._tile16x16; } else { @@ -424,21 +423,21 @@ export default class Display { // draw the current tile to the screen finishTile() { - this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y); - this._damage(this._tile_x, this._tile_y, + this._drawCtx.putImageData(this._tile, this._tileX, this._tileY); + this._damage(this._tileX, this._tileY, this._tile.width, this._tile.height); } - blitImage(x, y, width, height, arr, offset, from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { + blitImage(x, y, width, height, arr, offset, fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { // NB(directxman12): it's technically more performant here to use preallocated arrays, // but it's a lot of extra work for not a lot of payoff -- if we're using the render queue, // this probably isn't getting called *nearly* as much - const new_arr = new Uint8Array(width * height * 4); - new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length)); - this._renderQ_push({ + const newArr = new Uint8Array(width * height * 4); + newArr.set(new Uint8Array(arr.buffer, 0, newArr.length)); + this._renderQPush({ 'type': 'blit', - 'data': new_arr, + 'data': newArr, 'x': x, 'y': y, 'width': width, @@ -449,16 +448,16 @@ export default class Display { } } - blitRgbImage(x, y, width, height, arr, offset, from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { + blitRgbImage(x, y, width, height, arr, offset, fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { // NB(directxman12): it's technically more performant here to use preallocated arrays, // but it's a lot of extra work for not a lot of payoff -- if we're using the render queue, // this probably isn't getting called *nearly* as much - const new_arr = new Uint8Array(width * height * 3); - new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length)); - this._renderQ_push({ + const newArr = new Uint8Array(width * height * 3); + newArr.set(new Uint8Array(arr.buffer, 0, newArr.length)); + this._renderQPush({ 'type': 'blitRgb', - 'data': new_arr, + 'data': newArr, 'x': x, 'y': y, 'width': width, @@ -469,16 +468,16 @@ export default class Display { } } - blitRgbxImage(x, y, width, height, arr, offset, from_queue) { - if (this._renderQ.length !== 0 && !from_queue) { + blitRgbxImage(x, y, width, height, arr, offset, fromQueue) { + if (this._renderQ.length !== 0 && !fromQueue) { // NB(directxman12): it's technically more performant here to use preallocated arrays, // but it's a lot of extra work for not a lot of payoff -- if we're using the render queue, // this probably isn't getting called *nearly* as much - const new_arr = new Uint8Array(width * height * 4); - new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length)); - this._renderQ_push({ + const newArr = new Uint8Array(width * height * 4); + newArr.set(new Uint8Array(arr.buffer, 0, newArr.length)); + this._renderQPush({ 'type': 'blitRgbx', - 'data': new_arr, + 'data': newArr, 'x': x, 'y': y, 'width': width, @@ -583,23 +582,23 @@ export default class Display { this._damage(x, y, img.width, img.height); } - _renderQ_push(action) { + _renderQPush(action) { this._renderQ.push(action); if (this._renderQ.length === 1) { // If this can be rendered immediately it will be, otherwise // the scanner will wait for the relevant event - this._scan_renderQ(); + this._scanRenderQ(); } } - _resume_renderQ() { + _resumeRenderQ() { // "this" is the object that is ready, not the // display object - this.removeEventListener('load', this._noVNC_display._resume_renderQ); - this._noVNC_display._scan_renderQ(); + this.removeEventListener('load', this._noVNCDisplay._resumeRenderQ); + this._noVNCDisplay._scanRenderQ(); } - _scan_renderQ() { + _scanRenderQ() { let ready = true; while (ready && this._renderQ.length > 0) { const a = this._renderQ[0]; @@ -608,7 +607,7 @@ export default class Display { this.flip(true); break; case 'copy': - this.copyImage(a.old_x, a.old_y, a.x, a.y, a.width, a.height, true); + this.copyImage(a.oldX, a.oldY, a.x, a.y, a.width, a.height, true); break; case 'fill': this.fillRect(a.x, a.y, a.width, a.height, a.color, true); @@ -633,8 +632,8 @@ export default class Display { } this.drawImage(a.img, a.x, a.y); } else { - a.img._noVNC_display = this; - a.img.addEventListener('load', this._resume_renderQ); + a.img._noVNCDisplay = this; + a.img.addEventListener('load', this._resumeRenderQ); // We need to wait for this image to 'load' // to keep things in-order ready = false; diff --git a/core/inflator.js b/core/inflator.js index e61a5bd4..4b337607 100644 --- a/core/inflator.js +++ b/core/inflator.js @@ -22,6 +22,7 @@ export default class Inflate { setInput(data) { if (!data) { //FIXME: flush remaining data. + /* eslint-disable camelcase */ this.strm.input = null; this.strm.avail_in = 0; this.strm.next_in = 0; @@ -29,6 +30,7 @@ export default class Inflate { this.strm.input = data; this.strm.avail_in = this.strm.input.length; this.strm.next_in = 0; + /* eslint-enable camelcase */ } } @@ -41,8 +43,10 @@ export default class Inflate { this.strm.output = new Uint8Array(this.chunkSize); } + /* eslint-disable camelcase */ this.strm.next_out = 0; this.strm.avail_out = expected; + /* eslint-enable camelcase */ let ret = inflate(this.strm, 0); // Flush argument not used. if (ret < 0) { diff --git a/core/rfb.js b/core/rfb.js index 07d5bc06..ca50779e 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -947,7 +947,7 @@ export default class RFB extends EventTargetMixin { while (repeaterID.length < 250) { repeaterID += "\0"; } - this._sock.send_string(repeaterID); + this._sock.sendString(repeaterID); return true; } @@ -957,7 +957,7 @@ export default class RFB extends EventTargetMixin { const cversion = "00" + parseInt(this._rfbVersion, 10) + ".00" + ((this._rfbVersion * 10) % 10); - this._sock.send_string("RFB " + cversion + "\n"); + this._sock.sendString("RFB " + cversion + "\n"); Log.Debug('Sent ProtocolVersion: ' + cversion); this._rfbInitState = 'Security'; @@ -1071,7 +1071,7 @@ export default class RFB extends EventTargetMixin { String.fromCharCode(this._rfbCredentials.target.length) + this._rfbCredentials.username + this._rfbCredentials.target; - this._sock.send_string(xvpAuthStr); + this._sock.sendString(xvpAuthStr); this._rfbAuthScheme = 2; return this._negotiateAuthentication(); } @@ -1156,8 +1156,8 @@ export default class RFB extends EventTargetMixin { // XXX we assume lengths are <= 255 (should not be an issue in the real world) this._sock.send([0, 0, 0, user.length]); this._sock.send([0, 0, 0, pass.length]); - this._sock.send_string(user); - this._sock.send_string(pass); + this._sock.sendString(user); + this._sock.sendString(pass); this._rfbInitState = "SecurityResult"; return true; @@ -1193,8 +1193,8 @@ export default class RFB extends EventTargetMixin { this._sock.send([0, 0, 0, this._rfbCredentials.username.length]); this._sock.send([0, 0, 0, this._rfbCredentials.password.length]); - this._sock.send_string(this._rfbCredentials.username); - this._sock.send_string(this._rfbCredentials.password); + this._sock.sendString(this._rfbCredentials.username); + this._sock.sendString(this._rfbCredentials.password); this._rfbInitState = "SecurityResult"; return true; } diff --git a/core/util/logging.js b/core/util/logging.js index 8978a075..fe449e93 100644 --- a/core/util/logging.js +++ b/core/util/logging.js @@ -10,18 +10,18 @@ * Logging/debug routines */ -let _log_level = 'warn'; +let _logLevel = 'warn'; let Debug = () => {}; let Info = () => {}; let Warn = () => {}; let Error = () => {}; -export function init_logging(level) { +export function initLogging(level) { if (typeof level === 'undefined') { - level = _log_level; + level = _logLevel; } else { - _log_level = level; + _logLevel = level; } Debug = Info = Warn = Error = () => {}; @@ -46,11 +46,11 @@ export function init_logging(level) { } } -export function get_logging() { - return _log_level; +export function getLogging() { + return _logLevel; } export { Debug, Info, Warn, Error }; // Initialize logging level -init_logging(); +initLogging(); diff --git a/core/websock.js b/core/websock.js index 8fef0b28..3156aed6 100644 --- a/core/websock.js +++ b/core/websock.js @@ -144,7 +144,7 @@ export default class Websock { flush() { if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) { - this._websocket.send(this._encode_message()); + this._websocket.send(this._encodeMessage()); this._sQlen = 0; } } @@ -155,7 +155,7 @@ export default class Websock { this.flush(); } - send_string(str) { + sendString(str) { this.send(str.split('').map(chr => chr.charCodeAt(0))); } @@ -168,13 +168,13 @@ export default class Websock { this._eventHandlers[evt] = handler; } - _allocate_buffers() { + _allocateBuffers() { this._rQ = new Uint8Array(this._rQbufferSize); this._sQ = new Uint8Array(this._sQbufferSize); } init() { - this._allocate_buffers(); + this._allocateBuffers(); this._rQi = 0; this._websocket = null; } @@ -185,7 +185,7 @@ export default class Websock { this._websocket = new WebSocket(uri, protocols); this._websocket.binaryType = 'arraybuffer'; - this._websocket.onmessage = this._recv_message.bind(this); + this._websocket.onmessage = this._recvMessage.bind(this); this._websocket.onopen = () => { Log.Debug('>> WebSock.onopen'); if (this._websocket.protocol) { @@ -220,7 +220,7 @@ export default class Websock { } // private methods - _encode_message() { + _encodeMessage() { // Put in a binary arraybuffer // according to the spec, you can send ArrayBufferViews with the send method return new Uint8Array(this._sQ.buffer, 0, this._sQlen); @@ -231,30 +231,30 @@ export default class Websock { // The function also expands the receive que if needed, and for // performance reasons we combine these two actions to avoid // unneccessary copying. - _expand_compact_rQ(min_fit) { + _expandCompactRQ(minFit) { // if we're using less than 1/8th of the buffer even with the incoming bytes, compact in place // instead of resizing - const required_buffer_size = (this._rQlen - this._rQi + min_fit) * 8; - const resizeNeeded = this._rQbufferSize < required_buffer_size; + const requiredBufferSize = (this._rQlen - this._rQi + minFit) * 8; + const resizeNeeded = this._rQbufferSize < requiredBufferSize; if (resizeNeeded) { // Make sure we always *at least* double the buffer size, and have at least space for 8x // the current amount of data - this._rQbufferSize = Math.max(this._rQbufferSize * 2, required_buffer_size); + this._rQbufferSize = Math.max(this._rQbufferSize * 2, requiredBufferSize); } // we don't want to grow unboundedly if (this._rQbufferSize > MAX_RQ_GROW_SIZE) { this._rQbufferSize = MAX_RQ_GROW_SIZE; - if (this._rQbufferSize - this.rQlen < min_fit) { + if (this._rQbufferSize - this.rQlen < minFit) { throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit"); } } if (resizeNeeded) { - const old_rQbuffer = this._rQ.buffer; + const oldRQbuffer = this._rQ.buffer; this._rQ = new Uint8Array(this._rQbufferSize); - this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi, this._rQlen - this._rQi)); + this._rQ.set(new Uint8Array(oldRQbuffer, this._rQi, this._rQlen - this._rQi)); } else { if (ENABLE_COPYWITHIN) { this._rQ.copyWithin(0, this._rQi, this._rQlen); @@ -268,17 +268,17 @@ export default class Websock { } // push arraybuffer values onto the end of the receive que - _decode_message(data) { + _DecodeMessage(data) { const u8 = new Uint8Array(data); if (u8.length > this._rQbufferSize - this._rQlen) { - this._expand_compact_rQ(u8.length); + this._expandCompactRQ(u8.length); } this._rQ.set(u8, this._rQlen); this._rQlen += u8.length; } - _recv_message(e) { - this._decode_message(e.data); + _recvMessage(e) { + this._DecodeMessage(e.data); if (this.rQlen > 0) { this._eventHandlers.message(); if (this._rQlen == this._rQi) { diff --git a/tests/assertions.js b/tests/assertions.js index 07a5c297..05957c08 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -1,32 +1,32 @@ // noVNC specific assertions chai.use(function (_chai, utils) { - _chai.Assertion.addMethod('displayed', function (target_data) { + _chai.Assertion.addMethod('displayed', function (targetData) { const obj = this._obj; const ctx = obj._target.getContext('2d'); - const data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data; + const dataCl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data; // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that - const data = new Uint8Array(data_cl); - const len = data_cl.length; - new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size"); + const data = new Uint8Array(dataCl); + const len = dataCl.length; + new chai.Assertion(len).to.be.equal(targetData.length, "unexpected display size"); let same = true; for (let i = 0; i < len; i++) { - if (data[i] != target_data[i]) { + if (data[i] != targetData[i]) { same = false; break; } } if (!same) { // eslint-disable-next-line no-console - console.log("expected data: %o, actual data: %o", target_data, data); + console.log("expected data: %o, actual data: %o", targetData, data); } this.assert(same, "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}", "expected #{this} not to have displayed the image #{act}", - target_data, + targetData, data); }); - _chai.Assertion.addMethod('sent', function (target_data) { + _chai.Assertion.addMethod('sent', function (targetData) { const obj = this._obj; obj.inspect = () => { const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen), @@ -34,13 +34,13 @@ chai.use(function (_chai, utils) { res.prototype = obj; return res; }; - const data = obj._websocket._get_sent_data(); + const data = obj._websocket._getSentData(); let same = true; - if (data.length != target_data.length) { + if (data.length != targetData.length) { same = false; } else { for (let i = 0; i < data.length; i++) { - if (data[i] != target_data[i]) { + if (data[i] != targetData[i]) { same = false; break; } @@ -48,12 +48,12 @@ chai.use(function (_chai, utils) { } if (!same) { // eslint-disable-next-line no-console - console.log("expected data: %o, actual data: %o", target_data, data); + console.log("expected data: %o, actual data: %o", targetData, data); } this.assert(same, "expected #{this} to have sent the data #{exp}, but it actually sent #{act}", "expected #{this} not to have sent the data #{act}", - Array.prototype.slice.call(target_data), + Array.prototype.slice.call(targetData), Array.prototype.slice.call(data)); }); diff --git a/tests/fake.websocket.js b/tests/fake.websocket.js index 68ab3f84..623b25e4 100644 --- a/tests/fake.websocket.js +++ b/tests/fake.websocket.js @@ -1,7 +1,7 @@ import Base64 from '../core/base64.js'; // PhantomJS can't create Event objects directly, so we need to use this -function make_event(name, props) { +function makeEvent(name, props) { const evt = document.createEvent('Event'); evt.initEvent(name, true, true); if (props) { @@ -24,18 +24,18 @@ export default class FakeWebSocket { this.protocol = protocols[0]; } - this._send_queue = new Uint8Array(20000); + this._sendQueue = new Uint8Array(20000); this.readyState = FakeWebSocket.CONNECTING; this.bufferedAmount = 0; - this.__is_fake = true; + this._isFake = true; } close(code, reason) { this.readyState = FakeWebSocket.CLOSED; if (this.onclose) { - this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true })); + this.onclose(makeEvent("close", { 'code': code, 'reason': reason, 'wasClean': true })); } } @@ -45,12 +45,12 @@ export default class FakeWebSocket { } else { data = new Uint8Array(data); } - this._send_queue.set(data, this.bufferedAmount); + this._sendQueue.set(data, this.bufferedAmount); this.bufferedAmount += data.length; } - _get_sent_data() { - const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount); + _getSentData() { + const res = new Uint8Array(this._sendQueue.buffer, 0, this.bufferedAmount); this.bufferedAmount = 0; return res; } @@ -58,16 +58,16 @@ export default class FakeWebSocket { _open() { this.readyState = FakeWebSocket.OPEN; if (this.onopen) { - this.onopen(make_event('open')); + this.onopen(makeEvent('open')); } } - _receive_data(data) { + _receiveData(data) { // Break apart the data to expose bugs where we assume data is // neatly packaged for (let i = 0;i < data.length;i++) { let buf = data.subarray(i, i+1); - this.onmessage(make_event("message", { 'data': buf })); + this.onmessage(makeEvent("message", { 'data': buf })); } } } @@ -77,20 +77,20 @@ FakeWebSocket.CONNECTING = WebSocket.CONNECTING; FakeWebSocket.CLOSING = WebSocket.CLOSING; FakeWebSocket.CLOSED = WebSocket.CLOSED; -FakeWebSocket.__is_fake = true; +FakeWebSocket._isFake = true; FakeWebSocket.replace = () => { - if (!WebSocket.__is_fake) { - const real_version = WebSocket; + if (!WebSocket._isFake) { + const realVersion = WebSocket; // eslint-disable-next-line no-global-assign WebSocket = FakeWebSocket; - FakeWebSocket.__real_version = real_version; + FakeWebSocket._realVersion = realVersion; } }; FakeWebSocket.restore = () => { - if (WebSocket.__is_fake) { + if (WebSocket._isFake) { // eslint-disable-next-line no-global-assign - WebSocket = WebSocket.__real_version; + WebSocket = WebSocket._realVersion; } }; diff --git a/tests/playback-ui.js b/tests/playback-ui.js index 65c715a9..2cecb14c 100644 --- a/tests/playback-ui.js +++ b/tests/playback-ui.js @@ -1,4 +1,4 @@ -/* global VNC_frame_data, VNC_frame_encoding */ +/* global vncFrameData, vncFrameEncoding */ import * as WebUtil from '../app/webutil.js'; import RecordingPlayer from './playback.js'; @@ -41,7 +41,7 @@ function enableUI() { document.getElementById('mode1').checked = true; } - message("Loaded " + VNC_frame_data.length + " frames"); + message("Loaded " + vncFrameData.length + " frames"); const startButton = document.getElementById('startButton'); startButton.disabled = false; @@ -49,12 +49,12 @@ function enableUI() { message("Converting..."); - frames = VNC_frame_data; + frames = vncFrameData; let encoding; // Only present in older recordings - if (window.VNC_frame_encoding) { - encoding = VNC_frame_encoding; + if (window.vncFrameEncoding) { + encoding = vncFrameEncoding; } else { let frame = frames[0]; let start = frame.indexOf('{', 1) + 1; @@ -102,7 +102,7 @@ class IterationPlayer { this._iteration = undefined; this._player = undefined; - this._start_time = undefined; + this._startTime = undefined; this._frames = frames; @@ -115,7 +115,7 @@ class IterationPlayer { start(realtime) { this._iteration = 0; - this._start_time = (new Date()).getTime(); + this._startTime = (new Date()).getTime(); this._realtime = realtime; @@ -139,7 +139,7 @@ class IterationPlayer { _finish() { const endTime = (new Date()).getTime(); - const totalDuration = endTime - this._start_time; + const totalDuration = endTime - this._startTime; const evt = new CustomEvent('finish', { detail: diff --git a/tests/playback.js b/tests/playback.js index 5bd8103a..d8d84c2c 100644 --- a/tests/playback.js +++ b/tests/playback.js @@ -49,10 +49,10 @@ export default class RecordingPlayer { this._disconnected = disconnected; this._rfb = undefined; - this._frame_length = this._frames.length; + this._frameLength = this._frames.length; - this._frame_index = 0; - this._start_time = undefined; + this._frameIndex = 0; + this._startTime = undefined; this._realtime = true; this._trafficManagement = true; @@ -72,8 +72,8 @@ export default class RecordingPlayer { this._enablePlaybackMode(); // reset the frame index and timer - this._frame_index = 0; - this._start_time = (new Date()).getTime(); + this._frameIndex = 0; + this._startTime = (new Date()).getTime(); this._realtime = realtime; this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement; @@ -97,22 +97,22 @@ export default class RecordingPlayer { _queueNextPacket() { if (!this._running) { return; } - let frame = this._frames[this._frame_index]; + let frame = this._frames[this._frameIndex]; // skip send frames - while (this._frame_index < this._frame_length && frame.fromClient) { - this._frame_index++; - frame = this._frames[this._frame_index]; + while (this._frameIndex < this._frameLength && frame.fromClient) { + this._frameIndex++; + frame = this._frames[this._frameIndex]; } - if (this._frame_index >= this._frame_length) { + if (this._frameIndex >= this._frameLength) { Log.Debug('Finished, no more frames'); this._finish(); return; } if (this._realtime) { - const toffset = (new Date()).getTime() - this._start_time; + const toffset = (new Date()).getTime() - this._startTime; let delay = frame.timestamp - toffset; if (delay < 1) delay = 1; @@ -134,10 +134,10 @@ export default class RecordingPlayer { return; } - const frame = this._frames[this._frame_index]; + const frame = this._frames[this._frameIndex]; this._rfb._sock._recv_message({'data': frame.data}); - this._frame_index++; + this._frameIndex++; this._queueNextPacket(); } @@ -155,13 +155,13 @@ export default class RecordingPlayer { this._running = false; this._rfb._sock._eventHandlers.close({code: 1000, reason: ""}); delete this._rfb; - this.onfinish((new Date()).getTime() - this._start_time); + this.onfinish((new Date()).getTime() - this._startTime); } } _handleDisconnect(evt) { this._running = false; - this._disconnected(evt.detail.clean, this._frame_index); + this._disconnected(evt.detail.clean, this._frameIndex); } _handleCredentials(evt) { diff --git a/tests/test.deflator.js b/tests/test.deflator.js index 2f2fab3a..12e8a46b 100644 --- a/tests/test.deflator.js +++ b/tests/test.deflator.js @@ -17,12 +17,14 @@ function _inflator(compText, expected) { strm.output = new Uint8Array(chunkSize); } + /* eslint-disable camelcase */ strm.input = compText; strm.avail_in = strm.input.length; strm.next_in = 0; strm.next_out = 0; strm.avail_out = expected.length; + /* eslint-enable camelcase */ let ret = inflate(strm, 0); diff --git a/tests/test.display.js b/tests/test.display.js index 594f9514..a853778a 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -4,28 +4,28 @@ import Base64 from '../core/base64.js'; import Display from '../core/display.js'; describe('Display/Canvas Helper', function () { - const checked_data = new Uint8Array([ + const checkedData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); - const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]); + const basicData = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]); - function make_image_canvas(input_data) { + function makeImageCanvas(inputData) { const canvas = document.createElement('canvas'); canvas.width = 4; canvas.height = 4; const ctx = canvas.getContext('2d'); const data = ctx.createImageData(4, 4); - for (let i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; } + for (let i = 0; i < checkedData.length; i++) { data.data[i] = inputData[i]; } ctx.putImageData(data, 0, 0); return canvas; } - function make_image_png(input_data) { - const canvas = make_image_canvas(input_data); + function makeImagePng(inputData) { + const canvas = makeImageCanvas(inputData); const url = canvas.toDataURL(); const data = url.split(",")[1]; return Base64.decode(data); @@ -44,11 +44,11 @@ describe('Display/Canvas Helper', function () { it('should take viewport location into consideration when drawing images', function () { display.resize(4, 4); display.viewportChangeSize(2, 2); - display.drawImage(make_image_canvas(basic_data), 1, 1); + display.drawImage(makeImageCanvas(basicData), 1, 1); display.flip(); const expected = new Uint8Array(16); - for (let i = 0; i < 8; i++) { expected[i] = basic_data[i]; } + for (let i = 0; i < 8; i++) { expected[i] = basicData[i]; } for (let i = 8; i < 16; i++) { expected[i] = 0; } expect(display).to.have.displayed(expected); }); @@ -123,8 +123,8 @@ describe('Display/Canvas Helper', function () { it('should change the size of the logical canvas', function () { display.resize(5, 7); - expect(display._fb_width).to.equal(5); - expect(display._fb_height).to.equal(7); + expect(display._fbWidth).to.equal(5); + expect(display._fbHeight).to.equal(7); }); it('should keep the framebuffer data', function () { @@ -275,7 +275,7 @@ describe('Display/Canvas Helper', function () { display.flip(); display.fillRect(0, 0, 4, 4, [0, 0xff, 0]); const expected = []; - for (let i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) { + for (let i = 0; i < 4 * display._fbWidth * display._fbHeight; i += 4) { expected[i] = 0xff; expected[i+1] = expected[i+2] = 0; expected[i+3] = 0xff; @@ -288,7 +288,7 @@ describe('Display/Canvas Helper', function () { display.fillRect(0, 0, 2, 2, [0xff, 0, 0]); display.fillRect(2, 2, 2, 2, [0xff, 0, 0]); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); it('should support copying an portion of the canvas via #copyImage', function () { @@ -296,14 +296,14 @@ describe('Display/Canvas Helper', function () { display.fillRect(0, 0, 2, 2, [0xff, 0, 0x00]); display.copyImage(0, 0, 2, 2, 2, 2); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); it('should support drawing images via #imageRect', function (done) { - display.imageRect(0, 0, 4, 4, "image/png", make_image_png(checked_data)); + display.imageRect(0, 0, 4, 4, "image/png", makeImagePng(checkedData)); display.flip(); display.onflush = () => { - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); done(); }; display.flush(); @@ -315,12 +315,12 @@ describe('Display/Canvas Helper', function () { display.subTile(2, 2, 2, 2, [0xff, 0, 0]); display.finishTile(); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); // We have a special cache for 16x16 tiles that we need to test it('should support drawing a 16x16 tile', function () { - const large_checked_data = new Uint8Array(16*16*4); + const largeCheckedData = new Uint8Array(16*16*4); display.resize(16, 16); for (let y = 0;y < 16;y++) { @@ -328,11 +328,11 @@ describe('Display/Canvas Helper', function () { let pixel; if ((x < 4) && (y < 4)) { // NB: of course IE11 doesn't support #slice on ArrayBufferViews... - pixel = Array.prototype.slice.call(checked_data, (y*4+x)*4, (y*4+x+1)*4); + pixel = Array.prototype.slice.call(checkedData, (y*4+x)*4, (y*4+x+1)*4); } else { pixel = [0, 0xff, 0, 255]; } - large_checked_data.set(pixel, (y*16+x)*4); + largeCheckedData.set(pixel, (y*16+x)*4); } } @@ -341,39 +341,39 @@ describe('Display/Canvas Helper', function () { display.subTile(2, 2, 2, 2, [0xff, 0, 0]); display.finishTile(); display.flip(); - expect(display).to.have.displayed(large_checked_data); + expect(display).to.have.displayed(largeCheckedData); }); it('should support drawing BGRX blit images with true color via #blitImage', function () { const data = []; for (let i = 0; i < 16; i++) { - data[i * 4] = checked_data[i * 4 + 2]; - data[i * 4 + 1] = checked_data[i * 4 + 1]; - data[i * 4 + 2] = checked_data[i * 4]; - data[i * 4 + 3] = checked_data[i * 4 + 3]; + data[i * 4] = checkedData[i * 4 + 2]; + data[i * 4 + 1] = checkedData[i * 4 + 1]; + data[i * 4 + 2] = checkedData[i * 4]; + data[i * 4 + 3] = checkedData[i * 4 + 3]; } display.blitImage(0, 0, 4, 4, data, 0); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); it('should support drawing RGB blit images with true color via #blitRgbImage', function () { const data = []; for (let i = 0; i < 16; i++) { - data[i * 3] = checked_data[i * 4]; - data[i * 3 + 1] = checked_data[i * 4 + 1]; - data[i * 3 + 2] = checked_data[i * 4 + 2]; + data[i * 3] = checkedData[i * 4]; + data[i * 3 + 1] = checkedData[i * 4 + 1]; + data[i * 3 + 2] = checkedData[i * 4 + 2]; } display.blitRgbImage(0, 0, 4, 4, data, 0); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); it('should support drawing an image object via #drawImage', function () { - const img = make_image_canvas(checked_data); + const img = makeImageCanvas(checkedData); display.drawImage(img, 0, 0); display.flip(); - expect(display).to.have.displayed(checked_data); + expect(display).to.have.displayed(checkedData); }); }); @@ -382,22 +382,18 @@ describe('Display/Canvas Helper', function () { beforeEach(function () { display = new Display(document.createElement('canvas')); display.resize(4, 4); - sinon.spy(display, '_scan_renderQ'); - }); - - afterEach(function () { - window.requestAnimationFrame = this.old_requestAnimationFrame; + sinon.spy(display, '_scanRenderQ'); }); it('should try to process an item when it is pushed on, if nothing else is on the queue', function () { - display._renderQ_push({ type: 'noop' }); // does nothing - expect(display._scan_renderQ).to.have.been.calledOnce; + display._renderQPush({ type: 'noop' }); // does nothing + expect(display._scanRenderQ).to.have.been.calledOnce; }); it('should not try to process an item when it is pushed on if we are waiting for other items', function () { display._renderQ.length = 2; - display._renderQ_push({ type: 'noop' }); - expect(display._scan_renderQ).to.not.have.been.called; + display._renderQPush({ type: 'noop' }); + expect(display._scanRenderQ).to.not.have.been.called; }); it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () { @@ -407,13 +403,13 @@ describe('Display/Canvas Helper', function () { display.drawImage = sinon.spy(); display.fillRect = sinon.spy(); - display._scan_renderQ(); + display._scanRenderQ(); expect(display.drawImage).to.not.have.been.called; expect(display.fillRect).to.not.have.been.called; expect(img.addEventListener).to.have.been.calledOnce; display._renderQ[0].img.complete = true; - display._scan_renderQ(); + display._scanRenderQ(); expect(display.drawImage).to.have.been.calledOnce; expect(display.fillRect).to.have.been.calledOnce; expect(img.addEventListener).to.have.been.calledOnce; @@ -426,7 +422,7 @@ describe('Display/Canvas Helper', function () { display.drawImage = sinon.spy(); display.fillRect = sinon.spy(); - display._scan_renderQ(); + display._scanRenderQ(); expect(display.drawImage).to.not.have.been.called; expect(display.fillRect).to.not.have.been.called; expect(img.addEventListener).to.have.been.calledOnce; @@ -434,7 +430,7 @@ describe('Display/Canvas Helper', function () { display._renderQ[0].img.complete = true; display._renderQ[0].img.width = 4; display._renderQ[0].img.height = 4; - display._scan_renderQ(); + display._scanRenderQ(); expect(display.drawImage).to.have.been.calledOnce; expect(display.fillRect).to.have.been.calledOnce; expect(img.addEventListener).to.have.been.calledOnce; @@ -450,35 +446,35 @@ describe('Display/Canvas Helper', function () { it('should draw a blit image on type "blit"', function () { display.blitImage = sinon.spy(); - display._renderQ_push({ type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] }); + display._renderQPush({ type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] }); expect(display.blitImage).to.have.been.calledOnce; expect(display.blitImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0); }); it('should draw a blit RGB image on type "blitRgb"', function () { display.blitRgbImage = sinon.spy(); - display._renderQ_push({ type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] }); + display._renderQPush({ type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] }); expect(display.blitRgbImage).to.have.been.calledOnce; expect(display.blitRgbImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0); }); it('should copy a region on type "copy"', function () { display.copyImage = sinon.spy(); - display._renderQ_push({ type: 'copy', x: 3, y: 4, width: 5, height: 6, old_x: 7, old_y: 8 }); + display._renderQPush({ type: 'copy', x: 3, y: 4, width: 5, height: 6, oldX: 7, oldY: 8 }); expect(display.copyImage).to.have.been.calledOnce; expect(display.copyImage).to.have.been.calledWith(7, 8, 3, 4, 5, 6); }); it('should fill a rect with a given color on type "fill"', function () { display.fillRect = sinon.spy(); - display._renderQ_push({ type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]}); + display._renderQPush({ type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]}); expect(display.fillRect).to.have.been.calledOnce; expect(display.fillRect).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9]); }); it('should draw an image from an image object on type "img" (if complete)', function () { display.drawImage = sinon.spy(); - display._renderQ_push({ type: 'img', x: 3, y: 4, img: { complete: true } }); + display._renderQPush({ type: 'img', x: 3, y: 4, img: { complete: true } }); expect(display.drawImage).to.have.been.calledOnce; expect(display.drawImage).to.have.been.calledWith({ complete: true }, 3, 4); }); diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 029a1031..d5fa4733 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -70,11 +70,13 @@ function deflateWithSize(data) { strm.output = new Uint8Array(chunkSize); deflateInit(strm, 5); + /* eslint-disable camelcase */ strm.input = unCompData; strm.avail_in = strm.input.length; strm.next_in = 0; strm.next_out = 0; strm.avail_out = chunkSize; + /* eslint-enable camelcase */ deflate(strm, 3); @@ -99,8 +101,8 @@ describe('Remote Frame Buffer Protocol Client', function () { const _sQ = new Uint8Array(sock._sQbufferSize); const rQ = new Uint8Array(sock._rQbufferSize); - Websock.prototype._old_allocate_buffers = Websock.prototype._allocate_buffers; - Websock.prototype._allocate_buffers = function () { + Websock.prototype._oldAllocateBuffers = Websock.prototype._allocateBuffers; + Websock.prototype._allocateBuffers = function () { this._sQ = _sQ; this._rQ = rQ; }; @@ -108,7 +110,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); after(function () { - Websock.prototype._allocate_buffers = Websock.prototype._old_allocate_buffers; + Websock.prototype._allocateBuffers = Websock.prototype._oldAllocateBuffers; this.clock.restore(); window.requestAnimationFrame = raf; }); @@ -352,7 +354,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-8)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); client.clipboardPasteFrom('extended test'); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; @@ -450,7 +452,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sinon.spy(client._display, "viewportChangeSize"); - client._sock._websocket._receive_data(new Uint8Array(incoming)); + client._sock._websocket._receiveData(new Uint8Array(incoming)); // FIXME: Display implicitly calls viewportChangeSize() when // resizing the framebuffer, hence calledTwice. @@ -647,7 +649,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sinon.spy(client._display, "autoscale"); - client._sock._websocket._receive_data(new Uint8Array(incoming)); + client._sock._websocket._receiveData(new Uint8Array(incoming)); expect(client._display.autoscale).to.have.been.calledOnce; expect(client._display.autoscale).to.have.been.calledWith(70, 80); @@ -702,7 +704,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._supportsSetDesktopSize = false; - client._sock._websocket._receive_data(new Uint8Array(incoming)); + client._sock._websocket._receiveData(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 70, 80, 0, 0); @@ -711,7 +713,7 @@ describe('Remote Frame Buffer Protocol Client', function () { // Second message should not trigger a resize - client._sock._websocket._receive_data(new Uint8Array(incoming)); + client._sock._websocket._receiveData(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.not.have.been.called; }); @@ -794,7 +796,7 @@ describe('Remote Frame Buffer Protocol Client', function () { 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 ]; - client._sock._websocket._receive_data(new Uint8Array(incoming)); + client._sock._websocket._receiveData(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.not.have.been.called; }); @@ -1012,7 +1014,7 @@ describe('Remote Frame Buffer Protocol Client', function () { } arr[0] = 'R'; arr[1] = 'F'; arr[2] = 'B'; arr[3] = ' '; arr[11] = '\n'; - client._sock._websocket._receive_data(arr); + client._sock._websocket._receiveData(arr); } describe('version parsing', function () { @@ -1090,7 +1092,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sendVer('000.000', client); expect(client._rfbVersion).to.equal(0); - const sentData = client._sock._websocket._get_sent_data(); + const sentData = client._sock._websocket._getSentData(); expect(new Uint8Array(sentData.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0])); expect(sentData).to.have.length(250); }); @@ -1113,14 +1115,14 @@ describe('Remote Frame Buffer Protocol Client', function () { const authSchemeRaw = [1, 2, 3, 4]; const authScheme = (authSchemeRaw[0] << 24) + (authSchemeRaw[1] << 16) + (authSchemeRaw[2] << 8) + authSchemeRaw[3]; - client._sock._websocket._receive_data(new Uint8Array(authSchemeRaw)); + client._sock._websocket._receiveData(new Uint8Array(authSchemeRaw)); expect(client._rfbAuthScheme).to.equal(authScheme); }); it('should prefer no authentication is possible', function () { client._rfbVersion = 3.7; const authSchemes = [2, 1, 3]; - client._sock._websocket._receive_data(new Uint8Array(authSchemes)); + client._sock._websocket._receiveData(new Uint8Array(authSchemes)); expect(client._rfbAuthScheme).to.equal(1); expect(client._sock).to.have.sent(new Uint8Array([1, 1])); }); @@ -1128,7 +1130,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should choose for the most prefered scheme possible for versions >= 3.7', function () { client._rfbVersion = 3.7; const authSchemes = [2, 22, 16]; - client._sock._websocket._receive_data(new Uint8Array(authSchemes)); + client._sock._websocket._receiveData(new Uint8Array(authSchemes)); expect(client._rfbAuthScheme).to.equal(22); expect(client._sock).to.have.sent(new Uint8Array([22])); }); @@ -1137,7 +1139,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sinon.spy(client, "_fail"); client._rfbVersion = 3.7; const authSchemes = [1, 32]; - client._sock._websocket._receive_data(new Uint8Array(authSchemes)); + client._sock._websocket._receiveData(new Uint8Array(authSchemes)); expect(client._fail).to.have.been.calledOnce; }); @@ -1145,7 +1147,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbVersion = 3.7; const failureData = [0, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115]; sinon.spy(client, '_fail'); - client._sock._websocket._receive_data(new Uint8Array(failureData)); + client._sock._websocket._receiveData(new Uint8Array(failureData)); expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledWith( @@ -1156,7 +1158,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbVersion = 3.7; const authSchemes = [1, 1]; client._negotiateAuthentication = sinon.spy(); - client._sock._websocket._receive_data(new Uint8Array(authSchemes)); + client._sock._websocket._receiveData(new Uint8Array(authSchemes)); expect(client._rfbInitState).to.equal('Authentication'); expect(client._negotiateAuthentication).to.have.been.calledOnce; }); @@ -1168,7 +1170,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); function sendSecurity(type, cl) { - cl._sock._websocket._receive_data(new Uint8Array([1, type])); + cl._sock._websocket._receiveData(new Uint8Array([1, type])); } it('should fail on auth scheme 0 (pre 3.7) with the given message', function () { @@ -1182,7 +1184,7 @@ describe('Remote Frame Buffer Protocol Client', function () { } sinon.spy(client, '_fail'); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(client._fail).to.have.been.calledWith( 'Security negotiation failed on authentication scheme (reason: Whoopsies)'); }); @@ -1219,7 +1221,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._websocket._receive_data(new Uint8Array(challenge)); + client._sock._websocket._receiveData(new Uint8Array(challenge)); expect(client._rfbCredentials).to.be.empty; expect(spy).to.have.been.calledOnce; @@ -1229,11 +1231,11 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should encrypt the password with DES and then send it back', function () { client._rfbCredentials = { password: 'passwd' }; sendSecurity(2, client); - client._sock._websocket._get_sent_data(); // skip the choice of auth reply + client._sock._websocket._getSentData(); // skip the choice of auth reply const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._websocket._receive_data(new Uint8Array(challenge)); + client._sock._websocket._receiveData(new Uint8Array(challenge)); const desPass = RFB.genDES('passwd', challenge); expect(client._sock).to.have.sent(new Uint8Array(desPass)); @@ -1245,7 +1247,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._websocket._receive_data(new Uint8Array(challenge)); + client._sock._websocket._receiveData(new Uint8Array(challenge)); expect(client._rfbInitState).to.equal('SecurityResult'); }); @@ -1308,7 +1310,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbInitState = 'Security'; client._rfbVersion = 3.8; sendSecurity(16, client); - client._sock._websocket._get_sent_data(); // skip the security reply + client._sock._websocket._getSentData(); // skip the security reply }); function sendNumStrPairs(pairs, client) { @@ -1325,11 +1327,11 @@ describe('Remote Frame Buffer Protocol Client', function () { } } - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); } it('should skip tunnel negotiation if no tunnels are requested', function () { - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0])); expect(client._rfbTightVNC).to.be.true; }); @@ -1351,7 +1353,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should continue to sub-auth negotiation after tunnel negotiation', function () { sendNumStrPairs([[0, 'TGHT', 'NOTUNNEL']], client); - client._sock._websocket._get_sent_data(); // skip the tunnel choice here + client._sock._websocket._getSentData(); // skip the tunnel choice here sendNumStrPairs([[1, 'STDV', 'NOAUTH__']], client); expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1])); expect(client._rfbInitState).to.equal('SecurityResult'); @@ -1397,7 +1399,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should fall through to ServerInitialisation on a response code of 0', function () { - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0])); expect(client._rfbInitState).to.equal('ServerInitialisation'); }); @@ -1405,7 +1407,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbVersion = 3.8; sinon.spy(client, '_fail'); const failureData = [0, 0, 0, 1, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115]; - client._sock._websocket._receive_data(new Uint8Array(failureData)); + client._sock._websocket._receiveData(new Uint8Array(failureData)); expect(client._fail).to.have.been.calledWith( 'Security negotiation failed on security result (reason: whoops)'); }); @@ -1413,7 +1415,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fail on an error code of 1 with a standard message for version < 3.8', function () { sinon.spy(client, '_fail'); client._rfbVersion = 3.7; - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 1])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 1])); expect(client._fail).to.have.been.calledWith( 'Security handshake failed'); }); @@ -1421,7 +1423,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should result in securityfailure event when receiving a non zero status', function () { const spy = sinon.spy(); client.addEventListener("securityfailure", spy); - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 2])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 2])); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.status).to.equal(2); }); @@ -1432,7 +1434,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client.addEventListener("securityfailure", spy); const failureData = [0, 0, 0, 1, 0, 0, 0, 12, 115, 117, 99, 104, 32, 102, 97, 105, 108, 117, 114, 101]; - client._sock._websocket._receive_data(new Uint8Array(failureData)); + client._sock._websocket._receiveData(new Uint8Array(failureData)); expect(spy.args[0][0].detail.status).to.equal(1); expect(spy.args[0][0].detail.reason).to.equal('such failure'); }); @@ -1442,7 +1444,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("securityfailure", spy); const failureData = [0, 0, 0, 1, 0, 0, 0, 0]; - client._sock._websocket._receive_data(new Uint8Array(failureData)); + client._sock._websocket._receiveData(new Uint8Array(failureData)); expect(spy.args[0][0].detail.status).to.equal(1); expect('reason' in spy.args[0][0].detail).to.be.false; }); @@ -1451,7 +1453,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbVersion = 3.6; const spy = sinon.spy(); client.addEventListener("securityfailure", spy); - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 2])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 2])); expect(spy.args[0][0].detail.status).to.equal(2); expect('reason' in spy.args[0][0].detail).to.be.false; }); @@ -1462,7 +1464,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const client = makeRFB(); client._rfbConnectionState = 'connecting'; client._rfbInitState = 'SecurityResult'; - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0])); expect(client._rfbInitState).to.equal('ServerInitialisation'); }); @@ -1470,7 +1472,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const client = makeRFB('wss://host:8675', { shared: true }); client._rfbConnectionState = 'connecting'; client._rfbInitState = 'SecurityResult'; - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0])); expect(client._sock).to.have.sent(new Uint8Array([1])); }); @@ -1478,7 +1480,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const client = makeRFB('wss://host:8675', { shared: false }); client._rfbConnectionState = 'connecting'; client._rfbInitState = 'SecurityResult'; - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0])); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0])); expect(client._sock).to.have.sent(new Uint8Array([0])); }); }); @@ -1489,8 +1491,8 @@ describe('Remote Frame Buffer Protocol Client', function () { }); function sendServerInit(opts, client) { - const fullOpts = { width: 10, height: 12, bpp: 24, depth: 24, big_endian: 0, - true_color: 1, redMax: 255, greenMax: 255, blueMax: 255, + const fullOpts = { width: 10, height: 12, bpp: 24, depth: 24, bigEndian: 0, + trueColor: 1, redMax: 255, greenMax: 255, blueMax: 255, redShift: 16, greenShift: 8, blueShift: 0, name: 'a name' }; for (let opt in opts) { fullOpts[opt] = opts[opt]; @@ -1502,8 +1504,8 @@ describe('Remote Frame Buffer Protocol Client', function () { data.push(fullOpts.bpp); data.push(fullOpts.depth); - data.push(fullOpts.big_endian); - data.push(fullOpts.true_color); + data.push(fullOpts.bigEndian); + data.push(fullOpts.trueColor); push16(data, fullOpts.redMax); push16(data, fullOpts.greenMax); @@ -1517,15 +1519,15 @@ describe('Remote Frame Buffer Protocol Client', function () { push8(data, 0); push8(data, 0); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); const nameData = []; let nameLen = []; pushString(nameData, fullOpts.name); push32(nameLen, nameData.length); - client._sock._websocket._receive_data(new Uint8Array(nameLen)); - client._sock._websocket._receive_data(new Uint8Array(nameData)); + client._sock._websocket._receiveData(new Uint8Array(nameLen)); + client._sock._websocket._receiveData(new Uint8Array(nameData)); } it('should set the framebuffer width and height', function () { @@ -1560,7 +1562,7 @@ describe('Remote Frame Buffer Protocol Client', function () { for (let i = 0; i < 16 + 32 + 48; i++) { tightData.push(i); } - client._sock._websocket._receive_data(new Uint8Array(tightData)); + client._sock._websocket._receiveData(new Uint8Array(tightData)); expect(client._rfbConnectionState).to.equal('connected'); }); @@ -1684,7 +1686,7 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(rectData[i]); } - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); } it('should send an update request if there is sufficient data', function () { @@ -1692,14 +1694,14 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.fbUpdateRequest(expectedMsg, true, 0, 0, 640, 20); client._framebufferUpdate = () => true; - client._sock._websocket._receive_data(new Uint8Array([0])); + client._sock._websocket._receiveData(new Uint8Array([0])); expect(client._sock).to.have.sent(expectedMsg._sQ); }); it('should not send an update request if we need more data', function () { - client._sock._websocket._receive_data(new Uint8Array([0])); - expect(client._sock._websocket._get_sent_data()).to.have.length(0); + client._sock._websocket._receiveData(new Uint8Array([0])); + expect(client._sock._websocket._getSentData()).to.have.length(0); }); it('should resume receiving an update if we previously did not have enough data', function () { @@ -1707,21 +1709,21 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.fbUpdateRequest(expectedMsg, true, 0, 0, 640, 20); // just enough to set FBU.rects - client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 3])); - expect(client._sock._websocket._get_sent_data()).to.have.length(0); + client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 3])); + expect(client._sock._websocket._getSentData()).to.have.length(0); client._framebufferUpdate = function () { this._sock.rQskipBytes(1); return true; }; // we magically have enough data // 247 should *not* be used as the message type here - client._sock._websocket._receive_data(new Uint8Array([247])); + client._sock._websocket._receiveData(new Uint8Array([247])); expect(client._sock).to.have.sent(expectedMsg._sQ); }); it('should not send a request in continuous updates mode', function () { client._enabledContinuousUpdates = true; client._framebufferUpdate = () => true; - client._sock._websocket._receive_data(new Uint8Array([0])); + client._sock._websocket._receiveData(new Uint8Array([0])); - expect(client._sock._websocket._get_sent_data()).to.have.length(0); + expect(client._sock._websocket._getSentData()).to.have.length(0); }); it('should fail on an unsupported encoding', function () { @@ -2388,7 +2390,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should set the XVP version and fire the callback with the version on XVP_INIT', function () { const spy = sinon.spy(); client.addEventListener("capabilities", spy); - client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 1])); + client._sock._websocket._receiveData(new Uint8Array([250, 0, 10, 1])); expect(client._rfbXvpVer).to.equal(10); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.capabilities.power).to.be.true; @@ -2397,7 +2399,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fail on unknown XVP message types', function () { sinon.spy(client, "_fail"); - client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 237])); + client._sock._websocket._receiveData(new Uint8Array([250, 0, 10, 237])); expect(client._fail).to.have.been.calledOnce; }); }); @@ -2411,7 +2413,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedStr); }); @@ -2437,7 +2439,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-12)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); // Check that we give an response caps when we receive one expect(RFB.messages.extendedClipboardCaps).to.have.been.calledOnce; @@ -2463,7 +2465,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-8)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); }); describe('Handle Provide', function () { @@ -2487,7 +2489,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2514,7 +2516,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(sendData); + client._sock._websocket._receiveData(sendData); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2546,7 +2548,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(sendData); + client._sock._websocket._receiveData(sendData); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2570,7 +2572,7 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(flags); let expectedData = [0x01]; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(RFB.messages.extendedClipboardRequest).to.have.been.calledOnce; expect(RFB.messages.extendedClipboardRequest).to.have.been.calledWith(client._sock, expectedData); @@ -2593,7 +2595,7 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(flags); let expectedData = []; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData); @@ -2611,7 +2613,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client.clipboardPasteFrom("HejHej"); RFB.messages.extendedClipboardNotify.resetHistory(); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData); @@ -2637,7 +2639,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client.clipboardPasteFrom("HejHej"); expect(RFB.messages.extendedClipboardProvide).to.not.have.been.called; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._sock._websocket._receiveData(new Uint8Array(data)); expect(RFB.messages.extendedClipboardProvide).to.have.been.calledOnce; expect(RFB.messages.extendedClipboardProvide).to.have.been.calledWith(client._sock, expectedData, ["HejHej"]); @@ -2650,7 +2652,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fire the bell callback on Bell', function () { const spy = sinon.spy(); client.addEventListener("bell", spy); - client._sock._websocket._receive_data(new Uint8Array([2])); + client._sock._websocket._receiveData(new Uint8Array([2])); expect(spy).to.have.been.calledOnce; }); @@ -2664,7 +2666,7 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.clientFence(expectedMsg, (1<<0) | (1<<1), payload); RFB.messages.clientFence(incomingMsg, 0xffffffff, payload); - client._sock._websocket._receive_data(incomingMsg._sQ); + client._sock._websocket._receiveData(incomingMsg._sQ); expect(client._sock).to.have.sent(expectedMsg._sQ); @@ -2674,7 +2676,7 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.clientFence(expectedMsg, (1<<0), payload); RFB.messages.clientFence(incomingMsg, (1<<0) | (1<<31), payload); - client._sock._websocket._receive_data(incomingMsg._sQ); + client._sock._websocket._receiveData(incomingMsg._sQ); expect(client._sock).to.have.sent(expectedMsg._sQ); }); @@ -2686,7 +2688,7 @@ describe('Remote Frame Buffer Protocol Client', function () { expect(client._enabledContinuousUpdates).to.be.false; - client._sock._websocket._receive_data(new Uint8Array([150])); + client._sock._websocket._receiveData(new Uint8Array([150])); expect(client._enabledContinuousUpdates).to.be.true; expect(client._sock).to.have.sent(expectedMsg._sQ); @@ -2696,7 +2698,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._enabledContinuousUpdates = true; client._supportsContinuousUpdates = true; - client._sock._websocket._receive_data(new Uint8Array([150])); + client._sock._websocket._receiveData(new Uint8Array([150])); expect(client._enabledContinuousUpdates).to.be.false; }); @@ -2707,7 +2709,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._resize(450, 160); - expect(client._sock._websocket._get_sent_data()).to.have.length(0); + expect(client._sock._websocket._getSentData()).to.have.length(0); client._enabledContinuousUpdates = true; @@ -2718,7 +2720,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fail on an unknown message type', function () { sinon.spy(client, "_fail"); - client._sock._websocket._receive_data(new Uint8Array([87])); + client._sock._websocket._receiveData(new Uint8Array([87])); expect(client._fail).to.have.been.calledOnce; }); }); @@ -2763,7 +2765,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should send a mask of 0 on mouseup', function () { - client._mouse_buttonMask = 0x001; + client._mouseButtonMask = 0x001; client._handleMouseButton(105, 120, 0, 0x001); expect(RFB.messages.pointerEvent).to.have.been.calledWith( client._sock, 105, 120, 0x000); @@ -2892,13 +2894,13 @@ describe('Remote Frame Buffer Protocol Client', function () { // message events it('should do nothing if we receive an empty message and have nothing in the queue', function () { client._normalMsg = sinon.spy(); - client._sock._websocket._receive_data(new Uint8Array([])); + client._sock._websocket._receiveData(new Uint8Array([])); expect(client._normalMsg).to.not.have.been.called; }); it('should handle a message in the connected state as a normal message', function () { client._normalMsg = sinon.spy(); - client._sock._websocket._receive_data(new Uint8Array([1, 2, 3])); + client._sock._websocket._receiveData(new Uint8Array([1, 2, 3])); expect(client._normalMsg).to.have.been.called; }); @@ -2906,14 +2908,14 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfbConnectionState = 'connecting'; client._rfbInitState = 'ProtocolVersion'; client._initMsg = sinon.spy(); - client._sock._websocket._receive_data(new Uint8Array([1, 2, 3])); + client._sock._websocket._receiveData(new Uint8Array([1, 2, 3])); expect(client._initMsg).to.have.been.called; }); it('should process all normal messages directly', function () { const spy = sinon.spy(); client.addEventListener("bell", spy); - client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02])); + client._sock._websocket._receiveData(new Uint8Array([0x02, 0x02])); expect(spy).to.have.been.calledTwice; }); diff --git a/tests/test.util.js b/tests/test.util.js index fb1d0373..cd61f248 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -22,37 +22,37 @@ describe('Utils', function () { console.warn.restore(); console.error.restore(); console.info.restore(); - Log.init_logging(); + Log.initLogging(); }); it('should use noop for levels lower than the min level', function () { - Log.init_logging('warn'); + Log.initLogging('warn'); Log.Debug('hi'); Log.Info('hello'); expect(console.log).to.not.have.been.called; }); it('should use console.debug for Debug', function () { - Log.init_logging('debug'); + Log.initLogging('debug'); Log.Debug('dbg'); expect(console.debug).to.have.been.calledWith('dbg'); }); it('should use console.info for Info', function () { - Log.init_logging('debug'); + Log.initLogging('debug'); Log.Info('inf'); expect(console.info).to.have.been.calledWith('inf'); }); it('should use console.warn for Warn', function () { - Log.init_logging('warn'); + Log.initLogging('warn'); Log.Warn('wrn'); expect(console.warn).to.have.been.called; expect(console.warn).to.have.been.calledWith('wrn'); }); it('should use console.error for Error', function () { - Log.init_logging('error'); + Log.initLogging('error'); Log.Error('err'); expect(console.error).to.have.been.called; expect(console.error).to.have.been.calledWith('err'); diff --git a/tests/test.websock.js b/tests/test.websock.js index 33d5cec4..a8e17e6b 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -13,7 +13,7 @@ describe('Websock', function () { beforeEach(function () { sock = new Websock(); // skip init - sock._allocate_buffers(); + sock._allocateBuffers(); sock._rQ.set(RQ_TEMPLATE); sock._rQlen = RQ_TEMPLATE.length; }); @@ -33,51 +33,51 @@ describe('Websock', function () { describe('rQpeek8', function () { it('should peek at the next byte without poping it off the queue', function () { - const bef_len = sock.rQlen; + const befLen = sock.rQlen; const peek = sock.rQpeek8(); expect(sock.rQpeek8()).to.equal(peek); - expect(sock.rQlen).to.equal(bef_len); + expect(sock.rQlen).to.equal(befLen); }); }); describe('rQshift8()', function () { it('should pop a single byte from the receive queue', function () { const peek = sock.rQpeek8(); - const bef_len = sock.rQlen; + const befLen = sock.rQlen; expect(sock.rQshift8()).to.equal(peek); - expect(sock.rQlen).to.equal(bef_len - 1); + expect(sock.rQlen).to.equal(befLen - 1); }); }); describe('rQshift16()', function () { it('should pop two bytes from the receive queue and return a single number', function () { - const bef_len = sock.rQlen; + const befLen = sock.rQlen; const expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1]; expect(sock.rQshift16()).to.equal(expected); - expect(sock.rQlen).to.equal(bef_len - 2); + expect(sock.rQlen).to.equal(befLen - 2); }); }); describe('rQshift32()', function () { it('should pop four bytes from the receive queue and return a single number', function () { - const bef_len = sock.rQlen; + const befLen = sock.rQlen; const expected = (RQ_TEMPLATE[0] << 24) + (RQ_TEMPLATE[1] << 16) + (RQ_TEMPLATE[2] << 8) + RQ_TEMPLATE[3]; expect(sock.rQshift32()).to.equal(expected); - expect(sock.rQlen).to.equal(bef_len - 4); + expect(sock.rQlen).to.equal(befLen - 4); }); }); describe('rQshiftStr', function () { it('should shift the given number of bytes off of the receive queue and return a string', function () { - const bef_len = sock.rQlen; - const bef_rQi = sock.rQi; + const befLen = sock.rQlen; + const befRQi = sock.rQi; const shifted = sock.rQshiftStr(3); expect(shifted).to.be.a('string'); - expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3)))); - expect(sock.rQlen).to.equal(bef_len - 3); + expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3)))); + expect(sock.rQlen).to.equal(befLen - 3); }); it('should shift the entire rest of the queue off if no length is given', function () { @@ -112,12 +112,12 @@ describe('Websock', function () { describe('rQshiftBytes', function () { it('should shift the given number of bytes of the receive queue and return an array', function () { - const bef_len = sock.rQlen; - const bef_rQi = sock.rQi; + const befLen = sock.rQlen; + const befRQi = sock.rQi; const shifted = sock.rQshiftBytes(3); expect(shifted).to.be.an.instanceof(Uint8Array); - expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3)); - expect(sock.rQlen).to.equal(bef_len - 3); + expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3)); + expect(sock.rQlen).to.equal(befLen - 3); }); it('should shift the entire rest of the queue off if no length is given', function () { @@ -132,9 +132,9 @@ describe('Websock', function () { }); it('should not modify the receive queue', function () { - const bef_len = sock.rQlen; + const befLen = sock.rQlen; sock.rQslice(0, 2); - expect(sock.rQlen).to.equal(bef_len); + expect(sock.rQlen).to.equal(befLen); }); it('should return an array containing the given slice of the receive queue', function () { @@ -198,7 +198,7 @@ describe('Websock', function () { sock._websocket.readyState = WebSocket.OPEN; sock._sQ = new Uint8Array([1, 2, 3]); sock._sQlen = 3; - const encoded = sock._encode_message(); + const encoded = sock._encodeMessage(); sock.flush(); expect(sock._websocket.send).to.have.been.calledOnce; @@ -232,22 +232,22 @@ describe('Websock', function () { }); }); - describe('send_string', function () { + describe('sendString', function () { beforeEach(function () { sock.send = sinon.spy(); }); it('should call send after converting the string to an array', function () { - sock.send_string("\x01\x02\x03"); + sock.sendString("\x01\x02\x03"); expect(sock.send).to.have.been.calledWith([1, 2, 3]); }); }); }); describe('lifecycle methods', function () { - let old_WS; + let oldWS; before(function () { - old_WS = WebSocket; + oldWS = WebSocket; }); let sock; @@ -255,10 +255,10 @@ describe('Websock', function () { sock = new Websock(); // eslint-disable-next-line no-global-assign WebSocket = sinon.spy(); - WebSocket.OPEN = old_WS.OPEN; - WebSocket.CONNECTING = old_WS.CONNECTING; - WebSocket.CLOSING = old_WS.CLOSING; - WebSocket.CLOSED = old_WS.CLOSED; + WebSocket.OPEN = oldWS.OPEN; + WebSocket.CONNECTING = oldWS.CONNECTING; + WebSocket.CLOSING = oldWS.CLOSING; + WebSocket.CLOSED = oldWS.CLOSED; WebSocket.prototype.binaryType = 'arraybuffer'; }); @@ -306,30 +306,30 @@ describe('Websock', function () { expect(sock._websocket.close).not.to.have.been.called; }); - it('should reset onmessage to not call _recv_message', function () { - sinon.spy(sock, '_recv_message'); + it('should reset onmessage to not call _recvMessage', function () { + sinon.spy(sock, '_recvMessage'); sock.close(); sock._websocket.onmessage(null); try { - expect(sock._recv_message).not.to.have.been.called; + expect(sock._recvMessage).not.to.have.been.called; } finally { - sock._recv_message.restore(); + sock._recvMessage.restore(); } }); }); describe('event handlers', function () { beforeEach(function () { - sock._recv_message = sinon.spy(); + sock._recvMessage = sinon.spy(); sock.on('open', sinon.spy()); sock.on('close', sinon.spy()); sock.on('error', sinon.spy()); sock.open('ws://'); }); - it('should call _recv_message on a message', function () { + it('should call _recvMessage on a message', function () { sock._websocket.onmessage(null); - expect(sock._recv_message).to.have.been.calledOnce; + expect(sock._recvMessage).to.have.been.calledOnce; }); it('should call the open event handler on opening', function () { @@ -350,7 +350,7 @@ describe('Websock', function () { after(function () { // eslint-disable-next-line no-global-assign - WebSocket = old_WS; + WebSocket = oldWS; }); }); @@ -358,13 +358,13 @@ describe('Websock', function () { let sock; beforeEach(function () { sock = new Websock(); - sock._allocate_buffers(); + sock._allocateBuffers(); }); it('should support adding binary Uint8Array data to the receive queue', function () { const msg = { data: new Uint8Array([1, 2, 3]) }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03'); }); @@ -372,7 +372,7 @@ describe('Websock', function () { sock._eventHandlers.message = sinon.spy(); const msg = { data: new Uint8Array([1, 2, 3]).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._eventHandlers.message).to.have.been.calledOnce; }); @@ -380,7 +380,7 @@ describe('Websock', function () { sock._eventHandlers.message = sinon.spy(); const msg = { data: new Uint8Array([]).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._eventHandlers.message).not.to.have.been.called; }); @@ -391,7 +391,7 @@ describe('Websock', function () { sock.rQi = 6; const msg = { data: new Uint8Array([1, 2, 3]).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._rQlen).to.equal(0); expect(sock.rQi).to.equal(0); }); @@ -403,7 +403,7 @@ describe('Websock', function () { sock.rQi = 10; const msg = { data: new Uint8Array([1, 2]).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._rQlen).to.equal(12); expect(sock.rQi).to.equal(0); }); @@ -415,7 +415,7 @@ describe('Websock', function () { sock._rQbufferSize = 20; const msg = { data: new Uint8Array(30).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._rQlen).to.equal(30); expect(sock.rQi).to.equal(0); expect(sock._rQ.length).to.equal(240); // keep the invariant that rQbufferSize / 8 >= rQlen @@ -428,7 +428,7 @@ describe('Websock', function () { sock._rQbufferSize = 20; const msg = { data: new Uint8Array(6).buffer }; sock._mode = 'binary'; - sock._recv_message(msg); + sock._recvMessage(msg); expect(sock._rQlen).to.equal(6); expect(sock.rQi).to.equal(0); expect(sock._rQ.length).to.equal(48); @@ -450,13 +450,13 @@ describe('Websock', function () { it('should only send the send queue up to the send queue length', function () { sock._sQ = new Uint8Array([1, 2, 3, 4, 5]); sock._sQlen = 3; - const res = sock._encode_message(); + const res = sock._encodeMessage(); expect(res).to.array.equal(new Uint8Array([1, 2, 3])); }); it('should properly pass the encoded data off to the actual WebSocket', function () { sock.send([1, 2, 3]); - expect(sock._websocket._get_sent_data()).to.array.equal(new Uint8Array([1, 2, 3])); + expect(sock._websocket._getSentData()).to.array.equal(new Uint8Array([1, 2, 3])); }); }); }); diff --git a/utils/genkeysymdef.js b/utils/genkeysymdef.js index d21773f9..f539a0b2 100755 --- a/utils/genkeysymdef.js +++ b/utils/genkeysymdef.js @@ -9,14 +9,14 @@ const fs = require('fs'); -let show_help = process.argv.length === 2; +let showHelp = process.argv.length === 2; let filename; for (let i = 2; i < process.argv.length; ++i) { switch (process.argv[i]) { case "--help": case "-h": - show_help = true; + showHelp = true; break; case "--file": case "-f": @@ -26,11 +26,11 @@ for (let i = 2; i < process.argv.length; ++i) { } if (!filename) { - show_help = true; + showHelp = true; console.log("Error: No filename specified\n"); } -if (show_help) { +if (showHelp) { console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings"); console.log("Usage: node parse.js [options] filename:"); console.log(" -h [ --help ] Produce this help message"); diff --git a/utils/use_require.js b/utils/use_require.js index a410a192..c29f7715 100755 --- a/utils/use_require.js +++ b/utils/use_require.js @@ -22,31 +22,31 @@ const paths = { core: path.resolve(__dirname, '..', 'core'), app: path.resolve(__dirname, '..', 'app'), vendor: path.resolve(__dirname, '..', 'vendor'), - out_dir_base: path.resolve(__dirname, '..', 'build'), - lib_dir_base: path.resolve(__dirname, '..', 'lib'), + outDirBase: path.resolve(__dirname, '..', 'build'), + libDirBase: path.resolve(__dirname, '..', 'lib'), }; -const no_copy_files = new Set([ +const noCopyFiles = new Set([ // skip these -- they don't belong in the processed application path.join(paths.vendor, 'sinon.js'), path.join(paths.vendor, 'browser-es-module-loader'), path.join(paths.app, 'images', 'icons', 'Makefile'), ]); -const only_legacy_scripts = new Set([ +const onlyLegacyScripts = new Set([ path.join(paths.vendor, 'promise.js'), ]); -const no_transform_files = new Set([ +const noTransformFiles = new Set([ // don't transform this -- we want it imported as-is to properly catch loading errors path.join(paths.app, 'error-handler.js'), ]); -no_copy_files.forEach(file => no_transform_files.add(file)); +noCopyFiles.forEach(file => noTransformFiles.add(file)); // util.promisify requires Node.js 8.x, so we have our own function promisify(original) { - return function promise_wrap() { + return function promiseWrap() { const args = Array.prototype.slice.call(arguments); return new Promise((resolve, reject) => { original.apply(this, args.concat((err, value) => { @@ -72,10 +72,10 @@ const babelTransformFile = promisify(babel.transformFile); // walkDir *recursively* walks directories trees, // calling the callback for all normal files found. -function walkDir(base_path, cb, filter) { - return readdir(base_path) +function walkDir(basePath, cb, filter) { + return readdir(basePath) .then((files) => { - const paths = files.map(filename => path.join(base_path, filename)); + const paths = files.map(filename => path.join(basePath, filename)); return Promise.all(paths.map(filepath => lstat(filepath) .then((stats) => { if (filter !== undefined && !filter(filepath, stats)) return; @@ -87,157 +87,157 @@ function walkDir(base_path, cb, filter) { }); } -function transform_html(legacy_scripts, only_legacy) { +function transformHtml(legacyScripts, onlyLegacy) { // write out the modified vnc.html file that works with the bundle - const src_html_path = path.resolve(__dirname, '..', 'vnc.html'); - const out_html_path = path.resolve(paths.out_dir_base, 'vnc.html'); - return readFile(src_html_path) - .then((contents_raw) => { - let contents = contents_raw.toString(); + const srcHtmlPath = path.resolve(__dirname, '..', 'vnc.html'); + const outHtmlPath = path.resolve(paths.outDirBase, 'vnc.html'); + return readFile(srcHtmlPath) + .then((contentsRaw) => { + let contents = contentsRaw.toString(); - const start_marker = '\n'; - const end_marker = ''; - const start_ind = contents.indexOf(start_marker) + start_marker.length; - const end_ind = contents.indexOf(end_marker, start_ind); + const startMarker = '\n'; + const endMarker = ''; + const startInd = contents.indexOf(startMarker) + startMarker.length; + const endInd = contents.indexOf(endMarker, startInd); - let new_script = ''; + let newScript = ''; - if (only_legacy) { + if (onlyLegacy) { // Only legacy version, so include things directly - for (let i = 0;i < legacy_scripts.length;i++) { - new_script += ` \n`; + for (let i = 0;i < legacyScripts.length;i++) { + newScript += ` \n`; } } else { // Otherwise include both modules and legacy fallbacks - new_script += ' \n'; - for (let i = 0;i < legacy_scripts.length;i++) { - new_script += ` \n`; + newScript += ' \n'; + for (let i = 0;i < legacyScripts.length;i++) { + newScript += ` \n`; } } - contents = contents.slice(0, start_ind) + `${new_script}\n` + contents.slice(end_ind); + contents = contents.slice(0, startInd) + `${newScript}\n` + contents.slice(endInd); return contents; }) .then((contents) => { - console.log(`Writing ${out_html_path}`); - return writeFile(out_html_path, contents); + console.log(`Writing ${outHtmlPath}`); + return writeFile(outHtmlPath, contents); }); } -function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) { - if (!import_format) { +function makeLibFiles(importFormat, sourceMaps, withAppDir, onlyLegacy) { + if (!importFormat) { throw new Error("you must specify an import format to generate compiled noVNC libraries"); - } else if (!SUPPORTED_FORMATS.has(import_format)) { - throw new Error(`unsupported output format "${import_format}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`); + } else if (!SUPPORTED_FORMATS.has(importFormat)) { + throw new Error(`unsupported output format "${importFormat}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`); } - // NB: we need to make a copy of babel_opts, since babel sets some defaults on it - const babel_opts = () => ({ + // NB: we need to make a copy of babelOpts, since babel sets some defaults on it + const babelOpts = () => ({ plugins: [], presets: [ [ '@babel/preset-env', { targets: 'ie >= 11', - modules: import_format } ] + modules: importFormat } ] ], ast: false, - sourceMaps: source_maps, + sourceMaps: sourceMaps, }); // No point in duplicate files without the app, so force only converted files - if (!with_app_dir) { - only_legacy = true; + if (!withAppDir) { + onlyLegacy = true; } - let in_path; - let out_path_base; - if (with_app_dir) { - out_path_base = paths.out_dir_base; - in_path = paths.main; + let inPath; + let outPathBase; + if (withAppDir) { + outPathBase = paths.outDirBase; + inPath = paths.main; } else { - out_path_base = paths.lib_dir_base; + outPathBase = paths.libDirBase; } - const legacy_path_base = only_legacy ? out_path_base : path.join(out_path_base, 'legacy'); + const legacyPathBase = onlyLegacy ? outPathBase : path.join(outPathBase, 'legacy'); - fse.ensureDirSync(out_path_base); + fse.ensureDirSync(outPathBase); const helpers = require('./use_require_helpers'); - const helper = helpers[import_format]; + const helper = helpers[importFormat]; const outFiles = []; const legacyFiles = []; - const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve() + const handleDir = (jsOnly, vendorRewrite, inPathBase, filename) => Promise.resolve() .then(() => { - const out_path = path.join(out_path_base, path.relative(in_path_base, filename)); - const legacy_path = path.join(legacy_path_base, path.relative(in_path_base, filename)); + const outPath = path.join(outPathBase, path.relative(inPathBase, filename)); + const legacyPath = path.join(legacyPathBase, path.relative(inPathBase, filename)); if (path.extname(filename) !== '.js') { - if (!js_only) { - console.log(`Writing ${out_path}`); - return copy(filename, out_path); + if (!jsOnly) { + console.log(`Writing ${outPath}`); + return copy(filename, outPath); } return; // skip non-javascript files } - if (no_transform_files.has(filename)) { - return ensureDir(path.dirname(out_path)) + if (noTransformFiles.has(filename)) { + return ensureDir(path.dirname(outPath)) .then(() => { - console.log(`Writing ${out_path}`); - return copy(filename, out_path); + console.log(`Writing ${outPath}`); + return copy(filename, outPath); }); } - if (only_legacy_scripts.has(filename)) { - legacyFiles.push(legacy_path); - return ensureDir(path.dirname(legacy_path)) + if (onlyLegacyScripts.has(filename)) { + legacyFiles.push(legacyPath); + return ensureDir(path.dirname(legacyPath)) .then(() => { - console.log(`Writing ${legacy_path}`); - return copy(filename, legacy_path); + console.log(`Writing ${legacyPath}`); + return copy(filename, legacyPath); }); } return Promise.resolve() .then(() => { - if (only_legacy) { + if (onlyLegacy) { return; } - return ensureDir(path.dirname(out_path)) + return ensureDir(path.dirname(outPath)) .then(() => { - console.log(`Writing ${out_path}`); - return copy(filename, out_path); + console.log(`Writing ${outPath}`); + return copy(filename, outPath); }); }) - .then(() => ensureDir(path.dirname(legacy_path))) + .then(() => ensureDir(path.dirname(legacyPath))) .then(() => { - const opts = babel_opts(); + const opts = babelOpts(); if (helper && helpers.optionsOverride) { helper.optionsOverride(opts); } // Adjust for the fact that we move the core files relative // to the vendor directory - if (vendor_rewrite) { + if (vendorRewrite) { opts.plugins.push(["import-redirect", - {"root": legacy_path_base, + {"root": legacyPathBase, "redirect": { "vendor/(.+)": "./vendor/$1"}}]); } return babelTransformFile(filename, opts) .then((res) => { - console.log(`Writing ${legacy_path}`); + console.log(`Writing ${legacyPath}`); const {map} = res; let {code} = res; - if (source_maps === true) { + if (sourceMaps === true) { // append URL for external source map - code += `\n//# sourceMappingURL=${path.basename(legacy_path)}.map\n`; + code += `\n//# sourceMappingURL=${path.basename(legacyPath)}.map\n`; } - outFiles.push(`${legacy_path}`); - return writeFile(legacy_path, code) + outFiles.push(`${legacyPath}`); + return writeFile(legacyPath, code) .then(() => { - if (source_maps === true || source_maps === 'both') { - console.log(` and ${legacy_path}.map`); - outFiles.push(`${legacy_path}.map`); - return writeFile(`${legacy_path}.map`, JSON.stringify(map)); + if (sourceMaps === true || sourceMaps === 'both') { + console.log(` and ${legacyPath}.map`); + outFiles.push(`${legacyPath}.map`); + return writeFile(`${legacyPath}.map`, JSON.stringify(map)); } }); }); @@ -246,45 +246,45 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) { Promise.resolve() .then(() => { - const handler = handleDir.bind(null, true, false, in_path || paths.main); - const filter = (filename, stats) => !no_copy_files.has(filename); + const handler = handleDir.bind(null, true, false, inPath || paths.main); + const filter = (filename, stats) => !noCopyFiles.has(filename); return walkDir(paths.vendor, handler, filter); }) .then(() => { - const handler = handleDir.bind(null, true, !in_path, in_path || paths.core); - const filter = (filename, stats) => !no_copy_files.has(filename); + const handler = handleDir.bind(null, true, !inPath, inPath || paths.core); + const filter = (filename, stats) => !noCopyFiles.has(filename); return walkDir(paths.core, handler, filter); }) .then(() => { - if (!with_app_dir) return; - const handler = handleDir.bind(null, false, false, in_path); - const filter = (filename, stats) => !no_copy_files.has(filename); + if (!withAppDir) return; + const handler = handleDir.bind(null, false, false, inPath); + const filter = (filename, stats) => !noCopyFiles.has(filename); return walkDir(paths.app, handler, filter); }) .then(() => { - if (!with_app_dir) return; + if (!withAppDir) return; if (!helper || !helper.appWriter) { - throw new Error(`Unable to generate app for the ${import_format} format!`); + throw new Error(`Unable to generate app for the ${importFormat} format!`); } - const out_app_path = path.join(legacy_path_base, 'app.js'); - console.log(`Writing ${out_app_path}`); - return helper.appWriter(out_path_base, legacy_path_base, out_app_path) - .then((extra_scripts) => { - let legacy_scripts = []; + const outAppPath = path.join(legacyPathBase, 'app.js'); + console.log(`Writing ${outAppPath}`); + return helper.appWriter(outPathBase, legacyPathBase, outAppPath) + .then((extraScripts) => { + let legacyScripts = []; legacyFiles.forEach((file) => { - let rel_file_path = path.relative(out_path_base, file); - legacy_scripts.push(rel_file_path); + let relFilePath = path.relative(outPathBase, file); + legacyScripts.push(relFilePath); }); - legacy_scripts = legacy_scripts.concat(extra_scripts); + legacyScripts = legacyScripts.concat(extraScripts); - let rel_app_path = path.relative(out_path_base, out_app_path); - legacy_scripts.push(rel_app_path); + let relAppPath = path.relative(outPathBase, outAppPath); + legacyScripts.push(relAppPath); - transform_html(legacy_scripts, only_legacy); + transformHtml(legacyScripts, onlyLegacy); }) .then(() => { if (!helper.removeModules) return; @@ -292,15 +292,15 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) { return Promise.all(outFiles.map((filepath) => { unlink(filepath) .then(() => { - // Try to clean up any empty directories if this - // was the last file in there - const rmdir_r = dir => + // Try to clean up any empty directories if + // this was the last file in there + const rmdirR = dir => rmdir(dir) - .then(() => rmdir_r(path.dirname(dir))) + .then(() => rmdirR(path.dirname(dir))) .catch(() => { - // Assume the error was ENOTEMPTY and ignore it + // Assume the error was ENOTEMPTY and ignore it }); - return rmdir_r(path.dirname(filepath)); + return rmdirR(path.dirname(filepath)); }); })); }); @@ -312,11 +312,11 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) { } if (program.clean) { - console.log(`Removing ${paths.lib_dir_base}`); - fse.removeSync(paths.lib_dir_base); + console.log(`Removing ${paths.libDirBase}`); + fse.removeSync(paths.libDirBase); - console.log(`Removing ${paths.out_dir_base}`); - fse.removeSync(paths.out_dir_base); + console.log(`Removing ${paths.outDirBase}`); + fse.removeSync(paths.outDirBase); } -make_lib_files(program.as, program.withSourceMaps, program.withApp, program.onlyLegacy); +makeLibFiles(program.as, program.withSourceMaps, program.withApp, program.onlyLegacy); diff --git a/utils/use_require_helpers.js b/utils/use_require_helpers.js index 0a930ee6..8ad45726 100644 --- a/utils/use_require_helpers.js +++ b/utils/use_require_helpers.js @@ -4,7 +4,7 @@ const path = require('path'); // util.promisify requires Node.js 8.x, so we have our own function promisify(original) { - return function promise_wrap() { + return function promiseWrap() { const args = Array.prototype.slice.call(arguments); return new Promise((resolve, reject) => { original.apply(this, args.concat((err, value) => { @@ -19,39 +19,39 @@ const writeFile = promisify(fs.writeFile); module.exports = { 'amd': { - appWriter: (base_out_path, script_base_path, out_path) => { + appWriter: (baseOutPath, scriptBasePath, outPath) => { // setup for requirejs - const ui_path = path.relative(base_out_path, - path.join(script_base_path, 'app', 'ui')); - return writeFile(out_path, `requirejs(["${ui_path}"], function (ui) {});`) + const uiPath = path.relative(baseOutPath, + path.join(scriptBasePath, 'app', 'ui')); + return writeFile(outPath, `requirejs(["${uiPath}"], function (ui) {});`) .then(() => { - console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`); - const require_path = path.relative(base_out_path, - path.join(script_base_path, 'require.js')); - return [ require_path ]; + console.log(`Please place RequireJS in ${path.join(scriptBasePath, 'require.js')}`); + const requirePath = path.relative(baseOutPath, + path.join(scriptBasePath, 'require.js')); + return [ requirePath ]; }); }, }, 'commonjs': { - appWriter: (base_out_path, script_base_path, out_path) => { + appWriter: (baseOutPath, scriptBasePath, outPath) => { const browserify = require('browserify'); - const b = browserify(path.join(script_base_path, 'app/ui.js'), {}); + const b = browserify(path.join(scriptBasePath, 'app/ui.js'), {}); return promisify(b.bundle).call(b) - .then(buf => writeFile(out_path, buf)) + .then(buf => writeFile(outPath, buf)) .then(() => []); }, removeModules: true, }, 'systemjs': { - appWriter: (base_out_path, script_base_path, out_path) => { - const ui_path = path.relative(base_out_path, - path.join(script_base_path, 'app', 'ui.js')); - return writeFile(out_path, `SystemJS.import("${ui_path}");`) + appWriter: (baseOutPath, scriptBasePath, outPath) => { + const uiPath = path.relative(baseOutPath, + path.join(scriptBasePath, 'app', 'ui.js')); + return writeFile(outPath, `SystemJS.import("${uiPath}");`) .then(() => { - console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`); - const systemjs_path = path.relative(base_out_path, - path.join(script_base_path, 'system-production.js')); - return [ systemjs_path ]; + console.log(`Please place SystemJS in ${path.join(scriptBasePath, 'system-production.js')}`); + const systemjsPath = path.relative(baseOutPath, + path.join(scriptBasePath, 'system-production.js')); + return [ systemjsPath ]; }); }, },