The websocket module provides backend-proxied WebSocket connections:
connect(url) opens a connection and resolves with a connection id,
sendMessage(id, message) sends a text frame, disconnect(id) closes.
Incoming messages and connection state changes are pushed over the
ztron://websocket-message and ztron://websocket-status events, and
onMessage / onStatus return unlisten functions. Backed by the three
plugin:websocket|* commands (a port of tauri-plugin-websocket).
Permissions: websocket:allow-connect, websocket:allow-send,
websocket:allow-disconnect; the websocket:default set grants all
three commands at once. No scope — the plugin is constructed with no
arguments. From examples/hello/src/main.ts:
The matching capability entry is "websocket:default".
From examples/hello/frontend/src/main.ts (the anchor WEBSOCKET_OK is
its real run output; a round trip against a public echo server, comments
kept, excerpts elided):
The onMessage payload is { id, message } (shared event stream across
connections, disambiguated by id); the onStatus payload is
{ id, state }.
plugin:websocket|* totals 3 commands:
| Command | API |
|---|---|
connect |
connect(url) → { id } |
send |
sendMessage(id, message) |
disconnect |
disconnect(id) |
Full list in the Commands Reference and the API symbol reference.
Applicable version: ztron 0.3.1