git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: bbf9e423c5c7c91fb95d8d2b7f0bd30e6615b94a

Files: bbf9e423c5c7c91fb95d8d2b7f0bd30e6615b94a / modules / network.js

1575 bytesRaw
1var isVisible = require('is-visible').isVisible
2var h = require('hyperscript')
3var plugs = require('../plugs')
4
5var avatar = plugs.first(exports.avatar = [])
6var sbot_gossip_peers = plugs.first(exports.sbot_gossip_peers = [])
7//sbot_gossip_connect
8//sbot_gossip_add
9
10var human = require('human-time')
11
12function legacyToMultiServer(addr) {
13 return 'net:'+addr.host + ':'+addr.port + '~shs:'+addr.key.substring(1).replace('.ed25519','')
14}
15
16exports.screen_view = function (path) {
17
18 if(path !== '/network') return
19
20 var ol = h('ol.network')
21
22 var states = {
23 connected: 3,
24 connecting: 2,
25 disconnecting: 1
26 }
27
28 ;(function poll () {
29
30 //if this tab isn't open, don't update.
31 //todo: make a better way to do this...
32 if(!isVisible(ol))
33 return setTimeout(poll, 1000)
34
35 sbot_gossip_peers(function (err, list) {
36 ol.innerHTML = ''
37 list.sort(function (a, b) {
38 return (states[b.state] || 0) - (states[a.state] || 0) || b.stateChange - a.stateChange
39 }).forEach(function (peer) {
40 ol.appendChild(h('li',
41 avatar(peer.key, 'thumbnail'),
42 h('div',
43 peer.state || 'not connected',
44 ' ',
45 h('label',
46 {title: new Date(peer.stateChange).toString()},
47 peer.stateChange && ('(' + human(new Date(peer.stateChange))) + ')')
48 ),
49 'source:'+peer.source,
50 h('pre', legacyToMultiServer(peer))
51 )
52 )
53 })
54
55 setTimeout(poll, 5000)
56 })
57
58 })()
59
60 return h('div.column.scroll-y', ol)
61
62}
63
64
65
66
67
68
69
70
71
72
73
74
75

Built with git-ssb-web