Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
feat: add start/stop events to libp2p interface (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed May 19, 2023
1 parent 22b3051 commit 016c1e8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface IdentifyResult {
* Event names are `noun:verb` so the first part is the name of the object
* being acted on and the second is the action.
*/
export interface Libp2pEvents {
export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
/**
* This event is dispatched when a new network peer is discovered.
*
Expand Down Expand Up @@ -225,6 +225,28 @@ export interface Libp2pEvents {
* closed.
*/
'connection:close': CustomEvent<Connection>

/**
* This event notifies listeners that the node has started
*
* ```js
* libp2p.addEventListener('start', (event) => {
* console.info(libp2p.isStarted()) // true
* })
* ```
*/
'start': CustomEvent<Libp2p<T>>

/**
* This event notifies listeners that the node has stopped
*
* ```js
* libp2p.addEventListener('stop', (event) => {
* console.info(libp2p.isStarted()) // false
* })
* ```
*/
'stop': CustomEvent<Libp2p<T>>
}

/**
Expand Down Expand Up @@ -281,7 +303,7 @@ export interface PendingDial {
/**
* Libp2p nodes implement this interface.
*/
export interface Libp2p<T extends ServiceMap = Record<string, unknown>> extends Startable, EventEmitter<Libp2pEvents> {
export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, EventEmitter<Libp2pEvents<T>> {
/**
* The PeerId is a unique identifier for a node on the network.
*
Expand Down

0 comments on commit 016c1e8

Please sign in to comment.