Package Exports
- @libp2p/webrtc
Readme
@libp2p/webrtc
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/webrtcBrowser <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
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.