Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kuyoonjo/tauri-plugin-mqtt
https://github.com/kuyoonjo/tauri-plugin-mqtt
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kuyoonjo/tauri-plugin-mqtt
- Owner: kuyoonjo
- Created: 2024-10-19T18:28:56.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-20T19:16:05.000Z (3 months ago)
- Last Synced: 2024-10-20T23:49:01.864Z (3 months ago)
- Language: Rust
- Size: 195 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-tauri - tauri-plugin-mqtt - MQTT client support. (Development / Plugins)
README
# tauri-plugin-mqtt
This plugin only works with Tauri 2.x only.
## Install
```bash
cargo add tauri-plugin-mqtt
```
```bash
npm i @kuyoonjo/tauri-plugin-mqtt
```## Usage
### rust
```rusttauri::Builder::default()
.plugin(tauri_plugin_tcp::init())
...
```### javascript
```javascript
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);
```
#### Functions
```typescript
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, options?: Options);
```#### Interfaces
```typescript
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[];
};
};
}
```### permissions
add `"mqtt:default"` into `"permissions"` list of `src-tauri\capabilities\default.json`
```json
{
"$schema": "../gen/schemas/desktop-schema.json",
...
"permissions": [
"core:default",
...
"mqtt:default"
]
}
```## Support
| MacOS | Linux | Windows |
| ----- | ----- | ------- |
| ✅ | ✅ | ✅ |