25 lines
562 B
JavaScript
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);
|
|
}
|
|
}
|