Channel

external class Channel<T>(source)

A message channel used to stream values from Rust to the frontend.

A Channel is the JavaScript counterpart of tauri::ipc::Channel. Pass an instance as a command argument and the Rust command can declare a tauri::ipc::Channel<T> parameter with the same name; every value sent from Rust is then delivered to {@linkcode Channel.onmessage}. Messages are delivered in the order they were sent, even when they arrive out of order.

The channel stays alive until the Rust Channel is dropped, so it can be used for long-running work such as download progress or log streaming.

Raw byte payloads are delivered to the frontend as an ArrayBuffer rather than a JSON value, so declare the channel as Channel<ArrayBuffer> when the Rust side sends tauri::ipc::InvokeResponseBody::Raw — for example through a Channel<tauri::ipc::Response> whose values are built with tauri::ipc::Response::new(bytes).

Since

2.0.0

Constructors

Link copied to clipboard
constructor(onmessage: (response: T) -> Unit = definedExternally)

Properties

Link copied to clipboard
external var id: Double

The callback id returned from {@linkcode transformCallback}.

Link copied to clipboard
external var onmessage: (response: T) -> Unit

The handler called for every message sent by the Rust side of this channel.

Functions

Link copied to clipboard
external fun toJSON(): String