Browser Transport
strata_transport wraps the browser WebSocket API. It does not process
Strata frames. Use strata_client for frame encoding and decoding.
Build a URL
Section titled “Build a URL”strata_transport.websocket_url( host: "example.com", port: 443, path: "/socket/websocket", token: token, secure: True,)secure: True selects wss. secure: False selects ws.
The helper percent-encodes the token once as one query value. Pass the raw token text. Do not pre-encode it in the host application.
Open a socket
Section titled “Open a socket”strata_transport.open_socket( url, on_open, on_message, on_close,)The transport calls on_message only for text frames. It ignores binary
frames. The browser can call on_close for both the error and close
events. Make reconnect scheduling idempotent so that two callbacks do not
start two connections.
Send and close
Section titled “Send and close”send_text returns Ok(Nil) when the socket state is open and the call to
WebSocket.send returns. It returns Error(SocketNotOpen) for another socket
state. A browser exception from WebSocket.send still propagates to the
application.
close starts the browser close operation. The close callback reports the
result.
Replica ids
Section titled “Replica ids”random_replica_id uses crypto.randomUUID when the browser provides it. It
uses crypto.getRandomValues as the next choice. The last fallback uses
Math.random. Do not use this value as an authentication secret.