Tauri plugin

Setup

Install tauri-plugin-socketio and its JS API, register the plugin, grant the permissions.

tauri-plugin-socketio is a Tauri 2 plugin for Socket.IO v4 on top of socketio-next: one registry of named clients that Rust and the webviews share.

  • Rust connects clients through the plugin, or registers clients it built itself (for example in core code that must not depend on Tauri), optionally read-only for the webview.
  • JS connects its own clients (connect) or attaches to registered ones (attach) with an API close to socket.io-client: emit, emitWithAck, on / once / off / onAny, acks for server callbacks, binary anywhere in the arguments.
  • Events and state transitions go to each webview over its own IPC channel, in order, filtered by event name if asked. Subscriptions end when the webview reloads or closes.

The socket runs in Rust: no CORS, no browser websocket limits, TLS through rustls (or the platform library), and the connection survives page reloads.

Install

src-tauri/Cargo.toml
[dependencies]
tauri-plugin-socketio = "0.1"
pnpm add tauri-plugin-socketio-api   # or npm / yarn

The crate re-exports the client as tauri_plugin_socketio::socketio_next; add socketio-next yourself only when other crates of yours use it (same version).

Register the plugin

src-tauri/src/lib.rs
tauri::Builder::default()
    .plugin(tauri_plugin_socketio::init())

init() allows the webview to connect to any URL. To restrict it, build the plugin with an allow-list (see Security):

.plugin(
    tauri_plugin_socketio::Builder::new()
        .allow_url_prefix("https://api.example.com")
        .build(),
)

Permissions

src-tauri/capabilities/default.json
{
  "identifier": "default",
  "windows": ["main"],
  "permissions": ["core:default", "socketio:default"]
}

socketio:default allows every command; socketio:allow-read only observes. See Permissions.

First socket

import { connect } from 'tauri-plugin-socketio-api'

const socket = await connect('chat', { url: 'https://chat.example.com', auth: { token } })
socket.on('message', (text, from) => console.log(from, text))
await socket.emit('message', 'hi')

Cargo features

rustls (default) and native-tls, forwarded to socketio-next. If any crate in your build enables reqwest 0.13's rustls-no-provider (tauri-plugin-updater does), keep rustls on, or connects fail with TlsProviderMissing. On Android and iOS rustls with the bundled webpki roots works without setup.

The plugin needs Rust 1.85; the resolver then picks a tauri 2.x release that supports it (see MSRV).