This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,38 @@ ipfs.id()
187
187
This relies on a global ` Promise ` object. If you are in an environment where that is not
188
188
yet available you need to bring your own polyfill.
189
189
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
+
190
222
## Development
191
223
192
224
### Testing
You can’t perform that action at this time.
0 commit comments