fix: start waku & use waitForRemotePeer

This commit is contained in:
fryorcraken.eth 2022-08-20 18:12:47 +10:00
parent 7d94016076
commit cf6942d5fa
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 9 additions and 12 deletions

View File

@ -1,5 +1,11 @@
import { Dispatch, SetStateAction } from "react";
import { utils, Waku, WakuMessage } from "js-waku";
import {
Protocols,
utils,
waitForRemotePeer,
Waku,
WakuMessage,
} from "js-waku";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages";
@ -11,17 +17,8 @@ export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto";
export async function initWaku(): Promise<Waku> {
const waku = await createWaku({ defaultBootstrap: true });
// Wait to be connected to at least one peer
await new Promise((resolve, reject) => {
// If we are not connected to any peer within 10sec let's just reject
// As we are not implementing connection management in this example
setTimeout(reject, 10000);
waku.libp2p.connectionManager.addEventListener("peer:connect", () => {
resolve(null);
});
});
await waku.start();
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
return waku;
}