Package Exports
- libp2p-multiplex
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libp2p-multiplex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
js-libp2p-multiplex
multiplex implementation wrapper that is compatible with libp2p Stream Muxer expected interface
Usage
Install
> npm i libp2p-multiplex
In tour code
const multiplex = require('libp2p-multiplex')
API
Attaching it to a socket (duplex stream)
As a listener
const listener = multiplex(socket, true)
As a dialer
const dialer = multiplex(socket, false)
Opening a multiplex duplex stream
const conn = dialer.newStream((err, conn) => {})
conn.on('error', (err) => {})
note: Works the same on the listener side
Receiving incoming stream
dialer.on('stream', (conn) => {})
note: Works the same on the listener side
Close
dialer.close()
note: Works the same on the listener side
Other events
dialer.on('close', () => {})
dialer.on('error', () => {})
note: Works the same on the listener side