GithubHelp home page GithubHelp logo

dao-xyz / js-libp2p-yamux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chainsafe/js-libp2p-yamux

0.0 1.0 0.0 72 KB

Typescript implementation of Yamux

License: Other

JavaScript 0.14% TypeScript 99.86%

js-libp2p-yamux's Introduction

@chainsafe/libp2p-yamux

codecov CI

Yamux stream multiplexer for libp2p

Table of contents

Install

$ npm i @chainsafe/libp2p-yamux

Browser <script> tag

Loading this module through a script tag will make it's exports available as ChainsafeLibp2pYamux in the global namespace.

<script src="https://unpkg.com/@chainsafe/libp2p-yamux/dist/index.min.js"></script>

Usage

import { yamux } from '@chainsafe/libp2p-yamux'
import { pipe } from 'it-pipe'
import { duplexPair } from 'it-pair/duplex'
import all from 'it-all'

// Connect two yamux muxers to demo basic stream multiplexing functionality

const clientMuxer = yamux({
  client: true,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

const serverMuxer = yamux({
  client: false,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

// `p` is our "connections", what we use to connect the two sides
// In a real application, a connection is usually to a remote computer
const p = duplexPair()

// connect the muxers together
pipe(p[0], clientMuxer, p[0])
pipe(p[1], serverMuxer, p[1])

// now either side can open streams
const stream0 = clientMuxer.newStream()
const stream1 = serverMuxer.newStream()

// Send some data to the other side
const encoder = new TextEncoder()
const data = [encoder.encode('hello'), encoder.encode('world')]
pipe(data, stream0)

// Receive data back
const result = await pipe(stream0, all)

// close a stream
stream1.close()

// close the muxer
clientMuxer.close()

API

This library implements the StreamMuxerFactory, StreamMuxer and Stream interfaces defined in @libp2p/interfaces/stream-muxer.

Contribute

The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:

  • Go through the modules and check out existing issues. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
  • Perform code reviews. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.

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.

js-libp2p-yamux's People

Contributors

semantic-release-bot avatar dependabot[bot] avatar achingbrain avatar wemeetagain avatar marcus-pousette avatar tabcat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.