mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-14 06:40:02 -04:00
make set transport async for the user
This commit is contained in:
parent
7a1273e967
commit
8ed59e901d
2 changed files with 3 additions and 3 deletions
|
@ -43,10 +43,10 @@ Here is an example of using bare-mux:
|
|||
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
|
||||
const conn = new BareMuxConnection("/bare-mux/worker.js");
|
||||
// Set Bare-Client transport
|
||||
await conn.setTransport(`return (async ()=>{
|
||||
await conn.setTransport(`
|
||||
const exports = await import("/bare-mux/index.js");
|
||||
return new exports.BareClient("https://tomp.app");
|
||||
})()`);
|
||||
`);
|
||||
|
||||
/// As a proxy developer
|
||||
import { BareClient } from "@mercuryworkshop/bare-mux";
|
||||
|
|
|
@ -8,7 +8,7 @@ function handleConnection(port: MessagePort) {
|
|||
const port = event.data.port;
|
||||
const message: WorkerMessage = event.data.message;
|
||||
if (message.type === "set") {
|
||||
const func = new Function(message.client);
|
||||
const func = new Function("return (async ()=>{" + message.client + "})()");
|
||||
currentTransport = await func();
|
||||
console.log("set transport to ", currentTransport);
|
||||
port.postMessage(<WorkerResponse>{ type: "set" });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue