Community
Participate
Working Groups
In Firefox 24+, Connect fail with new WebSocket(wsurl, ["mqtt","mqttv3.1"]); The following is ok: new WebSocket(wsurl, "mqttv3.1");
What server were you connecting to and do you have any trace information? An array of subprotocols is a valid user (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) Did you also try new WebSocket(wsurl, "mqtt"); ?
(In reply to Al Stockdill-Mander from comment #1) > What server were you connecting to and do you have any trace information? > An array of subprotocols is a valid user > (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) Did you also > try new WebSocket(wsurl, "mqtt"); ? The server is MQ telemetry 7.5.0.1. The trace in console: ------------------ "NetworkError: 400 AMQHT0400E: Bad Request. - http://9.119.152.26:1883/mqtt" mqtt Firefox can't establish a connection to the server at ws://9.119.152.26:1883/mqtt. this.socket = new WebSocket(wsurl, ["mqtt","mqttv3.1"]); mqttws31.js (line 968) "NetworkError: 400 AMQHT0400E: Bad Request. - http://9.119.152.26:1883/mqtt" mqtt Connect fail. ErrorCode: 7, ErrorMsg: AMQJS0007E Socket error:undefined. Object { errorCode=7, errorMessage="AMQJS0007E Socket error:undefined.", invocationContext=undefined} TabConn.js (line 845) Firefox can't establish a connection to the server at ws://9.119.152.26:1883 /mqtt. this.socket = new WebSocket(wsurl, ["mqtt","mqttv3.1"]); --------------------------- new WebSocket(wsurl, "mqtt"); is also ok. It is ok to use MessageSight as server.
This appears to be an error in the server, it is legitimate for a client to present an array of sub protocols.
I would urge you to reconsider. While it is indeed true that the servers are non-compliant, they are unfortunately out there. Given that the code already has support for automatic fallback on protocol version, I see no reason to reject any attempt to support servers that only support a single protocol. Indeed, connecting to a mqtt3.1.1 server and asking for the "mqttv3.1" is already arguably wrong. Attached is a patch that, if the mqttVersion is set explicitly, only sends the appropriate websockets protocol, instead of the full array each time. Please consider the patch to public domain
Created attachment 245273 [details] if mqttVersion is set, only apply the matching websockets protocol
Actually there is a good option here for a fallback similar to the way we handle protocol levels
Implemented a simple switch so that mqttv3.1 is transmitted when V3 and mqtt is transmitted when V4.