mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
implement worker without proxies for better compatibility with old devices
This commit is contained in:
parent
e678d59a41
commit
5716e4cf05
3 changed files with 78 additions and 87 deletions
|
@ -1,25 +1,16 @@
|
|||
/* eslint-disable no-restricted-globals */
|
||||
import { decode } from 'blurhash';
|
||||
import { expose } from 'comlink';
|
||||
|
||||
/**
|
||||
* Decodes blurhash outside the main thread, in a web worker
|
||||
*
|
||||
* @param {string} hash - Hash to decode.
|
||||
* @param {number} width - Width of the decoded pixel array
|
||||
* @param {number} height - Height of the decoded pixel array.
|
||||
* @param {number} punch - Contrast of the decoded pixels
|
||||
* @returns {Uint8ClampedArray} - Returns the decoded pixels in the proxied response by Comlink
|
||||
*/
|
||||
function getPixels({
|
||||
hash,
|
||||
width,
|
||||
height
|
||||
}): Uint8ClampedArray {
|
||||
self.onmessage = ({ data: { hash, width, height } }): void => {
|
||||
try {
|
||||
return decode(hash, width, height);
|
||||
self.postMessage({
|
||||
pixels: decode(hash, width, height),
|
||||
hsh: hash,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
} catch {
|
||||
throw new TypeError(`Blurhash ${hash} is not valid`);
|
||||
}
|
||||
}
|
||||
|
||||
expose(getPixels);
|
||||
};
|
||||
/* eslint-enable no-restricted-globals */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue