silphius/app/net/client/local.js
2024-06-10 22:45:09 -05:00

20 lines
418 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.onmessage = (event) => {
this.accept(event.data);
};
}
disconnect() {
this.worker.terminate();
}
transmit(packed) {
this.worker.postMessage(packed);
}
}