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