Skip to content

Commit

Permalink
Clear potential connections if a connection succeeded (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlika authored Feb 8, 2025
1 parent a5f68ba commit c7b5738
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/p2p-media-loader-core/src/p2p/tracker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,29 @@ export class P2PTrackerClient {
) => {
const itemId = Peer.getPeerIdFromConnection(peerConnection);
let peerItem = this._peers.get(itemId);

if (peerItem?.peer) {
peerConnection.destroy();
return;
} else if (!peerItem) {
}

if (!peerItem) {
peerItem = { potentialConnections: new Set() };
peerConnection.idUtf8 = itemId;
peerItem.potentialConnections.add(peerConnection);
this._peers.set(itemId, peerItem);
}

peerItem.potentialConnections.add(peerConnection);

peerConnection.on("connect", () => {
if (peerItem.peer) return;

for (const connection of peerItem.potentialConnections) {
if (connection !== peerConnection) connection.destroy();
}

peerItem.potentialConnections.clear();

peerItem.peer = new Peer(
peerConnection,
{
Expand Down

0 comments on commit c7b5738

Please sign in to comment.