Expand description
Tauri 2 plugin for socketio-next: one registry of named Socket.IO clients that Rust and the webviews share. Guide: https://s00d.github.io/rust-socketio/tauri/setup.
- Rust registers clients with
SocketIo::connect(built and connected here) orSocketIo::insert(built elsewhere, e.g. by Tauri-free core code), optionallyAccess::ReadOnlyso the webview may only observe them. - JS (
tauri-plugin-socketio-api) connects its own clients or attaches to registered ones; events and state transitions reach it over a per-subscription IPC channel, in order.
use socketio_next::ClientBuilder;
use tauri_plugin_socketio::{Access, SocketIoExt};
// `tauri::Builder::default()` in an app
fn app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Builder<R> {
builder
.plugin(tauri_plugin_socketio::init())
.setup(|app| {
// before any await: no page script can take the id first
app.socketio().reserve("core");
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
// e.g. built by a crate that knows nothing about Tauri
let client = ClientBuilder::new("http://localhost:3000").connect().await?;
handle.socketio().insert("core", client, Access::ReadOnly)?;
Ok::<_, tauri_plugin_socketio::Error>(())
});
Ok(())
})
}Re-exports§
pub use socketio_next;
Structs§
- Args
- Event arguments over the IPC: JSON
args, and the binary attachments that the{"_placeholder":true,"num":n}objects inargsstand for (socket.io-parser’s encoding). Bytes travel as arrays of numbers; guest-js turns them intoUint8Arrays and back. - Builder
- Configures the plugin (id
socketio). - Client
Info - One registered client, as
list()reports it. - Error
Payload - An error as JS sees it:
kindis the variant name (ConnectRejected,NotConnected,AckTimeout,ConnectTimeout,AccessDenied,UnknownClient, …, engine.io failures by their own name such asHttpStatusorTlsProviderMissing),messagethe text (never a URL or query value),dataextra fields (ConnectRejected: the server’serr.data;HttpStatus:{ status, message };WebsocketClosed:{ code, reason }). - Link
LinkInfofor JS: durations in ms, instants as Unix epoch ms.- Socket
Io - Named socket.io clients shared by Rust and the webviews. Get it with
SocketIoExt::socketio; cheap to clone.
Enums§
- Access
- Who may drive a registered client from the webview.
- Error
- Errors of the plugin. Over the IPC they become
{ kind, message, data? }(seeErrorPayload); guest-js throws them asSocketIoError. - Message
- What a subscription’s channel carries.
- State
ConnectionStatefor JS:{ status, ... }with socket.io-client’s reason strings and delays in milliseconds.
Constants§
- ACK_TTL
- Server acks wait this long for the webview’s answer, then are forgotten.
- MAX_
CLIENTS_ PER_ WEBVIEW - Clients one webview may have connected (and not disconnected) at once; they are disconnected when its window is destroyed.
- MAX_
PENDING_ ACKS_ PER_ WEBVIEW - At most this many server acks of one client wait for one webview; past it the webview’s own oldest is forgotten (never another webview’s).
- MAX_
SUBSCRIPTIONS_ PER_ WEBVIEW - At most this many subscriptions per webview (over all clients).
Traits§
- Socket
IoExt app.socketio()on anything that is aManager(App,AppHandle,Window,Webview, …). Panics when the plugin is not registered (init).
Functions§
- init
- The plugin with the default configuration:
Builder::new().build().
Type Aliases§
- Result
- Result alias of the plugin.
- Subscription
Id - Identifies one subscription (unique for the life of the app).