fix(contacts): time-box mesh join and friend topic link at boot
Cap contacts hyperswarm join and _syncFriendTopicLinks so session startup cannot block forever. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -480,13 +480,21 @@ class PearcordContacts extends EventEmitter {
|
||||
this.emit('peer', { peerId, type: 'leave' })
|
||||
})
|
||||
})
|
||||
await this.swarm.join(topicToBuffer(contactsTopic(this.userId)), {
|
||||
const joinMs = Number(process.env.PEARCORD_MESH_JOIN_MS) || 8000
|
||||
await Promise.race([
|
||||
this.swarm.join(topicToBuffer(contactsTopic(this.userId)), {
|
||||
server: true,
|
||||
client: true
|
||||
})
|
||||
}),
|
||||
new Promise((resolve) => setTimeout(resolve, joinMs))
|
||||
])
|
||||
await this._flushSwarm(3500)
|
||||
this._meshJoined = true
|
||||
await this._syncFriendTopicLinks()
|
||||
const linkMs = Number(process.env.PEARCORD_CONTACTS_FRIEND_LINK_MS) || 8000
|
||||
await Promise.race([
|
||||
this._syncFriendTopicLinks(),
|
||||
new Promise((resolve) => setTimeout(resolve, linkMs))
|
||||
])
|
||||
if (this._lastSelfPresence) {
|
||||
await broadcastContactsGossip(this, RPC.PRESENCE_UPDATE, this._lastSelfPresence)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user