Livekitex.AccessToken (livekitex v0.1.0)

Provides functionality to create and manage LiveKit access tokens.

Summary

Functions

Creates a new AccessToken.

Sets attributes for the access token.

Sets metadata for the access token.

Sets the name for the access token.

Sets room configuration for the access token.

Sets room preset for the access token.

Sets the SHA256 hash for the access token.

Sets the SIP grant for the access token.

Sets the video grant for the access token.

Generates a JWT token from an AccessToken.

Generates a JWT token from an AccessToken, raising on error.

Types

t()

@type t() :: %Livekitex.AccessToken{
  api_key: String.t(),
  api_secret: String.t(),
  grants: Livekitex.Grants.ClaimGrant.t(),
  identity: String.t(),
  ttl: integer()
}

Functions

create(api_key, api_secret, options \\ [])

Creates a new AccessToken.

Parameters

  • api_key: The API key for your LiveKit project.
  • api_secret: The API secret for your LiveKit project.
  • options: A keyword list of options.
    • identity: The identity of the user.
    • name: The name of the user.
    • ttl: The time-to-live for the token in seconds. Defaults to 600 (10 minutes).
    • metadata: A string of metadata to associate with the user.
    • attributes: A map of attributes to associate with the user.

Examples

iex> Livekitex.AccessToken.create("api_key", "api_secret", identity: "user", name: "User Name")
%Livekitex.AccessToken{
  api_key: "api_key",
  api_secret: "api_secret",
  identity: "user",
  ttl: 600,
  grants: %Livekitex.Grants.ClaimGrant{name: "User Name"}
}

set_attributes(access_token, attributes)

Sets attributes for the access token.

Parameters

  • access_token: The AccessToken struct.
  • attributes: A map of attributes to associate with the user.

set_metadata(access_token, metadata)

Sets metadata for the access token.

Parameters

  • access_token: The AccessToken struct.
  • metadata: A string of metadata to associate with the user.

set_name(access_token, name)

Sets the name for the access token.

Parameters

  • access_token: The AccessToken struct.
  • name: The name of the user.

set_room_config(access_token, room_config)

Sets room configuration for the access token.

Parameters

  • access_token: The AccessToken struct.
  • room_config: A map representing room configuration.

set_room_preset(access_token, room_preset)

Sets room preset for the access token.

Parameters

  • access_token: The AccessToken struct.
  • room_preset: A string representing the room preset.

set_sha256(access_token, sha256)

Sets the SHA256 hash for the access token.

Parameters

  • access_token: The AccessToken struct.
  • sha256: The SHA256 hash string.

set_sip_grant(access_token, sip_grant)

Sets the SIP grant for the access token.

Parameters

  • access_token: The AccessToken struct.
  • sip_grant: A SipGrant struct or keyword list of SIP permissions.

Examples

iex> token = Livekitex.AccessToken.create("api_key", "api_secret", identity: "user")
iex> sip_grant = Livekitex.Grants.SipGrant.new(admin: true)
iex> token = Livekitex.AccessToken.set_sip_grant(token, sip_grant)

set_video_grant(access_token, video_grant)

Sets the video grant for the access token.

Parameters

  • access_token: The AccessToken struct.
  • video_grant: A VideoGrant struct or keyword list of video permissions.

Examples

iex> token = Livekitex.AccessToken.create("api_key", "api_secret", identity: "user")
iex> video_grant = Livekitex.Grants.VideoGrant.new(room_join: true, can_publish: true)
iex> token = Livekitex.AccessToken.set_video_grant(token, video_grant)

to_jwt(access_token)

Generates a JWT token from an AccessToken.

Examples

iex> token = Livekitex.AccessToken.create("devkey", "secret", identity: "user", name: "User Name")
iex> video_grant = Livekitex.Grants.VideoGrant.new(room_join: true)
iex> token = Livekitex.AccessToken.set_video_grant(token, video_grant)
iex> {:ok, jwt, _claims} = Livekitex.AccessToken.to_jwt(token)
iex> is_binary(jwt)
true

to_jwt!(access_token)

Generates a JWT token from an AccessToken, raising on error.

Examples

iex> token = Livekitex.AccessToken.create("devkey", "secret", identity: "user")
iex> video_grant = Livekitex.Grants.VideoGrant.new(room_join: true)
iex> token = Livekitex.AccessToken.set_video_grant(token, video_grant)
iex> jwt = Livekitex.AccessToken.to_jwt!(token)
iex> is_binary(jwt)
true