Skip to content

Instantly share code, notes, and snippets.

@cblgh

cblgh/single-chat.js

Created Nov 11, 2018
Embed
What would you like to do?
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