-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c81872a
commit 12b1a1d
Showing
3 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { IdentifyResult } from "@libp2p/interface"; | ||
import type { LightNode } from "@waku/interfaces"; | ||
|
||
/** | ||
* Wait for a remote peer to be identified with a given codec | ||
* @param waku - Waku node | ||
* @param codec - Codec to wait for | ||
* @returns Promise that resolves when the peer is identified | ||
* @internal | ||
* This function is introduced as `core/waitForRemotePeer` only accounts for core protocols like Filter, LightPush & Store | ||
* While this (currently) is not required by the SDK, it is required for the tests | ||
*/ | ||
export async function waitForRemotePeerWithCodec( | ||
waku: LightNode, | ||
codec: string | ||
): Promise<void> { | ||
await new Promise<void>((resolve) => { | ||
const cb = (evt: CustomEvent<IdentifyResult>): void => { | ||
if (evt.detail.protocols.includes(codec)) { | ||
waku.libp2p.removeEventListener("peer:identify", cb); | ||
resolve(); | ||
} | ||
}; | ||
waku.libp2p.addEventListener("peer:identify", cb); | ||
}); | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters