Commit 13be5ee9906beb5d8c2a24db46c68ef183c78d3a
poll for new local peers and update interface on discovery
Matt McKegg committed on 11/1/2016, 10:55:27 AMParent: e7dc89b429e48057d0f7dbb658a2c9072fafd580
Files changed
modules/obs-local.js | changed |
modules/obs-local.js | ||
---|---|---|
@@ -2,17 +2,29 @@ | ||
2 | 2 | var plugs = require('patchbay/plugs') |
3 | 3 | var sbot_gossip_peers = plugs.first(exports.sbot_gossip_peers = []) |
4 | 4 | var ip = require('ip') |
5 | 5 | |
6 | +var cache = null | |
7 | + | |
6 | 8 | exports.obs_local = function () { |
7 | - var result = MutantSet([], {nextTick: true}) | |
8 | - sbot_gossip_peers((err, peers) => { | |
9 | - if (err) throw console.log(err) | |
10 | - peers.filter((peer) => { | |
11 | - if (ip.isPrivate(peer.host) && (peer.source === 'local')) { | |
12 | - console.log(peer) | |
13 | - result.add(peer.key) | |
14 | - } | |
15 | - }) | |
16 | - }) | |
17 | - return result | |
9 | + if (cache) { | |
10 | + return cache | |
11 | + } else { | |
12 | + var result = MutantSet([], {nextTick: true}) | |
13 | + // todo: make this clean up on unlisten | |
14 | + | |
15 | + setTimeout(() => { | |
16 | + sbot_gossip_peers((err, peers) => { | |
17 | + if (err) throw console.log(err) | |
18 | + peers.filter((peer) => { | |
19 | + if (ip.isPrivate(peer.host) && (peer.source === 'local')) { | |
20 | + console.log(peer) | |
21 | + result.add(peer.key) | |
22 | + } | |
23 | + }) | |
24 | + }) | |
25 | + }, 5000) | |
26 | + | |
27 | + cache = result | |
28 | + return result | |
29 | + } | |
18 | 30 | } |
Built with git-ssb-web