Skip to content

Commit

Permalink
feat(feed): replicate remote feed from peers
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jun 16, 2018
1 parent 0ad19ba commit d2cc42f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,4 +776,28 @@ module.exports = async ({
p2p.on('feed', ({}, callback) => {
feedCall((data) => callback(data))
})

// call once to get bigest feed
let feedLock = false
this.p2p.events.on('peer', () => {
if(feedLock)
return
feedLock = true
setTimeout(() => {
p2p.emit('feed', null, (remoteFeed) => {
if(!remoteFeed)
return

if(remoteFeed.length <= feed.size())
return

console.log('replace our feed with remote feed')
feed.feed = remoteFeed
send('feedUpdate', {
feed: feed.feed
});
});
}, 1000)
})

}

0 comments on commit d2cc42f

Please sign in to comment.