Files: f096230a58e0b7b3a85a61e839a6088a8fe434c2 / modules / obs-local.js
696 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 | var ip = require('ip') |
5 | |
6 | var cache = null |
7 | |
8 | exports.obs_local = function () { |
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 | result.add(peer.key) |
21 | } |
22 | }) |
23 | }) |
24 | }, 5000) |
25 | |
26 | cache = result |
27 | return result |
28 | } |
29 | } |
30 |
Built with git-ssb-web