Skip to content

Commit c90f496

Browse files
authored
docs: update browser example and remove webrtc-direct example (#1751)
Add new transports to the browser example and remove the outdated webrtc-direct example as it uses a deprecated transport. Refs: #1488
1 parent 337f025 commit c90f496

File tree

13 files changed

+87
-328
lines changed

13 files changed

+87
-328
lines changed

.github/workflows/examples.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ jobs:
4242
pnet,
4343
protocol-and-stream-muxing,
4444
pubsub,
45-
transports,
46-
webrtc-direct
45+
transports
4746
]
4847
fail-fast: true
4948
steps:

README.md

Lines changed: 27 additions & 30 deletions
Large diffs are not rendered by default.

doc/CONFIGURATION.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ Bear in mind that a **transport** and **connection encryption** module are **req
6969
Some available transports are:
7070

7171
- [@libp2p/tcp](https://github.com/libp2p/js-libp2p-tcp) (not available in browsers)
72-
- [@libp2p/webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star)
73-
- [@libp2p/webrtc-direct](https://github.com/libp2p/js-libp2p-webrtc-direct)
72+
- [@libp2p/webrtc](https://github.com/libp2p/js-libp2p-webrtc)
7473
- [@libp2p/websockets](https://github.com/libp2p/js-libp2p-websockets)
7574
- [@libp2p/webtransport](https://github.com/libp2p/js-libp2p-webtransport) (Work in Progress)
7675

77-
If none of the available transports fulfills your needs, you can create a libp2p compatible transport. A libp2p transport just needs to be compliant with the [Transport Interface](https://github.com/libp2p/js-interfaces/tree/master/src/transport).
76+
If none of the available transports fulfils your needs, you can create a libp2p compatible transport. A libp2p transport just needs to be compliant with the [Transport Interface](https://github.com/libp2p/js-interfaces/tree/master/src/transport).
7877

7978
If you want to know more about libp2p transports, you should read the following content:
8079

examples/libp2p-in-the-browser/index.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import { createLibp2p } from 'libp2p'
2+
import { circuitRelayTransport } from 'libp2p/circuit-relay'
3+
import { identifyService } from 'libp2p/identify'
4+
import { kadDHT } from '@libp2p/kad-dht'
25
import { webSockets } from '@libp2p/websockets'
3-
import { webRTCStar } from '@libp2p/webrtc-star'
6+
import { webTransport } from '@libp2p/webtransport'
7+
import { webRTCDirect, webRTC } from '@libp2p/webrtc'
48
import { noise } from '@chainsafe/libp2p-noise'
59
import { mplex } from '@libp2p/mplex'
610
import { yamux } from '@chainsafe/libp2p-yamux'
711
import { bootstrap } from '@libp2p/bootstrap'
812

913
document.addEventListener('DOMContentLoaded', async () => {
10-
const wrtcStar = webRTCStar()
11-
1214
// Create our libp2p node
1315
const libp2p = await createLibp2p({
14-
addresses: {
15-
// Add the signaling server address, along with our PeerId to our multiaddrs list
16-
// libp2p will automatically attempt to dial to the signaling server so that it can
17-
// receive inbound connections from other peers
18-
listen: [
19-
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
20-
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
21-
]
22-
},
16+
// transports allow us to dial peers that support certain types of addresses
2317
transports: [
2418
webSockets(),
25-
wrtcStar.transport
19+
webTransport(),
20+
webRTC(),
21+
webRTCDirect(),
22+
circuitRelayTransport({
23+
// use content routing to find a circuit relay server we can reserve a
24+
// slot on
25+
discoverRelays: 1
26+
})
2627
],
2728
connectionEncryption: [noise()],
2829
streamMuxers: [yamux(), mplex()],
2930
peerDiscovery: [
30-
wrtcStar.discovery,
3131
bootstrap({
3232
list: [
3333
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
@@ -37,7 +37,18 @@ document.addEventListener('DOMContentLoaded', async () => {
3737
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
3838
]
3939
})
40-
]
40+
],
41+
services: {
42+
// the identify service is used by the DHT and the circuit relay transport
43+
// to find peers that support the relevant protocols
44+
identify: identifyService(),
45+
46+
// the DHT is used to find circuit relay servers we can reserve a slot on
47+
dht: kadDHT({
48+
// browser node ordinarily shouldn't be DHT servers
49+
clientMode: true
50+
})
51+
}
4152
})
4253

4354
// UI elements

examples/libp2p-in-the-browser/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
},
1010
"license": "ISC",
1111
"dependencies": {
12+
"@chainsafe/libp2p-gossipsub": "^7.0.0",
1213
"@chainsafe/libp2p-noise": "^12.0.0",
14+
"@chainsafe/libp2p-yamux": "^4.0.1",
1315
"@libp2p/bootstrap": "^8.0.0",
16+
"@libp2p/kad-dht": "^9.3.3",
1417
"@libp2p/mplex": "^8.0.1",
15-
"@libp2p/webrtc-star": "^7.0.0",
18+
"@libp2p/webrtc": "^1.2.0",
1619
"@libp2p/websockets": "^6.0.1",
20+
"@libp2p/webtransport": "^2.0.1",
1721
"libp2p": "file:../../"
1822
},
1923
"devDependencies": {

examples/webrtc-direct/README.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/webrtc-direct/dialer.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

examples/webrtc-direct/index.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/webrtc-direct/listener.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/webrtc-direct/package.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)