Transport architecture
Scramjet’s transport layer consists of:- BareClient - Main client interface from
@mercuryworkshop/bare-mux - Transport backends - Pluggable implementations (bare-server, epoxy, wisp, libcurl)
- BareMuxConnection - Worker-to-client communication bridge
bare-mux integration
bare-mux is Scramjet’s default transport multiplexer, allowing runtime transport switching.Installation
Service worker setup
The service worker creates aBareClient instance:
BareClient provides a fetch()-like API that automatically routes requests through the configured transport.Window/client setup
In the window context, Scramjet creates a separateBareClient:
Worker transport bridge
Workers need aMessagePort to communicate with the parent’s BareClient:
Why use BareMuxConnection?
Why use BareMuxConnection?
Workers cannot directly access the transport because:
- Isolation: Workers run in separate contexts without DOM access
- Shared state: Multiple workers need to share the same transport configuration
- Performance: Centralized transport reduces overhead
BareMuxConnection creates a MessageChannel that bridges the worker to the main context’s BareClient.Transport backends
bare-server (default)
The standard Bare server protocol:epoxy-transport
Epoxy uses WebTransport for improved performance:wisp protocol
Wisp provides WebSocket-based proxying:- Environments where HTTP proxying is restricted
- Bypassing certain network filters
- Multiplexing connections over a single WebSocket
libcurl-transport
Native performance using libcurl:libcurl-transport requires native bindings and is primarily used in Electron or Node.js environments.
Setting the transport
Static configuration
Set transport during Scramjet initialization:Dynamic transport switching
Users can switch transports at runtime:Transport switching is seamless - existing connections continue using the old transport while new requests use the updated configuration.
WebSocket proxying
Scramjet uses bare-mux’sBareWebSocket class for WebSocket connections:
WebSocket protocol handling
Different transports handle WebSockets differently:- bare-server: Upgrades HTTP connection to WebSocket
- wisp: Multiplexes over existing wisp WebSocket connection
- epoxy: Uses WebTransport streams
Request/response flow
Standard fetch request
Header rewriting
BareClient handles header transformations:Response types
BareClient returns aBareResponseFetch object: