Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Add support to subscribe to a specific topic #9

Closed
FokkeZB opened this issue Sep 16, 2016 · 3 comments
Closed

Add support to subscribe to a specific topic #9

FokkeZB opened this issue Sep 16, 2016 · 3 comments
Assignees

Comments

@FokkeZB
Copy link
Contributor

FokkeZB commented Sep 16, 2016

For example: /+/devices/+/up/temperature.

The challenge is that if the topic comes in the + are the actual app/device IDs so unless we duplicate MQTT's wildcard matching it's hard to map it to an event with the same name. Probably best to have a single event much like MQTT's message which includes the topic.

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Sep 18, 2016

Possible API:

// subscribe to a field (of optional specific device)
client.on('field', fieldPath, [deviceId], function(deviceId, field, payload) {
});

// subscribe to messages (of optional specific device)
client.on('message', [deviceId], function(deviceId, payload) {
});

What might be confusing is that - unless we handle field/deviceID mapping internally - if you'd use these APIs multiple times each callback would be called for any field/message topic.

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Sep 18, 2016

As per @johanstokking's suggestion on Slack we'll keep it simple and allow the user to optionally filter on a single or array of devices and to filter on a specific field.

@johanstokking
Copy link
Contributor

Yep, I'd say one method:

client.on('message', [devices], [field], function(deviceId, fields, payload) {
});

If [devices] is set, and either a string or an array, subscribe to that device or devices. Otherwise, subscribe to +. If [field] is set, subscribe to that field, otherwise subscribe to up.

Note that, when subscribing to a field, the fields parameter in the callback becomes a bit useless. When subscribing to the field temperature, we might want to have { temperature: payload } in there, just for consistency with the general up topic.

@FokkeZB FokkeZB added the doing label Sep 20, 2016
@FokkeZB FokkeZB assigned FokkeZB and unassigned FokkeZB Sep 20, 2016
johanstokking pushed a commit that referenced this issue Sep 21, 2016
* Add pre-commit, add mocha/should test, add device/field specific subscribe, closes #9

* re-add app_id and dev_id

* Simplified both code and API

* Add editorconfig, convert tabs to 2 spaces
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants