KASM-7072 refactor of noVNC rendering of rects (#134)
KASM-7072 Added threaded decoding of rects. Update replay test to work with threaded decoding. Update stats tracker to track dropped fps. --------- Co-authored-by: ryan.kuba <ryan.kuba@kasmweb.com> Co-authored-by: Ryan Kuba <ryankuba@gmail.com> Co-authored-by: Matt McClaskey <matt@kasmweb.com>
This commit is contained in:
parent
14c8c2af59
commit
bed156c565
|
|
@ -10,3 +10,7 @@ recordings
|
|||
*.swp
|
||||
*~
|
||||
noVNC-*.tgz
|
||||
/dist
|
||||
/index.html
|
||||
/package-lock.json
|
||||
/kasmvnc-version.txt
|
||||
|
|
|
|||
|
|
@ -53,7 +53,3 @@ KasmVNC is an absolute requirement. This fork of noVNC is explicitly modified to
|
|||
## Running noVNC
|
||||
|
||||
KasmVNC has a built in web server and the web code is baked into KasmVNC. There are no instructions to provide, just install KasmVNC follow the instructions to configure and run it.
|
||||
|
||||
## Development
|
||||
|
||||
The noVNC code is webpacked for performance reasons. The CI pipeline in the KasmVNC project is responsible for building the web code and packaging it with KasmVNC.
|
||||
|
|
|
|||
|
|
@ -1,72 +1,79 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC Authors
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
// NB: this should *not* be included as a module until we have
|
||||
// native support in the browsers, so that our error handler
|
||||
// can catch script-loading errors.
|
||||
// Fallback for all uncought errors
|
||||
function handleError(event, err) {
|
||||
try {
|
||||
const msg = document.getElementById('noVNC_fallback_errormsg');
|
||||
|
||||
// No ES6 can be used in this file since it's used for the translation
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
|
||||
(function _scope() {
|
||||
"use strict";
|
||||
|
||||
// Fallback for all uncaught errors
|
||||
function handleError(event, err) {
|
||||
try {
|
||||
const msg = document.getElementById('noVNC_fallback_errormsg');
|
||||
|
||||
// Only show the initial error
|
||||
if (msg.hasChildNodes()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip allowed errors
|
||||
let allowedErrors = [ "The user has exited the lock before this request was completed." ];
|
||||
if (event.message && allowedErrors.includes(event.message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let div = document.createElement("div");
|
||||
div.classList.add('noVNC_message');
|
||||
div.appendChild(document.createTextNode(event.message));
|
||||
msg.appendChild(div);
|
||||
|
||||
if (event.filename) {
|
||||
div = document.createElement("div");
|
||||
div.className = 'noVNC_location';
|
||||
let text = event.filename;
|
||||
if (event.lineno !== undefined) {
|
||||
text += ":" + event.lineno;
|
||||
if (event.colno !== undefined) {
|
||||
text += ":" + event.colno;
|
||||
}
|
||||
}
|
||||
div.appendChild(document.createTextNode(text));
|
||||
msg.appendChild(div);
|
||||
}
|
||||
|
||||
if (err && err.stack) {
|
||||
div = document.createElement("div");
|
||||
div.className = 'noVNC_stack';
|
||||
div.appendChild(document.createTextNode(err.stack));
|
||||
msg.appendChild(div);
|
||||
}
|
||||
|
||||
document.getElementById('noVNC_fallback_error')
|
||||
.classList.add("noVNC_open");
|
||||
} catch (exc) {
|
||||
document.write("Kasm encountered an error.");
|
||||
// Work around Firefox bug:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1685038
|
||||
if (event.message === "ResizeObserver loop completed with undelivered notifications.") {
|
||||
return false;
|
||||
}
|
||||
// Don't return true since this would prevent the error
|
||||
// from being printed to the browser console.
|
||||
return false;
|
||||
|
||||
// Only show the initial error
|
||||
if (msg.hasChildNodes()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let div = document.createElement("div");
|
||||
div.classList.add('noVNC_message');
|
||||
div.appendChild(document.createTextNode(event.message));
|
||||
msg.appendChild(div);
|
||||
|
||||
if (event.filename) {
|
||||
div = document.createElement("div");
|
||||
div.className = 'noVNC_location';
|
||||
let text = event.filename;
|
||||
if (event.lineno !== undefined) {
|
||||
text += ":" + event.lineno;
|
||||
if (event.colno !== undefined) {
|
||||
text += ":" + event.colno;
|
||||
}
|
||||
}
|
||||
div.appendChild(document.createTextNode(text));
|
||||
msg.appendChild(div);
|
||||
}
|
||||
|
||||
if (err && err.stack) {
|
||||
div = document.createElement("div");
|
||||
div.className = 'noVNC_stack';
|
||||
div.appendChild(document.createTextNode(err.stack));
|
||||
msg.appendChild(div);
|
||||
}
|
||||
|
||||
document.getElementById('noVNC_fallback_error')
|
||||
.classList.add("noVNC_open");
|
||||
|
||||
} catch (exc) {
|
||||
document.write("noVNC encountered an error.");
|
||||
}
|
||||
window.addEventListener('error', function onerror(evt) { handleError(evt, evt.error); });
|
||||
window.addEventListener('unhandledrejection', function onreject(evt) { handleError(evt.reason, evt.reason); });
|
||||
})();
|
||||
|
||||
// Try to disable keyboard interaction, best effort
|
||||
try {
|
||||
// Remove focus from the currently focused element in order to
|
||||
// prevent keyboard interaction from continuing
|
||||
if (document.activeElement) { document.activeElement.blur(); }
|
||||
|
||||
// Don't let any element be focusable when showing the error
|
||||
let keyboardFocusable = 'a[href], button, input, textarea, select, details, [tabindex]';
|
||||
document.querySelectorAll(keyboardFocusable).forEach((elem) => {
|
||||
elem.setAttribute("tabindex", "-1");
|
||||
});
|
||||
} catch (exc) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// Don't return true since this would prevent the error
|
||||
// from being printed to the browser console.
|
||||
return false;
|
||||
}
|
||||
|
||||
window.addEventListener('error', evt => handleError(evt, evt.error));
|
||||
window.addEventListener('unhandledrejection', evt => handleError(evt.reason, evt.reason));
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@
|
|||
"Video Mode Height:": "視訊模式高度:",
|
||||
"Documentation": "文件",
|
||||
"Drag Viewport": "拖曳視角",
|
||||
"KasmVNC encountered an error:": "KasmVNC 遭遇執行錯誤:"
|
||||
"KasmVNC encountered an error:": "KasmVNC 遭遇執行錯誤:",
|
||||
"Displays": "「展示」",
|
||||
"Enable Threaded Decoding": "啟用線程解碼",
|
||||
"Arrange Displays": "排列顯示",
|
||||
|
|
|
|||
|
|
@ -1380,7 +1380,7 @@ const UI = {
|
|||
try {
|
||||
let obj = JSON.parse(e.detail.text);
|
||||
let fps = UI.rfb.statsFps;
|
||||
document.getElementById("noVNC_connection_stats").innerHTML = "CPU: " + obj[0] + "/" + obj[1] + " | Network: " + obj[2] + "/" + obj[3] + " | FPS: " + fps;
|
||||
document.getElementById("noVNC_connection_stats").innerHTML = "CPU: " + obj[0] + "/" + obj[1] + " | Network: " + obj[2] + "/" + obj[3] + " | FPS: " + UI.rfb.statsFps + " Dropped FPS: " + UI.rfb.statsDroppedFps;
|
||||
console.log(e.detail.text);
|
||||
} catch (err) {
|
||||
console.log('Invalid bottleneck stats recieved from server.')
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
import * as Log from '../util/logging.js';
|
||||
import Inflator from "../inflator.js";
|
||||
import { hashUInt8Array } from '../util/int.js';
|
||||
import qoiWorker from './qoi/decoder.js?worker';
|
||||
|
||||
export default class TightDecoder {
|
||||
constructor(display) {
|
||||
|
|
@ -493,7 +494,7 @@ export default class TightDecoder {
|
|||
this._qoiRects = [];
|
||||
this._rectQlooping = false;
|
||||
for (let i = 0; i < this._threads; i++) {
|
||||
this._workers.push(new Worker("core/decoders/qoi/decoder.js"));
|
||||
this._workers.push(new qoiWorker());
|
||||
this._workers[i].onmessage = (evt) => {
|
||||
this._availableWorkers.push(i);
|
||||
switch(evt.data.result) {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@
|
|||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
import { deflateInit, deflate } from "../vendor/pako/lib/zlib/deflate.js";
|
||||
import { Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js";
|
||||
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
||||
import { deflateInit, deflate, Z_FULL_FLUSH } from "pako/lib/zlib/deflate.js";
|
||||
import ZStream from "pako/lib/zlib/zstream.js";
|
||||
|
||||
export default class Deflator {
|
||||
constructor() {
|
||||
|
|
|
|||
158
core/display.js
158
core/display.js
|
|
@ -12,6 +12,7 @@ import Base64 from "./base64.js";
|
|||
import { toSigned32bit } from './util/int.js';
|
||||
import { isWindows } from './util/browser.js';
|
||||
import { uuidv4 } from './util/strings.js';
|
||||
import UI from '../app/ui.js';
|
||||
|
||||
export default class Display {
|
||||
constructor(target, isPrimaryDisplay) {
|
||||
|
|
@ -65,7 +66,9 @@ export default class Display {
|
|||
// performance metrics
|
||||
this._flipCnt = 0;
|
||||
this._lastFlip = Date.now();
|
||||
this._droppedFrames = 0;
|
||||
this._droppedFrames = 0; // total count
|
||||
this._droppedFramesRate = 0; //frames dropped per second
|
||||
this._droppedFramesCnt = 0; //dropper frames temp counter
|
||||
this._droppedRects = 0;
|
||||
this._forcedFrameCnt = 0;
|
||||
this._missingFlipRect = 0;
|
||||
|
|
@ -74,8 +77,16 @@ export default class Display {
|
|||
let delta = Date.now() - this._lastFlip;
|
||||
if (delta > 0) {
|
||||
this._fps = (this._flipCnt / (delta / 1000)).toFixed(2);
|
||||
if (this._droppedFrames > this._droppedFramesCnt) {
|
||||
let droppedFrames = this._droppedFrames - this._droppedFramesCnt;
|
||||
this._droppedFramesRate = (droppedFrames / (delta / 1000)).toFixed(2);
|
||||
} else {
|
||||
this._droppedFramesRate = 0;
|
||||
}
|
||||
this._droppedFramesCnt = this._droppedFrames;
|
||||
}
|
||||
Log.Debug('Dropped Frames: ' + this._droppedFrames + ' Dropped Rects: ' + this._droppedRects + ' Forced Frames: ' + this._forcedFrameCnt + ' Missing Flips: ' + this._missingFlipRect + ' Late Flips: ' + this._lateFlipRect);
|
||||
|
||||
this._flipCnt = 0;
|
||||
this._lastFlip = Date.now();
|
||||
}.bind(this), 5000);
|
||||
|
|
@ -111,6 +122,8 @@ export default class Display {
|
|||
x2: 0,
|
||||
y2: 0
|
||||
}];
|
||||
this._threading = true;
|
||||
this._primaryChannel = null;
|
||||
|
||||
//optional offscreen canvas
|
||||
this._enableCanvasBuffer = false;
|
||||
|
|
@ -123,8 +136,7 @@ export default class Display {
|
|||
this.onflush = () => { }; // A flush request has finished
|
||||
|
||||
if (!this._isPrimaryDisplay) {
|
||||
this._screens[0].channel = new BroadcastChannel(`screen_${this._screenID}_channel`);
|
||||
this._screens[0].channel.addEventListener('message', this._handleSecondaryDisplayMessage.bind(this));
|
||||
window.addEventListener('message', this._handleSecondaryDisplayMessage.bind(this));
|
||||
}
|
||||
|
||||
Log.Debug("<< Display.constructor");
|
||||
|
|
@ -177,6 +189,11 @@ export default class Display {
|
|||
this._rescale(scale);
|
||||
}
|
||||
|
||||
get threading() { return this._threading; }
|
||||
set threading(bool) {
|
||||
this._threading = bool;
|
||||
}
|
||||
|
||||
get clipViewport() { return this._clipViewport; }
|
||||
set clipViewport(viewport) {
|
||||
this._clipViewport = viewport;
|
||||
|
|
@ -202,6 +219,7 @@ export default class Display {
|
|||
}
|
||||
|
||||
get fps() { return this._fps; }
|
||||
get droppedFps() { return this._droppedFramesRate; }
|
||||
|
||||
// ===== PUBLIC METHODS =====
|
||||
|
||||
|
|
@ -411,15 +429,12 @@ export default class Display {
|
|||
pixelRatio: pixelRatio,
|
||||
containerHeight: containerHeight,
|
||||
containerWidth: containerWidth,
|
||||
channel: null,
|
||||
channel: UI.displayWindows[this.screens.length],
|
||||
scale: scale,
|
||||
x2: x + serverWidth,
|
||||
y2: serverHeight
|
||||
}
|
||||
|
||||
new_screen.channel = new BroadcastChannel(`screen_${screenID}_channel`);
|
||||
//new_screen.channel.message = this._handleSecondaryDisplayMessage().bind(this);
|
||||
|
||||
this._screens.push(new_screen);
|
||||
new_screen.channel.postMessage({ eventType: "registered", screenIndex: new_screen.screenIndex });
|
||||
|
||||
|
|
@ -436,7 +451,7 @@ export default class Display {
|
|||
if (this._screens[i].screenID == screenID) {
|
||||
//flush all rects on target screen
|
||||
this._flushRectsScreen(i);
|
||||
this._screens[i].channel.close();
|
||||
UI.displayWindows.splice(i, 1);
|
||||
this._screens.splice(i, 1);
|
||||
removed = true;
|
||||
break;
|
||||
|
|
@ -706,12 +721,39 @@ export default class Display {
|
|||
}
|
||||
}
|
||||
|
||||
_handleVidChunk(data, chunk) {
|
||||
let rect = data[0];
|
||||
let that = data[1];
|
||||
let imageDecoder = data[2];
|
||||
imageDecoder.close();
|
||||
rect.img = chunk.image;
|
||||
that._asyncRenderQPush(rect);
|
||||
}
|
||||
|
||||
imageRect(x, y, width, height, mime, arr, frame_id) {
|
||||
/* The internal logic cannot handle empty images, so bail early */
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Use threaded image decoder
|
||||
if ((typeof ImageDecoder !== 'undefined') && (this._threading)) {
|
||||
let imageDecoder = new ImageDecoder({ data: arr, type: mime });
|
||||
let rect = {
|
||||
'type': 'vid',
|
||||
'img': null,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'frame_id': frame_id,
|
||||
'mime': mime
|
||||
}
|
||||
this._processRectScreens(rect);
|
||||
imageDecoder.decode().then(this._handleVidChunk.bind(null,[rect,this,imageDecoder]));
|
||||
return;
|
||||
}
|
||||
|
||||
let rect = {
|
||||
'type': 'img',
|
||||
'img': null,
|
||||
|
|
@ -785,11 +827,17 @@ export default class Display {
|
|||
|
||||
blitImage(x, y, width, height, arr, offset, frame_id, fromQueue) {
|
||||
if (!fromQueue) {
|
||||
var buf;
|
||||
if (!ArrayBuffer.isView(arr)) {
|
||||
buf = arr;
|
||||
} else {
|
||||
buf = arr.buffer;
|
||||
}
|
||||
// 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 newArr = new Uint8Array(width * height * 4);
|
||||
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
||||
newArr.set(new Uint8Array(buf, 0, newArr.length));
|
||||
let rect = {
|
||||
'type': 'blit',
|
||||
'data': newArr,
|
||||
|
|
@ -802,10 +850,17 @@ export default class Display {
|
|||
this._processRectScreens(rect);
|
||||
this._asyncRenderQPush(rect);
|
||||
} else {
|
||||
// NB(directxman12): arr must be an Type Array view
|
||||
let data = new Uint8ClampedArray(arr.buffer,
|
||||
var data;
|
||||
if (!ArrayBuffer.isView(arr)) {
|
||||
data = new Uint8ClampedArray(arr,
|
||||
arr.length + offset,
|
||||
width * height * 4);
|
||||
} else {
|
||||
data = new Uint8ClampedArray(arr.buffer,
|
||||
arr.byteOffset + offset,
|
||||
width * height * 4);
|
||||
}
|
||||
// NB(directxman12): arr must be an Type Array view
|
||||
let img = new ImageData(data, width, height);
|
||||
if (this._enableCanvasBuffer) {
|
||||
this._drawCtx.putImageData(img, x, y);
|
||||
|
|
@ -891,6 +946,9 @@ export default class Display {
|
|||
rect.screenLocations[0].screenIndex = 0;
|
||||
switch (rect.type) {
|
||||
case 'img':
|
||||
rect.img = new Image();
|
||||
rect.img.src = rect.src;
|
||||
break;
|
||||
case '_img':
|
||||
rect.img = new Image();
|
||||
rect.img.src = rect.src;
|
||||
|
|
@ -962,6 +1020,10 @@ export default class Display {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case 'vid':
|
||||
this.drawImage(a.img, pos.x, pos.y, a.width, a.height);
|
||||
a.img.close();
|
||||
break;
|
||||
default:
|
||||
this._syncFrameQueue.shift();
|
||||
continue;
|
||||
|
|
@ -1170,6 +1232,9 @@ export default class Display {
|
|||
case 'img':
|
||||
this.drawImage(a.img, screenLocation.x, screenLocation.y, a.width, a.height);
|
||||
break;
|
||||
case 'vid':
|
||||
this.drawImage(a.img, screenLocation.x, screenLocation.y, a.width, a.height);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1180,11 +1245,74 @@ export default class Display {
|
|||
case 'transparent':
|
||||
case 'flip':
|
||||
break;
|
||||
case 'vid':
|
||||
secondaryScreenRects++;
|
||||
if (this._screens[screenLocation.screenIndex].channel) {
|
||||
this._screens[screenLocation.screenIndex].channel.postMessage({
|
||||
eventType: 'rect',
|
||||
rect: {
|
||||
'type': 'vid',
|
||||
'img': a.img,
|
||||
'x': a.x,
|
||||
'y': a.y,
|
||||
'width': a.width,
|
||||
'height': a.height,
|
||||
'frame_id': a.frame_id,
|
||||
'screenLocations': a.screenLocations
|
||||
},
|
||||
screenLocationIndex: sI
|
||||
}, [a.img]);
|
||||
}
|
||||
break;
|
||||
case 'blit':
|
||||
secondaryScreenRects++;
|
||||
let buf = a.data.buffer;
|
||||
if (this._screens[screenLocation.screenIndex].channel) {
|
||||
this._screens[screenLocation.screenIndex].channel.postMessage({
|
||||
eventType: 'rect',
|
||||
rect: {
|
||||
'type': 'blit',
|
||||
'img': null,
|
||||
'data': buf,
|
||||
'x': a.x,
|
||||
'y': a.y,
|
||||
'width': a.width,
|
||||
'height': a.height,
|
||||
'frame_id': a.frame_id,
|
||||
'screenLocations': a.screenLocations
|
||||
},
|
||||
screenLocationIndex: sI
|
||||
}, [buf]);
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
secondaryScreenRects++;
|
||||
if (this._screens[screenLocation.screenIndex].channel) {
|
||||
this._screens[screenLocation.screenIndex].channel.postMessage({
|
||||
eventType: 'rect',
|
||||
rect: {
|
||||
'type': 'img',
|
||||
'img': null,
|
||||
'x': a.x,
|
||||
'y': a.y,
|
||||
'width': a.width,
|
||||
'height': a.height,
|
||||
'frame_id': a.frame_id,
|
||||
'screenLocations': a.screenLocations,
|
||||
'src' : a.src
|
||||
},
|
||||
screenLocationIndex: sI
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
secondaryScreenRects++;
|
||||
a.img = null;
|
||||
if (this._screens[screenLocation.screenIndex].channel) {
|
||||
this._screens[screenLocation.screenIndex].channel.postMessage({ eventType: 'rect', rect: a, screenLocationIndex: sI });
|
||||
if (this._screens[screenLocation.screenIndex].channel) {
|
||||
this._screens[screenLocation.screenIndex].channel.postMessage({
|
||||
eventType: 'rect',
|
||||
rect: a,
|
||||
screenLocationIndex: sI
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
|
||||
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
||||
import { inflateInit, inflate, inflateReset } from "pako/lib/zlib/inflate.js";
|
||||
import ZStream from "pako/lib/zlib/zstream.js";
|
||||
|
||||
export default class Inflate {
|
||||
constructor() {
|
||||
|
|
|
|||
11
core/rfb.js
11
core/rfb.js
|
|
@ -164,6 +164,8 @@ export default class RFB extends EventTargetMixin {
|
|||
this._clipboardServerCapabilitiesActions = {};
|
||||
this._clipboardServerCapabilitiesFormats = {};
|
||||
|
||||
this._threading = true;
|
||||
|
||||
// Internal objects
|
||||
this._sock = null; // Websock object
|
||||
this._display = null; // Display object
|
||||
|
|
@ -715,6 +717,7 @@ export default class RFB extends EventTargetMixin {
|
|||
}
|
||||
|
||||
get statsFps() { return this._display.fps; }
|
||||
get statsDroppedFps() { return this._display.droppedFps; }
|
||||
|
||||
get enableWebRTC() { return this._useUdp; }
|
||||
set enableWebRTC(value) {
|
||||
|
|
@ -739,6 +742,14 @@ export default class RFB extends EventTargetMixin {
|
|||
}
|
||||
}
|
||||
|
||||
get threading() { return this._threading; }
|
||||
set threading(value) {
|
||||
if (value !== this._threading) {
|
||||
this._threading = value;
|
||||
this._display.threading = value;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== PUBLIC METHODS =====
|
||||
|
||||
refreshSecondaryDisplays() {
|
||||
|
|
|
|||
|
|
@ -27,15 +27,22 @@ module.exports = (config) => {
|
|||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['mocha', 'sinon-chai'],
|
||||
frameworks: ['mocha'],
|
||||
|
||||
// list of files / patterns to load in the browser (loaded in order)
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
// node modules
|
||||
{ pattern: 'node_modules/chai/**', included: false },
|
||||
{ pattern: 'node_modules/sinon/**', included: false },
|
||||
{ pattern: 'node_modules/sinon-chai/**', included: false },
|
||||
// modules to test
|
||||
{ pattern: 'app/localization.js', included: false, type: 'module' },
|
||||
{ pattern: 'app/webutil.js', included: false, type: 'module' },
|
||||
{ pattern: 'core/**/*.js', included: false, type: 'module' },
|
||||
{ pattern: 'vendor/pako/**/*.js', included: false, type: 'module' },
|
||||
// tests
|
||||
{ pattern: 'tests/test.*.js', type: 'module' },
|
||||
// test support files
|
||||
{ pattern: 'tests/fake.*.js', included: false, type: 'module' },
|
||||
{ pattern: 'tests/assertions.js', type: 'module' },
|
||||
],
|
||||
|
|
|
|||
|
|
@ -95,5 +95,8 @@
|
|||
"rfb",
|
||||
"novnc",
|
||||
"websockify"
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"mime": "^4.0.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,13 +40,11 @@
|
|||
<link rel="apple-touch-icon" sizes="120x120" type="image/png" href="app/images/icons/368_kasm_logo_only_120x120.png">
|
||||
<link rel="apple-touch-icon" sizes="152x152" type="image/png" href="app/images/icons/368_kasm_logo_only_152x152.png">
|
||||
|
||||
<script src="vendor/interact.min.js"></script>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link rel="stylesheet" href="app/styles/base.css">
|
||||
<link rel="stylesheet" href="app/styles/screen.css">
|
||||
|
||||
<script src="app/error-handler.js"></script>
|
||||
<script type="module" src="app/error-handler.js"></script>
|
||||
|
||||
<script>
|
||||
let isInsideKasmVDI = false;
|
||||
|
|
@ -185,4 +183,4 @@
|
|||
document.addEventListener("fullscreenchange", fullscreenchanged);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ mv /home/ubuntu/record.bin.8 /usr/share/kasmvnc/www/recordings
|
|||
|
||||
Place recordings on the KasmVNC server in the /usr/share/kasmvnc/www/recordings directory, you may need to create this directory. Then navigate to https://server-ip:8444/tests/vnc_playback.html?data=record.bin.8 where record.bin.8 is the name of the playback file you placed in the recordings directory.
|
||||
|
||||
**If you are running a Dev container for KasmVNC** and running the front-end using nodejs, create a directory public/recordings from the root of the frontend code and place the videos in that location.
|
||||
|
||||
**Threaded Decoding**
|
||||
When threaded decoding on the client was added to KasmVNC in 1.4.0, this disrupted the playback testing framework. When threaded encoding is enabled, the client does not block on rendering, therefore the server will send frames as fast as it can regardless of if the client can process the frames or not. In this playback framework, the VNC session recording is played back without a frame rate limit and if threaded decoding is enabled the client will process as much of it as possible and end up discarding frames. To account for this, a target frame rate was added to the playback UI. When testing with threaded decoding enabled, be sure to set the iterations to 1 and provide a target frame rate. Keep increasing the target frame rate until you start dropping frames and then back the frame rate down until you get near 0.
|
||||
|
||||
## Pre-Test Modifications
|
||||
|
||||
Before running performance testing using recording playback, you need to run noVNC from source, rather than the 'compiled' webpack. See the docs at docs/DEVELOP.md for running noVNC from source.
|
||||
|
|
@ -39,13 +44,17 @@ The following recordings are used by Kasm Technologies to provide repeatable per
|
|||
|
||||
## Historical Statistics
|
||||
|
||||
This table keeps track of performance of pre-defined recordings, defined in the previous section, on static hardware that can be replicated over time to track performance improvements.
|
||||
This table keeps track of performance of pre-defined recordings, defined in the previous section, on static hardware that can be replicated over time to track performance improvements. Multi-threaded decoding was added during noVNC 1.3.0 development, previous testing did not include this feature.
|
||||
|
||||
| File | Commit | Hardware | OS | Browser | Webpacked | Result Avg |
|
||||
|------|-----|----|----|---------|-------|---------|
|
||||
| newyork.1 | 08233e6 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2446ms |
|
||||
| losangeles.1 | 08233e6 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2272ms |
|
||||
| newyork.1 | base64opt | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2273ms |
|
||||
| losangeles.1 | base64opt | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 1847ms |
|
||||
| newyork.1 | 4a6aa73 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 2128ms |
|
||||
| losangeles.1 | 4a6aa73 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 1766ms |
|
||||
| File | Commit/Version | Threaded | Hardware | OS | Browser | Webpacked | Result Avg |
|
||||
|------|--------|----------|----------|----|---------|-----------|------------|
|
||||
| newyork.1 | 08233e6 | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2446ms |
|
||||
| losangeles.1 | 08233e6 | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2272ms |
|
||||
| newyork.1 | base64opt | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2273ms |
|
||||
| losangeles.1 | base64opt | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 1847ms |
|
||||
| newyork.1 | 4a6aa73 | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 2128ms |
|
||||
| losangeles.1 | 4a6aa73 | N/A | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 1766ms |
|
||||
| newyork.1 | 1.3.0 | off | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 135 | False | 1956ms |
|
||||
| newyork.1 | 1.3.0 | **On** | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 135 | False | 696ms |
|
||||
| losangeles.1 | 1.3.0 | off | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 135 | False | 1166ms |
|
||||
| losangeles.1 | 1.3.0 | **On** | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 135 | False | 789ms |
|
||||
|
|
@ -41,6 +41,8 @@ function enableUI() {
|
|||
document.getElementById('mode1').checked = true;
|
||||
}
|
||||
|
||||
document.getElementById('threaded_decoding_on').checked = true;
|
||||
|
||||
/* eslint-disable-next-line camelcase */
|
||||
message("Loaded " + VNC_frame_data.length + " frames");
|
||||
|
||||
|
|
@ -101,7 +103,7 @@ function enableUI() {
|
|||
}
|
||||
|
||||
class IterationPlayer {
|
||||
constructor(iterations, frames) {
|
||||
constructor(iterations, frames, targetFramerate, threadedDecoding) {
|
||||
this._iterations = iterations;
|
||||
|
||||
this._iteration = undefined;
|
||||
|
|
@ -111,6 +113,10 @@ class IterationPlayer {
|
|||
|
||||
this._frames = frames;
|
||||
|
||||
this._targetFramerate = targetFramerate;
|
||||
|
||||
this._threadedDecoding = threadedDecoding;
|
||||
|
||||
this._state = 'running';
|
||||
|
||||
this.onfinish = () => {};
|
||||
|
|
@ -138,8 +144,14 @@ class IterationPlayer {
|
|||
this._finish();
|
||||
return;
|
||||
}
|
||||
|
||||
player.run(this._realtime, false);
|
||||
|
||||
if (this._iteration > 1) {
|
||||
setTimeout(() => {
|
||||
player.run(this._realtime, false, this._targetFramerate, this._threadedDecoding);
|
||||
}, 1000);
|
||||
} else {
|
||||
player.run(this._realtime, false, this._targetFramerate, this._threadedDecoding);
|
||||
}
|
||||
}
|
||||
|
||||
_finish() {
|
||||
|
|
@ -153,11 +165,15 @@ class IterationPlayer {
|
|||
this.onfinish(evt);
|
||||
}
|
||||
|
||||
_iterationFinish(duration) {
|
||||
_iterationFinish(duration, droppedFrames, droppedRects, numFrames) {
|
||||
const evt = new CustomEvent('iterationfinish',
|
||||
{ detail:
|
||||
{ duration: duration,
|
||||
number: this._iteration } } );
|
||||
number: this._iteration,
|
||||
droppedFrames: droppedFrames,
|
||||
droppedRects: droppedRects,
|
||||
numFrames: numFrames
|
||||
} } );
|
||||
this.oniterationfinish(evt);
|
||||
|
||||
this._nextIteration();
|
||||
|
|
@ -182,6 +198,7 @@ function start() {
|
|||
document.getElementById('startButton').disabled = true;
|
||||
|
||||
const iterations = document.getElementById('iterations').value;
|
||||
const targetFramerate = Number(document.getElementById('targetFramerate').value);
|
||||
|
||||
let realtime;
|
||||
|
||||
|
|
@ -193,9 +210,20 @@ function start() {
|
|||
realtime = true;
|
||||
}
|
||||
|
||||
const player = new IterationPlayer(iterations, frames);
|
||||
let threaded_decoding;
|
||||
|
||||
if (document.getElementById('threaded_decoding_on').checked) {
|
||||
message(`Starting playback with Threaded Decoding,`);
|
||||
threaded_decoding = true;
|
||||
} else {
|
||||
message(`Starting playback on decoding on main thread.`);
|
||||
threaded_decoding = false;
|
||||
}
|
||||
|
||||
const player = new IterationPlayer(iterations, frames, targetFramerate, threaded_decoding);
|
||||
player.oniterationfinish = (evt) => {
|
||||
message(`Iteration ${evt.detail.number} took ${evt.detail.duration}ms`);
|
||||
const fps = Math.round(evt.detail.numFrames / (evt.detail.duration / 1000))
|
||||
message(`Iteration ${evt.detail.number} took ${evt.detail.duration}ms at ${fps} FPS, Dropping ${evt.detail.droppedFrames} of ${evt.detail.numFrames} Frames and ${evt.detail.droppedRects} Rects`);
|
||||
};
|
||||
player.onrfbdisconnected = (evt) => {
|
||||
if (!evt.detail.clean) {
|
||||
|
|
|
|||
|
|
@ -73,13 +73,16 @@ export default class RecordingPlayer {
|
|||
this._startTime = undefined;
|
||||
this._realtime = true;
|
||||
this._trafficManagement = true;
|
||||
this._frameTimeLimit = 0;
|
||||
|
||||
this._running = false;
|
||||
|
||||
this.onfinish = () => {};
|
||||
|
||||
this._lastFrameTime = null;
|
||||
}
|
||||
|
||||
run(realtime, trafficManagement) {
|
||||
run(realtime, trafficManagement, targetFramerate, threaded_decoding) {
|
||||
// initialize a new RFB
|
||||
this._ws = new FakeWebSocket();
|
||||
this._rfb = new RFB(document.getElementById('VNC_screen'), document.getElementById('noVNC_keyboardinput'), this._ws);
|
||||
|
|
@ -88,6 +91,10 @@ export default class RecordingPlayer {
|
|||
this._handleDisconnect.bind(this));
|
||||
this._rfb.addEventListener("credentialsrequired",
|
||||
this._handleCredentials.bind(this));
|
||||
this._rfb.threading = threaded_decoding;
|
||||
|
||||
//clear the stats counter function so that we get totals at the end
|
||||
clearInterval(this._rfb._display._frameStatsInterval);
|
||||
|
||||
// reset the frame index and timer
|
||||
this._frameIndex = 0;
|
||||
|
|
@ -95,6 +102,7 @@ export default class RecordingPlayer {
|
|||
|
||||
this._realtime = realtime;
|
||||
this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement;
|
||||
this._frameTimeLimit = (targetFramerate > 0) ? 1000 / targetFramerate : 0;
|
||||
|
||||
this._running = true;
|
||||
this._queueNextPacket();
|
||||
|
|
@ -123,7 +131,20 @@ export default class RecordingPlayer {
|
|||
if (delay < 1) delay = 1;
|
||||
|
||||
setTimeout(this._doPacket.bind(this), delay);
|
||||
}
|
||||
else if (this._frameTimeLimit > 0 && this._lastFrameTime !== null) {
|
||||
const now = performance.now()
|
||||
const frameDelay = this._frameTimeLimit - (now - this._lastFrameTime)
|
||||
if (frameDelay > 0) {
|
||||
setTimeout(this._doPacket.bind(this), frameDelay)
|
||||
} else {
|
||||
setImmediate(this._doPacket.bind(this));
|
||||
}
|
||||
this._lastFrameTime = now
|
||||
} else {
|
||||
if (this._frameTimeLimit) {
|
||||
this._lastFrameTime = performance.now()
|
||||
}
|
||||
setImmediate(this._doPacket.bind(this));
|
||||
}
|
||||
}
|
||||
|
|
@ -160,8 +181,11 @@ export default class RecordingPlayer {
|
|||
} else {
|
||||
this._running = false;
|
||||
this._ws.onclose({code: 1000, reason: ""});
|
||||
let droppedFrames = this._rfb._display._droppedFrames;
|
||||
let droppedRects = this._rfb._display._droppedRects;
|
||||
let numFrames = this._rfb._display._flipCnt;
|
||||
delete this._rfb;
|
||||
this.onfinish((new Date()).getTime() - this._startTime);
|
||||
this.onfinish((new Date()).getTime() - this._startTime, droppedFrames, droppedRects, numFrames);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@
|
|||
Iterations: <input id='iterations'>
|
||||
Perftest:<input type='radio' id='mode1' name='mode' checked>
|
||||
Realtime:<input type='radio' id='mode2' name='mode'>
|
||||
<br><br>
|
||||
Threaded Decoding On:<input type='radio' id='threaded_decoding_on' name='threaded_decoding' checked>
|
||||
Off:<input type='radio' id='threaded_decoding_off' name='threaded_decoding'>
|
||||
<br><br>
|
||||
Target Frame Rate (0 = no limit): <input id='targetFramerate'>
|
||||
<br><br>
|
||||
|
||||
<input id='startButton' type='button' value='Start' disabled>
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ program
|
|||
const paths = {
|
||||
main: path.resolve(__dirname, '..'),
|
||||
core: path.resolve(__dirname, '..', 'core'),
|
||||
vendor: path.resolve(__dirname, '..', 'vendor'),
|
||||
libDirBase: path.resolve(__dirname, '..', 'lib'),
|
||||
};
|
||||
|
||||
|
|
@ -116,10 +115,6 @@ function makeLibFiles(sourceMaps) {
|
|||
});
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
const handler = handleDir.bind(null, false, paths.main);
|
||||
return walkDir(paths.vendor, handler);
|
||||
})
|
||||
.then(() => {
|
||||
const handler = handleDir.bind(null, true, paths.core);
|
||||
return walkDir(paths.core, handler);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,21 +0,0 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (C) 2014-2016 by Vitaly Puzrin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
This is an ES6-modules-compatible version of
|
||||
https://github.com/nodeca/pako, based on pako version 1.0.3.
|
||||
|
||||
It's more-or-less a direct translation of the original, with unused parts
|
||||
removed, and the dynamic support for non-typed arrays removed (since ES6
|
||||
modules don't work well with dynamic exports).
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// reduce buffer size, avoiding mem copy
|
||||
export function shrinkBuf (buf, size) {
|
||||
if (buf.length === size) { return buf; }
|
||||
if (buf.subarray) { return buf.subarray(0, size); }
|
||||
buf.length = size;
|
||||
return buf;
|
||||
};
|
||||
|
||||
|
||||
export function arraySet (dest, src, src_offs, len, dest_offs) {
|
||||
if (src.subarray && dest.subarray) {
|
||||
dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
|
||||
return;
|
||||
}
|
||||
// Fallback to ordinary array
|
||||
for (var i = 0; i < len; i++) {
|
||||
dest[dest_offs + i] = src[src_offs + i];
|
||||
}
|
||||
}
|
||||
|
||||
// Join array of chunks to single array.
|
||||
export function flattenChunks (chunks) {
|
||||
var i, l, len, pos, chunk, result;
|
||||
|
||||
// calculate data length
|
||||
len = 0;
|
||||
for (i = 0, l = chunks.length; i < l; i++) {
|
||||
len += chunks[i].length;
|
||||
}
|
||||
|
||||
// join chunks
|
||||
result = new Uint8Array(len);
|
||||
pos = 0;
|
||||
for (i = 0, l = chunks.length; i < l; i++) {
|
||||
chunk = chunks[i];
|
||||
result.set(chunk, pos);
|
||||
pos += chunk.length;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export var Buf8 = Uint8Array;
|
||||
export var Buf16 = Uint16Array;
|
||||
export var Buf32 = Int32Array;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
||||
// It doesn't worth to make additional optimizationa as in original.
|
||||
// Small size is preferable.
|
||||
|
||||
export default function adler32(adler, buf, len, pos) {
|
||||
var s1 = (adler & 0xffff) |0,
|
||||
s2 = ((adler >>> 16) & 0xffff) |0,
|
||||
n = 0;
|
||||
|
||||
while (len !== 0) {
|
||||
// Set limit ~ twice less than 5552, to keep
|
||||
// s2 in 31-bits, because we force signed ints.
|
||||
// in other case %= will fail.
|
||||
n = len > 2000 ? 2000 : len;
|
||||
len -= n;
|
||||
|
||||
do {
|
||||
s1 = (s1 + buf[pos++]) |0;
|
||||
s2 = (s2 + s1) |0;
|
||||
} while (--n);
|
||||
|
||||
s1 %= 65521;
|
||||
s2 %= 65521;
|
||||
}
|
||||
|
||||
return (s1 | (s2 << 16)) |0;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
export default {
|
||||
|
||||
/* Allowed flush values; see deflate() and inflate() below for details */
|
||||
Z_NO_FLUSH: 0,
|
||||
Z_PARTIAL_FLUSH: 1,
|
||||
Z_SYNC_FLUSH: 2,
|
||||
Z_FULL_FLUSH: 3,
|
||||
Z_FINISH: 4,
|
||||
Z_BLOCK: 5,
|
||||
Z_TREES: 6,
|
||||
|
||||
/* Return codes for the compression/decompression functions. Negative values
|
||||
* are errors, positive values are used for special but normal events.
|
||||
*/
|
||||
Z_OK: 0,
|
||||
Z_STREAM_END: 1,
|
||||
Z_NEED_DICT: 2,
|
||||
Z_ERRNO: -1,
|
||||
Z_STREAM_ERROR: -2,
|
||||
Z_DATA_ERROR: -3,
|
||||
//Z_MEM_ERROR: -4,
|
||||
Z_BUF_ERROR: -5,
|
||||
//Z_VERSION_ERROR: -6,
|
||||
|
||||
/* compression levels */
|
||||
Z_NO_COMPRESSION: 0,
|
||||
Z_BEST_SPEED: 1,
|
||||
Z_BEST_COMPRESSION: 9,
|
||||
Z_DEFAULT_COMPRESSION: -1,
|
||||
|
||||
|
||||
Z_FILTERED: 1,
|
||||
Z_HUFFMAN_ONLY: 2,
|
||||
Z_RLE: 3,
|
||||
Z_FIXED: 4,
|
||||
Z_DEFAULT_STRATEGY: 0,
|
||||
|
||||
/* Possible values of the data_type field (though see inflate()) */
|
||||
Z_BINARY: 0,
|
||||
Z_TEXT: 1,
|
||||
//Z_ASCII: 1, // = Z_TEXT (deprecated)
|
||||
Z_UNKNOWN: 2,
|
||||
|
||||
/* The deflate compression method */
|
||||
Z_DEFLATED: 8
|
||||
//Z_NULL: null // Use -1 or null inline, depending on var type
|
||||
};
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// Note: we can't get significant speed boost here.
|
||||
// So write code to minimize size - no pregenerated tables
|
||||
// and array tools dependencies.
|
||||
|
||||
|
||||
// Use ordinary array, since untyped makes no boost here
|
||||
export default function makeTable() {
|
||||
var c, table = [];
|
||||
|
||||
for (var n = 0; n < 256; n++) {
|
||||
c = n;
|
||||
for (var k = 0; k < 8; k++) {
|
||||
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
||||
}
|
||||
table[n] = c;
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
// Create table on load. Just 255 signed longs. Not a problem.
|
||||
var crcTable = makeTable();
|
||||
|
||||
|
||||
function crc32(crc, buf, len, pos) {
|
||||
var t = crcTable,
|
||||
end = pos + len;
|
||||
|
||||
crc ^= -1;
|
||||
|
||||
for (var i = pos; i < end; i++) {
|
||||
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
|
||||
}
|
||||
|
||||
return (crc ^ (-1)); // >>> 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,35 +0,0 @@
|
|||
export default function GZheader() {
|
||||
/* true if compressed data believed to be text */
|
||||
this.text = 0;
|
||||
/* modification time */
|
||||
this.time = 0;
|
||||
/* extra flags (not used when writing a gzip file) */
|
||||
this.xflags = 0;
|
||||
/* operating system */
|
||||
this.os = 0;
|
||||
/* pointer to extra field or Z_NULL if none */
|
||||
this.extra = null;
|
||||
/* extra field length (valid if extra != Z_NULL) */
|
||||
this.extra_len = 0; // Actually, we don't need it in JS,
|
||||
// but leave for few code modifications
|
||||
|
||||
//
|
||||
// Setup limits is not necessary because in js we should not preallocate memory
|
||||
// for inflate use constant limit in 65536 bytes
|
||||
//
|
||||
|
||||
/* space at extra (only when reading header) */
|
||||
// this.extra_max = 0;
|
||||
/* pointer to zero-terminated file name or Z_NULL */
|
||||
this.name = '';
|
||||
/* space at name (only when reading header) */
|
||||
// this.name_max = 0;
|
||||
/* pointer to zero-terminated comment or Z_NULL */
|
||||
this.comment = '';
|
||||
/* space at comment (only when reading header) */
|
||||
// this.comm_max = 0;
|
||||
/* true if there was or will be a header crc */
|
||||
this.hcrc = 0;
|
||||
/* true when done reading gzip header (not used when writing a gzip file) */
|
||||
this.done = false;
|
||||
}
|
||||
|
|
@ -1,324 +0,0 @@
|
|||
// See state defs from inflate.js
|
||||
var BAD = 30; /* got a data error -- remain here until reset */
|
||||
var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
literal and match bytes until either not enough input or output is
|
||||
available, an end-of-block is encountered, or a data error is encountered.
|
||||
When large enough input and output buffers are supplied to inflate(), for
|
||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||
inflate execution time is spent in this routine.
|
||||
|
||||
Entry assumptions:
|
||||
|
||||
state.mode === LEN
|
||||
strm.avail_in >= 6
|
||||
strm.avail_out >= 258
|
||||
start >= strm.avail_out
|
||||
state.bits < 8
|
||||
|
||||
On return, state.mode is one of:
|
||||
|
||||
LEN -- ran out of enough output space or enough available input
|
||||
TYPE -- reached end of block code, inflate() to interpret next block
|
||||
BAD -- error in block data
|
||||
|
||||
Notes:
|
||||
|
||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||
Therefore if strm.avail_in >= 6, then there is enough input to avoid
|
||||
checking for available input while decoding.
|
||||
|
||||
- The maximum bytes that a single length/distance pair can output is 258
|
||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||
requires strm.avail_out >= 258 for each loop to avoid checking for
|
||||
output space.
|
||||
*/
|
||||
export default function inflate_fast(strm, start) {
|
||||
var state;
|
||||
var _in; /* local strm.input */
|
||||
var last; /* have enough input while in < last */
|
||||
var _out; /* local strm.output */
|
||||
var beg; /* inflate()'s initial strm.output */
|
||||
var end; /* while out < end, enough space available */
|
||||
//#ifdef INFLATE_STRICT
|
||||
var dmax; /* maximum distance from zlib header */
|
||||
//#endif
|
||||
var wsize; /* window size or zero if not using window */
|
||||
var whave; /* valid bytes in the window */
|
||||
var wnext; /* window write index */
|
||||
// Use `s_window` instead `window`, avoid conflict with instrumentation tools
|
||||
var s_window; /* allocated sliding window, if wsize != 0 */
|
||||
var hold; /* local strm.hold */
|
||||
var bits; /* local strm.bits */
|
||||
var lcode; /* local strm.lencode */
|
||||
var dcode; /* local strm.distcode */
|
||||
var lmask; /* mask for first level of length codes */
|
||||
var dmask; /* mask for first level of distance codes */
|
||||
var here; /* retrieved table entry */
|
||||
var op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
var len; /* match length, unused bytes */
|
||||
var dist; /* match distance */
|
||||
var from; /* where to copy match from */
|
||||
var from_source;
|
||||
|
||||
|
||||
var input, output; // JS specific, because we have no pointers
|
||||
|
||||
/* copy state to local variables */
|
||||
state = strm.state;
|
||||
//here = state.here;
|
||||
_in = strm.next_in;
|
||||
input = strm.input;
|
||||
last = _in + (strm.avail_in - 5);
|
||||
_out = strm.next_out;
|
||||
output = strm.output;
|
||||
beg = _out - (start - strm.avail_out);
|
||||
end = _out + (strm.avail_out - 257);
|
||||
//#ifdef INFLATE_STRICT
|
||||
dmax = state.dmax;
|
||||
//#endif
|
||||
wsize = state.wsize;
|
||||
whave = state.whave;
|
||||
wnext = state.wnext;
|
||||
s_window = state.window;
|
||||
hold = state.hold;
|
||||
bits = state.bits;
|
||||
lcode = state.lencode;
|
||||
dcode = state.distcode;
|
||||
lmask = (1 << state.lenbits) - 1;
|
||||
dmask = (1 << state.distbits) - 1;
|
||||
|
||||
|
||||
/* decode literals and length/distances until end-of-block or not enough
|
||||
input data or output space */
|
||||
|
||||
top:
|
||||
do {
|
||||
if (bits < 15) {
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
}
|
||||
|
||||
here = lcode[hold & lmask];
|
||||
|
||||
dolen:
|
||||
for (;;) { // Goto emulation
|
||||
op = here >>> 24/*here.bits*/;
|
||||
hold >>>= op;
|
||||
bits -= op;
|
||||
op = (here >>> 16) & 0xff/*here.op*/;
|
||||
if (op === 0) { /* literal */
|
||||
//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
// "inflate: literal '%c'\n" :
|
||||
// "inflate: literal 0x%02x\n", here.val));
|
||||
output[_out++] = here & 0xffff/*here.val*/;
|
||||
}
|
||||
else if (op & 16) { /* length base */
|
||||
len = here & 0xffff/*here.val*/;
|
||||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
if (bits < op) {
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
}
|
||||
len += hold & ((1 << op) - 1);
|
||||
hold >>>= op;
|
||||
bits -= op;
|
||||
}
|
||||
//Tracevv((stderr, "inflate: length %u\n", len));
|
||||
if (bits < 15) {
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
}
|
||||
here = dcode[hold & dmask];
|
||||
|
||||
dodist:
|
||||
for (;;) { // goto emulation
|
||||
op = here >>> 24/*here.bits*/;
|
||||
hold >>>= op;
|
||||
bits -= op;
|
||||
op = (here >>> 16) & 0xff/*here.op*/;
|
||||
|
||||
if (op & 16) { /* distance base */
|
||||
dist = here & 0xffff/*here.val*/;
|
||||
op &= 15; /* number of extra bits */
|
||||
if (bits < op) {
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
if (bits < op) {
|
||||
hold += input[_in++] << bits;
|
||||
bits += 8;
|
||||
}
|
||||
}
|
||||
dist += hold & ((1 << op) - 1);
|
||||
//#ifdef INFLATE_STRICT
|
||||
if (dist > dmax) {
|
||||
strm.msg = 'invalid distance too far back';
|
||||
state.mode = BAD;
|
||||
break top;
|
||||
}
|
||||
//#endif
|
||||
hold >>>= op;
|
||||
bits -= op;
|
||||
//Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||
op = _out - beg; /* max distance in output */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
if (state.sane) {
|
||||
strm.msg = 'invalid distance too far back';
|
||||
state.mode = BAD;
|
||||
break top;
|
||||
}
|
||||
|
||||
// (!) This block is disabled in zlib defailts,
|
||||
// don't enable it for binary compatibility
|
||||
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
// if (len <= op - whave) {
|
||||
// do {
|
||||
// output[_out++] = 0;
|
||||
// } while (--len);
|
||||
// continue top;
|
||||
// }
|
||||
// len -= op - whave;
|
||||
// do {
|
||||
// output[_out++] = 0;
|
||||
// } while (--op > whave);
|
||||
// if (op === 0) {
|
||||
// from = _out - dist;
|
||||
// do {
|
||||
// output[_out++] = output[from++];
|
||||
// } while (--len);
|
||||
// continue top;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
from = 0; // window index
|
||||
from_source = s_window;
|
||||
if (wnext === 0) { /* very common case */
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
output[_out++] = s_window[from++];
|
||||
} while (--op);
|
||||
from = _out - dist; /* rest from output */
|
||||
from_source = output;
|
||||
}
|
||||
}
|
||||
else if (wnext < op) { /* wrap around window */
|
||||
from += wsize + wnext - op;
|
||||
op -= wnext;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
do {
|
||||
output[_out++] = s_window[from++];
|
||||
} while (--op);
|
||||
from = 0;
|
||||
if (wnext < len) { /* some from start of window */
|
||||
op = wnext;
|
||||
len -= op;
|
||||
do {
|
||||
output[_out++] = s_window[from++];
|
||||
} while (--op);
|
||||
from = _out - dist; /* rest from output */
|
||||
from_source = output;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* contiguous in window */
|
||||
from += wnext - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
output[_out++] = s_window[from++];
|
||||
} while (--op);
|
||||
from = _out - dist; /* rest from output */
|
||||
from_source = output;
|
||||
}
|
||||
}
|
||||
while (len > 2) {
|
||||
output[_out++] = from_source[from++];
|
||||
output[_out++] = from_source[from++];
|
||||
output[_out++] = from_source[from++];
|
||||
len -= 3;
|
||||
}
|
||||
if (len) {
|
||||
output[_out++] = from_source[from++];
|
||||
if (len > 1) {
|
||||
output[_out++] = from_source[from++];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
from = _out - dist; /* copy direct from output */
|
||||
do { /* minimum length is three */
|
||||
output[_out++] = output[from++];
|
||||
output[_out++] = output[from++];
|
||||
output[_out++] = output[from++];
|
||||
len -= 3;
|
||||
} while (len > 2);
|
||||
if (len) {
|
||||
output[_out++] = output[from++];
|
||||
if (len > 1) {
|
||||
output[_out++] = output[from++];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((op & 64) === 0) { /* 2nd level distance code */
|
||||
here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
|
||||
continue dodist;
|
||||
}
|
||||
else {
|
||||
strm.msg = 'invalid distance code';
|
||||
state.mode = BAD;
|
||||
break top;
|
||||
}
|
||||
|
||||
break; // need to emulate goto via "continue"
|
||||
}
|
||||
}
|
||||
else if ((op & 64) === 0) { /* 2nd level length code */
|
||||
here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
|
||||
continue dolen;
|
||||
}
|
||||
else if (op & 32) { /* end-of-block */
|
||||
//Tracevv((stderr, "inflate: end of block\n"));
|
||||
state.mode = TYPE;
|
||||
break top;
|
||||
}
|
||||
else {
|
||||
strm.msg = 'invalid literal/length code';
|
||||
state.mode = BAD;
|
||||
break top;
|
||||
}
|
||||
|
||||
break; // need to emulate goto via "continue"
|
||||
}
|
||||
} while (_in < last && _out < end);
|
||||
|
||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||
len = bits >> 3;
|
||||
_in -= len;
|
||||
bits -= len << 3;
|
||||
hold &= (1 << bits) - 1;
|
||||
|
||||
/* update state and return */
|
||||
strm.next_in = _in;
|
||||
strm.next_out = _out;
|
||||
strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
|
||||
strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
|
||||
state.hold = hold;
|
||||
state.bits = bits;
|
||||
return;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,322 +0,0 @@
|
|||
import * as utils from "../utils/common.js";
|
||||
|
||||
var MAXBITS = 15;
|
||||
var ENOUGH_LENS = 852;
|
||||
var ENOUGH_DISTS = 592;
|
||||
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
|
||||
|
||||
var CODES = 0;
|
||||
var LENS = 1;
|
||||
var DISTS = 2;
|
||||
|
||||
var lbase = [ /* Length codes 257..285 base */
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
];
|
||||
|
||||
var lext = [ /* Length codes 257..285 extra */
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
|
||||
];
|
||||
|
||||
var dbase = [ /* Distance codes 0..29 base */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577, 0, 0
|
||||
];
|
||||
|
||||
var dext = [ /* Distance codes 0..29 extra */
|
||||
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
|
||||
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
|
||||
28, 28, 29, 29, 64, 64
|
||||
];
|
||||
|
||||
export default function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
|
||||
{
|
||||
var bits = opts.bits;
|
||||
//here = opts.here; /* table entry for duplication */
|
||||
|
||||
var len = 0; /* a code's length in bits */
|
||||
var sym = 0; /* index of code symbols */
|
||||
var min = 0, max = 0; /* minimum and maximum code lengths */
|
||||
var root = 0; /* number of index bits for root table */
|
||||
var curr = 0; /* number of index bits for current table */
|
||||
var drop = 0; /* code bits to drop for sub-table */
|
||||
var left = 0; /* number of prefix codes available */
|
||||
var used = 0; /* code entries in table used */
|
||||
var huff = 0; /* Huffman code */
|
||||
var incr; /* for incrementing code, index */
|
||||
var fill; /* index for replicating entries */
|
||||
var low; /* low bits for current root entry */
|
||||
var mask; /* mask for low root bits */
|
||||
var next; /* next available space in table */
|
||||
var base = null; /* base value table to use */
|
||||
var base_index = 0;
|
||||
// var shoextra; /* extra bits table to use */
|
||||
var end; /* use base and extra for symbol > end */
|
||||
var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
|
||||
var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
|
||||
var extra = null;
|
||||
var extra_index = 0;
|
||||
|
||||
var here_bits, here_op, here_val;
|
||||
|
||||
/*
|
||||
Process a set of code lengths to create a canonical Huffman code. The
|
||||
code lengths are lens[0..codes-1]. Each length corresponds to the
|
||||
symbols 0..codes-1. The Huffman code is generated by first sorting the
|
||||
symbols by length from short to long, and retaining the symbol order
|
||||
for codes with equal lengths. Then the code starts with all zero bits
|
||||
for the first code of the shortest length, and the codes are integer
|
||||
increments for the same length, and zeros are appended as the length
|
||||
increases. For the deflate format, these bits are stored backwards
|
||||
from their more natural integer increment ordering, and so when the
|
||||
decoding tables are built in the large loop below, the integer codes
|
||||
are incremented backwards.
|
||||
|
||||
This routine assumes, but does not check, that all of the entries in
|
||||
lens[] are in the range 0..MAXBITS. The caller must assure this.
|
||||
1..MAXBITS is interpreted as that code length. zero means that that
|
||||
symbol does not occur in this code.
|
||||
|
||||
The codes are sorted by computing a count of codes for each length,
|
||||
creating from that a table of starting indices for each length in the
|
||||
sorted table, and then entering the symbols in order in the sorted
|
||||
table. The sorted table is work[], with that space being provided by
|
||||
the caller.
|
||||
|
||||
The length counts are used for other purposes as well, i.e. finding
|
||||
the minimum and maximum length codes, determining if there are any
|
||||
codes at all, checking for a valid set of lengths, and looking ahead
|
||||
at length counts to determine sub-table sizes when building the
|
||||
decoding tables.
|
||||
*/
|
||||
|
||||
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
|
||||
for (len = 0; len <= MAXBITS; len++) {
|
||||
count[len] = 0;
|
||||
}
|
||||
for (sym = 0; sym < codes; sym++) {
|
||||
count[lens[lens_index + sym]]++;
|
||||
}
|
||||
|
||||
/* bound code lengths, force root to be within code lengths */
|
||||
root = bits;
|
||||
for (max = MAXBITS; max >= 1; max--) {
|
||||
if (count[max] !== 0) { break; }
|
||||
}
|
||||
if (root > max) {
|
||||
root = max;
|
||||
}
|
||||
if (max === 0) { /* no symbols to code at all */
|
||||
//table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
|
||||
//table.bits[opts.table_index] = 1; //here.bits = (var char)1;
|
||||
//table.val[opts.table_index++] = 0; //here.val = (var short)0;
|
||||
table[table_index++] = (1 << 24) | (64 << 16) | 0;
|
||||
|
||||
|
||||
//table.op[opts.table_index] = 64;
|
||||
//table.bits[opts.table_index] = 1;
|
||||
//table.val[opts.table_index++] = 0;
|
||||
table[table_index++] = (1 << 24) | (64 << 16) | 0;
|
||||
|
||||
opts.bits = 1;
|
||||
return 0; /* no symbols, but wait for decoding to report error */
|
||||
}
|
||||
for (min = 1; min < max; min++) {
|
||||
if (count[min] !== 0) { break; }
|
||||
}
|
||||
if (root < min) {
|
||||
root = min;
|
||||
}
|
||||
|
||||
/* check for an over-subscribed or incomplete set of lengths */
|
||||
left = 1;
|
||||
for (len = 1; len <= MAXBITS; len++) {
|
||||
left <<= 1;
|
||||
left -= count[len];
|
||||
if (left < 0) {
|
||||
return -1;
|
||||
} /* over-subscribed */
|
||||
}
|
||||
if (left > 0 && (type === CODES || max !== 1)) {
|
||||
return -1; /* incomplete set */
|
||||
}
|
||||
|
||||
/* generate offsets into symbol table for each length for sorting */
|
||||
offs[1] = 0;
|
||||
for (len = 1; len < MAXBITS; len++) {
|
||||
offs[len + 1] = offs[len] + count[len];
|
||||
}
|
||||
|
||||
/* sort symbols by length, by symbol order within each length */
|
||||
for (sym = 0; sym < codes; sym++) {
|
||||
if (lens[lens_index + sym] !== 0) {
|
||||
work[offs[lens[lens_index + sym]]++] = sym;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Create and fill in decoding tables. In this loop, the table being
|
||||
filled is at next and has curr index bits. The code being used is huff
|
||||
with length len. That code is converted to an index by dropping drop
|
||||
bits off of the bottom. For codes where len is less than drop + curr,
|
||||
those top drop + curr - len bits are incremented through all values to
|
||||
fill the table with replicated entries.
|
||||
|
||||
root is the number of index bits for the root table. When len exceeds
|
||||
root, sub-tables are created pointed to by the root entry with an index
|
||||
of the low root bits of huff. This is saved in low to check for when a
|
||||
new sub-table should be started. drop is zero when the root table is
|
||||
being filled, and drop is root when sub-tables are being filled.
|
||||
|
||||
When a new sub-table is needed, it is necessary to look ahead in the
|
||||
code lengths to determine what size sub-table is needed. The length
|
||||
counts are used for this, and so count[] is decremented as codes are
|
||||
entered in the tables.
|
||||
|
||||
used keeps track of how many table entries have been allocated from the
|
||||
provided *table space. It is checked for LENS and DIST tables against
|
||||
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
|
||||
the initial root table size constants. See the comments in inftrees.h
|
||||
for more information.
|
||||
|
||||
sym increments through all symbols, and the loop terminates when
|
||||
all codes of length max, i.e. all codes, have been processed. This
|
||||
routine permits incomplete codes, so another loop after this one fills
|
||||
in the rest of the decoding tables with invalid code markers.
|
||||
*/
|
||||
|
||||
/* set up for code type */
|
||||
// poor man optimization - use if-else instead of switch,
|
||||
// to avoid deopts in old v8
|
||||
if (type === CODES) {
|
||||
base = extra = work; /* dummy value--not used */
|
||||
end = 19;
|
||||
|
||||
} else if (type === LENS) {
|
||||
base = lbase;
|
||||
base_index -= 257;
|
||||
extra = lext;
|
||||
extra_index -= 257;
|
||||
end = 256;
|
||||
|
||||
} else { /* DISTS */
|
||||
base = dbase;
|
||||
extra = dext;
|
||||
end = -1;
|
||||
}
|
||||
|
||||
/* initialize opts for loop */
|
||||
huff = 0; /* starting code */
|
||||
sym = 0; /* starting code symbol */
|
||||
len = min; /* starting code length */
|
||||
next = table_index; /* current table to fill in */
|
||||
curr = root; /* current table index bits */
|
||||
drop = 0; /* current bits to drop from code for index */
|
||||
low = -1; /* trigger new sub-table when len > root */
|
||||
used = 1 << root; /* use root table entries */
|
||||
mask = used - 1; /* mask for comparing low */
|
||||
|
||||
/* check available table space */
|
||||
if ((type === LENS && used > ENOUGH_LENS) ||
|
||||
(type === DISTS && used > ENOUGH_DISTS)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* process all codes and make table entries */
|
||||
for (;;) {
|
||||
/* create table entry */
|
||||
here_bits = len - drop;
|
||||
if (work[sym] < end) {
|
||||
here_op = 0;
|
||||
here_val = work[sym];
|
||||
}
|
||||
else if (work[sym] > end) {
|
||||
here_op = extra[extra_index + work[sym]];
|
||||
here_val = base[base_index + work[sym]];
|
||||
}
|
||||
else {
|
||||
here_op = 32 + 64; /* end of block */
|
||||
here_val = 0;
|
||||
}
|
||||
|
||||
/* replicate for those indices with low len bits equal to huff */
|
||||
incr = 1 << (len - drop);
|
||||
fill = 1 << curr;
|
||||
min = fill; /* save offset to next table */
|
||||
do {
|
||||
fill -= incr;
|
||||
table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
|
||||
} while (fill !== 0);
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
incr = 1 << (len - 1);
|
||||
while (huff & incr) {
|
||||
incr >>= 1;
|
||||
}
|
||||
if (incr !== 0) {
|
||||
huff &= incr - 1;
|
||||
huff += incr;
|
||||
} else {
|
||||
huff = 0;
|
||||
}
|
||||
|
||||
/* go to next symbol, update count, len */
|
||||
sym++;
|
||||
if (--count[len] === 0) {
|
||||
if (len === max) { break; }
|
||||
len = lens[lens_index + work[sym]];
|
||||
}
|
||||
|
||||
/* create new sub-table if needed */
|
||||
if (len > root && (huff & mask) !== low) {
|
||||
/* if first time, transition to sub-tables */
|
||||
if (drop === 0) {
|
||||
drop = root;
|
||||
}
|
||||
|
||||
/* increment past last table */
|
||||
next += min; /* here min is 1 << curr */
|
||||
|
||||
/* determine length of next table */
|
||||
curr = len - drop;
|
||||
left = 1 << curr;
|
||||
while (curr + drop < max) {
|
||||
left -= count[curr + drop];
|
||||
if (left <= 0) { break; }
|
||||
curr++;
|
||||
left <<= 1;
|
||||
}
|
||||
|
||||
/* check for enough space */
|
||||
used += 1 << curr;
|
||||
if ((type === LENS && used > ENOUGH_LENS) ||
|
||||
(type === DISTS && used > ENOUGH_DISTS)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
low = huff & mask;
|
||||
/*table.op[low] = curr;
|
||||
table.bits[low] = root;
|
||||
table.val[low] = next - opts.table_index;*/
|
||||
table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
|
||||
}
|
||||
}
|
||||
|
||||
/* fill in remaining table entry if code is incomplete (guaranteed to have
|
||||
at most one remaining entry, since if the code is incomplete, the
|
||||
maximum code length that was allowed to get this far is one bit) */
|
||||
if (huff !== 0) {
|
||||
//table.op[next + huff] = 64; /* invalid code marker */
|
||||
//table.bits[next + huff] = len - drop;
|
||||
//table.val[next + huff] = 0;
|
||||
table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
|
||||
}
|
||||
|
||||
/* set return parameters */
|
||||
//opts.table_index += used;
|
||||
opts.bits = root;
|
||||
return 0;
|
||||
};
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
export default {
|
||||
2: 'need dictionary', /* Z_NEED_DICT 2 */
|
||||
1: 'stream end', /* Z_STREAM_END 1 */
|
||||
0: '', /* Z_OK 0 */
|
||||
'-1': 'file error', /* Z_ERRNO (-1) */
|
||||
'-2': 'stream error', /* Z_STREAM_ERROR (-2) */
|
||||
'-3': 'data error', /* Z_DATA_ERROR (-3) */
|
||||
'-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
|
||||
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
||||
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,24 +0,0 @@
|
|||
export default function ZStream() {
|
||||
/* next input byte */
|
||||
this.input = null; // JS specific, because we have no pointers
|
||||
this.next_in = 0;
|
||||
/* number of bytes available at input */
|
||||
this.avail_in = 0;
|
||||
/* total number of input bytes read so far */
|
||||
this.total_in = 0;
|
||||
/* next output byte should be put there */
|
||||
this.output = null; // JS specific, because we have no pointers
|
||||
this.next_out = 0;
|
||||
/* remaining free space at output */
|
||||
this.avail_out = 0;
|
||||
/* total number of bytes output so far */
|
||||
this.total_out = 0;
|
||||
/* last error message, NULL if no error */
|
||||
this.msg = ''/*Z_NULL*/;
|
||||
/* not visible by applications */
|
||||
this.state = null;
|
||||
/* best guess about the data type: binary or text */
|
||||
this.data_type = 2/*Z_UNKNOWN*/;
|
||||
/* adler32 value of the uncompressed data */
|
||||
this.adler = 0;
|
||||
}
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
/* Copyright (c) 2014 Taylor Hakes
|
||||
* Copyright (c) 2014 Forbes Lindesay
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function (root) {
|
||||
|
||||
// Store setTimeout reference so promise-polyfill will be unaffected by
|
||||
// other code modifying setTimeout (like sinon.useFakeTimers())
|
||||
var setTimeoutFunc = setTimeout;
|
||||
|
||||
function noop() {}
|
||||
|
||||
// Polyfill for Function.prototype.bind
|
||||
function bind(fn, thisArg) {
|
||||
return function () {
|
||||
fn.apply(thisArg, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');
|
||||
if (typeof fn !== 'function') throw new TypeError('not a function');
|
||||
this._state = 0;
|
||||
this._handled = false;
|
||||
this._value = undefined;
|
||||
this._deferreds = [];
|
||||
|
||||
doResolve(fn, this);
|
||||
}
|
||||
|
||||
function handle(self, deferred) {
|
||||
while (self._state === 3) {
|
||||
self = self._value;
|
||||
}
|
||||
if (self._state === 0) {
|
||||
self._deferreds.push(deferred);
|
||||
return;
|
||||
}
|
||||
self._handled = true;
|
||||
Promise._immediateFn(function () {
|
||||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
||||
return;
|
||||
}
|
||||
var ret;
|
||||
try {
|
||||
ret = cb(self._value);
|
||||
} catch (e) {
|
||||
reject(deferred.promise, e);
|
||||
return;
|
||||
}
|
||||
resolve(deferred.promise, ret);
|
||||
});
|
||||
}
|
||||
|
||||
function resolve(self, newValue) {
|
||||
try {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
|
||||
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
||||
var then = newValue.then;
|
||||
if (newValue instanceof Promise) {
|
||||
self._state = 3;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(bind(then, newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._state = 1;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
} catch (e) {
|
||||
reject(self, e);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._state = 2;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function finale(self) {
|
||||
if (self._state === 2 && self._deferreds.length === 0) {
|
||||
Promise._immediateFn(function() {
|
||||
if (!self._handled) {
|
||||
Promise._unhandledRejectionFn(self._value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
||||
handle(self, self._deferreds[i]);
|
||||
}
|
||||
self._deferreds = null;
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise) {
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, self) {
|
||||
var done = false;
|
||||
try {
|
||||
fn(function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(self, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(self, reason);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(self, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
||||
|
||||
Promise.prototype.then = function (onFulfilled, onRejected) {
|
||||
var prom = new (this.constructor)(noop);
|
||||
|
||||
handle(this, new Handler(onFulfilled, onRejected, prom));
|
||||
return prom;
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
|
||||
function res(i, val) {
|
||||
try {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
then.call(val, function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve = function (value) {
|
||||
if (value && typeof value === 'object' && value.constructor === Promise) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
for (var i = 0, len = values.length; i < len; i++) {
|
||||
values[i].then(resolve, reject);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Use polyfill for setImmediate for performance gains
|
||||
Promise._immediateFn = (typeof setImmediate === 'function' && function (fn) { setImmediate(fn); }) ||
|
||||
function (fn) {
|
||||
setTimeoutFunc(fn, 0);
|
||||
};
|
||||
|
||||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
|
||||
if (typeof console !== 'undefined' && console) {
|
||||
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the immediate function to execute callbacks
|
||||
* @param fn {function} Function to execute
|
||||
* @deprecated
|
||||
*/
|
||||
Promise._setImmediateFn = function _setImmediateFn(fn) {
|
||||
Promise._immediateFn = fn;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the function to execute on unhandled rejection
|
||||
* @param {function} fn Function to execute on unhandled rejection
|
||||
* @deprecated
|
||||
*/
|
||||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
|
||||
Promise._unhandledRejectionFn = fn;
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = Promise;
|
||||
} else if (!root.Promise) {
|
||||
root.Promise = Promise;
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
const path = require('path');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
const HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||
// const SvgSpriteHtmlWebpackPlugin = require('svg-sprite-html-webpack');
|
||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
entry: {
|
||||
main: './app/ui.js',
|
||||
error_handler: './app/error-handler.js',
|
||||
promise: './vendor/promise.js',
|
||||
style: './app/styles/base.css'
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: '[name].bundle.js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /(node_modules)/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.(sa|sc|c)ss$/,
|
||||
use: [
|
||||
{
|
||||
loader: MiniCssExtractPlugin.loader
|
||||
},
|
||||
{
|
||||
loader: "css-loader",
|
||||
},
|
||||
// {
|
||||
// loader: "postcss-loader"
|
||||
// },
|
||||
{
|
||||
loader: "sass-loader",
|
||||
options: {
|
||||
implementation: require("sass")
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Now we apply rule for images
|
||||
test: /\.(png|jpe?g|gif|svg)$/,
|
||||
use: [
|
||||
{
|
||||
// Using file-loader for these files
|
||||
loader: "file-loader",
|
||||
|
||||
// In options we can set different things like format
|
||||
// and directory to save
|
||||
options: {
|
||||
outputPath: 'images'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Apply rule for fonts files
|
||||
test: /\.(woff|woff2|ttf|otf|eot)$/,
|
||||
use: [
|
||||
{
|
||||
// Using file-loader too
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
outputPath: 'fonts'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
// {
|
||||
// test: /\.svg$/,
|
||||
// exclude: /node_modules/,
|
||||
// use: SvgSpriteHtmlWebpackPlugin.getLoader(),
|
||||
// }
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new CssMinimizerPlugin(),
|
||||
],
|
||||
runtimeChunk: 'single',
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: '../index.html',
|
||||
template: 'vnc.html',
|
||||
minify: {
|
||||
html5: true,
|
||||
collapseWhitespace: true,
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
minifyURLs: false,
|
||||
removeAttributeQuotes: true,
|
||||
removeComments: true, // false for Vue SSR to find app placeholder
|
||||
removeEmptyAttributes: true,
|
||||
removeOptionalTags: true,
|
||||
removeRedundantAttributes: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributese: true,
|
||||
useShortDoctype: true
|
||||
}
|
||||
}),
|
||||
// new SvgSpriteHtmlWebpackPlugin({
|
||||
// append: true,
|
||||
// includeFiles: [
|
||||
// 'app/images/*.svg',
|
||||
// ],
|
||||
// generateSymbolId: function(svgFilePath, svgHash, svgContent) {
|
||||
// return svgHash.toString();
|
||||
// },
|
||||
// }),
|
||||
new HtmlWebpackInlineSVGPlugin({
|
||||
inlineAll: true,
|
||||
runPreEmit: true,
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: "[name].bundle.css"
|
||||
}),
|
||||
],
|
||||
};
|
||||
Loading…
Reference in New Issue