tauri-plugin-centrifugo 0.2.2

Tauri plugin for Centrifugo real-time communication built on the official centrifuge-client SDK
Documentation

npm version Crates.io Documentation docs.rs GitHub issues GitHub stars Donate

Tauri Plugin Centrifugo

Real-time messaging with a Centrifugo server for Tauri 2 apps on desktop, Android and iOS, built on the official Rust SDK centrifuge-client.

Documentation: https://s00d.github.io/tauri-plugin-centrifugo/

  • Real networks: reconnects with backoff, ping/pong liveness, wake-from-sleep detection, OS proxy settings and trust store (from the SDK).
  • Transports: WebSocket with JSON or Protobuf, optional HTTP-streaming fallback, custom headers.
  • Recovery: recoverable/positioned subscriptions, resume from a saved stream position, fossil delta compression.
  • Tokens: connection and subscription JWTs, refreshed before expiry by asking your frontend.
  • Operations: publish, RPC, send, history, presence, presence stats; base64 or raw JSON payloads.
Platform Supported
Windows · macOS · Linux ✅
Android ✅ (TLS with Mozilla roots via webpki-roots; user-installed CAs are not trusted)
iOS ✅

Server: Centrifugo v4+ (client protocol v2); HTTP streaming needs v5+ with http_stream enabled. Tested against Centrifugo v5.4.9.

Install

pnpm tauri add centrifugo     # or: npm run tauri add centrifugo / cargo tauri add centrifugo

or by hand:

cargo add tauri-plugin-centrifugo --manifest-path src-tauri/Cargo.toml
pnpm add tauri-plugin-centrifugo-api

Register the plugin and allow it in a capability:

// src-tauri/src/lib.rs
tauri::Builder::default()
    .plugin(tauri_plugin_centrifugo::init())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
// src-tauri/capabilities/default.json
{ "identifier": "default", "windows": ["main"], "permissions": ["core:default", "centrifugo:default"] }

Quick start

import { connect, onConnected, onPublication, helpers, utils } from "tauri-plugin-centrifugo-api";

await onConnected(({ payload }) => console.log("connected, client", payload.client));
await onPublication(({ payload }) => console.log(payload.channel, payload.rawJson ?? utils.decode(payload.data)));

await connect({
  url: "ws://localhost:8000/connection/websocket",
  token: "<connection JWT>",   // optional; or requestToken: true + onNeedToken/provideToken
  channels: ["news"],
  useProtobuf: false,
});

if (await helpers.waitForConnection()) {
  await helpers.publishJson("news", { text: "hello" });
}

Documentation

Getting started Install, permissions, quick start, example app
Connection & config Every connect() option, transports, state, errors
Events Every centrifugo:* event and its payload
Subscriptions Recovery, since, delta, join/leave
Tokens token vs requestToken, need_token / provideToken, need_sub_token / subRefresh
Rust backend The plugin's client and the SDK from Rust · docs.rs
Platforms Desktop, Android TLS, iOS, Centrifugo versions
API reference Generated from the sources: functions, types, Tauri commands, permissions
Deprecations ping, map publish, track/untrack
Changelog

Example app

examples/tauri-app is a Vue app for desktop and mobile; examples/server has a Centrifugo config for it:

centrifugo --config examples/server/centrifugo.json
cd examples/tauri-app && pnpm install && pnpm tauri dev

Development

cargo build && cargo test   # scenario tests over IPC, offline and against a real Centrifugo ($CENTRIFUGO_BIN or PATH; skipped if missing)
cargo mutants               # mutation testing (cargo install cargo-mutants; needs centrifugo too)
pnpm typecheck && pnpm test && pnpm build   # build also runs publint, attw and a dist smoke test
cd docs && pnpm install && pnpm dev         # documentation site

CI runs all of it on Linux, macOS and Windows against Centrifugo v5.4.9, and builds for Android; cargo-mutants runs only locally.

License

MIT, see LICENSE. If the plugin helps you, you can support it via DonationAlerts.