25 lines
558 B
JavaScript
25 lines
558 B
JavaScript
import Client from './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);
|
|
}
|
|
}
|