LiveKit.Config (LiveKit v0.1.0)

Copy Markdown View Source

Validated connection settings for a LiveKit deployment.

A config holds the server URL and the API credentials used to sign tokens. It performs no I/O and reads no environment variables: the application using the SDK is responsible for sourcing credentials and passing them in.

iex> {:ok, config} = LiveKit.Config.new(
...>   url: "https://example.livekit.cloud/",
...>   api_key: "api-key",
...>   api_secret: "api-secret"
...> )
iex> config.url
"https://example.livekit.cloud"

ws:// and wss:// URLs are accepted and normalized to their HTTP equivalents, since LiveKit deployments are commonly configured with the signalling URL.

Summary

Functions

The default receive timeout, in milliseconds.

The default connect timeout, in milliseconds.

Builds a validated config.

Same as new/1 but raises LiveKit.Error on invalid options.

Types

t()

@type t() :: %LiveKit.Config{
  api_key: String.t(),
  api_secret: String.t(),
  receive_timeout: pos_integer(),
  timeout: pos_integer(),
  url: String.t()
}

Functions

default_receive_timeout()

@spec default_receive_timeout() :: pos_integer()

The default receive timeout, in milliseconds.

Examples

iex> LiveKit.Config.default_receive_timeout()
30_000

default_timeout()

@spec default_timeout() :: pos_integer()

The default connect timeout, in milliseconds.

Examples

iex> LiveKit.Config.default_timeout()
15_000

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, LiveKit.Error.t()}

Builds a validated config.

Options

  • :url (required) - base URL of the LiveKit deployment. http, https, ws and wss schemes are accepted; ws/wss are rewritten to http/https. Trailing slashes are removed.
  • :api_key (required) - LiveKit API key.
  • :api_secret (required) - LiveKit API secret.
  • :timeout - connect timeout in milliseconds. Defaults to 15_000.
  • :receive_timeout - response timeout in milliseconds. Defaults to 30_000.

Examples

iex> {:ok, config} = LiveKit.Config.new(
...>   url: "http://localhost:7880",
...>   api_key: "devkey",
...>   api_secret: "secret"
...> )
iex> {config.url, config.timeout}
{"http://localhost:7880", 15_000}

iex> {:error, error} = LiveKit.Config.new(url: "ftp://example.com", api_key: "k", api_secret: "s")
iex> error.type
:configuration

new!(opts)

@spec new!(keyword()) :: t()

Same as new/1 but raises LiveKit.Error on invalid options.

Examples

iex> config = LiveKit.Config.new!(url: "https://example.livekit.cloud", api_key: "k", api_secret: "s")
iex> config.api_key
"k"