diff --git a/src/resources/messaging.js b/src/resources/messaging.js index a2d08e58..21ba9c95 100644 --- a/src/resources/messaging.js +++ b/src/resources/messaging.js @@ -205,6 +205,22 @@ class Messaging extends ResourceBase { this.last_peers = peer_ids console.log('New peers:', this.last_peers) } + //let's do a 15 second reconnect policy + if ( + this.ipfs.__reconnect_peers && + Date.now() - this.last_connect_time > 20000 && + this.last_peers + ) { + this.last_connect_time = Date.now() + //every 20 seconds either connect or ping + for (const peer of Object.keys(this.ipfs.__reconnect_peers)) { + if (!this.last_peers.includes(peer)) { + const peer_address = this.ipfs.__reconnect_peers[peer] + console.log('Reconnecting:', peer_address) + this.ipfs.swarm.connect(peer_address) + } + } + } }) } @@ -247,6 +263,7 @@ class Messaging extends ResourceBase { clearInterval(this.refreshIntervalId) } + this.last_connect_time = Date.now() this.refreshIntervalId = setInterval( this.refreshPeerList.bind(this), 5000