Skip to content

Commit

Permalink
Sort peers by latency
Browse files Browse the repository at this point in the history
  • Loading branch information
JustMaier committed Jul 3, 2019
1 parent 58680d3 commit a81e586
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bundles/peer-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export default function (opts) {
locationObj.latitude
]
const connection = parseConnection(peer.addr)
const latency = parseLatency(peer.latency)
const rawLatency = parseLatency(peer.latency)
const latency = rawLatency ? `${rawLatency}ms` : null
const notes = parseNotes(peer, bootstrapPeers)

return {
Expand All @@ -165,9 +166,10 @@ export default function (opts) {
coordinates,
connection,
latency,
rawLatency,
notes
}
})
}).sort(({ rawLatency: a }, { rawLatency: b }) => (a == null) - (b == null) || +(a > b) || -(a < b))
),

selectPeerCoordinates: createSelector(
Expand Down Expand Up @@ -288,7 +290,7 @@ const parseLatency = (latency) => {

value = unit === 's' ? value * 1000 : value

return `${value}ms`
return value
}

const parseNotes = (peer, bootstrapPeers) => {
Expand Down

0 comments on commit a81e586

Please sign in to comment.