Skip to content

Room Client API

Package room provides a client for LiveKit room management.

Client

type Client struct {
    // Internal fields
}

func NewClient(cfg Config) (*Client, error)

Config

type Config struct {
    // APIKey is the LiveKit API key.
    APIKey string

    // APISecret is the LiveKit API secret.
    APISecret string

    // URL is the LiveKit server URL (e.g., "wss://your-project.livekit.cloud").
    URL string
}

Room Management

// CreateRoom creates a new room.
func (c *Client) CreateRoom(ctx context.Context, name string) (*livekit.Room, error)

// DeleteRoom deletes a room.
func (c *Client) DeleteRoom(ctx context.Context, name string) error

// ListRooms lists all rooms.
func (c *Client) ListRooms(ctx context.Context) ([]*livekit.Room, error)

// GetRoom gets room info.
func (c *Client) GetRoom(ctx context.Context, name string) (*livekit.Room, error)

Token Generation

// GenerateClientToken generates a token for a participant to join.
func (c *Client) GenerateClientToken(roomName, identity, displayName string) (string, error)

// GenerateAgentToken generates a token for an agent with additional permissions.
func (c *Client) GenerateAgentToken(roomName, identity, displayName string) (string, error)

Participant Management

// ListParticipants lists participants in a room.
func (c *Client) ListParticipants(ctx context.Context, roomName string) ([]*livekit.ParticipantInfo, error)

// GetParticipant gets a specific participant.
func (c *Client) GetParticipant(ctx context.Context, roomName, identity string) (*livekit.ParticipantInfo, error)

// RemoveParticipant removes a participant from a room.
func (c *Client) RemoveParticipant(ctx context.Context, roomName, identity string) error

Example

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/plexusone/omni-livekit/room"
)

func main() {
    client, err := room.NewClient(room.Config{
        APIKey:    os.Getenv("LIVEKIT_API_KEY"),
        APISecret: os.Getenv("LIVEKIT_API_SECRET"),
        URL:       os.Getenv("LIVEKIT_URL"),
    })
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // Create a room
    r, err := client.CreateRoom(ctx, "my-meeting")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Created room: %s\n", r.Name)

    // Generate token for human participant
    humanToken, err := client.GenerateClientToken("my-meeting", "user-123", "Alice")
    if err != nil {
        log.Fatal(err)
    }

    // Build join URL
    joinURL := fmt.Sprintf("https://meet.livekit.io/custom?liveKitUrl=%s&token=%s",
        os.Getenv("LIVEKIT_URL"), humanToken)
    fmt.Printf("Join URL: %s\n", joinURL)

    // Generate token for agent
    agentToken, err := client.GenerateAgentToken("my-meeting", "ai-agent", "AI Assistant")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Agent token: %s...\n", agentToken[:50])

    // List participants
    participants, _ := client.ListParticipants(ctx, "my-meeting")
    for _, p := range participants {
        fmt.Printf("Participant: %s (%s)\n", p.Name, p.Identity)
    }

    // Clean up
    client.DeleteRoom(ctx, "my-meeting")
}

Token Permissions

Tokens generated by the client include appropriate permissions:

Client Token (Human)

  • Can subscribe to tracks
  • Can publish audio/video
  • Cannot manage room

Agent Token

  • Can subscribe to tracks
  • Can publish audio/video
  • Can get participant info
  • Extended TTL

See Also