diff --git a/frontend/src/components/RobotAvatar/RobohashGenerator.ts b/frontend/src/components/RobotAvatar/RobohashGenerator.ts index 36257efa..038cdf92 100644 --- a/frontend/src/components/RobotAvatar/RobohashGenerator.ts +++ b/frontend/src/components/RobotAvatar/RobohashGenerator.ts @@ -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]; diff --git a/frontend/src/components/RobotAvatar/robohash.worker.ts b/frontend/src/components/RobotAvatar/robohash.worker.ts index b8a513ad..f0c7da33 100644 --- a/frontend/src/components/RobotAvatar/robohash.worker.ts +++ b/frontend/src/components/RobotAvatar/robohash.worker.ts @@ -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 }); + })(); +}); diff --git a/frontend/src/models/Slot.model.ts b/frontend/src/models/Slot.model.ts index 9936e7eb..864820ed 100644 --- a/frontend/src/models/Slot.model.ts +++ b/frontend/src/models/Slot.model.ts @@ -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) { 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');