-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browserified MQTT.js defaults to connecting to localhost instead of server URL #1730
Browserified MQTT.js defaults to connecting to localhost instead of server URL #1730
Comments
@BrandonSmith would you like to submit a pr to fix this issue? you could use the |
I also meet this issue when trying to connect MQTT from It connects to But it works when I connect from This is my source code const opt: mqtt.IClientOptions = {
host,
protocol: "mqtt",
clientId,
clean: true,
key,
cert,
ca,
reconnectPeriod: 0,
};
const client: MqttClient = mqtt.connect(opt);
client.on('connect', () => {
console.log('client connected');
client.publish(
`topic`,
"abc",
);
}) |
You should not provide an Line 78 in 6591404
|
I am using the MQTT.js version from https://unpkg.com in the browser and experience the following issue.
In old versions (<=4.1.0), MQTT.js used to connect to the host that served the website and also used the same port if
connect()
was called without an URL. I do not know if it also selected wss over ws if the page was served via HTTPS, as I never used TLS.Starting with 4.2.1 (4.2.0 does not work in the browser) and also in the current 5.1.4 release, calling
connect()
without an URL always connects tows:https://localhost/
.This change in behavior was probably introduced in #1108.
I worked around this issue by using the following command:
The text was updated successfully, but these errors were encountered: