Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/resources/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
})
}

Expand Down Expand Up @@ -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
Expand Down