diff --git a/index.js b/index.js index 55f05e7..e23a4ea 100644 --- a/index.js +++ b/index.js @@ -480,13 +480,21 @@ class PearcordContacts extends EventEmitter { this.emit('peer', { peerId, type: 'leave' }) }) }) - await this.swarm.join(topicToBuffer(contactsTopic(this.userId)), { - server: true, - client: true - }) + 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) }