Skip to content

Commit 00fe0e1

Browse files
committed
allow setting a custom bare transport in bundled builds (normal builds still hardcoded)
1 parent e1eb4e6 commit 00fe0e1

File tree

9 files changed

+41
-337
lines changed

9 files changed

+41
-337
lines changed

packages/chrome/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"dependencies": {
1616
"@iconify/types": "^2.0.0",
1717
"@ktibow/iconset-ion": "^8.0.13",
18-
"@mercuryworkshop/epoxy-transport": "^2.1.27",
18+
"@mercuryworkshop/bare-mux-custom": "workspace:*",
19+
"@mercuryworkshop/epoxy-transport": "workspace:*",
20+
"@mercuryworkshop/libcurl-transport": "workspace:*",
1921
"@mercuryworkshop/scramjet": "workspace:scramjet",
2022
"devtools-protocol": "^0.0.1339468",
2123
"domhandler": "^5.0.3",

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
setConfig,
99
unrewriteUrl,
1010
type URLMeta,
11-
BareClient,
1211
ScramjetServiceWorker,
1312
} from "@mercuryworkshop/scramjet/bundled";
13+
import { BareClient } from "@mercuryworkshop/bare-mux-custom";
1414
import { ElementType, type Handler, Parser } from "htmlparser2";
1515
import { type ChildNode, DomHandler, Element, Comment, Node } from "domhandler";
1616
import * as tldts from "tldts";
@@ -32,6 +32,8 @@ import { createMenu } from "./components/Menu";
3232

3333
const ISOLATION_ORIGIN = import.meta.env.VITE_ISOLATION_ORIGIN;
3434

35+
import LibcurlClient from "@mercuryworkshop/libcurl-transport";
36+
3537
const cfg = {
3638
wisp: "ws://localhost:1337/",
3739
prefix: "/scramjet/",
@@ -85,7 +87,11 @@ const cfg = {
8587
};
8688

8789
setConfig(cfg);
88-
export const bare = new BareClient();
90+
export const bare = new BareClient(
91+
new LibcurlClient({
92+
wisp: cfg.wisp,
93+
})
94+
);
8995

9096
type Controller = {
9197
controllerframe: HTMLIFrameElement;

packages/scramjet/src/client/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ScramjetFrame } from "@/controller/frame";
2-
import { BareClient } from "../bare-mux-custom";
2+
import { BareClient } from "@mercuryworkshop/bare-mux-custom";
33
import { SCRAMJETCLIENT, SCRAMJETFRAME } from "@/symbols";
44
import { getOwnPropertyDescriptorHandler } from "@client/helpers";
55
import { createLocationProxy } from "@client/location";
66
import { createWrapFn } from "@client/shared/wrap";
77
import { NavigateEvent } from "@client/events";
88
import { rewriteUrl, unrewriteUrl, type URLMeta } from "@rewriters/url";
9-
import { config, flagEnabled } from "@/shared";
9+
import { bareTransport, config, flagEnabled } from "@/shared";
1010
import { CookieJar } from "@/shared/cookie";
1111
import { iswindow } from "./entry";
1212
import { SingletonBox } from "./singletonbox";
@@ -121,7 +121,7 @@ export class ScramjetClient {
121121

122122
this.box.registerClient(this, global as Self);
123123

124-
this.bare = new BareClient();
124+
this.bare = new BareClient(bareTransport!);
125125

126126
this.serviceWorker = this.global.navigator.serviceWorker;
127127

packages/scramjet/src/client/shared/requests/websocket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { config } from "@/shared";
2-
import { type BareWebSocket } from "../../../bare-mux-custom";
2+
import { type BareWebSocket } from "@mercuryworkshop/bare-mux-custom";
33
import { ScramjetClient } from "@client/index";
44

55
type FakeWebSocketState = {

packages/scramjet/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ export * from "./worker";
1010
export * from "./entry";
1111
export * from "./symbols";
1212
export * from "./types";
13-
14-
export { BareClient } from "./bare-mux-custom";

packages/scramjet/src/shared/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BareTransport } from "@/bare-mux-custom";
12
import { ScramjetConfig, ScramjetFlags } from "@/types";
23

34
export * from "./cookie";
@@ -32,3 +33,8 @@ export function setConfig(newConfig: ScramjetConfig) {
3233
config = newConfig;
3334
loadCodecs();
3435
}
36+
37+
export let bareTransport: BareTransport | null = null;
38+
export function setBareTransport(transport: BareTransport) {
39+
bareTransport = transport;
40+
}

packages/scramjet/src/worker/fetch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { BareClient, BareHeaders, BareResponseFetch } from "../bare-mux-custom";
1+
import {
2+
BareClient,
3+
BareHeaders,
4+
BareResponseFetch,
5+
} from "@mercuryworkshop/bare-mux-custom";
26

37
import { MessageW2C, ScramjetServiceWorker } from "@/worker";
48
import { renderError } from "@/worker/error";

packages/scramjet/src/worker/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
import { FakeServiceWorker } from "@/worker/fakesw";
66
import { handleFetch, ScramjetFetchContext } from "@/worker/fetch";
7-
import { BareClient } from "../bare-mux-custom";
7+
import { BareClient } from "@mercuryworkshop/bare-mux-custom";
88
import { ScramjetConfig, ScramjetDB } from "@/types";
99
import { asyncSetWasm } from "@rewriters/wasm";
1010
import { CookieJar } from "@/shared/cookie";
11-
import { ScramjetHeaders, setConfig, unrewriteUrl } from "@/shared";
11+
import {
12+
bareTransport,
13+
ScramjetHeaders,
14+
setConfig,
15+
unrewriteUrl,
16+
} from "@/shared";
1217
import { openDB } from "idb";
1318
import { ScramjetDownload } from "@client/events";
1419
import { renderError } from "./error";
@@ -128,7 +133,7 @@ export class ScramjetServiceWorker extends EventTarget {
128133

129134
if (this.config) {
130135
setConfig(this.config);
131-
this.client = new BareClient();
136+
this.client = new BareClient(bareTransport!);
132137
await asyncSetWasm();
133138
}
134139
}

0 commit comments

Comments
 (0)