Strata is pre-1.0. APIs, protocol, and storage format may change.
Erlang and Gun Transport
strata_transport_gun opens a WebSocket through
gluegun. It targets Erlang.
Configure the connection
Section titled “Configure the connection”import gluegun/connectionimport strata_transport_gun as gun
let options = gun.options() |> gun.with_secure(True) |> gun.with_timeout(connection.Milliseconds(10_000))options() uses a five-second timeout and an insecure TCP connection.
with_secure(True) selects TLS.
Open a socket
Section titled “Open a socket”gun.open_socket( host: "example.com", port: 443, path: "/socket/websocket", token: token, options: options, on_open: on_open, on_message: on_message, on_close: on_close,)The function appends one percent-encoded token query value to path.
Pass the raw token text. The function starts a receive process after the
connection opens.
open_socket returns Result(Socket, GluegunError). Handle this result before
you store the socket. The close callback receives:
Closedafter a normal WebSocket close frame;Failed(error)after a receive error.
The receive loop ignores non-text application frames.
Send and close
Section titled “Send and close”send_text and close return Result(Nil, GluegunError). Report an error or
start reconnect handling. Do not treat a failed send as a successful edit.