From eed1d39ec51acae14d476fcb1ec3717a87f80d36 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 14 May 2021 15:58:09 +1000 Subject: [PATCH] Clarify content topic format --- .cspell.json | 1 + CHANGELOG.md | 3 +++ README.md | 16 ++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.cspell.json b/.cspell.json index 4d72a4d1bd..382509d833 100644 --- a/.cspell.json +++ b/.cspell.json @@ -62,6 +62,7 @@ "unmounts", "untracked", "upgrader", + "vacp", "waku", "wakuv", "wakunode", diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c223a4d9..e88008c986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Clarify content topic format in README.md. + ## [0.2.0] - 2021-05-14 ### Added diff --git a/README.md b/README.md index 9f09c4a90c..2a4d1b2da2 100644 --- a/README.md +++ b/README.md @@ -35,23 +35,27 @@ waku.addPeerToAddressBook( ``` 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. -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 waku.relay.addObserver((msg) => { 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: ```javascript 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); ``` @@ -63,13 +67,13 @@ Query a waku store peer to check historical messages: ```javascript // 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) => { console.log("Message retrieved:", msg.payloadAsUtf8) }) // 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.forEach((msg) => { console.log("Message retrieved:", msg.payloadAsUtf8)