KASM-3574 worker cleanup (#49)
* KASM-3574 worker cleanup Co-authored-by: mattmcclaskey <matt@kasmweb.com>
This commit is contained in:
parent
34305e9956
commit
2f01048bc6
|
@ -28,12 +28,23 @@ export default class TightDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableQOI() {
|
// ===== PROPERTIES =====
|
||||||
if (!this._enableQOI) {
|
|
||||||
this._enableQOIWorkers();
|
get enableQOI() { return this._enableQOI; }
|
||||||
|
set enableQOI(enabled) {
|
||||||
|
if(this._enableQOI === enabled) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return this._enableQOI; //did it succeed
|
|
||||||
|
if (enabled) {
|
||||||
|
this._enableQOI = this._enableQOIWorkers();
|
||||||
|
} else {
|
||||||
|
this._enableQOI = false;
|
||||||
|
this._disableQOIWorkers();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== Public Methods =====
|
||||||
|
|
||||||
decodeRect(x, y, width, height, sock, display, depth, frame_id) {
|
decodeRect(x, y, width, height, sock, display, depth, frame_id) {
|
||||||
if (this._ctl === null) {
|
if (this._ctl === null) {
|
||||||
|
@ -87,6 +98,8 @@ export default class TightDecoder {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== Private Methods =====
|
||||||
|
|
||||||
_fillRect(x, y, width, height, sock, display, depth, frame_id) {
|
_fillRect(x, y, width, height, sock, display, depth, frame_id) {
|
||||||
if (sock.rQwait("TIGHT", 3)) {
|
if (sock.rQwait("TIGHT", 3)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -398,12 +411,33 @@ export default class TightDecoder {
|
||||||
return this._scratchBuffer;
|
return this._scratchBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _disableQOIWorkers() {
|
||||||
|
if (this._workers) {
|
||||||
|
this._enableQOI = false;
|
||||||
|
this._availableWorkers = null;
|
||||||
|
this._sabs = null;
|
||||||
|
this._sabsR = null;
|
||||||
|
this._arrs = null;
|
||||||
|
this._arrsR = null;
|
||||||
|
this._qoiRects = null;
|
||||||
|
this._rectQlooping = null;
|
||||||
|
for await (let i of Array.from(Array(this._threads).keys())) {
|
||||||
|
this._workers[i].terminate();
|
||||||
|
delete this._workers[i];
|
||||||
|
}
|
||||||
|
this._workers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_enableQOIWorkers() {
|
_enableQOIWorkers() {
|
||||||
|
const supportsSharedArrayBuffers = typeof SharedArrayBuffer !== "undefined";
|
||||||
|
if (!supportsSharedArrayBuffers) {
|
||||||
|
Log.Warn("Enabling QOI Failed, client not compatible.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let fullPath = window.location.pathname;
|
let fullPath = window.location.pathname;
|
||||||
let path = fullPath.substring(0, fullPath.lastIndexOf('/')+1);
|
let path = fullPath.substring(0, fullPath.lastIndexOf('/')+1);
|
||||||
let sabTest = typeof SharedArrayBuffer;
|
|
||||||
if (sabTest !== 'undefined') {
|
|
||||||
this._enableQOI = true;
|
|
||||||
if ((window.navigator.hardwareConcurrency) && (window.navigator.hardwareConcurrency >= 4)) {
|
if ((window.navigator.hardwareConcurrency) && (window.navigator.hardwareConcurrency >= 4)) {
|
||||||
this._threads = 16;
|
this._threads = 16;
|
||||||
} else {
|
} else {
|
||||||
|
@ -455,9 +489,7 @@ export default class TightDecoder {
|
||||||
for (let i = 0; i < this._threads; i++) {
|
for (let i = 0; i < this._threads; i++) {
|
||||||
this._workers[i].postMessage({path:path});
|
this._workers[i].postMessage({path:path});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this._enableQOI = false;
|
return true;
|
||||||
Log.Warn("Enabling QOI Failed, client not compatible.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
core/rfb.js
13
core/rfb.js
|
@ -491,15 +491,14 @@ export default class RFB extends EventTargetMixin {
|
||||||
if(this._enableQOI === enabled) {
|
if(this._enableQOI === enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (enabled) {
|
|
||||||
if (!this._decoders[encodings.encodingTight].enableQOI()) {
|
this._decoders[encodings.encodingTight].enableQOI = enabled;
|
||||||
//enabling qoi failed
|
this._enableQOI = this._decoders[encodings.encodingTight].enableQOI
|
||||||
return;
|
|
||||||
}
|
if (this._enableQOI === enabled) {
|
||||||
|
this._pendingApplyEncodingChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._enableQOI = enabled;
|
|
||||||
this._pendingApplyEncodingChanges = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get antiAliasing() { return this._display.antiAliasing; }
|
get antiAliasing() { return this._display.antiAliasing; }
|
||||||
|
|
Loading…
Reference in New Issue