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

Commit 20392b8

Browse files
apply cr
1 parent 689c9cf commit 20392b8

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

API/pubsub/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pubsub API
1111

1212
- `topic: string`
1313
- `options: Object` - (Optional), might contain the following properties:
14-
- `discover`: type: Boolean - Will use the DHT to find
14+
- `discover`: type: Boolean - Will use the DHT to find other peers.
1515
- `handler: (msg) => ()` - Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: string, seqno: Buffer, data: Buffer, topicCIDs: Array<string>}`.
1616
- `callback: (Error) => ()` (Optional) Called once the subscription is established.
1717

@@ -41,9 +41,10 @@ This works like `EventEmitter.removeListener`, as that only the `handler` passed
4141
##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)
4242

4343
- `topic: string`
44+
- `data: buffer` - The actual message to send
4445
- `callback: (Error) => ()` - Calls back with an error or nothing if the publish was successfull.
4546

46-
- Returns: `Promise` if no `callback` was passed otherwise `undefined`.
47+
If no `callback` is passed, a promise is returned.
4748

4849
#### `pubsub.ls`
4950

@@ -56,7 +57,7 @@ This works like `EventEmitter.removeListener`, as that only the `handler` passed
5657
- `topic: string`
5758
- `callback: (Error, Array<string>>) => ()` - Calls back with an error or a list of topicCIDs that this peer is subscribed to.
5859

59-
- Returns: `Promise<Array<string>>` if no `callback` was passed otherwise `undefined`.
60+
If no `callback` is passed, a promise is returned.
6061

6162
#### `pubsub.peers`
6263

@@ -69,4 +70,4 @@ This works like `EventEmitter.removeListener`, as that only the `handler` passed
6970
- `topic: string`
7071
- `callback: (Error, Array<string>>) => ()` - Calls back with an error or a list of peer ids subscribed to the `topic`.
7172

72-
- Returns: `Promise<Array<string>>` if no `callback` was passed otherwise `undefined`.
73+
If no `callback` is passed, a promise is returned.

src/object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = (common) => {
4242
})
4343
})
4444

45-
it.skip('template unixfs-dir', (done) => {
45+
it('template unixfs-dir', (done) => {
4646
ipfs.object.new('unixfs-dir', (err, node) => {
4747
expect(err).to.not.exist
4848
const nodeJSON = node.toJSON()

src/pubsub.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ module.exports = (common) => {
9292

9393
describe('single node', () => {
9494
describe('.publish', () => {
95-
it('message from string', (done) => {
96-
ipfs1.pubsub.publish(topic, 'hello friend', done)
95+
it('errors on string messags', (done) => {
96+
ipfs1.pubsub.publish(topic, 'hello friend', (err) => {
97+
expect(err).to.exist
98+
done()
99+
})
97100
})
98101

99102
it('message from buffer', (done) => {
@@ -124,7 +127,7 @@ module.exports = (common) => {
124127

125128
ipfs1.pubsub.subscribe(topic, handler, (err) => {
126129
expect(err).to.not.exist
127-
ipfs1.pubsub.publish(topic, 'hi', check)
130+
ipfs1.pubsub.publish(topic, new Buffer('hi'), check)
128131
})
129132
})
130133

@@ -163,7 +166,7 @@ module.exports = (common) => {
163166
(cb) => ipfs1.pubsub.subscribe(topic, handler2, cb)
164167
], (err) => {
165168
expect(err).to.not.exist
166-
ipfs1.pubsub.publish(topic, 'hello', check)
169+
ipfs1.pubsub.publish(topic, new Buffer('hello'), check)
167170
})
168171
})
169172

@@ -180,7 +183,7 @@ module.exports = (common) => {
180183
discover: true
181184
}, handler, (err) => {
182185
expect(err).to.not.exist
183-
ipfs1.pubsub.publish(topic, 'hi', check)
186+
ipfs1.pubsub.publish(topic, new Buffer('hi'), check)
184187
})
185188
})
186189
})
@@ -369,7 +372,7 @@ module.exports = (common) => {
369372
], (err) => {
370373
expect(err).to.not.exist
371374

372-
ipfs2.pubsub.publish(topic, expectedString, check)
375+
ipfs2.pubsub.publish(topic, new Buffer(expectedString), check)
373376
})
374377
})
375378

@@ -410,7 +413,7 @@ module.exports = (common) => {
410413
expect(err).to.not.exist
411414

412415
outbox.forEach((msg) => {
413-
ipfs2.pubsub.publish(topic, msg, check)
416+
ipfs2.pubsub.publish(topic, new Buffer(msg), check)
414417
})
415418
})
416419
})
@@ -464,7 +467,7 @@ module.exports = (common) => {
464467
() => sendCount < count,
465468
(cb) => {
466469
sendCount++
467-
ipfs2.pubsub.publish(topic, expectedString, cb)
470+
ipfs2.pubsub.publish(topic, new Buffer(expectedString), cb)
468471
},
469472
done
470473
)
@@ -480,7 +483,7 @@ module.exports = (common) => {
480483
() => sendCount < count,
481484
(cb) => {
482485
sendCount++
483-
ipfs1.pubsub.publish(topic, expectedString, cb)
486+
ipfs1.pubsub.publish(topic, new Buffer(expectedString), cb)
484487
},
485488
done
486489
)
@@ -548,7 +551,7 @@ module.exports = (common) => {
548551
}
549552

550553
return ipfs1.pubsub.subscribe(topic, sub)
551-
.then(() => ipfs1.pubsub.publish(topic, 'hi'))
554+
.then(() => ipfs1.pubsub.publish(topic, new Buffer('hi')))
552555
})
553556

554557
it('.peers', () => {

0 commit comments

Comments
 (0)