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

Commit a63988b

Browse files
committed
docs: add PubSub interface spec, refactor tests
1 parent eb65994 commit a63988b

File tree

3 files changed

+464
-390
lines changed

3 files changed

+464
-390
lines changed

API/pubsub/README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
pubsub API
2+
==========
3+
4+
#### `pubsub.subscribe`
5+
6+
> Subscribe to an IPFS Topic
7+
8+
##### `Go` **WIP**
9+
10+
##### `JavaScript` - ipfs.pubsub.subscribe(topic, options, callback)
11+
12+
- `topic` - type: String
13+
- `options` - type: Object, optional, might contain the following properties:
14+
- `discover`: type: Boolean - Will use the DHT to find
15+
16+
`callback` must follow `function (err, subscription) {}` where Subscription is a Node.js Stream in Object mode, emiting a `data` event for each new message on the subscribed topic.`err` is an error if the operation was not successful.
17+
18+
`subscription` has a `.cancel` event in order to cancel the subscription.
19+
20+
If no `callback` is passed, a [promise][] is returned.
21+
22+
> _In the future, topic can also be type of TopicDescriptor (https://github.com/libp2p/pubsub-notes/blob/master/flooding/flooding.proto#L23). However, for now, only strings are supported._
23+
24+
#### `pubsub.publish`
25+
26+
> Publish a data message to a pubsub topic
27+
28+
##### `Go` **WIP**
29+
30+
##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)
31+
32+
- `topic` - type: String
33+
- `data` - type: Buffer
34+
35+
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
36+
37+
If no `callback` is passed, a [promise][] is returned.
38+
39+
#### `pubsub.ls`
40+
41+
> Returns the list of subscriptions the peer is subscribed to.
42+
43+
##### `Go` **WIP**
44+
45+
##### `JavaScript` - ipfs.pubsub.ls(topic, callback)
46+
47+
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
48+
49+
If no `callback` is passed, a [promise][] is returned.
50+
51+
#### `pubsub.peers`
52+
53+
> Returns the peers that are subscribed to one topic.
54+
55+
##### `Go` **WIP**
56+
57+
##### `JavaScript` - ipfs.pubsub.peers(topic, callback)
58+
59+
- `topic` - type: String
60+
61+
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
62+
63+
If no `callback` is passed, a [promise][] is returned.

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ exports.swarm = require('./swarm')
99
exports.block = require('./block')
1010
exports.dht = require('./dht')
1111
exports.pubsub = require('./pubsub')
12-
exports.pubsubMessage = require('./pubsub-message')

0 commit comments

Comments
 (0)