npm.io
0.1.1 • Published yesterday

@stateforward/yamux.ts

Licence
MPL-2.0
Version
0.1.1
Deps
1
Size
110 kB
Vulns
0
Weekly
0

@stateforward/yamux.ts

Browser-native Yamux multiplexing over Web Streams.

Installation

npm install @stateforward/yamux.ts

Runtime Dependency

  • @stateforward/hsm.ts

Development

  • npm run build
  • npm run benchmark
  • npm run conformance
  • npm test
  • npm run test:browser
  • npm run test:coverage
  • npm run test:fuzz
  • npm run typecheck

Conformance

npm run conformance builds this package and runs bidirectional echo, concurrency, half-close, reset, GOAWAY, peer-close, and malformed-frame cases against github.com/hashicorp/yamux pinned by conformance/go.mod.

Benchmark

npm run benchmark builds this package and compares client-opened echo streams over an in-memory transport against yamux-js.

See docs/performance.md for profiling notes and optimization history.

API

  • Session
  • SessionRole
  • SessionOptions
  • WaitOptions
  • PingOptions
  • SessionEvent
  • Client
  • ClientOptions
  • clientStreamIDs
  • ClientEvent
  • createClient
  • Server
  • ServerOptions
  • serverStreamIDs
  • ServerEvent
  • createServer
  • Stream
  • StreamOptions
  • StreamEvent
  • PROTOCOL_VERSION
  • HEADER_SIZE
  • INITIAL_STREAM_WINDOW
  • MAX_UINT32
  • YamuxHeader
  • YamuxFrame
  • decodeHeader
  • encodeHeader
  • hasFlag
  • frameToBytes
  • isFrameType
  • YamuxFrameType
  • YamuxFlag
  • YamuxGoAwayCode
  • YamuxError
  • YamuxErrorCode
  • abortedError
  • timeoutError

Example

import { createClient } from "@stateforward/yamux.ts";

const session = createClient({
  readable: socket.readable,
  writable: socket.writable,
});

const stream = await session.openStream();
const writer = stream.writable.getWriter();

await writer.write(new TextEncoder().encode("hello"));
await writer.close();