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

@ -6,7 +6,13 @@ import { createGlobalProxy } from "./global";
import { getOwnPropertyDescriptorHandler } from "./helpers";
import { createLocationProxy } from "./location";
import { nativeGetOwnPropertyDescriptor } from "./natives";
import { CookieStore, config, decodeUrl, encodeUrl } from "../shared";
import {
BareClient,
CookieStore,
config,
decodeUrl,
encodeUrl,
} from "../shared";
import { createWrapFn } from "./shared/wrap";
import { NavigateEvent } from "./events";
@ -53,6 +59,7 @@ export class ScramjetClient {
globalProxy: any;
locationProxy: any;
serviceWorker: ServiceWorkerContainer;
bare: any;
descriptors: Record<string, PropertyDescriptor> = {};
natives: Record<string, any> = {};
@ -83,7 +90,19 @@ export class ScramjetClient {
this.locationProxy = createLocationProxy(this, global);
this.globalProxy = createGlobalProxy(this, global);
this.wrapfn = createWrapFn(this, global);
if (iswindow) {
this.bare = new BareClient();
} else {
this.bare = new BareClient(
new Promise((resolve) => {
addEventListener("message", (e) => {
if (e.data instanceof MessagePort) {
resolve(e.data);
}
});
})
);
}
global[SCRAMJETCLIENT] = this;
}