Livekitex (livekitex v0.1.0)

LiveKit Elixir SDK - A comprehensive client library for LiveKit.

LiveKit is an open-source WebRTC infrastructure for building real-time video and audio applications. This SDK provides a complete set of tools for integrating with LiveKit servers, including:

  • Room management and participant control
  • Access token generation and validation
  • Webhook processing and validation
  • Structured logging and telemetry

Quick Start

# Configure the SDK
config :livekitex,
  api_key: "your_api_key",
  api_secret: "your_api_secret",
  host: "your_livekit_host"

# Create a room service client
client = Livekitex.room_service()

# Create a room
{:ok, room} = Livekitex.RoomService.create_room(client, "my-room")

# Generate an access token
token = Livekitex.access_token("participant_identity")
|> Livekitex.AccessToken.add_grant(%Livekitex.Grants.VideoGrant{
  room_join: true,
  room: "my-room"
})
|> Livekitex.AccessToken.to_jwt()

Configuration

The SDK can be configured through multiple sources:

  1. Application configuration (config.exs)
  2. Environment variables
  3. Runtime configuration

See Livekitex.Config for detailed configuration options.

Services

Summary

Functions

Creates an access token for the given identity.

Creates an admin token with full permissions.

Gets the current configuration.

Updates configuration at runtime.

Creates a room join token for the given identity and room.

Creates a room service client with current configuration.

Starts the LiveKit SDK application.

Stops the LiveKit SDK application.

Gets the current SDK version.

Functions

access_token(identity, opts \\ [])

Creates an access token for the given identity.

Parameters

  • identity - Participant identity
  • opts - Token options (optional)

Options

  • :ttl - Token time-to-live in seconds (default: 600)
  • :name - Participant name
  • :metadata - Additional metadata
  • :attributes - Additional attributes

Examples

token = Livekitex.access_token("user123")
|> Livekitex.AccessToken.set_video_grant(%Livekitex.Grants.VideoGrant{
  room_join: true,
  room: "my-room"
})
|> Livekitex.AccessToken.to_jwt()

admin_token(opts \\ [])

Creates an admin token with full permissions.

This token can be used for administrative operations like creating rooms, managing participants, etc.

Parameters

  • opts - Token options (optional)

Options

  • :ttl - Token time-to-live in seconds (default: 3600)
  • :room - Specific room (optional, for room-specific admin)

Examples

{:ok, token} = Livekitex.admin_token()

{:ok, token} = Livekitex.admin_token(room: "my-room", ttl: 7200)

config()

Gets the current configuration.

Examples

config = Livekitex.config()
# %{host: "localhost:7880", api_key: "...", ...}

configure(key, value)

Updates configuration at runtime.

Parameters

  • key - Configuration key
  • value - Configuration value

Examples

Livekitex.configure(:host, "production.livekit.io:443")
Livekitex.configure(:use_tls, true)

room_join_token(identity, room, opts \\ [])

Creates a room join token for the given identity and room.

This is a convenience function that creates an access token with room join permissions.

Parameters

  • identity - Participant identity
  • room - Room name
  • opts - Additional options

Options

  • :ttl - Token time-to-live in seconds (default: 3600)
  • :can_publish - Can publish tracks (default: true)
  • :can_subscribe - Can subscribe to tracks (default: true)
  • :can_publish_data - Can publish data (default: true)
  • :hidden - Hidden participant (default: false)
  • :recorder - Recorder participant (default: false)
  • :metadata - Participant metadata

Examples

{:ok, token} = Livekitex.room_join_token("user123", "my-room")

{:ok, token} = Livekitex.room_join_token("user123", "my-room",
  can_publish: false,
  metadata: %{"role" => "viewer"}
)

room_service()

Creates a room service client with current configuration.

Examples

client = Livekitex.room_service()
{:ok, room} = Livekitex.RoomService.create_room(client, "my-room")

start()

Starts the LiveKit SDK application.

This sets up telemetry and other infrastructure.

Examples

Livekitex.start()

stop()

Stops the LiveKit SDK application.

Examples

Livekitex.stop()

validate_webhook(body, auth_header, api_secret \\ nil)

Validates a webhook request.

Parameters

  • body - Raw webhook body
  • auth_header - Authorization header
  • api_secret - API secret (optional, uses configured secret if not provided)

Examples

{:ok, event} = Livekitex.validate_webhook(body, auth_header)

{:ok, event} = Livekitex.validate_webhook(body, auth_header, "custom_secret")

version()

Gets the current SDK version.

Examples

iex> Livekitex.version()
"0.1.0"