can the Paho subscribe.onSuccess method access the topic name?

64 views
Skip to first unread message

Carlos Suarez

unread,
Nov 17, 2015, 11:58:16 PM11/17/15
to MQTT
Hello,
I'm using the Javascript Paho library and utility.

My client subscribes:

this.client.subscribe(topic, {
    onSuccess
: this.subscribeSuccess,
    onFailure
: this.subscribeFailure,
    qos
: Number(qos)
});


And in the onSuccess method I would like to access the name of the topic to which the client just subscribed:

subscribeSuccess
(context){
    console
.info('Successfully subscribed to ' + topic);
}

How can I access the topic subscribed to?

Sidenote: This is within a VueJS object.

thank you

Nicholas O'Leary

unread,
Nov 18, 2015, 2:21:52 AM11/18/15
to MQTT

Something like the following would do it:

var that=this;
this.client.subscribe(topic, {
    onSuccess: function() { that.subscribeSuccess(topic) },


    onFailure: this.subscribeFailure,
    qos: Number(qos)
});

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Nicholas O'Leary

unread,
Nov 18, 2015, 2:23:01 AM11/18/15
to MQTT

(Replying from a moving train on my phone, so take what I posted as a hint rather than something that will definitely work out of he box)

Carlos Suarez

unread,
Nov 19, 2015, 2:34:54 AM11/19/15
to MQTT
Will do. Thank you, Knolleary

Carlos Suarez

unread,
Nov 19, 2015, 2:40:21 AM11/19/15
to MQTT
Worked like a charm! Thanks again Knolleary.


On Wednesday, November 18, 2015 at 2:23:01 AM UTC-5, knolleary wrote:
Reply all
Reply to author
Forward
0 new messages