Websocket connections fail with JavaScript Paho Client

You might stumble across a bug using Firefox to connect to a Mosquitto MQTT service.

Symptoms experienced in the Firefox console:

AMQJS0007E Socket error:undefined

Firefox can’t establish a connection to the server at wss://localhost:9001/mqtt

 

This is likely due to an issue in protocol handling of HTTP2. Whilst Chromium does not attempt a HTTP2 connection in this case, Firefox tries it first and gets a reply from the server.

 

Workaround 1 (Firefox local):

Set `network.http.spdy.websockets` to `false` in Firefox `about:config`.

Workaround 2 (Server side):

Use a version of libwebsockets compiled without HTTP2 support.

Compile flag is `-DLWS_WITH_HTTP2=OFF` in cmake to build with http/2 support disabled.

You can find prebuild versions version in the

Workaround 3 (Server side):
Proxy the MQTT requests using HTTP1.1 only. (Using Apache Webserver or NGINX)