@libp2p/mplex
Version:
JavaScript implementation of https://github.com/libp2p/mplex
60 lines • 1.76 kB
JavaScript
/**
* @packageDocumentation
*
* This is a [simple stream multiplexer(https://docs.libp2p.io/concepts/multiplex/mplex/) that has been deprecated.
*
* Please use [@chainsafe/libp2p-yamux](https://www.npmjs.com/package/@chainsafe/libp2p-yamux) instead.
*
* @example
*
* ```TypeScript
* import { mplex } from '@libp2p/mplex'
* import { pipe } from 'it-pipe'
*
* const factory = mplex()
*
* const muxer = factory.createStreamMuxer(components, {
* onStream: stream => { // Receive a duplex stream from the remote
* // ...receive data from the remote and optionally send data back
* },
* onStreamEnd: stream => {
* // ...handle any tracking you may need of stream closures
* }
* })
*
* pipe(conn, muxer, conn) // conn is duplex connection to another peer
*
* const stream = muxer.newStream() // Create a new duplex stream to the remote
*
* // Use the duplex stream to send some data to the remote...
* pipe([1, 2, 3], stream)
* ```
*/
import { serviceCapabilities } from '@libp2p/interface';
import { MplexStreamMuxer } from './mplex.js';
class Mplex {
protocol = '/mplex/6.7.0';
_init;
components;
constructor(components, init = {}) {
this.components = components;
this._init = init;
}
[Symbol.toStringTag] = '@libp2p/mplex';
[serviceCapabilities] = [
'@libp2p/stream-multiplexing'
];
createStreamMuxer(init = {}) {
return new MplexStreamMuxer(this.components, {
...init,
...this._init
});
}
}
/**
* @deprecated mplex is deprecated as it has no flow control. Please use yamux instead.
*/
export function mplex(init = {}) {
return (components) => new Mplex(components, init);
}
//# sourceMappingURL=index.js.map