Protofy icon indicating copy to clipboard operation
Protofy copied to clipboard

Fix onEvent mask and wildcard handling error

Open noreplydev opened this issue 9 months ago • 0 comments

Fix flows onEvent mask: Parsing from JSON to Object a Object not a string, this leads to an error parsing to Object and Object.

Fix MQTT topic subscription check: If we see how is handled mqtt subscription on Protofy/apps/api/src/api.ts there is an error if we use wildcards. On topicSub we add a value to subscriptions with let's say the key "test/#" (which is wildcard for all messages that came from test, something like test/*. Then on

  
mqtt.on("message", (messageTopic, message) => {
    const topic = messageTopic.toString()
    let parsedMessage = message.toString()
    try {
        parsedMessage = JSON.parse(parsedMessage);
    } catch (err) { }

    if(subscriptions[topic]) {  <--------------- HERE
        // Handle wildcard subscriptions
        const validSubscriptions = Object.keys(subscriptions).filter(subscription => {
    
    ...

We check if we're subscribed to that topic. A topic like:

test/sample

Will always fail even if we're subscribed with wildcard to test/# since on our subscriptions map we're subscribed to test/# not test/sample.

noreplydev avatar May 08 '24 14:05 noreplydev