Created
October 28, 2014 19:00
-
-
Save jtremback/712afed6d2b1bd460c61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
var pull = require('pull-stream') | |
var net = require('net') | |
var toStream = require('pull-stream-to-stream') | |
var rimraf = require('rimraf') | |
rimraf.sync('./following1.db') // delete the db from last time | |
var ssb1 = require('../create')('./following1.db') | |
var feed1 = ssb1.createFeed() | |
rimraf.sync('./following2.db') // delete the db from last time | |
var ssb2 = require('../create')('./following2.db') | |
var feed2 = ssb2.createFeed() | |
var count = 0; | |
setInterval(function () { | |
feed1.add('msg', 'hello there! ' + count++, function () {}) | |
}, 2000) | |
feed1.add('pub', { address: { host: 'localhost', port: 1234 }}, function () {}) // Is this neccesary? Not sure... | |
feed2.add('flw', { $feed: feed1.id, $rel: 'follows' }, function () {}) | |
net.createServer(function (connection) { | |
connection.pipe(toStream(ssb1.createReplicationStream())).pipe(connection); | |
}).listen(1234); | |
var connection = net.connect(1234) | |
connection.pipe(toStream(ssb2.createReplicationStream())).pipe(connection) | |
pull( | |
ssb2.createFeedStream({ tail: true }), | |
pull.drain(function (message) { | |
console.log('MESSAGE: ', message) | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment