diff --git a/src/lib/wait_for_remote_peer.ts b/src/lib/wait_for_remote_peer.ts index e52d9c4139..634eac8401 100644 --- a/src/lib/wait_for_remote_peer.ts +++ b/src/lib/wait_for_remote_peer.ts @@ -44,6 +44,8 @@ export async function waitForRemotePeer( ): Promise { protocols = protocols ?? [Protocols.Relay]; + if (!waku.isStarted()) return Promise.reject("Waku node is not started"); + const promises = []; if (protocols.includes(Protocols.Relay)) { diff --git a/src/lib/waku.ts b/src/lib/waku.ts index 942cee0372..a23cc6dddb 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -107,8 +107,6 @@ export async function createWaku(options?: CreateOptions): Promise { const wakuLightPush = new WakuLightPush(libp2p, options); const wakuFilter = new WakuFilter(libp2p, options); - await libp2p.start(); - return new Waku(options ?? {}, libp2p, wakuStore, wakuLightPush, wakuFilter); } @@ -233,6 +231,10 @@ export class Waku { await this.libp2p.stop(); } + isStarted(): boolean { + return this.libp2p.isStarted(); + } + /** * Register a decryption key to attempt decryption of messages received via * [[WakuRelay]] and [[WakuStore]]. This can either be a private key for