Skip to content

Commit e437c0a

Browse files
committed
chore: add reference for events in the API doc
1 parent 6b67f7b commit e437c0a

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

doc/API.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* [`metrics.protocols`](#metricsprotocols)
2929
* [`metrics.forPeer`](#metricsforpeer)
3030
* [`metrics.forProtocol`](#metricsforprotocol)
31+
* [Events](#events)
3132
* [Types](#types)
3233
* [`Stats`](#stats)
3334

@@ -96,39 +97,6 @@ Required keys in the `options` object:
9697

9798
</details>
9899

99-
Once you have a libp2p instance, you are able to listen to several events it emits, so that you can be noticed of relevant network events.
100-
101-
<details><summary>Events</summary>
102-
103-
#### An error has occurred
104-
105-
`libp2p.on('error', (err) => {})`
106-
107-
- `err`: instance of `Error`
108-
109-
#### A peer has been discovered
110-
111-
`libp2p.on('peer:discovery', (peer) => {})`
112-
113-
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
114-
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.
115-
116-
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
117-
118-
#### We have a new connection to a peer
119-
120-
`libp2p.on('peer:connect', (peer) => {})`
121-
122-
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
123-
124-
#### We have closed a connection to a peer
125-
126-
`libp2p.on('peer:disconnect', (peer) => {})`
127-
128-
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
129-
130-
</details>
131-
132100
## Libp2p Instance Methods
133101

134102
### start
@@ -777,6 +745,37 @@ const peerStats = libp2p.metrics.forProtocol('/meshsub/1.0.0')
777745
console.log(peerStats.toJSON())
778746
```
779747

748+
## Events
749+
750+
Once you have a libp2p instance, you are able to listen to several events it emits, so that you can be noticed of relevant network events.
751+
752+
#### An error has occurred
753+
754+
`libp2p.on('error', (err) => {})`
755+
756+
- `err`: instance of `Error`
757+
758+
#### A peer has been discovered
759+
760+
`libp2p.on('peer:discovery', (peer) => {})`
761+
762+
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
763+
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.
764+
765+
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
766+
767+
#### We have a new connection to a peer
768+
769+
`libp2p.on('peer:connect', (peer) => {})`
770+
771+
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
772+
773+
#### We have closed a connection to a peer
774+
775+
`libp2p.on('peer:disconnect', (peer) => {})`
776+
777+
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
778+
780779
## Types
781780

782781
### Stats

doc/GETTING_STARTED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Looking at the [available peer discovery](./CONFIGURATION.md#peer-discovery) pro
175175
- If your application is browser based you can use the transport `js-libp2p-webrtc-star`, which includes a rendezvous based peer sharing mechanism.
176176
- A random walk approach can be used via `js-libp2p-kad-dht`, to crawl the network and find new peers along the way.
177177

178-
Reviewing the events specification on [Libp2p.create](./API.md#create), each time a peer is discovered a `peer:discovery` event will be emitted by the node.
178+
Reviewing the events specification on [Events](./API.md#events), each time a peer is discovered a `peer:discovery` event will be emitted by the node.
179179

180180
We will consider in this guide that we already know some peers and also that we are creating an application that might be used by people within the same office network. Accordingly, we will install `libp2p-bootstrap` and `libp2p-mdns`
181181

0 commit comments

Comments
 (0)