mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 23:30:00 -04:00
allow websockets in dedicated workers
This commit is contained in:
parent
70e0a684ae
commit
3b9017e464
8 changed files with 42 additions and 21 deletions
|
@ -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]);
|
||||
})();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue