Crates.io | tauri-plugin-mqtt |
lib.rs | tauri-plugin-mqtt |
version | 0.1.0 |
source | src |
created_at | 2024-10-19 18:33:00.225334 |
updated_at | 2024-10-19 18:33:00.225334 |
description | MQTT Client for Tauri App |
homepage | |
repository | https://github.com/kuyoonjo/tauri-plugin-mqtt |
max_upload_size | |
id | 1415635 |
size | 48,638 |
This plugin only works with Tauri 2.x only.
cargo add tauri-plugin-mqtt
npm i @kuyoonjo/tauri-plugin-mqtt
tauri::Builder::default()
.plugin(tauri_plugin_tcp::init())
...
import { connect, disconnect, publish, subscribe, unsubscribe } from "@kuyoonjo/tauri-plugin-mqtt";
// Server side
const id = 'unique-id';
await connect(id, 'mqtt://test.mosquitto.org');
await disconnect(id);
let topic = '/tauri-plugin-mqtt';
await subscribe(id, topic, 0);
await publish(id, topic, 0, false, 'hello');
await listen((x) => {
console.log(x.payload);
});
await unsubscribe(id, topic);
await disconnect(id);
export async function publish(
id: string,
topic: String,
qos: number,
retain: boolean,
payload: string | number[],
);
export async function subscribe(
id: string,
topic: String,
qos: number,
);
export async function unsubscribe(
id: string,
topic: String,
);
export async function connect(id: string, uri: string, tlsOptions?: TlsOptions);
export async function disconnect(id: string);
export function listen(handler: EventCallback<Payload>, options?: Options);
export interface TlsOptions {
skipVerification?: boolean;
ca?: number[];
alpn?: number[][];
client_cert?: number[];
client_key?: number[];
}
export interface Payload {
id: string;
event: {
connect?: [];
disconnect?: [];
message?: {
dup: boolean;
qos: 0 | 1 | 2;
retain: boolean;
topic: string;
pkid: number;
payload: number[];
};
};
}
add "mqtt:default"
into "permissions"
list of src-tauri\capabilities\default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
...
"permissions": [
"core:default",
...
"mqtt:default"
]
}
MacOS | Linux | Windows |
---|---|---|
✅ | ✅ | ✅ |