A system for managing http transports in a project such as Ultraviolet.
Find a file
2024-07-07 17:01:22 -05:00
src clean up settransport 2024-07-07 14:54:55 -07:00
.gitignore fetch working 2024-07-07 01:11:13 -07:00
package.json update paths in package.json 2024-07-07 17:01:22 -05:00
pnpm-lock.yaml clean up settransport 2024-07-07 14:54:55 -07:00
README.md make set transport async for the user 2024-07-07 14:21:04 -07:00
rollup.config.js fetch working 2024-07-07 01:11:13 -07:00
tsconfig.json clean up settransport 2024-07-07 14:54:55 -07:00

Bare-Mux

A system for managing http transports in a project such as Ultraviolet.

Written to make the job of creating new standards for transporting http data seamless.

Implements the TompHTTP Bare client interface in a modular way.

Specifically, this is what allows proxies such as Nebula to switch HTTP transports seamlessly.

A transport is a module that implements the BareTransport interface.

export interface BareTransport {
  init: () => Promise<void>;
  ready: boolean;
  connect: (
    url: URL,
    origin: string,
    protocols: string[],
    requestHeaders: BareHeaders,
    onopen: (protocol: string) => void,
    onmessage: (data: Blob | ArrayBuffer | string) => void,
    onclose: (code: number, reason: string) => void,
    onerror: (error: string) => void,
  ) => [( (data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void )] => void;

  request: (
    remote: URL,
    method: string,
    body: BodyInit | null,
    headers: BareHeaders,
    signal: AbortSignal | undefined
  ) => Promise<TransferrableResponse>;

  meta: () => BareMeta
}

Examples of transports include EpoxyTransport, CurlTransport, and Bare-Client.

Here is an example of using bare-mux:

/// As an end-user
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
const conn = new BareMuxConnection("/bare-mux/worker.js");
// Set Bare-Client transport
await conn.setTransport(`
    const exports = await import("/bare-mux/index.js");
    return new exports.BareClient("https://tomp.app");
`);

/// As a proxy developer
import { BareClient } from "@mercuryworkshop/bare-mux";
const client = new BareClient();
// Fetch
const resp = await client.fetch("https://example.com");
// Create websocket
const ws = client.createWebSocket("wss://echo.websocket.events");