Skip to content

Commit 70060e8

Browse files
DougAnderson444achingbrain
authored andcommitted
docs: Update readme docs to reflect v0.45.x api (#1821)
Fixes #1810
1 parent 25504ae commit 70060e8

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

examples/pubsub/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ await node1.peerStore.patch(node2.peerId, {
6565
})
6666
await node1.dial(node2.peerId)
6767

68-
node1.pubsub.addEventListener("message", (evt) => {
68+
node1.services.pubsub.addEventListener("message", (evt) => {
6969
console.log(`node1 received: ${uint8ArrayToString(evt.detail.data)} on topic ${evt.detail.topic}`)
7070
})
71-
await node1.pubsub.subscribe(topic)
71+
await node1.services.pubsub.subscribe(topic)
7272

7373
// Will not receive own published messages by default
74-
node2.pubsub.addEventListener("message", (evt) => {
74+
node2.services.pubsub.addEventListener("message", (evt) => {
7575
console.log(`node2 received: ${uint8ArrayToString(evt.detail.data)} on topic ${evt.detail.topic}`)
7676
})
77-
await node2.pubsub.subscribe(topic)
77+
await node2.services.pubsub.subscribe(topic)
7878

7979
// node2 publishes "news" every second
8080
setInterval(() => {
81-
node2.pubsub.publish(topic, uint8ArrayFromString('Bird bird bird, bird is the word!')).catch(err => {
81+
node2.services.pubsub.publish(topic, uint8ArrayFromString('Bird bird bird, bird is the word!')).catch(err => {
8282
console.error(err)
8383
})
8484
}, 1000)

examples/pubsub/message-filtering/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,32 @@ import { toString as uint8ArrayToString } from "uint8arrays/to-string";
5858

5959
const topic = 'fruit'
6060

61-
node1.pubsub.addEventListener('message', (msg) => {
61+
node1.services.pubsub.addEventListener('message', (msg) => {
6262
if (msg.detail.topic !== topic) {
6363
return
6464
}
6565

6666
console.log(`node1 received: ${uint8ArrayToString(msg.data)}`)
6767
})
68-
await node1.pubsub.subscribe(topic)
68+
await node1.services.pubsub.subscribe(topic)
6969

70-
node2.pubsub.addEventListener('message', (msg) => {
70+
node2.services.pubsub.addEventListener('message', (msg) => {
7171
if (msg.detail.topic !== topic) {
7272
return
7373
}
7474

7575
console.log(`node2 received: ${uint8ArrayToString(msg.data)}`)
7676
})
77-
await node2.pubsub.subscribe(topic)
77+
await node2.services.pubsub.subscribe(topic)
7878

79-
node3.pubsub.addEventListener('message', (msg) => {
79+
node3.services.pubsub.addEventListener('message', (msg) => {
8080
if (msg.detail.topic !== topic) {
8181
return
8282
}
8383

8484
console.log(`node3 received: ${uint8ArrayToString(msg.data)}`)
8585
})
86-
await node3.pubsub.subscribe(topic)
86+
await node3.services.pubsub.subscribe(topic)
8787
```
8888
Finally, let's define the additional filter in the fruit topic.
8989

@@ -97,17 +97,17 @@ const validateFruit = (msgTopic, msg) => {
9797
}
9898
}
9999

100-
node1.pubsub.topicValidators.set(topic, validateFruit)
101-
node2.pubsub.topicValidators.set(topic, validateFruit)
102-
node3.pubsub.topicValidators.set(topic, validateFruit)
100+
node1.services.pubsub.topicValidators.set(topic, validateFruit)
101+
node2.services.pubsub.topicValidators.set(topic, validateFruit)
102+
node3.services.pubsub.topicValidators.set(topic, validateFruit)
103103
```
104104

105105
In this example, node one has an outdated version of the system, or is a malicious node. When it tries to publish fruit, the messages are re-shared and all the nodes share the message. However, when it tries to publish a vehicle the message is not re-shared.
106106

107107
```JavaScript
108108
for (const fruit of ['banana', 'apple', 'car', 'orange']) {
109109
console.log('############## fruit ' + fruit + ' ##############')
110-
await node1.pubsub.publish(topic, uint8ArrayFromString(fruit))
110+
await node1.services.pubsub.publish(topic, uint8ArrayFromString(fruit))
111111
}
112112
```
113113

0 commit comments

Comments
 (0)