Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

libp2p/js-libp2p-mplex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f532a2a ยท Jul 21, 2023
Jun 28, 2023
Nov 23, 2022
Sep 6, 2022
May 17, 2023
May 17, 2023
Apr 9, 2022
Apr 18, 2023
Jun 15, 2023
Feb 14, 2022
Feb 14, 2022
Feb 14, 2022
Jul 21, 2023
Jun 15, 2023
Apr 9, 2022

Repository files navigation

๐Ÿ“ Archived - this module has been merged into js-libp2p

@libp2p/mplex

libp2p.io Discuss codecov CI

JavaScript implementation of https://github.com/libp2p/mplex

Table of contents

Install

$ npm i @libp2p/mplex

Browser <script> tag

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>

Usage

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)

API Docs

License

Licensed under either of

Contribution

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.