From 016c1e82b060c93c80546cd8c493ec6e6c97cbec Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 19 May 2023 15:39:20 +0100 Subject: [PATCH] feat: add start/stop events to libp2p interface (#407) --- packages/interface-libp2p/src/index.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/interface-libp2p/src/index.ts b/packages/interface-libp2p/src/index.ts index be6497198..3e0a606ca 100644 --- a/packages/interface-libp2p/src/index.ts +++ b/packages/interface-libp2p/src/index.ts @@ -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 { /** * This event is dispatched when a new network peer is discovered. * @@ -225,6 +225,28 @@ export interface Libp2pEvents { * closed. */ 'connection:close': CustomEvent + + /** + * This event notifies listeners that the node has started + * + * ```js + * libp2p.addEventListener('start', (event) => { + * console.info(libp2p.isStarted()) // true + * }) + * ``` + */ + 'start': CustomEvent> + + /** + * This event notifies listeners that the node has stopped + * + * ```js + * libp2p.addEventListener('stop', (event) => { + * console.info(libp2p.isStarted()) // false + * }) + * ``` + */ + 'stop': CustomEvent> } /** @@ -281,7 +303,7 @@ export interface PendingDial { /** * Libp2p nodes implement this interface. */ -export interface Libp2p> extends Startable, EventEmitter { +export interface Libp2p extends Startable, EventEmitter> { /** * The PeerId is a unique identifier for a node on the network. *