? looking for an example of listening/connecting via websocket to Losant Broker

Hi

I am trying to work out how to have d3.js plot a stream of data listening on a websocket. (MQTT output from a workflow);

Trying to do this at the lowest level with minimal additional dependencies.

Haven’t quite worked out how using JS to authenticate / subscribe at a websocket level (using wss://) against the losant broker.

Any examples around ?

Thanks

Tim

So the easiest thing to do would be to just use the losant-mqtt npm module, and choose the ‘wss’ transport option. The library works in the browser without issue (we actually use it in our own frontend, for the device simulator).

If you want minimal dependencies, the mqtt npm module can also be used directly in browser, and you again would choose ‘wss’ as the connection protocol. If you want even fewer dependencies than that, I think you would end up rolling your own minimal mqtt client. If you want to go down that road, probably the best example to follow would be the source code of the mqtt npm module.