mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-16 15:40:01 -04:00
create readme
This commit is contained in:
parent
e2b85c3d99
commit
7a1273e967
1 changed files with 58 additions and 0 deletions
58
README.md
Normal file
58
README.md
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# Bare-Mux
|
||||||
|
A system for managing http transports in a project such as [Ultraviolet](https://github.com/Titaniumnetwork-dev/Ultraviolet).
|
||||||
|
|
||||||
|
Written to make the job of creating new standards for transporting http data seamless.
|
||||||
|
|
||||||
|
Implements the [TompHTTP Bare](https://github.com/tomphttp/specifications/) client interface in a modular way.
|
||||||
|
|
||||||
|
Specifically, this is what allows proxies such as [Nebula](https://github.com/NebulaServices/Nebula) to switch HTTP transports seamlessly.
|
||||||
|
|
||||||
|
A transport is a module that implements the `BareTransport` interface.
|
||||||
|
```js
|
||||||
|
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](https://github.com/MercuryWorkshop/EpoxyTransport), [CurlTransport](https://github.com/MercuryWorkshop/CurlTransport), and [Bare-Client](https://github.com/MercuryWorkshop/Bare-as-module3).
|
||||||
|
|
||||||
|
Here is an example of using bare-mux:
|
||||||
|
```js
|
||||||
|
/// 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(`return (async ()=>{
|
||||||
|
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");
|
||||||
|
```
|
Loading…
Add table
Add a link
Reference in a new issue