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

feat: add start/stop events to libp2p interface #407

Merged
merged 3 commits into from
May 19, 2023
Merged
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
26 changes: 24 additions & 2 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
@@ -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.
*
@@ -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>>
}

/**
@@ -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.
*