mirror of https://github.com/waku-org/js-waku.git
Refresh peer stats every second
This commit is contained in:
parent
076192aa66
commit
31b007c398
|
@ -76,6 +76,13 @@ function App() {
|
||||||
);
|
);
|
||||||
const [messages, setMessages] = useState<Message[]>([]);
|
const [messages, setMessages] = useState<Message[]>([]);
|
||||||
const [address, setAddress] = useState<string>();
|
const [address, setAddress] = useState<string>();
|
||||||
|
const [peerStats, setPeerStats] = useState<{
|
||||||
|
relayPeers: number;
|
||||||
|
lightPushPeers: number;
|
||||||
|
}>({
|
||||||
|
relayPeers: 0,
|
||||||
|
lightPushPeers: 0,
|
||||||
|
});
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
|
@ -147,12 +154,17 @@ function App() {
|
||||||
};
|
};
|
||||||
}, [waku, address, EncryptionKeyPair]);
|
}, [waku, address, EncryptionKeyPair]);
|
||||||
|
|
||||||
let relayPeers = 0;
|
useEffect(() => {
|
||||||
let lightPushPeers = 0;
|
if (!waku) return;
|
||||||
if (waku) {
|
|
||||||
relayPeers = waku.relay.getPeers().size;
|
const interval = setInterval(() => {
|
||||||
lightPushPeers = waku.lightPush.peers.length;
|
setPeerStats({
|
||||||
}
|
relayPeers: waku.relay.getPeers().size,
|
||||||
|
lightPushPeers: waku.lightPush.peers.length,
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [waku]);
|
||||||
|
|
||||||
let addressDisplay = '';
|
let addressDisplay = '';
|
||||||
if (address) {
|
if (address) {
|
||||||
|
@ -176,7 +188,8 @@ function App() {
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Typography className={classes.peers} aria-label="connected-peers">
|
<Typography className={classes.peers} aria-label="connected-peers">
|
||||||
Peers: {relayPeers} relay, {lightPushPeers} light push
|
Peers: {peerStats.relayPeers} relay, {peerStats.lightPushPeers}{' '}
|
||||||
|
light push
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h6" className={classes.title}>
|
<Typography variant="h6" className={classes.title}>
|
||||||
Ethereum Direct Message
|
Ethereum Direct Message
|
||||||
|
|
|
@ -75,6 +75,13 @@ function App() {
|
||||||
);
|
);
|
||||||
const [messages, setMessages] = useState<Message[]>([]);
|
const [messages, setMessages] = useState<Message[]>([]);
|
||||||
const [address, setAddress] = useState<string>();
|
const [address, setAddress] = useState<string>();
|
||||||
|
const [peerStats, setPeerStats] = useState<{
|
||||||
|
relayPeers: number;
|
||||||
|
lightPushPeers: number;
|
||||||
|
}>({
|
||||||
|
relayPeers: 0,
|
||||||
|
lightPushPeers: 0,
|
||||||
|
});
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
|
@ -133,12 +140,17 @@ function App() {
|
||||||
};
|
};
|
||||||
}, [waku, address, provider?.provider?.request]);
|
}, [waku, address, provider?.provider?.request]);
|
||||||
|
|
||||||
let relayPeers = 0;
|
useEffect(() => {
|
||||||
let lightPushPeers = 0;
|
if (!waku) return;
|
||||||
if (waku) {
|
|
||||||
relayPeers = waku.relay.getPeers().size;
|
const interval = setInterval(() => {
|
||||||
lightPushPeers = waku.lightPush.peers.length;
|
setPeerStats({
|
||||||
}
|
relayPeers: waku.relay.getPeers().size,
|
||||||
|
lightPushPeers: waku.lightPush.peers.length,
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [waku]);
|
||||||
|
|
||||||
let addressDisplay = '';
|
let addressDisplay = '';
|
||||||
if (address) {
|
if (address) {
|
||||||
|
@ -162,7 +174,8 @@ function App() {
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Typography className={classes.peers} aria-label="connected-peers">
|
<Typography className={classes.peers} aria-label="connected-peers">
|
||||||
Peers: {relayPeers} relay, {lightPushPeers} light push
|
Peers: {peerStats.relayPeers} relay, {peerStats.lightPushPeers}{' '}
|
||||||
|
light push
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h6" className={classes.title}>
|
<Typography variant="h6" className={classes.title}>
|
||||||
Ethereum Direct Message
|
Ethereum Direct Message
|
||||||
|
|
Loading…
Reference in New Issue