silphius/app/client/local.js
2024-07-21 02:57:29 -05:00

25 lines
562 B
JavaScript

import Client from '@/net/client.js';
export default class LocalClient extends Client {
async connect() {
this.worker = new Worker(
new URL('../server/worker.js', import.meta.url),
{type: 'module'},
);
this.worker.addEventListener('message', (event) => {
if (0 === event.data) {
this.worker.terminate();
this.worker = undefined;
return;
}
this.accept(event.data);
});
}
disconnect() {
this.worker.postMessage(0);
}
transmit(packed) {
this.worker.postMessage(packed);
}
}