Create a p2p webrtc swarm around a hyperlog.
This is a fork of substack/swarmlog that
changes the API a bit. The key difference is that hyperswarm
consumes a
hyperlog rather than producing it. This makes it easy to supply your own
non-standard hyperlog implementation conforming to its API, like
noffle/ipfs-hyperlog.
Create a hyperlog publisher that will write a new message every second:
publish.js
:
var hyperlog = require('hyperlog')
var hyperswarm = require('hyperswarm')
var memdb = require('memdb')
var log = hyperlog(memdb(), {
valueEncoding: 'json'
})
var swarm = hyperswarm(log, {
topic: 'example',
hubs: [ 'https://signalhub.mafintosh.com' ]
})
var times = 0
setInterval(function () {
log.append({ time: Date.now(), msg: 'HELLO!x' + times })
times++
}, 1000)
and a follower that will consume the log:
var hyperlog = require('hyperlog')
var hyperswarm = require('hyperswarm')
var memdb = require('memdb')
var log = hyperlog(memdb(), {
valueEncoding: 'json'
})
var swarm = hyperswarm(log, {
topic: 'example',
hubs: [ 'https://signalhub.mafintosh.com' ]
})
log.createReadStream({ live: true })
.on('data', function (data) {
console.log('RECEIVED', data)
})
var hyperswarm = require('hyperswarm')
Create a hyperswarm instance swarm
from a hyperlog log
and options:
opts.topic
- a string indicating some topic to use to look for common peersopts.hubs
- array of signalhub hubs to useopts.peerStream(peer)
- optional function that should return the stream to use for a peer swarm connection. Use this if you want to multiplex some other protocols on the same swarm alongside the hyperlog replication.
Optionally provide a wrtc instance as opts.wrtc
to create a hyperswarm in
Node.
The underlying signalhub instance.
Currently the swarm relies on signalhub to assist in the webrtc swarm setup, but ideally in the future this could be replaced or augmented with a webrtc DHT.
npm install hyperswarm
BSD
Forked from substack/swarmlog, which is also BSD licensed.