@yume-chan/multiplex-websocket
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Multiplex WebSocket

travis-ci Greenkeeper badge

A simple multiplex protocol for WebSocket

Install

npm install @yume-chan/multiplex-websocket

Node.js

ws is a peer dependency, you need to install it separately for Node.js.

npm install ws

Browsers

This package uses Node.js built-in modules (Buffer, event and stream), so it needs polyfills to run in browsers.

Webpack should work, although not tested.

API

export default class MultiplexWebSocket {
    static connect(url: string): Promise<MultiplexWebSocket>;

    constructor(raw: WebSocket);

    addChannel(): MultiplexWebSocketChannel;
    close(): void;

    on(type: 'channel', listener: (channel: MultiplexWebSocketChannel, head: Buffer) => void): this;
    on(type: 'error', listener: (error: Error) => void): this;
    on(type: 'close', listener: () => void): this;

    off(type: 'channel', listener: (channel: MultiplexWebSocketChannel, head: Buffer) => void): this;
    off(type: 'error', listener: (error: Error) => void): this;
    off(type: 'close', listener: () => void): this;
}

export class MultiplexWebSocketChannel extends Duplex { }

MultiplexWebSocketChannel is a duplex stream so you can use common stream operations (.read(), .write(), .pipe(), .on('data')) on it.

Development

This project uses pnpm (GitHub) to manage dependency packages.

Install dependencies

pnpm i

You may also use npm, but the lockfile may become out of sync.

Testing

npm test

Coverage

npm run coverage

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @yume-chan/multiplex-websocket

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

69.4 kB

Total Files

25

Last publish

Collaborators

  • yume-chan