Encoding of LiveKit JWT grants.
Grants are explicit structs rather than free-form maps:
LiveKit.Grants.Video- room and media permissions (videoclaim)LiveKit.Grants.SIP- SIP permissions (sipclaim)LiveKit.Grants.Agent- cloud agent permissions (agentclaim)LiveKit.Grants.Claims- the container holding identity, name, metadata, attributes and the grants above
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
nilfields are omitted, so a token only carries what was set.- Explicit
falseis preserved, since LiveKit distinguishes "denied" from "unset" for permissions such ascanPublish. - 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
@type grant() :: LiveKit.Grants.Claims.t() | LiveKit.Grants.Video.t() | LiveKit.Grants.SIP.t() | LiveKit.Grants.Agent.t()
Functions
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{})
%{}
@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