allow websockets in dedicated workers

This commit is contained in:
Percs 2024-08-31 14:06:02 -05:00
parent 70e0a684ae
commit 3b9017e464
8 changed files with 42 additions and 21 deletions

View file

@ -1,9 +1,9 @@
import { encodeUrl } from "../../shared";
import { encodeUrl, BareMuxConnection } from "../../shared";
import { ScramjetClient } from "../client";
export default function (client: ScramjetClient, self: typeof globalThis) {
client.Proxy("Worker", {
construct({ args }) {
construct({ args, call }) {
if (args[0] instanceof URL) args[0] = args[0].href;
if (args[0].startsWith("blob:") || args[0].startsWith("data:")) {
if (args[0].startsWith("blob:")) {
@ -27,6 +27,13 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
if (args[1] && args[1].type === "module") {
args[0] += "&type=module";
}
const worker = call();
const conn = new BareMuxConnection();
(async () => {
const port = await conn.getInnerPort();
worker.postMessage(port, [port]);
})();
},
});
}