Skip to content
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

docs: update browser example and remove webrtc-direct example #1751

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
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
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).
Copy link
Member

Choose a reason for hiding this comment

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

Is there an official guideline on whether we use American or British English? I don't want any culture wars 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, force of habit.

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