mirror of https://github.com/waku-org/nwaku.git
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:
parent
ad5d5e2401
commit
4745135ee6
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue