Compare commits

..

2 Commits

Author SHA1 Message Date
MrMasrozYTLIVE
5d6728f39f Filtering all the peers except myself now 2024-06-10 17:57:52 +03:00
MrMasrozYTLIVE
051aa09c2d Opps i had array of arrays of peers in message json 2024-06-10 17:55:23 +03:00
2 changed files with 4 additions and 5 deletions

2
app.js
View File

@ -297,7 +297,7 @@ function sendMessage(e) {
onMessageAdded(config.userName, message, config.userAvatar);
let peersPublicKeys = [];
peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')));
peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).flat(1));
peersPublicKeys.push(swarm.keyPair.publicKey.toString('hex'));
const messageObj = JSON.stringify({

View File

@ -22,10 +22,9 @@ class Client extends EventEmitter {
this.swarm.on('update', () => {
console.log(`Peers count: ${this.swarm.connections.size}`);
if(this.swarm.connections.size > 0) {
let arr = [];
[...this.swarm.peers].forEach(peer => arr.push([peer.topics]));
console.log([...this.swarm.peers])
console.log(arr);
let peers = [...this.swarm.peers].filter(peer => peer.remotePublicKey.toString('hex').startsWith("51be150"))
console.log(peers[0])
console.log([peers[0].topics]);
}
});
}