fix: use new js-waku API
This commit is contained in:
parent
ec9a7489b0
commit
4db0a2d650
|
@ -163,15 +163,12 @@ function App() {
|
|||
if (!waku) return;
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
let lightPushPeers = 0;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
for await (const _peer of waku.store.peers) {
|
||||
lightPushPeers++;
|
||||
}
|
||||
const lightPushPeers = await waku.store.peers();
|
||||
const relayPeers = waku.relay.getMeshPeers();
|
||||
|
||||
setPeerStats({
|
||||
relayPeers: waku.relay.getPeers().size,
|
||||
lightPushPeers,
|
||||
relayPeers: relayPeers.length,
|
||||
lightPushPeers: lightPushPeers.length,
|
||||
});
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
|
|
|
@ -133,7 +133,7 @@ function sendMessage(
|
|||
.push(msg)
|
||||
.then((res) => {
|
||||
console.log("Message sent", res);
|
||||
callback(res ? res.isSuccess : false);
|
||||
callback(res?.isSuccess ?? false);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Failed to send message", e);
|
||||
|
|
|
@ -4,12 +4,13 @@ import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
|
|||
import { validatePublicKeyMessage } from "./crypto";
|
||||
import { Message } from "./messaging/Messages";
|
||||
import { equals } from "uint8arrays/equals";
|
||||
import { createWaku } from "js-waku/lib/create_waku";
|
||||
|
||||
export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto";
|
||||
export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto";
|
||||
|
||||
export async function initWaku(): Promise<Waku> {
|
||||
const waku = await Waku.create({ bootstrap: { default: true } });
|
||||
const waku = await createWaku({ defaultBootstrap: true });
|
||||
|
||||
// Wait to be connected to at least one peer
|
||||
await new Promise((resolve, reject) => {
|
||||
|
@ -17,7 +18,7 @@ export async function initWaku(): Promise<Waku> {
|
|||
// As we are not implementing connection management in this example
|
||||
|
||||
setTimeout(reject, 10000);
|
||||
waku.libp2p.connectionManager.on("peer:connect", () => {
|
||||
waku.libp2p.connectionManager.addEventListener("peer:connect", () => {
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue