Tauri commands
The #[tauri::command] functions in src/commands.rs, which the JS package calls
with invoke('plugin:centrifugo|<name>', args). You normally use the JavaScript API
instead; this list is for calling commands directly. From Rust, see Rust backend.
Arguments are sent in camelCase; the Window parameter is injected by Tauri and not listed.
| Command | Description |
|---|---|
connect | Establish a connection to Centrifugo server |
disconnect | Close the connection to Centrifugo server |
set_token | Set or update the authentication token |
provide_token | Answer a pending centrifugo:need_token request |
publish | Publish a message to a specific channel |
rpc | Execute an RPC method on the Centrifugo server |
presence | Get presence information for a channel |
presence_stats | Get presence statistics for a channel |
history | Get message history for a channel |
send | Send a message directly to the server |
refresh | Answer a pending need_token request |
sub_refresh | Answer a pending need_sub_token request for a channel |
ping | Deprecated: check that the client is connected |
is_connected | Check if currently connected to Centrifugo server |
get_subscriptions | Get current channel subscriptions |
get_connection_state | Get detailed connection state |
add_subscription | Add a new channel subscription |
add_subscription_with_options | Add a channel subscription with options |
remove_subscription | Remove a channel subscription |
remove_all_subscriptions | Remove every channel subscription |
Commands
connect
Establish a connection to Centrifugo server
Closes a previous client, creates a new one, subscribes to config.channels
and starts connecting. Returns at once; progress arrives as events, and the
SDK reconnects with backoff by itself.
Events Emitted
centrifugo:connecting- Connection attempt startedcentrifugo:connected- Connection establishedcentrifugo:subscribed- Channel subscriptions successfulcentrifugo:error- Connection or subscription errors
invoke('plugin:centrifugo|connect', { config })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
config | config | StartConfig |
Returns (). Rust: async fn. Permission: centrifugo:allow-connect.
disconnect
Close the connection to Centrifugo server
Closes the connection and drops the client with all its subscriptions.
Events Emitted
centrifugo:disconnected- Connection closed
invoke('plugin:centrifugo|disconnect')
No arguments.
Returns (). Rust: async fn. Permission: centrifugo:allow-disconnect.
set_token
Set or update the authentication token
Replaces the connection token; the SDK uses it from the next connect
attempt. Fails with NotConnected when there is no client.
invoke('plugin:centrifugo|set_token', { token })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
token | token | String |
Returns (). Rust: async fn. Permission: centrifugo:allow-set-token.
provide_token
Answer a pending centrifugo:need_token request
An empty token means "no token": anonymous on connect, unauthorized on refresh. Fails when no request is pending.
invoke('plugin:centrifugo|provide_token', { token })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
token | token | String |
Returns (). Rust: async fn. Permission: centrifugo:allow-provide-token.
publish
Publish a message to a specific channel
data is base64 unless dataEncoding is rawJson. Map publish
(type/key/removed) is rejected with Not supported.
Requirements
- Must be connected to Centrifugo server
- The server must allow client publishing in the channel
invoke('plugin:centrifugo|publish', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | PublishRequest |
Returns (). Rust: async fn. Permission: centrifugo:allow-publish.
rpc
Execute an RPC method on the Centrifugo server
This command sends an RPC request and waits for the response. The request data should be base64-encoded.
Requirements
- Must be connected to Centrifugo server
invoke('plugin:centrifugo|rpc', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | RpcRequest |
Returns String. Rust: async fn. Permission: centrifugo:allow-rpc.
presence
Get presence information for a channel
Returns the client IDs currently present in the channel.
invoke('plugin:centrifugo|presence', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | PresenceRequest |
Returns Vec<String>. Rust: async fn. Permission: centrifugo:allow-presence.
presence_stats
Get presence statistics for a channel
Returns aggregated statistics about the number of clients and users in a channel.
invoke('plugin:centrifugo|presence_stats', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | PresenceStatsRequest |
Returns (u32, u32). Rust: async fn. Permission: centrifugo:allow-presence-stats.
history
Get message history for a channel
Retrieves publications from the channel history (limit, reverse;
since is ignored). The channel must have history enabled.
invoke('plugin:centrifugo|history', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | HistoryRequest |
Returns Vec<PublicationData>. Rust: async fn. Permission: centrifugo:allow-history.
send
Send a message directly to the server
Sends an async message to the server (not to a channel, no reply).
invoke('plugin:centrifugo|send', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | SendRequest |
Returns (). Rust: async fn. Permission: centrifugo:allow-send.
refresh
Answer a pending need_token request
Answers a pending centrifugo:need_token request with the token; when none
is pending, sets the token for the next connect. The SDK refreshes tokens
itself before they expire.
invoke('plugin:centrifugo|refresh', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | RefreshRequest |
Returns (). Rust: async fn. Permission: centrifugo:allow-refresh.
sub_refresh
Answer a pending need_sub_token request for a channel
Answers a pending centrifugo:need_sub_token request for request.channel.
Fails when none is pending. Track/untrack fields are rejected with
Not supported; signature is ignored.
invoke('plugin:centrifugo|sub_refresh', { request })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
request | request | SubRefreshRequest |
Returns (). Rust: async fn. Permission: centrifugo:allow-sub-refresh.
ping
Deprecated: check that the client is connected
The SDK keeps the connection alive with server pings and has no client
ping; this only fails with NotConnected when not connected.
invoke('plugin:centrifugo|ping')
No arguments.
Returns (). Rust: async fn. Permission: centrifugo:allow-ping.
is_connected
Check if currently connected to Centrifugo server
Returns the current connection status without establishing a connection.
invoke('plugin:centrifugo|is_connected')
No arguments.
Returns bool. Rust: async fn. Permission: centrifugo:allow-is-connected.
get_subscriptions
Get current channel subscriptions
Returns the channels added through the plugin; the value is true while
subscribed.
invoke('plugin:centrifugo|get_subscriptions')
No arguments.
Returns HashMap<String, bool>. Rust: async fn. Permission: centrifugo:allow-get-subscriptions.
get_connection_state
Get detailed connection state
One of connecting, connected, closed, disconnected (also when there
is no client).
invoke('plugin:centrifugo|get_connection_state')
No arguments.
Returns String. Rust: async fn. Permission: centrifugo:allow-get-connection-state.
add_subscription
Add a new channel subscription
Subscribes to a channel with default options. Fails with NotConnected
when there is no client.
Events Emitted
centrifugo:subscribing- Subscription attempt startedcentrifugo:subscribed- Subscription successfulcentrifugo:error- Subscription errors
invoke('plugin:centrifugo|add_subscription', { channel })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
channel | channel | String |
Returns (). Rust: async fn. Permission: centrifugo:allow-add-subscription.
add_subscription_with_options
Add a channel subscription with options
Token (private channel, refreshed via centrifugo:need_sub_token),
recovery, join/leave, positioning, fossil delta, resume position.
Events Emitted
centrifugo:subscribing,centrifugo:subscribed,centrifugo:error
invoke('plugin:centrifugo|add_subscription_with_options', { options })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
options | options | SubscribeOptions |
Returns (). Rust: async fn. Permission: centrifugo:allow-add-subscription-with-options.
remove_subscription
Remove a channel subscription
Unsubscribes from a channel and forgets it. Unknown channels are ignored.
Events Emitted
centrifugo:unsubscribed- Unsubscription successful
invoke('plugin:centrifugo|remove_subscription', { channel })
| Argument (JS) | Rust parameter | Type |
|---|---|---|
channel | channel | String |
Returns (). Rust: async fn. Permission: centrifugo:allow-remove-subscription.
remove_all_subscriptions
Remove every channel subscription
invoke('plugin:centrifugo|remove_all_subscriptions')
No arguments.
Returns (). Rust: async fn. Permission: centrifugo:allow-remove-all-subscriptions.