Skip to content

Commit

Permalink
docs: update browser example and remove webrtc-direct example (#1751)
Browse files Browse the repository at this point in the history
Add new transports to the browser example and remove the outdated webrtc-direct example as it uses a deprecated transport.

Refs: #1488
  • Loading branch information
achingbrain authored May 12, 2023
1 parent 337f025 commit c90f496
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 328 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
pnet,
protocol-and-stream-muxing,
pubsub,
transports,
webrtc-direct
transports
]
fail-fast: true
steps:
Expand Down
57 changes: 27 additions & 30 deletions README.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ Bear in mind that a **transport** and **connection encryption** module are **req
Some available transports are:

- [@libp2p/tcp](https://github.com/libp2p/js-libp2p-tcp) (not available in browsers)
- [@libp2p/webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star)
- [@libp2p/webrtc-direct](https://github.com/libp2p/js-libp2p-webrtc-direct)
- [@libp2p/webrtc](https://github.com/libp2p/js-libp2p-webrtc)
- [@libp2p/websockets](https://github.com/libp2p/js-libp2p-websockets)
- [@libp2p/webtransport](https://github.com/libp2p/js-libp2p-webtransport) (Work in Progress)

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).
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).

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

Expand Down
41 changes: 26 additions & 15 deletions examples/libp2p-in-the-browser/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { createLibp2p } from 'libp2p'
import { circuitRelayTransport } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p/identify'
import { kadDHT } from '@libp2p/kad-dht'
import { webSockets } from '@libp2p/websockets'
import { webRTCStar } from '@libp2p/webrtc-star'
import { webTransport } from '@libp2p/webtransport'
import { webRTCDirect, webRTC } from '@libp2p/webrtc'
import { noise } from '@chainsafe/libp2p-noise'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux'
import { bootstrap } from '@libp2p/bootstrap'

document.addEventListener('DOMContentLoaded', async () => {
const wrtcStar = webRTCStar()

// Create our libp2p node
const libp2p = await createLibp2p({
addresses: {
// Add the signaling server address, along with our PeerId to our multiaddrs list
// libp2p will automatically attempt to dial to the signaling server so that it can
// receive inbound connections from other peers
listen: [
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
]
},
// transports allow us to dial peers that support certain types of addresses
transports: [
webSockets(),
wrtcStar.transport
webTransport(),
webRTC(),
webRTCDirect(),
circuitRelayTransport({
// use content routing to find a circuit relay server we can reserve a
// slot on
discoverRelays: 1
})
],
connectionEncryption: [noise()],
streamMuxers: [yamux(), mplex()],
peerDiscovery: [
wrtcStar.discovery,
bootstrap({
list: [
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
Expand All @@ -37,7 +37,18 @@ document.addEventListener('DOMContentLoaded', async () => {
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
]
})
]
],
services: {
// the identify service is used by the DHT and the circuit relay transport
// to find peers that support the relevant protocols
identify: identifyService(),

// the DHT is used to find circuit relay servers we can reserve a slot on
dht: kadDHT({
// browser node ordinarily shouldn't be DHT servers
clientMode: true
})
}
})

// UI elements
Expand Down
6 changes: 5 additions & 1 deletion examples/libp2p-in-the-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
},
"license": "ISC",
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^7.0.0",
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/bootstrap": "^8.0.0",
"@libp2p/kad-dht": "^9.3.3",
"@libp2p/mplex": "^8.0.1",
"@libp2p/webrtc-star": "^7.0.0",
"@libp2p/webrtc": "^1.2.0",
"@libp2p/websockets": "^6.0.1",
"@libp2p/webtransport": "^2.0.1",
"libp2p": "file:../../"
},
"devDependencies": {
Expand Down
32 changes: 0 additions & 32 deletions examples/webrtc-direct/README.md

This file was deleted.

57 changes: 0 additions & 57 deletions examples/webrtc-direct/dialer.js

This file was deleted.

17 changes: 0 additions & 17 deletions examples/webrtc-direct/index.html

This file was deleted.

33 changes: 0 additions & 33 deletions examples/webrtc-direct/listener.js

This file was deleted.

23 changes: 0 additions & 23 deletions examples/webrtc-direct/package.json

This file was deleted.

79 changes: 0 additions & 79 deletions examples/webrtc-direct/test.js

This file was deleted.

5 changes: 0 additions & 5 deletions examples/webrtc-direct/vite.config.js

This file was deleted.

Loading

0 comments on commit c90f496

Please sign in to comment.