diff --git a/examples/v2/basic2.nim b/examples/v2/basic2.nim index 0ffe527cb..05014f12e 100644 --- a/examples/v2/basic2.nim +++ b/examples/v2/basic2.nim @@ -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 diff --git a/waku/node/v2/wakunode2.nim b/waku/node/v2/wakunode2.nim index 14159ae0d..73a92390c 100644 --- a/waku/node/v2/wakunode2.nim +++ b/waku/node/v2/wakunode2.nim @@ -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"