Livekitex (livekitex v0.1.34)
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:
- Application configuration (config.exs)
- Environment variables
- Runtime configuration
See Livekitex.Config for detailed configuration options.
Services
Livekitex.RoomService- Room and participant managementLivekitex.EgressService- Egress managementLivekitex.SIPService- SIP trunks, dispatch rules, and participantsLivekitex.Webhook- Webhook validation and processingLivekitex.AccessToken- Token generation and validation
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 egress service client with current configuration.
Creates a room join token for the given identity and room.
Creates a room service client with current configuration.
Creates a SIP service client with current configuration.
Starts the LiveKit SDK application.
Stops the LiveKit SDK application.
Validates a webhook request.
Gets the current SDK version.
Functions
Creates an access token for the given identity.
Parameters
identity- Participant identityopts- 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()
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)
Gets the current configuration.
Examples
config = Livekitex.config()
# %{host: "localhost:7880", api_key: "...", ...}
Updates configuration at runtime.
Parameters
key- Configuration keyvalue- Configuration value
Examples
Livekitex.configure(:host, "production.livekit.io:443")
Livekitex.configure(:use_tls, true)
Creates a egress service client with current configuration.
Examples
client = Livekitex.egress_service()
# EgressService calls
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 identityroom- Room nameopts- 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"}
)
Creates a room service client with current configuration.
Examples
client = Livekitex.room_service()
{:ok, room} = Livekitex.RoomService.create_room(client, "my-room")
Creates a SIP service client with current configuration.
For LiveKit Cloud, ensure config.host is your cloud domain without scheme
(e.g. "test-xxxx.livekit.cloud"). HTTPS is used by default.
Examples
client = Livekitex.sip_service()
# SIPService calls
Starts the LiveKit SDK application.
This sets up telemetry and other infrastructure.
Examples
Livekitex.start()
Stops the LiveKit SDK application.
Examples
Livekitex.stop()
Validates a webhook request.
Parameters
body- Raw webhook bodyauth_header- Authorization headerapi_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")
Gets the current SDK version.
Examples
iex> is_binary(Livekitex.version()) true