Skip to content

Commit

Permalink
add docs to IWaku interface
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko committed Oct 4, 2024
1 parent 4b94686 commit 690e630
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
72 changes: 71 additions & 1 deletion packages/interfaces/src/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,86 @@ export interface IWaku {
health: IHealthManager;
connectionManager: IConnectionManager;

/**
* Dials to the provided peer
*
* @param {PeerId | MultiaddrInput} peer information to use for dialing
* @param {Protocols[]} [protocols] array of Waku protocols to be used for dialing. If no provided - will be derived from mounted protocols.
*
* @returns {Promise<Stream>} `Promise` that will resolve to a `Stream` to a dialed peer
*
* @example
* ```typescript
* await waku.dial(remotePeerId, [Protocols.LightPush]);
*
* waku.isConnected() === true;
* ```
*/
dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise<Stream>;

/**
* Starts all services and components related to functionality of Waku node.
*
* @returns {Promise<boolean>} `Promise` that will resolve when started.
*
* @example
* ```typescript
* await waku.start();
*
* waku.isStarted() === true;
* ```
*/
start(): Promise<void>;

/**
* Stops all recurring processes and services that are needed for functionality of Waku node.
*
* @returns {Promise<boolean>} `Promise` that resolves when stopped.
*
* @example
* ```typescript
* await waku.stop();
*
* waku.isStarted === false;
* ```
*/
stop(): Promise<void>;

connect(): Promise<void>;
/**
* Resolves when Waku successfully gains connection to a remote peers that fits provided requirements.
* Must be used after attempting to connect to nodes, using {@link IWaku.dial} or
* if was bootstrapped by using {@link IPeerExchange} or {@link DnsDiscoveryComponents}.
*
* @param {Protocols[]} [protocols] Protocols that need to be enabled by remote peers
* @param {number} [timeoutMs] Timeout value in milliseconds after which promise rejects
*
* @returns {Promise<void>} `Promise` that **resolves** if all desired protocols are fulfilled by
* at least one remote peer, **rejects** if the timeoutMs is reached
* @throws If passing a protocol that is not mounted or Waku node is not started
*
* @example
* ```typescript
* try {
* // let's wait for at least one LightPush node and timeout in 1 second
* await waku.connect([Protocols.LightPush], 1000);
* } catch(e) {
* waku.isConnected() === false;
* console.error("Failed to connect due to", e);
* }
*
* waku.isConnected() === true;
* ```
*/
connect(protocols?: Protocols[], timeoutMs?: number): Promise<void>;

/**
* @returns {boolean} `true` if the node was started and `false` otherwise
*/
isStarted(): boolean;

/**
* @returns {boolean} `true` if the node has working connection and `false` otherwise
*/
isConnected(): boolean;
}

Expand Down
6 changes: 0 additions & 6 deletions packages/sdk/src/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ export class WakuNode implements IWaku {
);
}

/**
* Dials to the provided peer.
*
* @param peer The peer to dial
* @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols
*/
public async dial(
peer: PeerId | MultiaddrInput,
protocols?: Protocols[]
Expand Down

0 comments on commit 690e630

Please sign in to comment.