27#include "livekit/result.h"
28#include "livekit/visibility.h"
139 std::chrono::milliseconds
timeout = std::chrono::seconds(30);
145 std::string
base_url =
"https://cloud-api.livekit.io";
161 virtual std::future<Result<TokenSourceResponse, TokenSourceError>>
fetch() = 0;
191 static std::unique_ptr<LiteralTokenSource>
create(std::string server_url, std::string participant_token);
205 static std::unique_ptr<LiteralTokenSource>
create(
208 std::future<Result<TokenSourceResponse, TokenSourceError>>
fetch()
override;
215 std::function<std::future<Result<TokenSourceResponse, TokenSourceError>>()> provider_;
232 static std::unique_ptr<CustomTokenSource>
create(
243 std::function<std::future<Result<TokenSourceResponse, TokenSourceError>>(
const TokenRequestOptions&)> provider_;
271 using HttpTransport = std::function<Result<std::string, std::string>(
272 const std::string& method,
const std::string& url,
const std::map<std::string, std::string>& headers,
273 const std::string& json_body, std::chrono::milliseconds timeout)>;
279 std::string endpoint_url_;
281 HttpTransport transport_;
283 friend struct EndpointTokenSourceTestAccess;
299 static std::unique_ptr<SandboxTokenSource>
create(
const std::string& sandbox_id,
307 std::unique_ptr<TokenSourceConfigurable> endpoint_;
309 friend struct SandboxTokenSourceTestAccess;
326 static std::unique_ptr<CachingTokenSource>
create(std::unique_ptr<TokenSourceConfigurable> inner);
341 std::unique_ptr<TokenSourceConfigurable> inner_;
342 mutable std::mutex mutex_;
343 std::optional<TokenRequestOptions> cached_options_;
344 std::optional<TokenSourceResponse> cached_details_;
Decorator that adds JWT-aware caching to another configurable token source.
Definition token_source.h:318
std::future< Result< TokenSourceResponse, TokenSourceError > > fetch(const TokenRequestOptions &options={}) override
Fetch connection credentials.
static std::unique_ptr< CachingTokenSource > create(std::unique_ptr< TokenSourceConfigurable > inner)
Wrap inner with JWT-aware caching.
void invalidate()
Clear any cached credentials so the next fetch re-queries the inner source.
std::optional< TokenSourceResponse > cachedResponse() const
Return the currently cached credentials, if any.
Token source that delegates token generation to your callback.
Definition token_source.h:223
static std::unique_ptr< CustomTokenSource > create(std::function< std::future< Result< TokenSourceResponse, TokenSourceError > >(const TokenRequestOptions &)> provider)
Create a token source that delegates fetching to provider.
std::future< Result< TokenSourceResponse, TokenSourceError > > fetch(const TokenRequestOptions &options={}) override
Token source that calls your backend token endpoint over HTTP.
Definition token_source.h:253
std::future< Result< TokenSourceResponse, TokenSourceError > > fetch(const TokenRequestOptions &options={}) override
static std::unique_ptr< EndpointTokenSource > create(std::string endpoint_url, TokenEndpointOptions options={})
Create a token source that fetches credentials from endpoint_url.
Token source that returns credentials you already created yourself.
Definition token_source.h:182
static std::unique_ptr< LiteralTokenSource > create(std::string server_url, std::string participant_token)
Create a token source from a static server URL and participant token.
static std::unique_ptr< LiteralTokenSource > create(std::function< std::future< Result< TokenSourceResponse, TokenSourceError > >()> provider)
Create a token source from an async provider that returns full credentials.
std::future< Result< TokenSourceResponse, TokenSourceError > > fetch() override
Fetch connection credentials.
Lightweight success-or-error return type for non-exceptional API failures.
Definition result.h:40
Token source that uses LiveKit Cloud's sandbox token server (development only).
Definition token_source.h:292
std::future< Result< TokenSourceResponse, TokenSourceError > > fetch(const TokenRequestOptions &options={}) override
Fetch connection credentials.
static std::unique_ptr< SandboxTokenSource > create(const std::string &sandbox_id, const SandboxTokenServerOptions &options={})
Create a token source backed by the LiveKit Cloud sandbox token server.
Base interface for token sources that generate credentials from request options.
Definition token_source.h:165
virtual std::future< Result< TokenSourceResponse, TokenSourceError > > fetch(const TokenRequestOptions &options={})=0
Fetch connection credentials.
Base interface for token sources that provide full credentials directly.
Definition token_source.h:154
virtual std::future< Result< TokenSourceResponse, TokenSourceError > > fetch()=0
Fetch connection credentials.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
Options for SandboxTokenSource.
Definition token_source.h:143
std::string base_url
LiveKit Cloud API base URL (default https://cloud-api.livekit.io).
Definition token_source.h:145
HTTP options for EndpointTokenSource.
Definition token_source.h:128
std::map< std::string, std::string > headers
Additional request headers.
Definition token_source.h:133
std::string method
HTTP method (default POST).
Definition token_source.h:130
std::chrono::milliseconds timeout
Request timeout (default 30 seconds).
Definition token_source.h:139
Per-call options sent to configurable token sources (endpoint, sandbox, custom).
Definition token_source.h:68
std::optional< std::string > agent_metadata
Opaque metadata passed to the dispatched agent job at startup.
Definition token_source.h:118
std::optional< std::string > participant_name
Participant display name shown in UIs and room rosters.
Definition token_source.h:81
std::optional< std::string > room_name
Target room name encoded into the token request.
Definition token_source.h:75
std::optional< std::string > participant_identity
Stable participant identity encoded into the JWT.
Definition token_source.h:88
std::optional< std::string > agent_deployment
LiveKit Cloud deployment to target for agent dispatch.
Definition token_source.h:124
std::optional< std::string > agent_name
Name of a registered LiveKit agent to dispatch into the room.
Definition token_source.h:111
std::map< std::string, std::string > participant_attributes
Key/value participant attributes encoded into the token request.
Definition token_source.h:100
std::optional< std::string > participant_metadata
Opaque participant metadata string stored on the participant record.
Definition token_source.h:94
Error returned when token fetching fails.
Definition token_source.h:149
Credentials produced by a token source and consumed by Room::connect.
Definition token_source.h:43
std::optional< std::string > room_name
Name of the room the participant will join. May be unset if not specified.
Definition token_source.h:54
std::optional< std::string > participant_name
Display name for the participant in the room. May be unset if not specified.
Definition token_source.h:51
std::string server_url
WebSocket URL of the LiveKit server. Use this to establish the connection.
Definition token_source.h:45
std::string participant_token
JWT token containing participant permissions and metadata. Required for authentication.
Definition token_source.h:48