A Node.js library that implements a duplex stream over WebSocket, specifically designed to work with MQTT.js. Version 0.1.3 is the latest stable release with no recent updates. Key differentiators: optimized _writev for MQTT.js cork/write/uncork patterns, supports both browser WebSocket and Node.js ws library, and enables async socket creation for signed URLs (e.g., AWS IoT). Alternatives like websocket-stream lack these optimizations.
npm install mqtt-websocket-streamNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a WebSocket stream for MQTT.js and connects to an MQTT broker with pub/sub.
Always pass a WebSocket object (new WebSocket(url)) instead of the URL string.
callback(null, webSocketInstance) on success; callback(error) on failure.
Implement reconnection logic externally by creating a new stream and reconnecting MQTT client.
Configure bundler to polyfill Node.js stream or use browser-specific build.
client = mqtt.connect({ stream: () => mqttStream })npm install ws; const WebSocket = require('ws');Ensure the callback is invoked with (null, webSocket) or (error).