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