Skip to content

Browserified MQTT.js defaults to connecting to localhost instead of server URL #1730

@dstolpmann

Description

@dstolpmann

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 to ws://localhost/.

This change in behavior was probably introduced in #1108.

I worked around this issue by using the following command:

mqtt.connect((location.protocol == "https:" ? "wss" : "ws") + "://" + location.hostname + ":" + location.port)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions