sclausen / ngx-mqtt

This library isn't just a wrapper around MQTT.js for angular. It uses observables and takes care of subscription handling and message routing.
https://sclausen.github.io/ngx-mqtt/
MIT License
186 stars 82 forks source link

Topic match error: “sport/+” does not match “sport/” #219

Open milabi opened 1 year ago

milabi commented 1 year ago

https://github.com/sclausen/ngx-mqtt/blob/f6f115b4a84fbbacfb1cf572df987531d57e5b90/projects/ngx-mqtt/src/lib/mqtt.service.ts#L156

Should the above code be changed to

return t !== undefined ? match() : false; 

[For example, “sport/tennis/+” matches “sport/tennis/player1” and “sport/tennis/player2”, but not “sport/tennis/player1/ranking”. Also, because the single-level wildcard matches only a single level, “sport/+” does not match “sport” but it does match “sport/”. jump to docs https://docs.oasis-open.org

sclausen commented 1 year ago

Yes, you’re right. I’ll fix it. Why didn’t I used those topics and filters for my tests? 🤔

milabi commented 1 year ago

I have a question. What is the purpose of this filter. The server already has a filter for filtering topics.

sclausen commented 1 year ago

Since the mqtt.js client will receive all messages for all subscribed topic filters, this code will ensure that only the messages matching the topic filter you created the specific observables with will be received. So you don't have to manually filter out the messages your specific component doesn't need.