mqtt5-wasm
MQTT v5.0 and v3.1.1 WebAssembly client and broker for browser environments.
Features
- WebSocket transport - Connect to remote MQTT brokers via
ws://orwss:// - In-tab broker - Run a complete MQTT broker in the browser
- MessagePort/BroadcastChannel - Inter-tab and worker communication
- Broker bridging - Connect multiple in-browser brokers via MessagePort
- Full QoS support - QoS 0, 1, and 2 with proper acknowledgment
- Shared subscriptions - Load balancing across multiple subscribers
- Event callbacks - Connection, disconnect, and error event handlers
- Automatic keepalive - Connection health monitoring with timeout detection
- Will messages - Last Will and Testament (LWT) support
Installation
npm (browser/bundler)
Cargo (Rust)
[]
= "0.7"
Build with wasm-pack:
Usage
Basic Example
import init from "mqtt5-wasm";
await ;
const client = ;
await client.;
await client.;
await client.;
await client.;
Event Callbacks
const client = ;
client.;
client.;
client.;
await client.;
In-Browser Broker
import init from "mqtt5-wasm";
await ;
const broker = ;
const port = broker.;
const client = ;
await client.;
Documentation
See the main repository for complete documentation and examples.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.