git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 13be5ee9906beb5d8c2a24db46c68ef183c78d3a

poll for new local peers and update interface on discovery

Matt McKegg committed on 11/1/2016, 10:55:27 AM
Parent: e7dc89b429e48057d0f7dbb658a2c9072fafd580

Files changed

modules/obs-local.jschanged
modules/obs-local.jsView
@@ -2,17 +2,29 @@
22 var plugs = require('patchbay/plugs')
33 var sbot_gossip_peers = plugs.first(exports.sbot_gossip_peers = [])
44 var ip = require('ip')
55
6+var cache = null
7+
68 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+ }
1830 }

Built with git-ssb-web