diff --git a/README.md b/README.md index 73133a7cb6..b20cff987b 100644 --- a/README.md +++ b/README.md @@ -413,8 +413,8 @@ The core API is grouped into several areas: - [dht (not implemented, yet!)](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/) - [pubsub](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md) - - [`ipfs.pubsub.subscribe(topic, options, handler, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubsubscribe) - - [`ipfs.pubsub.unsubscribe(topic, handler)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubunsubscribe) + - [`ipfs.pubsub.subscribe(topic, handler, options, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubsubscribe) + - [`ipfs.pubsub.unsubscribe(topic, handler, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubunsubscribe) - [`ipfs.pubsub.publish(topic, data, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubpublish) - [`ipfs.pubsub.ls(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubls) - [`ipfs.pubsub.peers(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubpeers) diff --git a/package.json b/package.json index 3d93c9f430..707ca981ea 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,8 @@ "expose-loader": "^0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.64.3", - "ipfsd-ctl": "~0.33.1", + "interface-ipfs-core": "~0.65.5", + "ipfsd-ctl": "~0.34.0", "lodash": "^4.17.10", "mocha": "^5.1.1", "ncp": "^2.0.0", @@ -105,7 +105,7 @@ "hapi-set-header": "^1.0.2", "hoek": "^5.0.3", "human-to-milliseconds": "^1.0.0", - "ipfs-api": "^20.2.1", + "ipfs-api": "^21.0.0", "ipfs-bitswap": "~0.20.0", "ipfs-block": "~0.7.1", "ipfs-block-service": "~0.14.0", diff --git a/src/core/components/pubsub.js b/src/core/components/pubsub.js index d5825960e2..d125b6d2dc 100644 --- a/src/core/components/pubsub.js +++ b/src/core/components/pubsub.js @@ -1,13 +1,13 @@ 'use strict' const promisify = require('promisify-es6') +const setImmediate = require('async/setImmediate') module.exports = function pubsub (self) { return { - subscribe: (topic, options, handler, callback) => { + subscribe: (topic, handler, options, callback) => { if (typeof options === 'function') { - callback = handler - handler = options + callback = options options = {} } @@ -20,13 +20,19 @@ module.exports = function pubsub (self) { resolve() }) }) - } else { - self._libp2pNode.pubsub.subscribe(topic, options, handler, callback) } + + self._libp2pNode.pubsub.subscribe(topic, options, handler, callback) }, - unsubscribe: (topic, handler) => { + unsubscribe: (topic, handler, callback) => { self._libp2pNode.pubsub.unsubscribe(topic, handler) + + if (!callback) { + return Promise.resolve() + } + + setImmediate(() => callback()) }, publish: promisify((topic, data, callback) => { diff --git a/src/http/api/resources/pubsub.js b/src/http/api/resources/pubsub.js index 065746c62e..8b88bd3dce 100644 --- a/src/http/api/resources/pubsub.js +++ b/src/http/api/resources/pubsub.js @@ -33,16 +33,13 @@ exports.subscribe = { res.write('{}\n') const unsubscribe = () => { - ipfs.pubsub.unsubscribe(topic, handler) - res.end() + ipfs.pubsub.unsubscribe(topic, handler, () => res.end()) } request.once('disconnect', unsubscribe) request.once('finish', unsubscribe) - ipfs.pubsub.subscribe(topic, { - discover: discover - }, handler, (err) => { + ipfs.pubsub.subscribe(topic, handler, { discover: discover }, (err) => { if (err) { return reply(err) }