mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-02 12:53:08 +00:00
test using a locally run node
This commit is contained in:
parent
cde23d9ec3
commit
ccbcff7ae3
@ -8,6 +8,7 @@ import { ChatMessage } from "./chat_message";
|
|||||||
import { useNodePeers } from "./hooks";
|
import { useNodePeers } from "./hooks";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
|
import { multiaddr } from "@multiformats/multiaddr";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
@ -40,8 +41,8 @@ export default function Room(props: Props) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!node || (!bootstrapPeers && !peerExchangePeers) || started) return;
|
if (!node || (!bootstrapPeers && !peerExchangePeers) || started) return;
|
||||||
|
|
||||||
const peerId = Array.from(bootstrapPeers)[0];
|
// const peerId = Array.from(bootstrapPeers)[0];
|
||||||
if (!peerId) return;
|
// if (!peerId) return;
|
||||||
|
|
||||||
// pings work well and can be interpreted as a good source of checking connectivity with a peer
|
// pings work well and can be interpreted as a good source of checking connectivity with a peer
|
||||||
// however, the peer:disconnect event is not triggered when we manually go offline
|
// however, the peer:disconnect event is not triggered when we manually go offline
|
||||||
@ -49,11 +50,25 @@ export default function Room(props: Props) {
|
|||||||
node.libp2p.connectionManager.addEventListener("peer:disconnect", (cb) => {
|
node.libp2p.connectionManager.addEventListener("peer:disconnect", (cb) => {
|
||||||
console.log("peer:disconnect", cb);
|
console.log("peer:disconnect", cb);
|
||||||
});
|
});
|
||||||
setInterval(() => {
|
|
||||||
ping(node, peerId);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
// replace with your own node ID to reproduce
|
||||||
|
const peerId = multiaddr(
|
||||||
|
"/ip4/127.0.0.1/tcp/8002/ws/p2p/16Uiu2HAmHLN5F9M8s8u2ttGU6CYo3qPXA3j5dc9Q2WMsiJRSh46Z"
|
||||||
|
);
|
||||||
|
console.log("dialing");
|
||||||
|
node
|
||||||
|
.dial(peerId)
|
||||||
|
.then(() => {
|
||||||
|
console.log("dialed");
|
||||||
|
setInterval(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
return ping(node, peerId);
|
||||||
|
}, 3000);
|
||||||
setStarted(true);
|
setStarted(true);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(`Dial error: ${err}`);
|
||||||
|
});
|
||||||
}, [node, bootstrapPeers, peerExchangePeers, started]);
|
}, [node, bootstrapPeers, peerExchangePeers, started]);
|
||||||
|
|
||||||
const onSend = async (text: string) => {
|
const onSend = async (text: string) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user