I'm using MQTT.JS in a React component. For some reason when I try to connect to my HiveMQ host the connect function prepends the URL with "localhost"
Does anyone have an idea why this is happening?
First I called the connect function with an option object which contained a "host" key. The result was that the connect function ignored the host key and connected to ws://localhost directly
const mqttConnect = (mqttOptions) => {
console.log(JSON.stringify(mqttOptions, null, 4))
setClient(mqtt.connect( mqttOptions ))
}
The second thing I tried was to call the function naming the host explicitly by including it as the first argument. That resulted in the connect function prepending the host URL with ws://localhost
const mqttConnect = (mqttOptions) => {
console.log(JSON.stringify(mqttOptions, null, 4))
setClient(mqtt.connect( mqttOptions.host, mqttOptions) )
}
This is what the options object looks like:
mqttOptions: { "host": "58xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0c.s1.eu.hivemq.cloud", "port": "8884", "clientId": "icodefusion", "username": "icode", "password": "password", "protocol": "MQTT" }
I included a snapshot of the error https://imagizer.imageshack.com/img923/3495/UEAqem.jpg