paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
websockify support (websocket binary protocol)
Test setup
mosquitto broker listening on 1883
websockify websocket to TCP bridge set up to bridge public-ip:9001 to localhost:1883
sample page subscribing to broker via mqttws31.js
What happens
websockify refuses connection from client:
host17-79-dynamic.183-80-r.retail... - - [31/Mar/2016 15:49:20] code 400, message Client must support 'binary' or 'base64' protocol
Solution
I have been able to fix this issue by patching:
this.socket = new WebSocket(wsurl, ["mqttv3.1"]);
to:
this.socket = new WebSocket(wsurl, ["binary"]);
Request
still I think that a proper option could be added to paho.MQTT.Client class to support this scenario, something like:
var options = { binaryMode: true,
or some explicit string option override.
thank you!
Adding binary support should be trivial.. I have to ask though, why not just enable WebSocket support in your Mosquitto config?
Like this:
listener 1883
protocol mqtt
listener 80
protocol websockets
yes but i have some legacy ubuntu 12.04 lts installation so i needed a workaround... :) Il 04/Mag/2016 11:21, "James Sutton" [email protected] ha scritto:
Adding binary support should be trivial.. I have to ask though, why not just enable WebSocket support in your Mosquitto config?
Like this:
listener 1883 protocol mqtt
listener 80 protocol websockets
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/eclipse/paho.mqtt.javascript/issues/57#issuecomment-216808545
Good point, how does this look? https://github.com/jpwsutton/paho.mqtt.javascript/blob/issue_57/src/mqttws31.js#L1722 I've added a property to the connectOptions called webSocketBinary. It defaults to false, but if set to true, it will override the WebSocket type to binary (as can be seen here: https://github.com/jpwsutton/paho.mqtt.javascript/blob/issue_57/src/mqttws31.js#L976)
I am wondering if we can specify more than one subprotocol, e.g. this.socket = new WebSocket(wsurl, ["binary","mqttv3.1"]);
I'm using the webSocketBinary enhancement on my RaspberryPi with MQTT 3.1 v 1.3.4 and websockify without any issue by more than 6 month. I hope this can help to add this to the master branch.