Files: c17210ec353dee6e28ecd08ebdc1c50a65d99dec / modules / network.js
1662 bytesRaw
1 | var isVisible = require('is-visible').isVisible |
2 | var h = require('hyperscript') |
3 | var plugs = require('../plugs') |
4 | |
5 | var avatar = plugs.first(exports.avatar = []) |
6 | var sbot_gossip_peers = plugs.first(exports.sbot_gossip_peers = []) |
7 | //sbot_gossip_connect |
8 | //sbot_gossip_add |
9 | |
10 | var human = require('human-time') |
11 | |
12 | function legacyToMultiServer(addr) { |
13 | return 'net:'+addr.host + ':'+addr.port + '~shs:'+addr.key.substring(1).replace('.ed25519','') |
14 | } |
15 | |
16 | exports.menu_items = function () { |
17 | return h('a', {href: '#/network'}, '/network') |
18 | } |
19 | |
20 | exports.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