git ssb

16+

Dominic / patchbay



Tree: 9e65f9951f21778ee286834004367aa2b46bc882

Files: 9e65f9951f21778ee286834004367aa2b46bc882 / modules / network.js

1662 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.menu_items = function () {
17 return h('a', {href: '#/network'}, '/network')
18}
19
20exports.screen_view = function (path) {
21
22 if(path !== '/network') return
23
24 var ol = h('ol.network')
25
26 var states = {
27 connected: 3,
28 connecting: 2,
29 disconnecting: 1
30 }
31
32 ;(function poll () {
33
34 //if this tab isn't open, don't update.
35 //todo: make a better way to do this...
36 if(!isVisible(ol))
37 return setTimeout(poll, 1000)
38
39 sbot_gossip_peers(function (err, list) {
40 ol.innerHTML = ''
41 list.sort(function (a, b) {
42 return (states[b.state] || 0) - (states[a.state] || 0) || b.stateChange - a.stateChange
43 }).forEach(function (peer) {
44 ol.appendChild(h('li',
45 avatar(peer.key, 'thumbnail'),
46 h('div',
47 peer.state || 'not connected',
48 ' ',
49 h('label',
50 {title: new Date(peer.stateChange).toString()},
51 peer.stateChange && ('(' + human(new Date(peer.stateChange))) + ')')
52 ),
53 'source:'+peer.source,
54 h('pre', legacyToMultiServer(peer))
55 )
56 )
57 })
58
59 setTimeout(poll, 5000)
60 })
61
62 })()
63
64 return h('div.column.scroll-y', ol)
65
66}
67
68
69
70
71
72
73
74
75
76
77
78
79

Built with git-ssb-web