Skip to content

Commit

Permalink
fix: close signaling connection
Browse files Browse the repository at this point in the history
Fixes: libp2p#173

Before this change, connecting to a webRTC peer over a relay would result in two open connections to the peer. One private-to-private webRTC connection and one relayed connection (used for signalling).

In the browser-to-browser example, dialling B -> A simply returns the first existing connection to A (Added when dialling A -> B). The first connection is not the webRTC connection but rather the relayed connection. This causes the echo to break after the relay is closed or after the reservation expires.

After signalling is complete, the relayed peer connection is no longer needed and can be closed. The only connection to the peer is webRTC at this point.
  • Loading branch information
Marcel-G committed Jun 10, 2023
1 parent 3c8a3af commit 85567a5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/private-to-private/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export class WebRTCTransport implements Transport, Startable {
// reset the stream in case of any error
signalingStream.reset()
throw err
} finally {
// Close the signaling connection
await connection.close()
}
}

Expand All @@ -143,6 +146,9 @@ export class WebRTCTransport implements Transport, Startable {
} catch (err) {
stream.reset()
throw err
} finally {
// Close the signaling connection
await connection.close()
}
}
}
Expand Down

0 comments on commit 85567a5

Please sign in to comment.