Skip to content
Strata is pre-1.0. APIs, protocol, and storage format may change.

strata_admin/websocket

Browser WebSocket bridge for the admin SPA.

Why the admin app could not send a text frame.

pub type SendError {
SocketNotOpen
}

An opaque handle for a native browser WebSocket connection.

pub type Socket

An opaque handle for a browser WebSocket event object passed to callbacks.

pub type WsEvent

Start the browser WebSocket close operation.

pub fn close(Socket) -> Nil

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
) -> Socket

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) -> String

Register a callback for the next open event.

The browser calls the callback at most once.

pub fn register_open(
Socket,
fn() -> Nil
) -> Nil

Send one text frame. Returns Error(SocketNotOpen) when the browser socket is not open.

pub fn send(
Socket,
String
) -> Result(Nil, SendError)

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