silphius/app/client/local.js

25 lines
562 B
JavaScript
Raw Normal View History

2024-07-21 02:57:29 -05:00
import Client from '@/net/client.js';
2024-06-10 22:42:30 -05:00
export default class LocalClient extends Client {
async connect() {
this.worker = new Worker(
new URL('../server/worker.js', import.meta.url),
{type: 'module'},
);
2024-06-15 20:59:11 -05:00
this.worker.addEventListener('message', (event) => {
if (0 === event.data) {
this.worker.terminate();
2024-06-21 04:43:32 -05:00
this.worker = undefined;
2024-06-15 20:59:11 -05:00
return;
}
2024-06-10 22:42:30 -05:00
this.accept(event.data);
2024-06-15 20:59:11 -05:00
});
2024-06-10 22:42:30 -05:00
}
disconnect() {
2024-06-15 20:59:11 -05:00
this.worker.postMessage(0);
2024-06-10 22:42:30 -05:00
}
transmit(packed) {
this.worker.postMessage(packed);
}
}