moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

mqtt.js client does not detect that it was served from https #587

Closed btsimonh closed 7 years ago

btsimonh commented 7 years ago

hi, just close this if it's already been asked....

Was just setting up mosca on HTTPS, and using the demo html with: var client = mqtt.connect(); it tries to connect via ws: (as indicated by the chrome console, with denied because unsecure content). with: var client = mqtt.connect('wss://{ip:port}'); it works fine.

Maybe the mqtt client lib could detect if on an https page, and if so default to wss: rather than ws:?

not urgent, as easy workaround...

mcollina commented 7 years ago

It should be fixed in https://github.com/mqttjs/MQTT.js/pull/518.

btsimonh commented 7 years ago

looking at the package.json of the installed mqtt.js, it seems mosca's dependency on ^1.6.3 results in a maximum version of mqtt of <2.0.0. mqtt.js is on 2.2.1, and we get 1.14.1 from npm. (my mosca is 2.2.0). is this expected behavior?

the part of the (npm installed) package.json i'm looking at is: "_requested": { "raw": "mqtt@^1.6.3", "scope": null, "escapedName": "mqtt", "name": "mqtt", "rawSpec": "^1.6.3", "spec": ">=1.6.3 <2.0.0", "type": "range" },

If i change the dependency in mosca's package.json to ^2.0.0, the npm update happily updates mqtt.js to 2.2.1

btsimonh commented 7 years ago

Note to anyone who does upgrade mqtt.js - before it will be served by mosca, you must run: npm run-script bundle to get the served mqtt.js in the right place. @mcollina - I still get the same error though. Anything I'm missing?

mcollina commented 7 years ago

Maybe I didn't understand the problem. It's probably worth opening an issue up on MQTT.js. It should pick it up automatically.