mqtt5-wasm 0.6.1 → 0.7.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 +47 -6
- package/mqtt5_wasm.d.ts +2 -2
- package/mqtt5_wasm.js +14 -14
- package/mqtt5_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,12 +4,15 @@ MQTT v5.0 and v3.1.1 WebAssembly client and broker for browser environments.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **WebSocket transport** - Connect to remote MQTT brokers
|
|
7
|
+
- **WebSocket transport** - Connect to remote MQTT brokers via `ws://` or `wss://`
|
|
8
8
|
- **In-tab broker** - Run a complete MQTT broker in the browser
|
|
9
|
-
- **MessagePort/BroadcastChannel** - Inter-tab communication
|
|
9
|
+
- **MessagePort/BroadcastChannel** - Inter-tab and worker communication
|
|
10
10
|
- **Broker bridging** - Connect multiple in-browser brokers via MessagePort
|
|
11
|
-
- **Full QoS support** - QoS 0, 1, and 2
|
|
12
|
-
- **
|
|
11
|
+
- **Full QoS support** - QoS 0, 1, and 2 with proper acknowledgment
|
|
12
|
+
- **Shared subscriptions** - Load balancing across multiple subscribers
|
|
13
|
+
- **Event callbacks** - Connection, disconnect, and error event handlers
|
|
14
|
+
- **Automatic keepalive** - Connection health monitoring with timeout detection
|
|
15
|
+
- **Will messages** - Last Will and Testament (LWT) support
|
|
13
16
|
|
|
14
17
|
## Installation
|
|
15
18
|
|
|
@@ -23,7 +26,7 @@ npm install mqtt5-wasm
|
|
|
23
26
|
|
|
24
27
|
```toml
|
|
25
28
|
[dependencies]
|
|
26
|
-
mqtt5-wasm = "0.
|
|
29
|
+
mqtt5-wasm = "0.7"
|
|
27
30
|
```
|
|
28
31
|
|
|
29
32
|
Build with wasm-pack:
|
|
@@ -34,19 +37,57 @@ wasm-pack build --target web --features client,broker
|
|
|
34
37
|
|
|
35
38
|
## Usage
|
|
36
39
|
|
|
40
|
+
### Basic Example
|
|
41
|
+
|
|
37
42
|
```javascript
|
|
38
43
|
import init, { WasmMqttClient } from "mqtt5-wasm";
|
|
39
44
|
|
|
40
45
|
await init();
|
|
41
46
|
const client = new WasmMqttClient("browser-client");
|
|
42
47
|
|
|
43
|
-
await client.connect("
|
|
48
|
+
await client.connect("wss://broker.example.com:8084/mqtt");
|
|
44
49
|
|
|
45
50
|
await client.subscribe_with_callback("sensors/#", (topic, payload) => {
|
|
46
51
|
console.log(`${topic}: ${new TextDecoder().decode(payload)}`);
|
|
47
52
|
});
|
|
48
53
|
|
|
49
54
|
await client.publish("sensors/temp", new TextEncoder().encode("25.5"));
|
|
55
|
+
|
|
56
|
+
await client.disconnect();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Event Callbacks
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const client = new WasmMqttClient("browser-client");
|
|
63
|
+
|
|
64
|
+
client.on_connect((reasonCode, sessionPresent) => {
|
|
65
|
+
console.log(`Connected: reason=${reasonCode}, session=${sessionPresent}`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
client.on_disconnect(() => {
|
|
69
|
+
console.log("Disconnected from broker");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
client.on_error((error) => {
|
|
73
|
+
console.error(`Error: ${error}`);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await client.connect("wss://broker.example.com:8084/mqtt");
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### In-Browser Broker
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
import init, { WasmBroker, WasmMqttClient } from "mqtt5-wasm";
|
|
83
|
+
|
|
84
|
+
await init();
|
|
85
|
+
|
|
86
|
+
const broker = new WasmBroker();
|
|
87
|
+
const port = broker.create_client_port();
|
|
88
|
+
|
|
89
|
+
const client = new WasmMqttClient("local-client");
|
|
90
|
+
await client.connect_message_port(port);
|
|
50
91
|
```
|
|
51
92
|
|
|
52
93
|
## Documentation
|
package/mqtt5_wasm.d.ts
CHANGED
|
@@ -368,10 +368,10 @@ export interface InitOutput {
|
|
|
368
368
|
readonly wasmwillmessage_willDelayInterval: (a: number) => number;
|
|
369
369
|
readonly wasm_bindgen__convert__closures_____invoke__ha9d3e198cd0951b0: (a: number, b: number, c: any) => void;
|
|
370
370
|
readonly wasm_bindgen__closure__destroy__h849099dfd9acf928: (a: number, b: number) => void;
|
|
371
|
+
readonly wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a: (a: number, b: number, c: any) => void;
|
|
372
|
+
readonly wasm_bindgen__closure__destroy__h25acc308bc5379fe: (a: number, b: number) => void;
|
|
371
373
|
readonly wasm_bindgen__convert__closures_____invoke__hf9723d0014506a5b: (a: number, b: number) => void;
|
|
372
374
|
readonly wasm_bindgen__closure__destroy__he9d43d9a42a0e056: (a: number, b: number) => void;
|
|
373
|
-
readonly wasm_bindgen__convert__closures_____invoke__h834c21a82254f81d: (a: number, b: number, c: any) => void;
|
|
374
|
-
readonly wasm_bindgen__closure__destroy__h1cc6a113486e5735: (a: number, b: number) => void;
|
|
375
375
|
readonly wasm_bindgen__convert__closures_____invoke__h1ee277075b103ebf: (a: number, b: number, c: any, d: any) => void;
|
|
376
376
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
377
377
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
package/mqtt5_wasm.js
CHANGED
|
@@ -255,12 +255,12 @@ function wasm_bindgen__convert__closures_____invoke__ha9d3e198cd0951b0(arg0, arg
|
|
|
255
255
|
wasm.wasm_bindgen__convert__closures_____invoke__ha9d3e198cd0951b0(arg0, arg1, arg2);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
function
|
|
259
|
-
wasm.
|
|
258
|
+
function wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a(arg0, arg1, arg2) {
|
|
259
|
+
wasm.wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a(arg0, arg1, arg2);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
function
|
|
263
|
-
wasm.
|
|
262
|
+
function wasm_bindgen__convert__closures_____invoke__hf9723d0014506a5b(arg0, arg1) {
|
|
263
|
+
wasm.wasm_bindgen__convert__closures_____invoke__hf9723d0014506a5b(arg0, arg1);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
function wasm_bindgen__convert__closures_____invoke__h1ee277075b103ebf(arg0, arg1, arg2, arg3) {
|
|
@@ -2048,19 +2048,24 @@ function __wbg_get_imports() {
|
|
|
2048
2048
|
const ret = v0;
|
|
2049
2049
|
return ret;
|
|
2050
2050
|
};
|
|
2051
|
-
imports.wbg.
|
|
2052
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
2051
|
+
imports.wbg.__wbindgen_cast_5208882bb9fe3820 = function(arg0, arg1) {
|
|
2052
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 358, function: Function { arguments: [], shim_idx: 359, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2053
2053
|
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__he9d43d9a42a0e056, wasm_bindgen__convert__closures_____invoke__hf9723d0014506a5b);
|
|
2054
2054
|
return ret;
|
|
2055
2055
|
};
|
|
2056
|
+
imports.wbg.__wbindgen_cast_663c73182bf372f2 = function(arg0, arg1) {
|
|
2057
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 369, function: Function { arguments: [Externref], shim_idx: 370, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2058
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h849099dfd9acf928, wasm_bindgen__convert__closures_____invoke__ha9d3e198cd0951b0);
|
|
2059
|
+
return ret;
|
|
2060
|
+
};
|
|
2056
2061
|
imports.wbg.__wbindgen_cast_a6d58121ace2ceaa = function(arg0, arg1) {
|
|
2057
2062
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 7, function: Function { arguments: [NamedExternref("ErrorEvent")], shim_idx: 8, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2058
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2063
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h25acc308bc5379fe, wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a);
|
|
2059
2064
|
return ret;
|
|
2060
2065
|
};
|
|
2061
2066
|
imports.wbg.__wbindgen_cast_d3f7166d7f91ad34 = function(arg0, arg1) {
|
|
2062
2067
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 7, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2063
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2068
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h25acc308bc5379fe, wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a);
|
|
2064
2069
|
return ret;
|
|
2065
2070
|
};
|
|
2066
2071
|
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
@@ -2068,14 +2073,9 @@ function __wbg_get_imports() {
|
|
|
2068
2073
|
const ret = arg0;
|
|
2069
2074
|
return ret;
|
|
2070
2075
|
};
|
|
2071
|
-
imports.wbg.__wbindgen_cast_e7f97fba0726b4ab = function(arg0, arg1) {
|
|
2072
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 366, function: Function { arguments: [Externref], shim_idx: 367, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2073
|
-
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h849099dfd9acf928, wasm_bindgen__convert__closures_____invoke__ha9d3e198cd0951b0);
|
|
2074
|
-
return ret;
|
|
2075
|
-
};
|
|
2076
2076
|
imports.wbg.__wbindgen_cast_fac85390ef55bfaa = function(arg0, arg1) {
|
|
2077
2077
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 7, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 8, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2078
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2078
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h25acc308bc5379fe, wasm_bindgen__convert__closures_____invoke__h083737b2f77d415a);
|
|
2079
2079
|
return ret;
|
|
2080
2080
|
};
|
|
2081
2081
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
package/mqtt5_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED