-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Is this related to a new or existing framework?
React
Is this related to a new or existing API?
PubSub
Is this related to another service?
IoT Core
Describe the feature you'd like to request
Amplify javascript library for service integration in PubSub category should provide an easy and straight forward way to extract the topic value for the message received for an AWSIoTProvider or 3d party provider's subscription.
At the moment, developers must use metaprogramming techniques (through class reflection) to retrieve the value of the topic attached to the original message as Symbol(topic). This is awkward and inconvenient.
Describe the solution you'd like
I'm proposing a change to the "onMessage" event to either:
- Include topic name as an additional parameter (currently the event's data object has 2 parameters: value and provider) and emit it to the event handler without contaminating the original message value. Or...
- Introduce a method on the provider class, something like getTopic() or getTopic(value) that would retrieve the topic value for the received message. This approach might be less desirable due to the stateless nature of the provider object in relationship to the message value.
Describe alternatives you've considered
At some point in 2022, the Amplify library was modified to attached property "topicSymbol" directly to the message. The customers complained that the IoT messages gets contaminated with unwanted parameters, so the "fix" was reverted back to using reflection in March 2023. However, this approach still leaves the message object altered through Symbol property.
The current workaround is cumbersome as it requires to assign a single event handler per each topic the client subscribes to, so there's no need to read the topic name. If subscribed to multiple topic, the client code must use class reflection methods to retrieve the topic name from the message value, which is inadequate.
References:
5147c5c#diff-2a29f8a41f2b66733bb64a134e53acb5e67615e026667885a5686ce933d3869eR300
#11114
Additional context
No response
Is this something that you'd be interested in working on?
- 👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change