Skip to content

Commit 016c1e8

Browse files
authored
feat: add start/stop events to libp2p interface (libp2p#407)
1 parent 22b3051 commit 016c1e8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

packages/interface-libp2p/src/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export interface IdentifyResult {
108108
* Event names are `noun:verb` so the first part is the name of the object
109109
* being acted on and the second is the action.
110110
*/
111-
export interface Libp2pEvents {
111+
export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
112112
/**
113113
* This event is dispatched when a new network peer is discovered.
114114
*
@@ -225,6 +225,28 @@ export interface Libp2pEvents {
225225
* closed.
226226
*/
227227
'connection:close': CustomEvent<Connection>
228+
229+
/**
230+
* This event notifies listeners that the node has started
231+
*
232+
* ```js
233+
* libp2p.addEventListener('start', (event) => {
234+
* console.info(libp2p.isStarted()) // true
235+
* })
236+
* ```
237+
*/
238+
'start': CustomEvent<Libp2p<T>>
239+
240+
/**
241+
* This event notifies listeners that the node has stopped
242+
*
243+
* ```js
244+
* libp2p.addEventListener('stop', (event) => {
245+
* console.info(libp2p.isStarted()) // false
246+
* })
247+
* ```
248+
*/
249+
'stop': CustomEvent<Libp2p<T>>
228250
}
229251

230252
/**
@@ -281,7 +303,7 @@ export interface PendingDial {
281303
/**
282304
* Libp2p nodes implement this interface.
283305
*/
284-
export interface Libp2p<T extends ServiceMap = Record<string, unknown>> extends Startable, EventEmitter<Libp2pEvents> {
306+
export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, EventEmitter<Libp2pEvents<T>> {
285307
/**
286308
* The PeerId is a unique identifier for a node on the network.
287309
*

0 commit comments

Comments
 (0)