Merge pull request #159 from status-im/content-topic

Clarify content topic format
This commit is contained in:
Franck Royer 2021-05-15 19:43:19 +10:00 committed by GitHub
commit 35fcb4d880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -62,6 +62,7 @@
"unmounts", "unmounts",
"untracked", "untracked",
"upgrader", "upgrader",
"vacp",
"waku", "waku",
"wakuv", "wakuv",
"wakunode", "wakunode",

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Clarify content topic format in README.md.
## [0.2.0] - 2021-05-14 ## [0.2.0] - 2021-05-14
### Added ### Added

View File

@ -35,23 +35,27 @@ waku.addPeerToAddressBook(
``` ```
The `contentTopic` is a metadata `string` that allows categorization of messages on the waku network. The `contentTopic` is a metadata `string` that allows categorization of messages on the waku network.
Depending on your use case, you can either create a new `contentTopic` or look at the [RFCs](https://rfc.vac.dev/) and use an existing `contentTopic`. Depending on your use case, you can either create one (or several) new `contentTopic`(s) or look at the [RFCs](https://rfc.vac.dev/) and use an existing `contentTopic`.
See the [Waku v2 Message spec](https://rfc.vac.dev/spec/14/) for more details. See the [Waku v2 Message spec](https://rfc.vac.dev/spec/14/) for more details.
Listen to new messages received via [Waku v2 Relay](https://rfc.vac.dev/spec/11/), filtering the `contentTopic` to `waku/2/my-cool-app/proto`: For example, if you were to use a new `contentTopic` such as `"my-cool-app"`,
here is how to listen to new messages received via [Waku v2 Relay](https://rfc.vac.dev/spec/11/):
```javascript ```javascript
waku.relay.addObserver((msg) => { waku.relay.addObserver((msg) => {
console.log("Message received:", msg.payloadAsUtf8) console.log("Message received:", msg.payloadAsUtf8)
}, ["waku/2/my-cool-app/proto"]); }, ["my-cool-app"]);
``` ```
Note that the guidelines regarding content topic format are yet to be defined, see [vacp2p/rfc#364](https://github.com/vacp2p/rfc/issues/364).
The examples chat apps currently use content topic `"dingpu"`.
Send a message on the waku relay network: Send a message on the waku relay network:
```javascript ```javascript
import { WakuMessage } from 'js-waku'; import { WakuMessage } from 'js-waku';
const msg = WakuMessage.fromUtf8String("Here is a message!", "waku/2/my-cool-app/proto") const msg = WakuMessage.fromUtf8String("Here is a message!", "my-cool-app")
await waku.relay.send(msg); await waku.relay.send(msg);
``` ```
@ -63,13 +67,13 @@ Query a waku store peer to check historical messages:
```javascript ```javascript
// Process messages once they are all retrieved: // Process messages once they are all retrieved:
const messages = await waku.store.queryHistory(storePeerId, ["waku/2/my-cool-app/proto"]); const messages = await waku.store.queryHistory(storePeerId, ["my-cool-app"]);
messages.forEach((msg) => { messages.forEach((msg) => {
console.log("Message retrieved:", msg.payloadAsUtf8) console.log("Message retrieved:", msg.payloadAsUtf8)
}) })
// Or, pass a callback function to be executed as pages are received: // Or, pass a callback function to be executed as pages are received:
waku.store.queryHistory(storePeerId, ["waku/2/my-cool-app/proto"], waku.store.queryHistory(storePeerId, ["my-cool-app"],
(messages) => { (messages) => {
messages.forEach((msg) => { messages.forEach((msg) => {
console.log("Message retrieved:", msg.payloadAsUtf8) console.log("Message retrieved:", msg.payloadAsUtf8)