allow transferables while setting client

This commit is contained in:
Toshit Chawda 2024-07-16 18:23:33 -07:00
parent 646a521e49
commit d750186782
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
3 changed files with 15 additions and 9 deletions

View file

@ -105,18 +105,21 @@ export class BareMuxConnection {
return (await this.worker.sendMessage({ type: "get" })).name;
}
async setTransport(path: string, options: any[]) {
async setTransport(path: string, options: any[], transferables?: Transferable[]) {
await this.setManualTransport(`
const { default: BareTransport } = await import("${path}");
return [new BareTransport(${options.map(x => JSON.stringify(x)).join(", ")}), "${path}"];
`);
return [BareTransport, "${path}"];
`, options, transferables);
}
async setManualTransport(functionBody: string) {
async setManualTransport(functionBody: string, options: any[], transferables?: Transferable[]) {
await this.worker.sendMessage({
type: "set",
client: functionBody,
});
client: {
function: functionBody,
args: options,
},
}, transferables);
}
getInnerPort(): MessagePort | Promise<MessagePort> {