Change from ssb-gossip to ssb-conn

This commit is contained in:
Christian Bundy 2019-11-15 11:42:32 -08:00
parent 7ab8c076a9
commit 0142a75f15
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
5 changed files with 39 additions and 22 deletions

View File

@ -6,7 +6,7 @@
"license": "AGPL-3.0",
"dependencies": {
"@fraction/base16-css": "^1.1.0",
"@fraction/flotilla": "^1.0.1",
"@fraction/flotilla": "^2.0.0",
"debug": "^4.1.1",
"highlight.js": "^9.16.2",
"hyperaxe": "^1.3.0",

View File

@ -5,8 +5,11 @@ const metaView = require('./views/meta')
module.exports = async function metaPage ({ theme }) {
const status = await meta.status()
const peers = await meta.peers()
console.log(JSON.stringify(peers, null, 1))
const { themeNames } = require('@fraction/base16-css')
return metaView({ status, theme, themeNames })
return metaView({ status, peers, theme, themeNames })
}

View File

@ -20,6 +20,9 @@ const rawConnect = () => new Promise((resolve, reject) => {
ls: 'source',
want: 'async'
},
conn: {
peers: 'source'
},
createUserStream: 'source',
createHistoryStream: 'source',
get: 'sync',

View File

@ -1,6 +1,7 @@
'use strict'
const cooler = require('./lib/cooler')
const pull = require('pull-stream')
module.exports = {
whoami: async () => {
@ -21,6 +22,18 @@ module.exports = {
},
peers: async () => {
const ssb = await cooler.connect()
return cooler.get(ssb.conn)
const peersSource = await cooler.read(ssb.conn.peers)
return new Promise((resolve, reject) => {
pull(
peersSource,
// https://github.com/staltz/ssb-conn/issues/9
pull.take(1),
pull.collect((err, val) => {
if (err) return reject(err)
resolve(val[0])
})
)
})
}
}

View File

@ -1,20 +1,18 @@
'use strict'
const highlightJs = require('highlight.js')
const {
a,
button,
code,
div,
form,
h1,
h2,
h3,
h4,
label,
li,
option,
p,
pre,
progress,
section,
select,
@ -22,24 +20,27 @@ const {
} = require('hyperaxe')
const template = require('./components/template')
module.exports = ({ status, theme, themeNames }) => {
module.exports = ({ status, peers, theme, themeNames }) => {
const max = status.sync.since
const progressElements = Object.entries(status.sync.plugins).map((e) => {
const [key, val] = e
const id = `progress-${key}`
return [
return div(
label({ for: id }, key),
progress({ id, value: val, max }, val)
]
)
})
const localPeers = Object.keys(status.local || []).map((key) => li(key))
const remotePeers = Object.keys(status.gossip || []).map((key) => li(key))
const raw = JSON.stringify(status, null, 2)
const rawHighlighted = highlightJs.highlight('json', raw).value
const peerList = (peers || [])
.map(([key, data]) =>
li(
a(
{ href: `/author/${encodeURIComponent(data.key)}` },
code(data.key)
)
)
)
const themeElements = themeNames.map((cur) => {
const isCurrentTheme = cur === theme
@ -98,12 +99,9 @@ module.exports = ({ status, theme, themeNames }) => {
h2('Status'),
h3('Indexes'),
progressElements,
h3('Peers'),
h4('Local'),
ul(localPeers),
h4('Remote'),
ul(remotePeers),
h2('Raw'),
pre({ innerHTML: rawHighlighted }))
peerList.length > 0
? [h3('Peers'), ul(peerList)]
: null
)
)
}