Skip to content

Instantly share code, notes, and snippets.

@cblgh
Created November 11, 2018 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblgh/1239ea17337ea11aea369ae3a4c77983 to your computer and use it in GitHub Desktop.
Save cblgh/1239ea17337ea11aea369ae3a4c77983 to your computer and use it in GitHub Desktop.
var hypercore = require('hypercore')
var pump = require("pump")
var disco = require("discovery-swarm")
var feed = hypercore('./single-chat-feed', {
valueEncoding: 'json'
})
var swarm = disco()
feed.ready(function () {
console.log("pub", feed.key.toString("hex"))
swarm.join(feed.discoveryKey)
swarm.on("connection", function (connection) {
pump(connection, feed.replicate({ live: true }), connection)
})
})
process.stdin.on("data", function(data) {
feed.append({
type: 'chat-message',
nickname: 'dat-lover',
text: data.toString(),
timestamp: new Date().toISOString()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment