mqtt5-wasm 0.10.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  MQTT v5.0 and v3.1.1 WebAssembly client and broker for browser environments.
4
4
 
5
+ > **Upgrading from 0.x?** See the [Migration Guide](MIGRATION-1.0.md) for the complete list of renamed types, methods, and properties.
6
+
5
7
  ## Features
6
8
 
7
9
  - **WebSocket transport** - Connect to remote MQTT brokers via `ws://` or `wss://`
@@ -28,7 +30,7 @@ npm install mqtt5-wasm
28
30
 
29
31
  ```toml
30
32
  [dependencies]
31
- mqtt5-wasm = "0.10"
33
+ mqtt5-wasm = "1.0"
32
34
  ```
33
35
 
34
36
  Build with wasm-bindgen:
@@ -43,14 +45,14 @@ wasm-bindgen --target web --out-dir pkg target/wasm32-unknown-unknown/release/mq
43
45
  ### Basic Example
44
46
 
45
47
  ```javascript
46
- import init, { WasmMqttClient } from "mqtt5-wasm";
48
+ import init, { MqttClient } from "mqtt5-wasm";
47
49
 
48
50
  await init();
49
- const client = new WasmMqttClient("browser-client");
51
+ const client = new MqttClient("browser-client");
50
52
 
51
53
  await client.connect("wss://broker.example.com:8084/mqtt");
52
54
 
53
- await client.subscribe_with_callback("sensors/#", (topic, payload) => {
55
+ await client.subscribeWithCallback("sensors/#", (topic, payload) => {
54
56
  console.log(`${topic}: ${new TextDecoder().decode(payload)}`);
55
57
  });
56
58
 
@@ -62,17 +64,17 @@ await client.disconnect();
62
64
  ### Event Callbacks
63
65
 
64
66
  ```javascript
65
- const client = new WasmMqttClient("browser-client");
67
+ const client = new MqttClient("browser-client");
66
68
 
67
- client.on_connect((reasonCode, sessionPresent) => {
69
+ client.onConnect((reasonCode, sessionPresent) => {
68
70
  console.log(`Connected: reason=${reasonCode}, session=${sessionPresent}`);
69
71
  });
70
72
 
71
- client.on_disconnect(() => {
73
+ client.onDisconnect(() => {
72
74
  console.log("Disconnected from broker");
73
75
  });
74
76
 
75
- client.on_error((error) => {
77
+ client.onError((error) => {
76
78
  console.error(`Error: ${error}`);
77
79
  });
78
80
 
@@ -82,13 +84,13 @@ await client.connect("wss://broker.example.com:8084/mqtt");
82
84
  ### Connectivity Detection
83
85
 
84
86
  ```javascript
85
- const client = new WasmMqttClient("browser-client");
87
+ const client = new MqttClient("browser-client");
86
88
 
87
- client.on_connectivity_change((online) => {
89
+ client.onConnectivityChange((online) => {
88
90
  console.log(online ? "Network available" : "Network lost");
89
91
  });
90
92
 
91
- if (!client.is_browser_online()) {
93
+ if (!client.isBrowserOnline()) {
92
94
  console.log("Currently offline");
93
95
  }
94
96
  ```
@@ -96,15 +98,15 @@ if (!client.is_browser_online()) {
96
98
  ### In-Browser Broker
97
99
 
98
100
  ```javascript
99
- import init, { WasmBroker, WasmMqttClient } from "mqtt5-wasm";
101
+ import init, { Broker, MqttClient } from "mqtt5-wasm";
100
102
 
101
103
  await init();
102
104
 
103
- const broker = new WasmBroker();
104
- const port = broker.create_client_port();
105
+ const broker = new Broker();
106
+ const port = broker.createClientPort();
105
107
 
106
- const client = new WasmMqttClient("local-client");
107
- await client.connect_message_port(port);
108
+ const client = new MqttClient("local-client");
109
+ await client.connectMessagePort(port);
108
110
  ```
109
111
 
110
112
  ### Broker Lifecycle Events
@@ -112,29 +114,29 @@ await client.connect_message_port(port);
112
114
  Monitor broker activity with lifecycle callbacks:
113
115
 
114
116
  ```javascript
115
- const broker = new WasmBroker();
117
+ const broker = new Broker();
116
118
 
117
- broker.on_client_connect((event) => {
119
+ broker.onClientConnect((event) => {
118
120
  console.log(`Client connected: ${event.clientId}, cleanStart: ${event.cleanStart}`);
119
121
  });
120
122
 
121
- broker.on_client_disconnect((event) => {
123
+ broker.onClientDisconnect((event) => {
122
124
  console.log(`Client disconnected: ${event.clientId}, reason: ${event.reason}`);
123
125
  });
124
126
 
125
- broker.on_client_publish((event) => {
127
+ broker.onClientPublish((event) => {
126
128
  console.log(`Publish: ${event.topic} (${event.payloadSize} bytes, QoS ${event.qos})`);
127
129
  });
128
130
 
129
- broker.on_client_subscribe((event) => {
131
+ broker.onClientSubscribe((event) => {
130
132
  console.log(`Subscribe: ${event.clientId} -> ${event.subscriptions.map(s => s.topic)}`);
131
133
  });
132
134
 
133
- broker.on_client_unsubscribe((event) => {
135
+ broker.onClientUnsubscribe((event) => {
134
136
  console.log(`Unsubscribe: ${event.clientId} -> ${event.topics}`);
135
137
  });
136
138
 
137
- broker.on_message_delivered((event) => {
139
+ broker.onMessageDelivered((event) => {
138
140
  console.log(`Message delivered: packetId=${event.packetId}, QoS ${event.qos}`);
139
141
  });
140
142
  ```