0.0.5 • Published 6 years ago
@yume-chan/multiplex-websocket v0.0.5
Multiplex WebSocket
A simple multiplex protocol for WebSocket
Install
npm install @yume-chan/multiplex-websocketNode.js
ws is a peer dependency, you need to install it separately for Node.js.
npm install wsBrowsers
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 iYou may also use npm, but the lockfile may become out of sync.
Testing
npm testCoverage
npm run coverageLicense
MIT