Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Editor/TokenSourceComponentConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty("_token"));
break;

case TokenSourceType.Sandbox:
case TokenSourceType.Development:
EditorGUILayout.HelpBox(
"Use this for development to create tokens from a sandbox token server. " +
"\nWARNING: ONLY USE THIS OPTION FOR LOCAL DEVELOPMENT, SINCE THE SANDBOX TOKEN SERVER NEEDS NO AUTHENTICATION.",
"Use this for development to create tokens from a development token server. " +
"\nWARNING: ONLY USE THIS OPTION FOR LOCAL DEVELOPMENT, SINCE THE DEVELOPMENT TOKEN SERVER NEEDS NO AUTHENTICATION.",
MessageType.Info);
EditorGUILayout.PropertyField(serializedObject.FindProperty("_sandboxId"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("_tokenServerId"));
DrawConnectionOptions();
break;

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ To help getting started with tokens, use `TokenSourceComponent.cs` with a `Token
#### 1. Literal
Use this to pass a pregenerated server URL and token. Generate tokens via the [LiveKit CLI](https://docs.livekit.io/frontends/build/authentication/custom/#manual-token-creation) or from your [LiveKit Cloud](https://cloud.livekit.io/) project's API key page.

#### 2. Sandbox
For development and testing. Follow the [sandbox token server guide](https://docs.livekit.io/frontends/build/authentication/sandbox-token-server/) to enable your project's sandbox and get the sandbox ID. Optional connection fields (room name, participant name, agent name, etc.) can be configured in the inspector — leave blank for server defaults.
#### 2. Development
For development and testing. Follow the [development token server guide](https://docs.livekit.io/frontends/build/authentication/sandbox-token-server/) to enable your project's development token server and get the token server ID. Optional connection fields (room name, participant name, agent name, etc.) can be configured in the inspector — leave blank for server defaults.

#### 3. Endpoint
For production. Point to your own token endpoint URL and add any required authentication headers. Uses the same connection options as Sandbox. See the [endpoint token generation guide](https://docs.livekit.io/frontends/build/authentication/endpoint/).
For production. Point to your own token endpoint URL and add any required authentication headers. Uses the same connection options as Development. See the [endpoint token generation guide](https://docs.livekit.io/frontends/build/authentication/endpoint/).

#### Usage

Expand Down Expand Up @@ -186,7 +186,7 @@ yield return fetch;
var details = fetch.Result;

// Configurable sources accept TokenSourceFetchOptions per call:
ITokenSourceConfigurable configurable = new TokenSourceSandbox("<sandbox-id>");
ITokenSourceConfigurable configurable = new TokenSourceDevelopment("<token-server-id>");
// or: new TokenSourceEndpoint("https://your.token-server/api/token", headers);

var configurableFetch = configurable.FetchConnectionDetails(new TokenSourceFetchOptions { RoomName = "lobby" });
Expand Down
13 changes: 10 additions & 3 deletions Runtime/Scripts/TokenSource/TokenSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,20 @@ private static string NullIfEmpty(string value) =>
string.IsNullOrEmpty(value) ? null : value;
}


[Obsolete("Use TokenSourceDevelopment instead")]
public class TokenSourceSandbox : TokenSourceDevelopment
{
public TokenSourceSandbox(string sandboxId) : base(sandboxId) {}
}

/// <summary>
/// Convenience <see cref="TokenSourceEndpoint"/> preconfigured for LiveKit Cloud sandbox token servers.
/// Convenience <see cref="TokenSourceEndpoint"/> preconfigured for LiveKit Cloud development token servers.
/// Intended for development and testing only — see
/// https://docs.livekit.io/frontends/build/authentication/sandbox-token-server/.
/// </summary>
public class TokenSourceSandbox : TokenSourceEndpoint
public class TokenSourceDevelopment : TokenSourceEndpoint
{
public TokenSourceSandbox(string sandboxId) : base("https://cloud-api.livekit.io/api/v2/sandbox/connection-details", new[] { new StringPair { key = "X-Sandbox-ID", value = sandboxId } }) {}
public TokenSourceDevelopment(string tokenServerId) : base("https://cloud-api.livekit.io/api/v2/sandbox/connection-details", new[] { new StringPair { key = "X-Sandbox-ID", value = tokenServerId } }) {}
}
}
6 changes: 3 additions & 3 deletions Runtime/Scripts/TokenSource/TokenSourceComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LiveKit
/// <summary>
/// MonoBehaviour wrapper that builds an <see cref="ITokenSource"/> from an inspector-assigned
/// <see cref="TokenSourceComponentConfig"/> ScriptableObject. To skip the asset entirely, instantiate
/// <see cref="TokenSourceLiteral"/>, <see cref="TokenSourceSandbox"/>, <see cref="TokenSourceEndpoint"/>,
/// <see cref="TokenSourceLiteral"/>, <see cref="TokenSourceDevelopment"/>, <see cref="TokenSourceEndpoint"/>,
/// or <see cref="TokenSourceCustom"/> directly at runtime.
/// </summary>
public class TokenSourceComponent : MonoBehaviour
Expand All @@ -34,8 +34,8 @@ public void Awake()

switch (_config.TokenSourceType)
{
case TokenSourceType.Sandbox:
_tokenSource = new TokenSourceSandbox(_config.SandboxId);
case TokenSourceType.Development:
_tokenSource = new TokenSourceDevelopment(_config.TokenServerId);
break;

case TokenSourceType.Endpoint:
Expand Down
16 changes: 9 additions & 7 deletions Runtime/Scripts/TokenSource/TokenSourceComponentConfig.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;

namespace LiveKit
{
public enum TokenSourceType
{
Literal,
Sandbox,
Development,
Endpoint
}

Expand All @@ -27,14 +28,15 @@ public class TokenSourceComponentConfig : ScriptableObject
[SerializeField] private string _serverUrl;
[SerializeField] private string _token;

// Sandbox fields
[SerializeField] private string _sandboxId;
// Development fields
[FormerlySerializedAs("_sandboxId")]
[SerializeField] private string _tokenServerId;

// Endpoint fields
[SerializeField] private string _endpointUrl;
[SerializeField] private List<StringPair> _endpointHeaders;

// Shared connection options (Sandbox + Endpoint)
// Shared connection options (Development + Endpoint)
[SerializeField] private string _roomName;
[SerializeField] private string _participantName;
[SerializeField] private string _participantIdentity;
Expand All @@ -50,8 +52,8 @@ public class TokenSourceComponentConfig : ScriptableObject
public string ServerUrl => _serverUrl;
public string Token => _token;

// Sandbox
public string SandboxId => _sandboxId?.Trim('"');
// Development
public string TokenServerId => _tokenServerId?.Trim('"');

// Endpoint
public string EndpointUrl => _endpointUrl;
Expand All @@ -70,7 +72,7 @@ public class TokenSourceComponentConfig : ScriptableObject
public bool IsValid => _tokenSourceType switch
{
TokenSourceType.Literal => !string.IsNullOrEmpty(ServerUrl) && ServerUrl.StartsWith("ws") && !string.IsNullOrEmpty(Token),
TokenSourceType.Sandbox => !string.IsNullOrEmpty(SandboxId),
TokenSourceType.Development => !string.IsNullOrEmpty(TokenServerId),
TokenSourceType.Endpoint => !string.IsNullOrEmpty(EndpointUrl),
_ => false
};
Expand Down
4 changes: 2 additions & 2 deletions Samples~/Agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ The app is configured to connect to the LiveKit homepage agent by default, which

To switch from the default agent to your own, you first need a LiveKit agent to speak with. For a no-code setup, use the [Agent Builder](https://docs.livekit.io/agents/start/builder/). For more customization, try our starter agent for [Python](https://github.com/livekit-examples/agent-starter-python), [Node.js](https://github.com/livekit-examples/agent-starter-node), or [create your own from scratch](https://docs.livekit.io/agents/start/voice-ai/).

Second, you need a token server. For development, the easiest option is the sandbox token server: enable it from your project's Options on the Settings page in LiveKit Cloud and copy the sandboxId.
Second, you need a token server. For development, the easiest option is the development token server: enable it from your project's Options on the Settings page in LiveKit Cloud and copy the token server ID.

Then create a new TokenSoureComponentConfig asset for your sandbox and reference it in the scene on the `TokenSourceComponent` script instead of the `HomepageAgent.asset`:
Then create a new TokenSoureComponentConfig asset for your development token server and reference it in the scene on the `TokenSourceComponent` script instead of the `HomepageAgent.asset`:

### Common sample package

Expand Down
Loading