Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mercuryworkshop/bare-mux

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mercuryworkshop/bare-mux

  • 2.1.1
  • npm
  • Socket score

Version published
Weekly downloads
3.4K
increased by27.12%
Maintainers
0
Weekly downloads
 
Created
Source

bare-mux

npm version

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

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
}

A guide to making a transport can be found here.

Upgrading

A guide for updating from v1 to v2 can be found here.

Older bare-mux versions

Starting from v2, bare-mux uses SharedWorkers to provide stability and improve on resource usage.

If you operate using an older bare-mux, we encourage you to update.

If you're too lazy to do either of the above, you can install an outdated and unsupported version of bare-mux.

npm install @mercuryworkshop/bare-mux@1

Usage

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("/path/to/transport/index.mjs", ["arg1", { wisp: "wss://wisp.mercurywork.shop" }, "arg3"]);
// Epoxy Client as an example
await conn.setTransport("/epoxy/index.mjs", [{ wisp: "wss://wisp.mercurywork.shop/" }]);
/// 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");

FAQs

Package last updated on 11 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc