View Source ExTURN.Client (ex_turn v0.1.0)

Memory-based TURN client.

Summary

Types

Messages that can be passed to handle_message/2.

Notifications emitted by the client.

Notification message.

t()

Type describing ExTURN.Client struct.

Types

@type addr() :: {:inet.ip_address(), :inet.port_number()}
@type message() ::
  {:socket_data, :inet.ip_address(), :inet.port_number(), binary()}
  | notification_message()

Messages that can be passed to handle_message/2.

@type notification() :: {:ex_turn, client_ref :: reference(), notification_message()}

Notifications emitted by the client.

Every notification has to be passed back to the client with handle_message/2.

@opaque notification_message()

Notification message.

Handled by the client. User code must not rely on its structure.

@type on_handle_message() ::
  {:ok, t()}
  | {:send, addr(), binary(), t()}
  | {:allocation_created, addr(), t()}
  | {:permission_created, :inet.ip_address(), t()}
  | {:channel_created, addr(), t()}
  | {:data, src :: addr(), binary(), t()}
  | {:error, reason :: atom(), t()}

Return values of handle_message/2.

  • :ok - no further actions are required.
  • :send - requires data to be sent over a socket owned by the user.
  • :allocation_created - an allocation has been successfully created.
  • :permission_created - a permission has been successfully created and the client is ready to send data with send/3.
  • :channel_created - a channel has been successfully created and all subsequent calls to send/3 will use channel data message format.
  • :data - data has been received from a peer.
  • :error - an error has occured and the client cannot be used anymore.
@type t() :: %ExTURN.Client{
  addr_channel: %{required(addr()) => pos_integer()},
  channel_addr: %{required(pos_integer()) => addr()},
  key: binary(),
  nonce: binary(),
  password: binary(),
  permissions: MapSet.t(:inet.ip_address()),
  realm: binary(),
  ref: reference(),
  state: :new | :auth | :alloc | :allocated | :error,
  transactions: %{required(transaction_id :: integer()) => ExSTUN.Message.t()},
  turn_ip: :inet.ip_address(),
  turn_port: :inet.port_number(),
  uri: ExSTUN.URI.t(),
  username: binary()
}

Type describing ExTURN.Client struct.

Possible states:

  • :new - the first allocation request has not been sent yet
  • :auth - the first allocation request has been sent
  • :alloc - an actuall allocation request with auth attributes has been sent
  • :allocated - an allocation has been successfully created
  • :error - an error has occured and the client cannot be used anymore.

Functions

@spec allocate(t()) :: {:send, addr(), binary(), t()}
Link to this function

create_channel(client, ip, port)

View Source
@spec create_channel(t(), :inet.ip_address(), :inet.port_number()) ::
  {:ok, t()} | {:send, addr(), binary(), t()}
Link to this function

create_permission(client, ip)

View Source
@spec create_permission(t(), :inet.ip_address()) :: {:send, addr(), binary(), t()}
Link to this function

handle_message(client, msg)

View Source
@spec handle_message(t(), message()) :: on_handle_message()
Link to this function

has_channel?(client, ip, port)

View Source
@spec has_channel?(t(), :inet.ip_address(), :inet.port_number()) :: boolean()
Link to this function

has_permission?(client, ip)

View Source
@spec has_permission?(t(), :inet.ip_address()) :: boolean()
Link to this function

new(uri, username, password)

View Source
@spec new(ExSTUN.URI.t(), binary(), binary()) ::
  {:ok, t()} | {:error, :unsupported_turn_uri | :invalid_turn_server}
@spec send(t(), addr(), binary()) :: {:ok, t()} | {:send, addr(), binary(), t()}