Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
fix: parcels count (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Arregui authored Jul 25, 2022
1 parent 6fe62c9 commit 0c41fe3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/peers/peersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,20 @@ export class PeersService implements IPeersService {
}

getParcels(): ParcelInfo[] {
const result: ParcelInfo[] = []
const countPerParcel = new Map<string, ParcelInfo>()

const countPerParcel = new Map<[number, number], number>()
for (const id of this.peerRealm.getClientsIds()) {
const parcel = this.peers[id]?.parcel
if (parcel) {
const count = countPerParcel.get(parcel) || 0
countPerParcel.set(parcel, count + 1)
const [parcelX, parcelY] = parcel
const key = `${parcelX}:${parcelY}`
const info = countPerParcel.get(key) || { peersCount: 0, parcel: { x: parcelX, y: parcelY } }
info.peersCount += 1
countPerParcel.set(key, info)
}
}

countPerParcel.forEach((peersCount, [x, y]) => {
result.push({ peersCount, parcel: { x, y } })
})

return result
return Array.from(countPerParcel.values())
}

getConnectedPeersInfo(): { ok: true; peers: PeerInfo[] } | { ok: false; message: string } {
Expand Down

0 comments on commit 0c41fe3

Please sign in to comment.