chore: refactor ConnectionManager#get

This commit is contained in:
Cayman
2020-06-09 15:50:13 -05:00
committed by Jacob Heun
parent 8f680e20e9
commit 90a9d93968

View File

@ -215,16 +215,9 @@ class ConnectionManager extends EventEmitter {
* @returns {Connection}
*/
get (peerId) {
if (!PeerId.isPeerId(peerId)) {
throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
}
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')
const connections = this.getAll(peerId)
if (connections.length) {
return connections[0]
}
return null
}