mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-15 07:10:00 -04:00
clean up settransport
This commit is contained in:
parent
508b265df2
commit
c8c3aeb761
4 changed files with 13 additions and 14 deletions
|
@ -21,7 +21,6 @@
|
|||
"@rollup/plugin-inject": "^5.0.5",
|
||||
"@rollup/plugin-replace": "^5.0.5",
|
||||
"rollup": "^4.9.6",
|
||||
"rollup-plugin-typescript2": "^0.36.0",
|
||||
"tslib": "^2.6.3"
|
||||
"rollup-plugin-typescript2": "^0.36.0"
|
||||
}
|
||||
}
|
||||
|
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -20,9 +20,6 @@ importers:
|
|||
rollup-plugin-typescript2:
|
||||
specifier: ^0.36.0
|
||||
version: 0.36.0(rollup@4.18.0)(typescript@5.5.3)
|
||||
tslib:
|
||||
specifier: ^2.6.3
|
||||
version: 2.6.3
|
||||
|
||||
packages:
|
||||
|
||||
|
|
|
@ -8,10 +8,17 @@ function handleConnection(port: MessagePort) {
|
|||
const port = event.data.port;
|
||||
const message: WorkerMessage = event.data.message;
|
||||
if (message.type === "set") {
|
||||
const func = new Function("return (async ()=>{" + message.client + "})()");
|
||||
currentTransport = await func();
|
||||
console.log("set transport to ", currentTransport);
|
||||
port.postMessage(<WorkerResponse>{ type: "set" });
|
||||
try {
|
||||
const AsyncFunction = (async function () {}).constructor;
|
||||
// @ts-expect-error
|
||||
const func = new AsyncFunction(message.client);
|
||||
console.log(func);
|
||||
currentTransport = await func();
|
||||
console.log("set transport to ", currentTransport);
|
||||
port.postMessage(<WorkerResponse>{ type: "set" });
|
||||
} catch(err) {
|
||||
port.postMessage(<WorkerResponse>{ type: "error", error: err });
|
||||
}
|
||||
} else if (message.type === "fetch") {
|
||||
try {
|
||||
if (!currentTransport) throw new Error("No BareTransport was set. Try creating a BareMuxConnection and calling set() on it.");
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2021",
|
||||
"lib": [
|
||||
"es2021",
|
||||
"DOM"
|
||||
],
|
||||
"paths": {
|
||||
"tslib": [
|
||||
"./node_modules/tslib/tslib.d.ts"
|
||||
]
|
||||
},
|
||||
"declaration": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue