Created
November 11, 2018 00:34
-
-
Save cblgh/1239ea17337ea11aea369ae3a4c77983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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