shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

Client message callback #314

Closed jahnli closed 3 years ago

jahnli commented 3 years ago

How can a client receive callbacks for only one topic

I currently subscribe to multiple topics, but I only want to receive callbacks from one topic. What should I do

shamblett commented 3 years ago

You can use topic filtering here, use this to filter for your topic of interest, your listener stream still receives all topics.

jahnli commented 3 years ago

Is there a way to make the listener flow accept only one topic

jahnli commented 3 years ago

At present, I have two pages that require message callback use update.listen, I don't know whether to do update.listens on both pages or do it in one place

jahnli commented 3 years ago

@shamblett Looking forward to your reply

shamblett commented 3 years ago

Not sure what you mean, if you attach a topic filter to the client and listen on it you will only get updates for that topic, not others, you can chain topic filters or attach as many as you like. Don't know what you mean by 'pages', I don't use flutter so I wouldn't know how best to do this in your case. Please read the API docs.

jahnli commented 3 years ago

I mean can it be used in multiple places (updates.listen or filter ) ? @shamblett

shamblett commented 3 years ago

Yes its a broadcast stream all listeners will receive the filtered topic

shamblett commented 3 years ago

There is an example of topic filtering in the examples directory, named mqtt_client_wildcard_filtered.dart. Maybe if you looked through these examples first and read the API docs you will get further with this.