import React, { useState, useEffect, useRef } from 'react'; import { setupWaku } from './lib/waku'; import { startLightPushSequence } from './lib/waku/lightpush'; import { startFilterSubscription } from './lib/waku/filter'; import { TelemetryClient } from './lib/telemetry/client'; import { TELEMETRY_URL } from './constants'; import MessageList from './components/MessageList'; import Stats from './components/Stats'; import CountdownTimer from './components/CountdownTimer'; import { Message } from './lib/telemetry/types'; import SuccessIndicator from './components/SuccessIndicator'; let currentSequenceId = 1; function App() { const [sentMessages, setSentMessages] = useState([]); const [receivedMessages, setReceivedMessages] = useState([]); const [selfReceivedMessages, setSelfReceivedMessages] = useState([]); const [stats, setStats] = useState({ sent: 0, received: 0, selfReceived: 0 }); const [nextMessageCountdown, setNextMessageCountdown] = useState(null); const [lastSentSuccess, setLastSentSuccess] = useState(null); const [nodeInfo, setNodeInfo] = useState({ totalConnections: 0, filterPeers: 0, lightPushPeers: 0, storePeers: 0, }); const isRunning = useRef(false); useEffect(() => { const initWaku = async () => { const waku = await setupWaku(); const telemetryClient = new TelemetryClient(TELEMETRY_URL); telemetryClient.start(); const updateNodeInfo = () => { setNodeInfo({ totalConnections: waku.libp2p.getConnections().length, filterPeers: waku.filter.connectedPeers.length, lightPushPeers: waku.lightPush.connectedPeers.length, storePeers: waku.store.connectedPeers.length, }); }; updateNodeInfo(); const nodeInfoInterval = setInterval(updateNodeInfo, 5000); startFilterSubscription(waku, telemetryClient, (content, isSelf) => { const message: Message = { content, sequenceId: currentSequenceId, timestamp: Date.now() }; if (isSelf) { setSelfReceivedMessages(prev => [...prev, message]); setStats(prev => ({ ...prev, selfReceived: prev.selfReceived + 1 })); } else { setReceivedMessages(prev => [...prev, message]); setStats(prev => ({ ...prev, received: prev.received + 1 })); } }); const updateSequenceId = (newId: number) => { currentSequenceId = newId === 1 ? 1 : currentSequenceId + 1; console.log("Updated sequence ID to:", currentSequenceId); }; startLightPushSequence( waku, telemetryClient, (messageText, success) => { const message: Message = { content: messageText, sequenceId: currentSequenceId, timestamp: Date.now() }; setSentMessages(prev => [message, ...prev]); setStats(prev => ({ ...prev, sent: prev.sent + 1 })); setLastSentSuccess(success); }, updateSequenceId, setNextMessageCountdown, isRunning ); return () => { clearInterval(nodeInfoInterval); telemetryClient.stop(); }; }; initWaku(); }, []); return (

Waku Message Monitor

Node Info

Total Connections

{nodeInfo.totalConnections}

Filter Peers

{nodeInfo.filterPeers}

LightPush Peers

{nodeInfo.lightPushPeers}

Store Peers

{nodeInfo.storePeers}

); } export default App;