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

strata_transport

Browser IO transport facade for Strata clients.

Why a browser send did not happen.

pub type SendError {
SocketNotOpen
}

A browser event for a WebSocket close or error.

pub type CloseEvent = browser.CloseEvent

A browser WebSocket handle.

The browser owns the underlying connection.

pub type Socket = browser.Socket

Start the browser WebSocket close operation.

pub fn close(browser.Socket) -> Nil

Open a browser WebSocket and return its handle immediately.

The browser calls on_open when the connection opens. It calls on_message only for text frames. It calls on_close for a close or error event.

pub fn open_socket(
String,
fn(browser.Socket) -> Nil,
fn(String) -> Nil,
fn(browser.CloseEvent) -> Nil
) -> browser.Socket

Create a local replica identifier.

Do not use this value as an authentication secret.

pub fn random_replica_id() -> String

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

pub fn send_text(
browser.Socket,
String
) -> Result(Nil, SendError)

Build a WebSocket URL with one encoded token query parameter.

Set secure to True to use wss. Set it to False to use ws.

pub fn websocket_url(
host: String,
port: Int,
path: String,
token: String,
secure: Bool
) -> String