Skip to content

docs: update webrtc example to latest API #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions content/guides/getting-started/webrtc.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ Next, open the `src/index.js` file in your code editor and find the call to `cre
```js
const libp2p = await createLibp2p({
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is handled globally by the connection gater now.

webSockets(),
webTransport(),
webRTC(),
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
// Allow private addresses for local testing
Expand Down Expand Up @@ -218,16 +217,19 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:
+import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'

const libp2p = await createLibp2p({
+ addresses: {
+ listen: [
+ // 👇 Required to create circuit relay reservations in order to respond to incoming WebRTC connections
+ '/p2p-circuit',
+ ],
+ },
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
webSockets(),
webTransport(),
webRTC(),
+ circuitRelayTransport({
+ discoverRelays: 1,
+ }),
+ circuitRelayTransport(),
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
// Allow private addresses for local testing
Expand All @@ -254,7 +256,7 @@ Observe that the beginning of the multiaddr is the same as the relay, followed b

![diagram showing circuit relay](/webrtc-guide/circuit-relay-diagram.png)

By adding `circuitRelayTransport` with the `discoverRelays` option, js-libp2p was able to create circuit relay reservation (time and bandwidth-constrained) on the relay.
By adding a `circuitRelayTransport` and configuring a `/p2p-circuit` listen address, js-libp2p was able to create circuit relay reservation (time and bandwidth-constrained) on the relay.

### Testing circuit relay

Expand All @@ -275,16 +277,18 @@ Update the `src/index.js` file as follows, making sure to replace the multiaddr
+import { bootstrap } from '@libp2p/bootstrap'

const libp2p = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit',
],
},
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
webSockets(),
webTransport(),
webRTC(),
circuitRelayTransport({
discoverRelays: 1,
}),
circuitRelayTransport(),
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
// Allow private addresses for local testing
Expand Down Expand Up @@ -312,22 +316,20 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:

```diff
const libp2p = await createLibp2p({
+ addresses: {
+ listen: [
addresses: {
listen: [
'/p2p-circuit',
+ // 👇 Listen for webRTC connections
+ '/webrtc',
+ ],
+ },
],
},
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
webSockets(),
webTransport(),
webRTC(),
circuitRelayTransport({
discoverRelays: 1,
}),
circuitRelayTransport(),
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
// Allow private addresses for local testing
Expand Down Expand Up @@ -393,20 +395,17 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:
const libp2p = await createLibp2p({
addresses: {
listen: [
// 👇 Listen for webRTC connections
'/p2p-circuit',
'/webrtc',
],
},
transports: [
// Allow all WebSocket connections inclusing without TLS
webSockets({ filter: filters.all }),
webSockets(),
webTransport(),
webRTC(),
circuitRelayTransport({
discoverRelays: 1,
}),
circuitRelayTransport(),
],
connectionEncryption: [noise()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
// Allow private addresses for local testing
Expand Down