aedes
aedes copied to clipboard
feat: preUnsubscribe handler
Invoked then a client unsubscribes from topics. Just like authorizeSubscribe, this function allows modifying the topics before executing the unsubscribe. This is needed in cases where topics are modified in authorizeSubscribe. For example:
aedes.authorizeSubscribe = (client, subscription, callback) => {
// overwrite subscription: force client to its namespace
subscription.topic = `/${client.id}/${subscription.topic}`;
callback(null, subscription);
}
aedes.preUnsubscribe = (client, packet, callback) => {
// overwrite unsubscriptions: force client to its namespace
for (let i in packet.unsubscriptions) {
packet.unsubscriptions[i] = `/${client.id}/${packet.unsubscriptions[i]}`;
}
callback(client, packet)
}
Pull Request Test Coverage Report for Build 709159642
- 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.002%) to 99.555%
Totals | |
---|---|
Change from base Build 689232499: | 0.002% |
Covered Lines: | 804 |
Relevant Lines: | 805 |
💛 - Coveralls
The main question is what's the use case of modifying subscription topic in authorizeSubscribe
?
@gnought You mean preSubscribe
?
@gnought the example I'm providing in the description is the use-case I need it for: I need to force clients into their own namespace, without the clients needing to know about their namespaces. Clients may subscribe to #
, i.e., get everything, but will actually be reduced to /${client.id}/#
, i.e., everything in their namespace only.
@robertsLando I've made preUnsubscribe
async as you suggested.
I believe you also hook authorizePublish
to modify the PUBLISH topic, am I right?
yes, exactly, @gnought .
How about if we add the support of client isolation? Will it fit in your case? @chfritz
@mcollina : will do. @gnought : maybe. What do you mean by support for client isolation?
Just like your use case, we prepend some client-specific string in client topics.
I see. Yes, I think that would work for me.