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} * @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
} }