Skip to content

Instantly share code, notes, and snippets.

@ninabreznik
Created August 20, 2020 15:21
Show Gist options
  • Save ninabreznik/b30ed3403eeb2c79eef56b1cdee8b7a4 to your computer and use it in GitHub Desktop.
Save ninabreznik/b30ed3403eeb2c79eef56b1cdee8b7a4 to your computer and use it in GitHub Desktop.
MakeFeed
const Hypercore = require('hypercore')
const reallyReady = require('hypercore-really-ready')
const ram = require('random-access-memory')
const hyperswarm = require('hyperswarm')
makeFeed()
// MAKE FEED and SEED IT
async function makeFeed () {
const feed = Hypercore(ram)
await feed.ready()
await feed.append('Hello World!')
await feed.append('Pozdravljen svet!')
await feed.append('你好,世界!')
await feed.append('Hola Mundo!')
await feed.append('สวัสดีชาวโลก!')
await feed.append('Hallo Welt!')
await feed.append('Bonjour le monde!')
await feed.append('Здраво Свете!')
await feed.append('Hai dunia!')
const feedkey = feed.key
const swarmkey = feed.discoveryKey
const swarm = hyperswarm()
swarm.join(swarmkey, { lookup: true, announce: true })
await reallyReady(feed)
swarm.on('connection', (socket, info) => {
console.log('new connection!')
// you can now use the socket as a stream, eg:
socket.pipe(feed.replicate(info.client)).pipe(socket)
})
console.log('Feedkey', feedkey.toString('hex'))
console.log('Swarmkey', swarmkey.toString('hex'))
return({ feedkey,swarmkey })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment