Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PubsubBaseProtocol extends EventEmitter {
/**
* Map of topics to which peers are subscribed to
*
* @type {Map<string, Set<PeerStreams>>}
* @type {Map<string, Set<string>>}
*/
this.topics = new Map()

Expand Down Expand Up @@ -273,6 +273,11 @@ class PubsubBaseProtocol extends EventEmitter {
this.log('delete peer', id)
this.peers.delete(id)

// remove peer from topics map
for (const peers of this.topics.values()) {
peers.delete(id)
}

return peerStreams
}

Expand Down Expand Up @@ -328,7 +333,6 @@ class PubsubBaseProtocol extends EventEmitter {
return []
}
return Array.from(peersInTopic)
.map((peer) => peer.id.toB58String())
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/pubsub.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ describe('pubsub base protocol', () => {
const peer = new PeerStreams({ id: peerId })
const id = peer.id.toB58String()

pubsub.topics.set(topic, new Set([peer]))
pubsub.topics.set(topic, new Set([id]))
pubsub.peers.set(id, peer)

peersSubscribed = pubsub.getSubscribers(topic)
Expand Down