Skip to content

Dial using WebRTC without the need to set up any Signalling Rendezvous Point!

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

cerc-io/js-libp2p-webrtc-direct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-libp2p-webrtc-direct

Discourse posts Dependency Status js-standard-style

A WebRTC transport built for libp2p (not mandatory to use with libp2p) that doesn't require the set up a signalling server. Caveat, you can only establish Browser to Node.js and Node.js to Node.js connections.

Lead Maintainer

Vasco Santos.

Table of Contents

Install

npm

> npm install libp2p-webrtc-direct

NOTE: To run build scripts node-pre-gyp is required. You can install it by running npm install -g node-pre-gyp.

Usage

const WebRTCDirect = require('libp2p-webrtc-direct')
const multiaddr = require('multiaddr')
const pipe = require('pull-stream')
const { collect } = require('streaming-iterables')

;(async () => {
  const addr = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct')
  const upgrader = {
    upgradeInbound: async maConn => maConn,
    upgradeOutbound: async maConn => maConn,
  }
  const webRTCDirect = new WebRTCDirect({upgrader})

  const listener = webRTCDirect.createListener((socket) => {
    console.log('new connection opened')
    pipe(
            ['hello'],
            socket
    )
  })

  await listener.listen(addr)
  console.log('listening')

  const conn = await webRTCDirect.dial(addr)
  const values = await pipe(
          conn,
          collect
  )
  console.log(`Value: ${values.toString()}`)

  // Close connection after reading
  await listener.close()
})()

Outputs:

listening
new connection opened
Value: hello

Note that it may take some time for the connection to be established.

API

Transport

Connection

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 would be 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.
  • Add tests. There can never be enough tests.

License

MIT © Protocol Labs

About

Dial using WebRTC without the need to set up any Signalling Rendezvous Point!

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.9%
  • JavaScript 2.1%