Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

fix: switch observer edge cases #246

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ module.exports = (swtch) => {

function willObserve (peerInfo, transport, protocol, direction, bufferLength) {
peerInfo.then((pi) => {
const peerId = pi.id.toB58String()
setImmediate(() => observer.emit('message', peerId, transport, protocol, direction, bufferLength))
if (pi) {
const peerId = pi.id.toB58String()
setImmediate(() => observer.emit('message', peerId, transport, protocol, direction, bufferLength))
}
})
}
}
7 changes: 5 additions & 2 deletions src/protocol-muxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ module.exports = function protocolMuxer (protocols, observer) {
}

const handler = (protocol, _conn) => {
const conn = observeConn(null, protocol, _conn, observer)
protocols[protocol].handlerFunc.call(null, protocol, conn)
const handlerFunc = protocols[protocol].handlerFunc
if (handlerFunc) {
const conn = observeConn(null, protocol, _conn, observer)
handlerFunc(protocol, conn)
}
}

ms.addHandler(protocol, handler, protocols[protocol].matchFunc)
Expand Down