Node API: Implement publish (#91)

* Fix init signature according to Node API

See https://github.com/status-im/nim-waku/blob/master/docs/api/v2/node.md

* Update docs and example

* Node API: Basic subscribe

* Modify example with subscribe handler

* Waku Node: Implement basic publish topic
This commit is contained in:
Oskar Thorén 2020-07-28 16:18:30 +08:00 committed by GitHub
parent ad5d5e2401
commit 4745135ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -23,10 +23,15 @@ proc runBackground(conf: WakuNodeConf) {.async.} =
# Subscribe to a topic
let topic = "foobar"
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
info "Hit subscribe handler", topic=topic, data=data
info "Hit subscribe handler", topic=topic, data=data, decoded=cast[string](data)
node.subscribe(topic, handler)
# Publish to a topic
let message = cast[seq[byte]]("hello world")
node.publish(topic, message)
discard runBackground(conf)
runForever()
# TODO Lets start with Nim Node API first

View File

@ -286,12 +286,13 @@ method unsubscribe*(w: WakuNode, contentFilter: ContentFilter) =
## TODO Implement.
method publish*(w: WakuNode, topic: Topic, message: Message) =
echo "NYI"
## Publish a `Message` to a PubSub topic.
##
## Status: Not yet implemented.
## TODO Implement as wrapper around `waku_protocol`, and ensure Message is
## passed, not `data` field.
## Status: Partially implemented.
## TODO: Esure Message is passed, not seq[byte] `data` field.
let wakuSub = w.switch.pubSub.get()
# XXX Consider awaiting here
discard wakuSub.publish(topic, message)
method publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message: Message) =
echo "NYI"