koorchik / node-mole-rpc

Transport agnostic spec compliant JSON RPC client and server
MIT License
61 stars 13 forks source link

MQTTTransportServer reassign data in onMessage #1

Closed unsigned6 closed 5 years ago

unsigned6 commented 5 years ago

in onMessage handler callback data argument reassign data from upper scope:

    async onMessage(callback) {
        await this.mqttClient.subscribe(this.inTopic);
        this.mqttClient.on('message', (topic, data) => { 
            callback(data.toString(), (data) => {
                const outTopic = 
                    typeof this.outTopic === "function" 
                    ? this.outTopic({inTopic: topic})
                    : this.outTopic;

                this._send(outTopic, data)
            })
        });
    }

Should data argument in callback use another name? After renaming data->callbackData was able to receive messages from client.

koorchik commented 5 years ago

Fixed