Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b66463b

Browse files
jacobheunvasco-santos
authored andcommitted
fix: correct pubsub methods for next libp2p release
1 parent 2f5e467 commit b66463b

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"just-flatten-it": "^2.1.0",
122122
"just-safe-set": "^2.1.0",
123123
"kind-of": "^6.0.2",
124-
"libp2p": "libp2p/js-libp2p#feat/integrate-gossipsub-by-default",
124+
"libp2p": "~0.26.0-rc.0",
125125
"libp2p-bootstrap": "~0.9.3",
126126
"libp2p-crypto": "~0.16.0",
127127
"libp2p-delegated-content-routing": "^0.2.3",

src/core/components/pubsub.js

+9-18
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,56 @@ module.exports = function pubsub (self) {
1616
options = {}
1717
}
1818

19-
if (!self._options.EXPERIMENTAL.pubsub) {
19+
if (!self.libp2p.pubsub) {
2020
return callback
2121
? setImmediate(() => callback(errPubsubDisabled()))
2222
: Promise.reject(errPubsubDisabled())
2323
}
2424

2525
if (!callback) {
26-
return new Promise((resolve, reject) => {
27-
self.libp2p.pubsub.subscribe(topic, options, handler, (err) => {
28-
if (err) {
29-
return reject(err)
30-
}
31-
resolve()
32-
})
33-
})
26+
return self.libp2p.pubsub.subscribe(topic, handler, options)
3427
}
3528

3629
self.libp2p.pubsub.subscribe(topic, options, handler, callback)
3730
},
3831

3932
unsubscribe: (topic, handler, callback) => {
40-
if (!self._options.EXPERIMENTAL.pubsub) {
33+
if (!self.libp2p.pubsub) {
4134
return callback
4235
? setImmediate(() => callback(errPubsubDisabled()))
4336
: Promise.reject(errPubsubDisabled())
4437
}
4538

46-
self.libp2p.pubsub.unsubscribe(topic, handler)
47-
4839
if (!callback) {
49-
return Promise.resolve()
40+
return self.libp2p.pubsub.unsubscribe(topic, handler)
5041
}
5142

52-
setImmediate(() => callback())
43+
self.libp2p.pubsub.unsubscribe(topic, handler, callback)
5344
},
5445

5546
publish: promisify((topic, data, callback) => {
56-
if (!self._options.EXPERIMENTAL.pubsub) {
47+
if (!self.libp2p.pubsub) {
5748
return setImmediate(() => callback(errPubsubDisabled()))
5849
}
5950
self.libp2p.pubsub.publish(topic, data, callback)
6051
}),
6152

6253
ls: promisify((callback) => {
63-
if (!self._options.EXPERIMENTAL.pubsub) {
54+
if (!self.libp2p.pubsub) {
6455
return setImmediate(() => callback(errPubsubDisabled()))
6556
}
6657
self.libp2p.pubsub.ls(callback)
6758
}),
6859

6960
peers: promisify((topic, callback) => {
70-
if (!self._options.EXPERIMENTAL.pubsub) {
61+
if (!self.libp2p.pubsub) {
7162
return setImmediate(() => callback(errPubsubDisabled()))
7263
}
7364
self.libp2p.pubsub.peers(topic, callback)
7465
}),
7566

7667
setMaxListeners (n) {
77-
if (!self._options.EXPERIMENTAL.pubsub) {
68+
if (!self.libp2p.pubsub) {
7869
throw errPubsubDisabled()
7970
}
8071
self.libp2p.pubsub.setMaxListeners(n)

0 commit comments

Comments
 (0)