strata_transport/browser
Browser WebSocket bridge.
CloseEvent
Section titled “CloseEvent”A native browser event for a WebSocket close or error.
pub type CloseEventSendError
Section titled “SendError”Why a browser send did not happen.
pub type SendError { SocketNotOpen}Socket
Section titled “Socket”A handle to a native browser WebSocket.
The browser owns the underlying connection.
pub type SocketFunctions
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 only for text frames. It calls on_close for a close or error
event.
pub fn open_socket( String, fn(Socket) -> Nil, fn(String) -> Nil, fn(CloseEvent) -> Nil) -> Socketrandom_replica_id
Section titled “random_replica_id”Create a local replica identifier.
The function prefers browser cryptographic random APIs. It uses
Math.random only when those APIs are not available. Do not use the value
as an authentication secret.
pub fn random_replica_id() -> Stringsend_text
Section titled “send_text”Send one text frame. Returns Error(SocketNotOpen) when the browser
socket is not open.
pub fn send_text( Socket, String) -> Result(Nil, SendError)websocket_url
Section titled “websocket_url”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