$ npm install libp2p-floodsub
libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).
> npm install libp2p-floodsub
const FloodSub = require('libp2p-floodsub')
// registrar is provided by libp2p
const fsub = new FloodSub(peerId, registrar, options)
await fsub.start()
fsub.on('fruit', (data) => {
console.log(data)
})
fsub.subscribe('fruit')
fsub.publish('fruit', new Buffer('banana'))
const options = {…}
const floodsub = new Floodsub(peerId, registrar, options)
Options is an optional object with the following key-value pairs:
emitSelf
: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to false).For the remaining API, see https://github.com/libp2p/js-libp2p-pubsub
Floodsub emits two kinds of events:
<topic>
when a message is received for a particular topic fsub.on('fruit', (data) => { ... })
data
: a Buffer containing the data that was published to the topicfloodsub:subscription-change
when the local peer receives an update to the subscriptions of a remote peer. fsub.on('floodsub:subscription-change', (peerId, topics, changes) => { ... })
peerId
: a PeerId objecttopics
: the topics that the peer is now subscribed tochanges
: an array of { topicID: <topic>, subscribe: <boolean> }
eg [ { topicID: 'fruit', subscribe: true }, { topicID: 'vegetables': false } ]
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
Copyright (c) Protocol Labs, Inc. under the MIT License. See LICENSE file for details.
© 2010 - cnpmjs.org x YWFE | Home | YWFE