mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-22 13:31:32 +00:00
chore: refactor ConnectionManager#get
This commit is contained in:
@ -215,16 +215,9 @@ class ConnectionManager extends EventEmitter {
|
|||||||
* @returns {Connection}
|
* @returns {Connection}
|
||||||
*/
|
*/
|
||||||
get (peerId) {
|
get (peerId) {
|
||||||
if (!PeerId.isPeerId(peerId)) {
|
const connections = this.getAll(peerId)
|
||||||
throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
|
if (connections.length) {
|
||||||
}
|
return connections[0]
|
||||||
|
|
||||||
const id = peerId.toB58String()
|
|
||||||
const connections = this.connections.get(id)
|
|
||||||
|
|
||||||
// Return the first, open connection
|
|
||||||
if (connections) {
|
|
||||||
return connections.find(connection => connection.stat.status === 'open')
|
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user