LiveKit.RoomService (LiveKit v0.1.0)

Copy Markdown View Source

LiveKit RoomService API — create and administer rooms and participants.

Every function is a thin wrapper around LiveKit.Twirp.call/6. It builds the protobuf request from keyword options, signs a short-lived service token that carries only the grants that method needs, and returns {:ok, response} | {:error, %LiveKit.Error{}}.

iex> client = LiveKit.Client.new!(url: "http://localhost:7880", api_key: "k", api_secret: "s")
iex> {:error, error} = LiveKit.RoomService.delete_room(client, [])
iex> error.type
:validation

Required options are validated before any HTTP request is made. Nested protobuf fields such as :egress, :agents, :permission and :attributes accept the corresponding LiveKit.Proto.* values directly.

Summary

Functions

Creates a room with the given settings.

Deletes a room by name. Requires :room.

Forwards a participant's tracks to another room (cloud-only).

Fetches a participant by identity. Requires :room and :identity.

Lists participants in a room. Requires :room.

Lists active rooms. Pass :names to filter by room name.

Moves a participant to another room (cloud-only).

Mutes or unmutes a published track. Requires :room, :identity, :track_sid, and :muted.

Performs a server-side RPC against a participant in a room.

Removes a participant from a room. Requires :room and :identity.

Sends data over the data channel to participants in a room.

Updates participant metadata, permissions, name, or attributes.

Updates room metadata. Requires :room and :metadata.

Subscribes or unsubscribes a participant from tracks.

Functions

create_room(client, opts \\ [])

@spec create_room(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.Room.t()} | {:error, LiveKit.Error.t()}

Creates a room with the given settings.

Requires :name. Optional fields: :room_preset, :empty_timeout, :departure_timeout, :max_participants, :node_id, :metadata, :tags, :egress, :min_playout_delay, :max_playout_delay, :sync_streams, :replay_enabled, :agents.

delete_room(client, opts \\ [])

@spec delete_room(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.DeleteRoomResponse.t()} | {:error, LiveKit.Error.t()}

Deletes a room by name. Requires :room.

forward_participant(client, opts \\ [])

@spec forward_participant(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.ForwardParticipantResponse.t()}
  | {:error, LiveKit.Error.t()}

Forwards a participant's tracks to another room (cloud-only).

Requires :room, :identity, and :destination_room.

get_participant(client, opts \\ [])

@spec get_participant(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.ParticipantInfo.t()} | {:error, LiveKit.Error.t()}

Fetches a participant by identity. Requires :room and :identity.

list_participants(client, opts \\ [])

@spec list_participants(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.ListParticipantsResponse.t()}
  | {:error, LiveKit.Error.t()}

Lists participants in a room. Requires :room.

list_rooms(client, opts \\ [])

@spec list_rooms(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.ListRoomsResponse.t()} | {:error, LiveKit.Error.t()}

Lists active rooms. Pass :names to filter by room name.

move_participant(client, opts \\ [])

@spec move_participant(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.MoveParticipantResponse.t()} | {:error, LiveKit.Error.t()}

Moves a participant to another room (cloud-only).

Requires :room, :identity, and :destination_room.

mute_published_track(client, opts \\ [])

@spec mute_published_track(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.MuteRoomTrackResponse.t()} | {:error, LiveKit.Error.t()}

Mutes or unmutes a published track. Requires :room, :identity, :track_sid, and :muted.

perform_rpc(client, opts \\ [])

@spec perform_rpc(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.PerformRpcResponse.t()} | {:error, LiveKit.Error.t()}

Performs a server-side RPC against a participant in a room.

Requires :room, :destination_identity, :method, and :payload. Optional: :response_timeout_ms.

remove_participant(client, opts \\ [])

@spec remove_participant(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.RemoveParticipantResponse.t()}
  | {:error, LiveKit.Error.t()}

Removes a participant from a room. Requires :room and :identity.

Optional: :revoke_token_ts.

send_data(client, opts \\ [])

@spec send_data(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.SendDataResponse.t()} | {:error, LiveKit.Error.t()}

Sends data over the data channel to participants in a room.

Requires :room, :data, and :kind. Optional: :destination_sids, :destination_identities, :topic, :nonce.

When :nonce is omitted, a 16-byte random nonce is generated so receivers can de-dupe messages.

update_participant(client, opts \\ [])

@spec update_participant(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.ParticipantInfo.t()} | {:error, LiveKit.Error.t()}

Updates participant metadata, permissions, name, or attributes.

Requires :room and :identity. Optional: :metadata, :permission, :name, :attributes.

update_room_metadata(client, opts \\ [])

@spec update_room_metadata(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, LiveKit.Proto.Room.t()} | {:error, LiveKit.Error.t()}

Updates room metadata. Requires :room and :metadata.

update_subscriptions(client, opts \\ [])

@spec update_subscriptions(
  LiveKit.Client.t(),
  keyword()
) ::
  {:ok, LiveKit.Proto.UpdateSubscriptionsResponse.t()}
  | {:error, LiveKit.Error.t()}

Subscribes or unsubscribes a participant from tracks.

Requires :room, :identity, and :subscribe. Optional: :track_sids, :participant_tracks.