fix protocol not defined bug

This commit is contained in:
Tarun Singh 2021-12-23 19:39:47 -05:00
parent d3c90df8a8
commit 4118de6d53

View file

@ -94,6 +94,10 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
return new Promise((resolve, reject) => {
const { port, username, password, interval = 20 } = options;
try {
// Adds mqtt protocol to the hostname if not already present
if (!/^(?:http|mqtt)s?:\/\//.test(hostname)) {
hostname = "mqtt://" + hostname;
}
let client = mqtt.connect(hostname, {
port,
username,