strata_admin/websocket
Browser WebSocket bridge for the admin SPA.
SendError
Section titled “SendError”Why the admin app could not send a text frame.
pub type SendError { SocketNotOpen}Socket
Section titled “Socket”An opaque handle for a native browser WebSocket connection.
pub type SocketWsEvent
Section titled “WsEvent”An opaque handle for a browser WebSocket event object passed to callbacks.
pub type WsEventFunctions
Section titled “Functions”Start the browser WebSocket close operation.
pub fn close(Socket) -> Nilopen_socket
Section titled “open_socket”Open a browser WebSocket and return its handle immediately.
The browser calls on_open when the connection opens. It calls
on_message for each message and calls on_close for a close or error
event.
pub fn open_socket( String, fn(WsEvent) -> Nil, fn(String) -> Nil, fn(WsEvent) -> Nil) -> Socketquery_param
Section titled “query_param”Return a query parameter from the current page URL.
Return an empty string if the parameter is absent or empty.
pub fn query_param(String) -> Stringregister_open
Section titled “register_open”Register a callback for the next open event.
The browser calls the callback at most once.
pub fn register_open( Socket, fn() -> Nil) -> NilSend one text frame. Returns Error(SocketNotOpen) when the browser
socket is not open.
pub fn send( Socket, String) -> Result(Nil, SendError)websocket_url
Section titled “websocket_url”Build the admin WebSocket URL for the current page host.
The function uses wss on an HTTPS page and ws on another page. It
adds the token as one encoded query parameter.
pub fn websocket_url(String) -> String