JSPM

@libp2p/webrtc

4.0.21-e1798aa26
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10595
  • Score
    100M100P100Q143144F
  • License Apache-2.0 OR MIT

A libp2p transport using WebRTC connections

Package Exports

  • @libp2p/webrtc

Readme

@libp2p/webrtc

libp2p.io Discuss codecov CI

A libp2p transport using WebRTC connections

About

A libp2p transport based on WebRTC datachannels.

Example

import { createLibp2p } from 'libp2p'
import { noise } from '@chainsafe/libp2p-noise'
import { multiaddr } from '@multiformats/multiaddr'
import first from 'it-first'
import { pipe } from 'it-pipe'
import { fromString, toString } from 'uint8arrays'
import { webRTC } from '@libp2p/webrtc'

const node = await createLibp2p({
  transports: [
    webRTC()
  ],
  connectionEncryption: [
    noise()
  ]
})

await node.start()

const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
const stream = await node.dialProtocol(ma, '/my-protocol/1.0.0', {
  signal: AbortSignal.timeout(10_000)
})

await pipe(
  [fromString(`Hello js-libp2p-webrtc\n`)],
  stream,
  async function (source) {
    for await (const buf of source) {
      console.info(toString(buf.subarray()))
    }
  }
)

Install

$ npm i @libp2p/webrtc

Browser <script> tag

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

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

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.