pub struct SocketIo { /* private fields */ }Expand description
Named socket.io clients shared by Rust and the webviews. Get it with
SocketIoExt::socketio; cheap to clone.
Ids are unique: connect and insert fail with
Error::AlreadyExists for an id in use, so a client is never replaced behind the back of
whoever holds it. remove it first. reserve an id in
setup when Rust registers it later: webviews then cannot take it.
Implementations§
Source§impl SocketIo
impl SocketIo
Sourcepub fn reserve(&self, id: impl Into<String>)
pub fn reserve(&self, id: impl Into<String>)
Keeps id for Rust: a webview’s connect with it fails with Error::Reserved, while
connect and insert from Rust work. Call it in
setup (it is synchronous) for every id Rust registers later, so no page script can
take the id first. Reservations last for the life of the app.
Sourcepub async fn connect(
&self,
id: impl Into<String>,
builder: ClientBuilder,
) -> Result<Client>
pub async fn connect( &self, id: impl Into<String>, builder: ClientBuilder, ) -> Result<Client>
Builds builder, connects and registers the client under id with Access::Full.
Fails with the connect error, or Error::AlreadyExists (then the new client is
dropped, which closes it).
Sourcepub fn insert(
&self,
id: impl Into<String>,
client: Client,
access: Access,
) -> Result<()>
pub fn insert( &self, id: impl Into<String>, client: Client, access: Access, ) -> Result<()>
Registers a client built elsewhere, e.g. by Rust code that must stay free of Tauri.
With Access::ReadOnly the webview can observe it but never emit, ack or disconnect
it, whatever its capabilities allow. The registry keeps a clone; the client lives until
it is removed and every other clone is dropped.
Sourcepub fn remove(&self, id: &str) -> Option<Client>
pub fn remove(&self, id: &str) -> Option<Client>
Unregisters id: its subscriptions end (their channels are dropped) and its pending
server acks are forgotten. Does not disconnect: the client is handed back (call
Client::disconnect on it, or drop it; dropping the last clone closes it).
Sourcepub fn subscribe(
&self,
id: &str,
events: Option<Vec<String>>,
channel: Channel<Message>,
) -> Result<SubscriptionId>
pub fn subscribe( &self, id: &str, events: Option<Vec<String>>, channel: Channel<Message>, ) -> Result<SubscriptionId>
Forwards the client’s state transitions and events (all, or only events) to
channel as Messages, starting with a snapshot of the current state. Ends with
unsubscribe, remove or when a send fails.
Server acks are not offered to subscriptions made from Rust (answer them in a handler).
Sourcepub fn unsubscribe(&self, id: &str, subscription: SubscriptionId) -> bool
pub fn unsubscribe(&self, id: &str, subscription: SubscriptionId) -> bool
Stops a subscription; false when it was gone already.