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

strata_transport_gun

Erlang/Gun WebSocket transport for Strata.

The reason that the receive process stopped.

pub type CloseEvent {
Closed
Failed(error.GluegunError)
}

The peer sent a WebSocket close frame.

Gluegun returned an error while it received a frame.

Connection settings for open_socket.

pub type Options {
Options(timeout: connection.Timeout, secure: Bool)
}

A handle to a Gluegun WebSocket.

open_socket starts a process that receives frames from this socket.

pub type Socket

Close the WebSocket.

Return a Gluegun error if the close operation fails.

pub fn close(Socket) -> Result(Nil, error.GluegunError)

Build the WebSocket connection path with an encoded token query parameter.

pub fn connection_path(
String,
String
) -> String

Open a WebSocket and start a receive process.

The function connects before it returns. It calls on_open after the connection succeeds. It then starts a process that calls on_message for each text frame. The process ignores other data frames. It calls on_close when the peer closes the socket or when a receive operation fails.

The function returns a Gluegun error if the connection fails. It does not call a callback when the connection fails.

pub fn open_socket(
host: String,
port: Int,
path: String,
token: String,
options: Options,
on_open: fn(Socket) -> Nil,
on_message: fn(String) -> Nil,
on_close: fn(CloseEvent) -> Nil
) -> Result(Socket, error.GluegunError)

Return the default connection settings.

The defaults use a five-second timeout and an insecure TCP connection.

pub fn options() -> Options

Send one text frame.

Return a Gluegun error if the send fails.

pub fn send_text(
Socket,
String
) -> Result(Nil, error.GluegunError)

Select the connection transport.

Set secure to True to use TLS. Set it to False to use TCP.

pub fn with_secure(
Options,
Bool
) -> Options

Set the connection timeout.

pub fn with_timeout(
Options,
connection.Timeout
) -> Options