Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
/**
* PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
* from the worker thread and starts reading the input stream from
* [remoteWritableStream.writable]
*/
thread.decrypt(
options,
ids,
sizes,
transfer(readablePorts, readablePorts),
transfer(writablePorts, writablePorts),
);
});
// encryption jobs submitted and still processing
(async function() {
const canvas: any =
offScreenCanvasSupport === OFFSCREEN_2D_CANVAS_SUPPORT.SUPPORTED
? canvasRef.current.transferControlToOffscreen()
: canvasRef.current;
// This has been done because it wasn't getting correctly transferred
// in firefox.
const dimensions = JSON.parse(
JSON.stringify(visualizerRef.current.getBoundingClientRect())
);
await canvasProxy(
transfer(
{
canvas,
message: VISUALIZER_MESSAGES.INIT,
dimensions,
range,
mode
},
[canvas]
)
);
})();
}, []);
await new EncryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
/**
* PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
* from the worker thread and starts reading the input stream from
* [remoteWritableStream.writable]
*/
thread.encrypt(
options,
ids,
sizes,
transfer(readablePorts, readablePorts),
transfer(writablePorts, writablePorts),
);
});
// encryption jobs submitted and still processing
await new EncryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
/**
* PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
* from the worker thread and starts reading the input stream from
* [remoteWritableStream.writable]
*/
thread.encrypt(
options,
ids,
sizes,
transfer(readablePorts, readablePorts),
transfer(writablePorts, writablePorts),
);
});
// encryption jobs submitted and still processing
await new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
/**
* PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
* from the worker thread and starts reading the input stream from
* [remoteWritableStream.writable]
*/
thread.decrypt(
options,
ids,
sizes,
transfer(readablePorts, readablePorts),
transfer(writablePorts, writablePorts),
);
});
// encryption jobs submitted and still processing
new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
await thread.get(transfer(writablePorts, writablePorts), resources);
});
return readables as PenumbraFile[];
resources.map(async (resource) => {
if (!('url' in resource)) {
throw new Error(
'PenumbraDecryptionWorker.getBuffers(): RemoteResource missing URL',
);
}
const buffer = await new Response(
await fetchAndDecrypt(resource),
).arrayBuffer();
return Comlink.transfer(buffer, buffer);
}),
);
export async function checkSupportFor2dOffscreenCanvas() {
const canvas = document.createElement("canvas");
try {
const _canvas: any = canvas.transferControlToOffscreen();
return await testProxy(transfer(_canvas, [_canvas]));
} catch (e) {
return OFFSCREEN_2D_CANVAS_SUPPORT.NOT_SUPPORTED;
}
}
export function mandelbrot_pixels(point, zoom, size) {
const maxIter = PALETTE_SIZE - 1;
const pxs = new Uint8ClampedArray(size.x * size.y * 4);
const ratio_x = 1 / zoom;
const ratio_y = 1 / zoom;
for (let i = 0; i < pxs.length; i += 4) {
let idx = i / 4 | 0;
let x = idx % size.x;
let y = idx / size.x | 0;
let px = point.x + x * ratio_x;
let py = point.y + y * ratio_y;
let n = mandelbrot(px, py, maxIter);
n = (n * 4) % palette.length;
pxs.set(palette.subarray(n, n + 4), i);
}
return Comlink.transfer(pxs, [pxs.buffer]);
}