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

Add field/device specific subscribe, closes #9 and closes #8 #18

Merged
merged 4 commits into from
Sep 21, 2016

Conversation

FokkeZB
Copy link
Contributor

@FokkeZB FokkeZB commented Sep 20, 2016

Closes #9 and #8

This also introduces Mocha/Should tests that run before every commit.

For the new API of on('message') and on('activation') see the client test

Also, dev_id and app_id are no longer added to the payload since the callbacks now get these via arguments. > Re-added to not break #2 / #19

@FokkeZB FokkeZB changed the title Add pre-commit, add mocha/should test, add device/field specific subscribe Add field/device specific subscribe, closes #9 and closes #8 Sep 20, 2016
@FokkeZB
Copy link
Contributor Author

FokkeZB commented Sep 21, 2016

I simplified the code and API. Both activation and message callbacks now just have 2 arguments: devId and data. Since if you filter on a field the callback is only called for that field, there's no need to pass that as argument.

}
this.ee.emit(topic, devId, payload); // full topic, including field if any
this.ee.emit(parts.slice(0, 2).concat('+', parts.slice(3)).join('/'), devId, payload); // any device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want SDK users to work directly with our topic structure?

Copy link
Contributor Author

@FokkeZB FokkeZB Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't, as you can see in on() and off() we translate their arguments to the topic that we only internally use as the eventName so that the above 2 emitted events reach the right listeners. See the client test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

client = new ttn.Client(BROKER); // don't pass appId and appAccessKey to the test broker
client.appId = Math.floor(Math.random() * 16777215).toString(16); // but set random appId afterwards
return client;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert tabs to spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert tabs to spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@johanstokking johanstokking merged commit c7c837b into master Sep 21, 2016
@johanstokking johanstokking deleted the feature/9 branch September 21, 2016 11:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants