JavaScript implementation of https://github.com/libp2p/mplex
$ npm i @libp2p/mplex
Loading this module through a script tag will make it's exports available as Libp2pMplex
in the global namespace.
<script src="https://unpkg.com/@libp2p/mplex/dist/index.min.js"></script>
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)
Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.