Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 7e59518

Browse files
committed
Add pubsub info in readme
1 parent e6ded63 commit 7e59518

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,38 @@ ipfs.id()
187187
This relies on a global `Promise` object. If you are in an environment where that is not
188188
yet available you need to bring your own polyfill.
189189

190+
### Publish/Subscribe (experimental)
191+
192+
js-ipfs-api supports the up-and-coming feature publish/subscribe. This requires you
193+
to use a development build of go-ipfs from the `feat/floodsub` branch (issue for tracking here: https://github.com/ipfs/go-ipfs/pull/3202).
194+
195+
Usage:
196+
197+
```js
198+
ipfsApi.pubsub.subscribe('my-topic', (err, subscription) => {
199+
if (err) {
200+
console.log('Something went wrong setting up the subscription')
201+
throw err
202+
}
203+
subscription.on('data', (msg) => {
204+
console.log('message', msg.data)
205+
// => 'Hello there!'
206+
})
207+
setTimeout(() => {
208+
// Stop subscription after 10 seconds
209+
subscription.cancel()
210+
}, 1000 * 10)
211+
})
212+
213+
ipfsApi.pubsub.publish('my-topic', 'Hello there!', (err, successful) => {
214+
if (err) {
215+
console.log('Something went wrong publishing a message')
216+
throw err
217+
}
218+
// successful = true/false
219+
})
220+
```
221+
190222
## Development
191223

192224
### Testing

0 commit comments

Comments
 (0)