mqtt-websocket-stream
This node module implements MQTT.js compatible duplex stream over WebSocket. It is an alternative implementation to websocket-stream that is better suited to work with MQTT.js. This module is used on aws-mqtt to connect to AWS IoT MQTT broker.
Features
- The stream implements
_writev
to efficiently write multiple small buffers that MQTT.js writes to the stream (MQTT.js callscork
, multiplewrite
and thenuncork
on the stream to send one packet) - Can work with browser's WebSocket, as well as server WebSocket implementation (ws)
- Supports async socket creation, when instantiation of the WebStream needs to be delayed/async, for example to async sign the url to connect to.
Usage
npm install mqtt-websocket-stream --save
In node environment:
const stream = urlstream
In browser environment (using Babel/Webpack):
const stream = urlstream
Passing an async factory:
const stream = { }stream