From dd02cddcb80e52d920f8ac889bbfc957020d3ab9 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 12 Apr 2021 16:13:35 -0700 Subject: [PATCH] ensure that 'peer' is emitted before 'connect' event fires This is just a defensive code change to ensure that if signal() were somehow able to cause the peer to synchronously emit the 'connect' event that we won't cause the 'error' listener to be unregistered before 'peer' is emitted and the user has a chance to register their own 'error' listener --- lib/client/websocket-tracker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 6e71e76..815b034 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -278,8 +278,8 @@ class WebSocketTracker extends Tracker { if (this._trackerId) params.trackerid = this._trackerId this._send(params) }) - peer.signal(data.offer) this.client.emit('peer', peer) + peer.signal(data.offer) } if (data.answer && data.peer_id) { @@ -287,8 +287,8 @@ class WebSocketTracker extends Tracker { peer = this.peers[offerId] if (peer) { peer.id = common.binaryToHex(data.peer_id) - peer.signal(data.answer) this.client.emit('peer', peer) + peer.signal(data.answer) clearTimeout(peer.trackerTimeout) peer.trackerTimeout = null