Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staltz feedback #16

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
prettier logging for connections
mixmix committed Oct 25, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3f775d0f84c2d9986a25c092cd80db6388264d93
21 changes: 19 additions & 2 deletions src/ssb-server.js
Original file line number Diff line number Diff line change
@@ -57,8 +57,21 @@ module.exports = function SSB (opts = {}) {
pull(
ssb.conn.peers(),
flatMap(evs => evs),
pull.map(ev => [ev[1].key, ev[1].state].join(' - ')),
pull.log()
pull.asyncMap((ev, cb) => {
const feedId = ev[1].key
ssb.aboutSelf.get(feedId, (err, details) => {
cb(null, {
state: ev[1].state,
name: err ? feedId : (details.name || feedId)
})
})
}),
pull.drain(({ state, name }) => {
const output = `${state.padStart(13, ' ')} - ${name}`
state === 'connected'
? console.log(green(output))
: console.log(output)
})
)

peers.forEach(({ name, id, host, invite }) => {
@@ -111,3 +124,7 @@ module.exports = function SSB (opts = {}) {

return ssb
}

function green (string) {
return '\x1b[32m' + string + '\x1b[0m'
}