Files: 996cb9ffec97abd3bf8391f3a15e462d01fd663d / modules / obs-connected.js
639 bytesRaw
1 | var MutantSet = require('@mmckegg/mutant/set') |
2 | var plugs = require('patchbay/plugs') |
3 | var sbot_gossip_peers = plugs.first(exports.sbot_gossip_peers = []) |
4 | |
5 | var cache = null |
6 | |
7 | exports.obs_connected = function () { |
8 | if (cache) { |
9 | return cache |
10 | } else { |
11 | var result = MutantSet([], {nextTick: true}) |
12 | // todo: make this clean up on unlisten |
13 | |
14 | refresh() |
15 | setInterval(refresh, 10e3) |
16 | |
17 | cache = result |
18 | return result |
19 | } |
20 | |
21 | // scope |
22 | |
23 | function refresh () { |
24 | sbot_gossip_peers((err, peers) => { |
25 | if (err) throw console.log(err) |
26 | result.set(peers.filter(x => x.state === 'connected').map(x => x.key)) |
27 | }) |
28 | } |
29 | } |
30 |
Built with git-ssb-web