From 1ebf725ac4be02d637afc20ef23cf23a41d4fe65 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 15 Feb 2018 19:39:06 +0100 Subject: [PATCH] docs: add docs --- README.md | 6 +++++- src/pubsub.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a411d9ba..870021bb 100644 --- a/README.md +++ b/README.md @@ -249,9 +249,13 @@ class Node extends libp2p { > PeerInfo instance of the node +#### `libp2p.pubsub` + +> Same API as IPFS PubSub, defined in the [CORE API Spec](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PUBSUB.md). Just replace `ipfs` by `libp2p` and you are golden. + --------------------- -`DHT methods exposed` +`DHT methods also exposed for the time being` #### `libp2p.dht.put(key, value, callback)` diff --git a/src/pubsub.js b/src/pubsub.js index 51354df8..b3d92637 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -11,7 +11,7 @@ module.exports = (node) => { return { subscribe: (topic, options, handler, callback) => { - if (!node.isStarted()) { + if (!node.isStarted() && !floodSub.started) { return setImmediate(() => callback(new Error(NOT_STARTED_YET))) } @@ -34,6 +34,10 @@ module.exports = (node) => { }, unsubscribe: (topic, handler) => { + if (!node.isStarted() && !floodSub.started) { + throw new Error(NOT_STARTED_YET) + } + floodSub.removeListener(topic, handler) if (floodSub.listenerCount(topic) === 0) { @@ -42,7 +46,7 @@ module.exports = (node) => { }, publish: (topic, data, callback) => { - if (!node.isStarted()) { + if (!node.isStarted() && !floodSub.started) { return setImmediate(() => callback(new Error(NOT_STARTED_YET))) } @@ -56,7 +60,7 @@ module.exports = (node) => { }, ls: (callback) => { - if (!node.isStarted()) { + if (!node.isStarted() && !floodSub.started) { return setImmediate(() => callback(new Error(NOT_STARTED_YET))) } @@ -66,7 +70,7 @@ module.exports = (node) => { }, peers: (topic, callback) => { - if (!node.isStarted()) { + if (!node.isStarted() && !floodSub.started) { return setImmediate(() => callback(new Error(NOT_STARTED_YET))) }