mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Minor improvements to MQTT Trigger-Node
This commit is contained in:
parent
b77fd59303
commit
23f8b2b4df
|
@ -3,10 +3,10 @@ import {
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
IDataObject,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
ITriggerResponse,
|
ITriggerResponse,
|
||||||
IDataObject,
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import * as mqtt from 'mqtt';
|
import * as mqtt from 'mqtt';
|
||||||
|
@ -75,7 +75,7 @@ export class MqttTrigger implements INodeType {
|
||||||
const credentials = this.getCredentials('mqtt');
|
const credentials = this.getCredentials('mqtt');
|
||||||
|
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
throw new Error('Credentials are mandatory!');
|
throw new Error('Credentials are mandatory!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const topics = (this.getNodeParameter('topics') as string).split(',');
|
const topics = (this.getNodeParameter('topics') as string).split(',');
|
||||||
|
@ -105,7 +105,7 @@ export class MqttTrigger implements INodeType {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
async function manualTriggerFunction() {
|
async function manualTriggerFunction() {
|
||||||
await new Promise(( resolve, reject ) => {
|
await new Promise((resolve, reject) => {
|
||||||
client.on('connect', () => {
|
client.on('connect', () => {
|
||||||
client.subscribe(topics, (err, granted) => {
|
client.subscribe(topics, (err, granted) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -120,7 +120,7 @@ export class MqttTrigger implements INodeType {
|
||||||
if (options.jsonParseMessage) {
|
if (options.jsonParseMessage) {
|
||||||
try {
|
try {
|
||||||
message = JSON.parse(message.toString());
|
message = JSON.parse(message.toString());
|
||||||
} catch (err) {}
|
} catch (err) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
result.message = message;
|
result.message = message;
|
||||||
|
@ -131,8 +131,7 @@ export class MqttTrigger implements INodeType {
|
||||||
result = message;
|
result = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.emit([self.helpers.returnJsonArray([result],
|
self.emit([self.helpers.returnJsonArray([result])]);
|
||||||
)]);
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue