Skip to content

Commit 623096e

Browse files
authored
Merge pull request #403 from libp2p/docs/update-webrtc-example
docs: update webrtc example to latest API
2 parents 88ebf48 + 89adbd0 commit 623096e

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

content/guides/getting-started/webrtc.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,11 @@ Next, open the `src/index.js` file in your code editor and find the call to `cre
155155
```js
156156
const libp2p = await createLibp2p({
157157
transports: [
158-
// Allow all WebSocket connections inclusing without TLS
159-
webSockets({ filter: filters.all }),
158+
webSockets(),
160159
webTransport(),
161160
webRTC(),
162161
],
163-
connectionEncryption: [noise()],
162+
connectionEncrypters: [noise()],
164163
streamMuxers: [yamux()],
165164
connectionGater: {
166165
// Allow private addresses for local testing
@@ -218,16 +217,19 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:
218217
+import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
219218

220219
const libp2p = await createLibp2p({
220+
+ addresses: {
221+
+ listen: [
222+
+ // 👇 Required to create circuit relay reservations in order to respond to incoming WebRTC connections
223+
+ '/p2p-circuit',
224+
+ ],
225+
+ },
221226
transports: [
222-
// Allow all WebSocket connections inclusing without TLS
223-
webSockets({ filter: filters.all }),
227+
webSockets(),
224228
webTransport(),
225229
webRTC(),
226-
+ circuitRelayTransport({
227-
+ discoverRelays: 1,
228-
+ }),
230+
+ circuitRelayTransport(),
229231
],
230-
connectionEncryption: [noise()],
232+
connectionEncrypters: [noise()],
231233
streamMuxers: [yamux()],
232234
connectionGater: {
233235
// Allow private addresses for local testing
@@ -254,7 +256,7 @@ Observe that the beginning of the multiaddr is the same as the relay, followed b
254256

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

257-
By adding `circuitRelayTransport` with the `discoverRelays` option, js-libp2p was able to create circuit relay reservation (time and bandwidth-constrained) on the relay.
259+
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.
258260

259261
### Testing circuit relay
260262

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

277279
const libp2p = await createLibp2p({
280+
addresses: {
281+
listen: [
282+
'/p2p-circuit',
283+
],
284+
},
278285
transports: [
279-
// Allow all WebSocket connections inclusing without TLS
280-
webSockets({ filter: filters.all }),
286+
webSockets(),
281287
webTransport(),
282288
webRTC(),
283-
circuitRelayTransport({
284-
discoverRelays: 1,
285-
}),
289+
circuitRelayTransport(),
286290
],
287-
connectionEncryption: [noise()],
291+
connectionEncrypters: [noise()],
288292
streamMuxers: [yamux()],
289293
connectionGater: {
290294
// Allow private addresses for local testing
@@ -312,22 +316,20 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:
312316

313317
```diff
314318
const libp2p = await createLibp2p({
315-
+ addresses: {
316-
+ listen: [
319+
addresses: {
320+
listen: [
321+
'/p2p-circuit',
317322
+ // 👇 Listen for webRTC connections
318323
+ '/webrtc',
319-
+ ],
320-
+ },
324+
],
325+
},
321326
transports: [
322-
// Allow all WebSocket connections inclusing without TLS
323-
webSockets({ filter: filters.all }),
327+
webSockets(),
324328
webTransport(),
325329
webRTC(),
326-
circuitRelayTransport({
327-
discoverRelays: 1,
328-
}),
330+
circuitRelayTransport(),
329331
],
330-
connectionEncryption: [noise()],
332+
connectionEncrypters: [noise()],
331333
streamMuxers: [yamux()],
332334
connectionGater: {
333335
// Allow private addresses for local testing
@@ -393,20 +395,17 @@ In the `src/index.js` file, update the call to `createLibp2p` as follows:
393395
const libp2p = await createLibp2p({
394396
addresses: {
395397
listen: [
396-
// 👇 Listen for webRTC connections
398+
'/p2p-circuit',
397399
'/webrtc',
398400
],
399401
},
400402
transports: [
401-
// Allow all WebSocket connections inclusing without TLS
402-
webSockets({ filter: filters.all }),
403+
webSockets(),
403404
webTransport(),
404405
webRTC(),
405-
circuitRelayTransport({
406-
discoverRelays: 1,
407-
}),
406+
circuitRelayTransport(),
408407
],
409-
connectionEncryption: [noise()],
408+
connectionEncrypters: [noise()],
410409
streamMuxers: [yamux()],
411410
connectionGater: {
412411
// Allow private addresses for local testing

0 commit comments

Comments
 (0)