mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Recover WebWorkers
This commit is contained in:
parent
d8490d7530
commit
383112dc90
@ -26,10 +26,9 @@ class RoboGenerator {
|
||||
const numCores = 8;
|
||||
|
||||
for (let i = 0; i < numCores; i++) {
|
||||
// FIXME
|
||||
// const worker = new Worker(new URL('./robohash.worker.ts', import.meta.url));
|
||||
// worker.onmessage = this.assignTasksToWorkers.bind(this);
|
||||
// this.workers.push({ worker, busy: false });
|
||||
const worker = new Worker(new URL('./robohash.worker.ts', import.meta.url));
|
||||
worker.onmessage = this.assignTasksToWorkers.bind(this);
|
||||
this.workers.push({ worker, busy: false });
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,8 +81,6 @@ class RoboGenerator {
|
||||
hash,
|
||||
size,
|
||||
) => {
|
||||
// FIXME
|
||||
return '';
|
||||
const cacheKey = `${size}px;${hash}`;
|
||||
if (this.assetsCache[cacheKey]) {
|
||||
return this.assetsCache[cacheKey];
|
||||
|
@ -1,18 +1,17 @@
|
||||
// FIXME
|
||||
// import { async_generate_robohash } from 'robo-identities-wasm';
|
||||
import { async_generate_robohash } from 'robo-identities-wasm';
|
||||
|
||||
// // Listen for messages from the main thread
|
||||
// self.addEventListener('message', (event) => {
|
||||
// void (async () => {
|
||||
// const { hash, size, cacheKey } = event.data;
|
||||
// Listen for messages from the main thread
|
||||
self.addEventListener('message', (event) => {
|
||||
void (async () => {
|
||||
const { hash, size, cacheKey } = event.data;
|
||||
|
||||
// // Generate the image using async_image_base
|
||||
// const t0 = performance.now();
|
||||
// const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256);
|
||||
// const imageUrl = `data:image/png;base64,${avatarB64}`;
|
||||
// const t1 = performance.now();
|
||||
// console.log(`Avatar generated in: ${t1 - t0} ms`);
|
||||
// // Send the result back to the main thread
|
||||
// self.postMessage({ cacheKey, imageUrl });
|
||||
// })();
|
||||
// });
|
||||
// Generate the image using async_image_base
|
||||
const t0 = performance.now();
|
||||
const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256);
|
||||
const imageUrl = `data:image/png;base64,${avatarB64}`;
|
||||
const t1 = performance.now();
|
||||
console.log(`Avatar generated in: ${t1 - t0} ms`);
|
||||
// Send the result back to the main thread
|
||||
self.postMessage({ cacheKey, imageUrl });
|
||||
})();
|
||||
});
|
||||
|
@ -1,16 +1,14 @@
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { Robot, type Order } from '.';
|
||||
import { robohash } from '../components/RobotAvatar/RobohashGenerator';
|
||||
// import { generate_roboname } from 'robo-identities-wasm';
|
||||
import { generate_roboname } from 'robo-identities-wasm';
|
||||
|
||||
class Slot {
|
||||
constructor(token: string, shortAliases: string[], robotAttributes: Record<any, any>) {
|
||||
this.token = token;
|
||||
|
||||
this.hashId = sha256(sha256(this.token));
|
||||
// FIXME
|
||||
// this.nickname = generate_roboname(this.hashId);
|
||||
this.nickname = 'Robot';
|
||||
this.nickname = generate_roboname(this.hashId);
|
||||
// trigger RoboHash avatar generation in webworker and store in RoboHash class cache.
|
||||
void robohash.generate(this.hashId, 'small');
|
||||
void robohash.generate(this.hashId, 'large');
|
||||
|
Loading…
Reference in New Issue
Block a user