LiveKit.Grants (LiveKit v0.1.0)

Copy Markdown View Source

Encoding of LiveKit JWT grants.

Grants are explicit structs rather than free-form maps:

All encoding lives here so that claim names stay in one place.

iex> LiveKit.Grants.to_claims(%LiveKit.Grants.Video{room_list: true})
%{"roomList" => true}

Encoding rules

  • nil fields are omitted, so a token only carries what was set.
  • Explicit false is preserved, since LiveKit distinguishes "denied" from "unset" for permissions such as canPublish.
  • Struct metadata (:__struct__) never reaches the claims.
  • Empty maps and lists (for example attributes: %{}) are omitted.

Summary

Functions

Converts a grant struct into a map of LiveKit JWT claims with string keys.

Validates that a term is a supported grant struct.

Types

Functions

to_claims(grant)

@spec to_claims(grant()) :: map()

Converts a grant struct into a map of LiveKit JWT claims with string keys.

Examples

iex> LiveKit.Grants.to_claims(%LiveKit.Grants.Video{room_join: true, room: "lobby", hidden: false})
%{"roomJoin" => true, "room" => "lobby", "hidden" => false}

iex> LiveKit.Grants.to_claims(%LiveKit.Grants.Claims{})
%{}

validate(kind, grant)

@spec validate(:video | :sip | :agent, term()) ::
  {:ok, grant()} | {:error, LiveKit.Error.t()}

Validates that a term is a supported grant struct.

Examples

iex> LiveKit.Grants.validate(:video, %LiveKit.Grants.Video{room_list: true})
{:ok, %LiveKit.Grants.Video{room_list: true}}

iex> {:error, error} = LiveKit.Grants.validate(:video, %{room_list: true})
iex> error.type
:validation