From fedce5425fab7e4ee2917af0fae4a68ffac291f9 Mon Sep 17 00:00:00 2001 From: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Date: Wed, 26 Aug 2026 12:07:00 +0200 Subject: [PATCH] Replace deprecated sandbox for development token source Needs to be squashed to sandbox change --- .env.example | 7 ++++--- README.md | 19 ++++++++++++------- lib/controllers/app_ctrl.dart | 11 ++++++++--- lib/main.dart | 2 +- pubspec.yaml | 2 +- test/widget_test.dart | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index 0ffe18a..dd5611a 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ -# Copy this file to assets/.env and set your token server sandbox ID, -# found in your LiveKit Cloud project's Settings page. +# Copy this file to assets/.env and set your development token server ID, +# found on your LiveKit Cloud project's Settings page under "Development token server". +# See https://docs.livekit.io/frontends/build/authentication/development-token-server/ # Without it, the app connects to a default agent. -LIVEKIT_SANDBOX_ID= \ No newline at end of file +LIVEKIT_TOKEN_SERVER_ID= diff --git a/README.md b/README.md index 9e1f05d..6d11a93 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,26 @@ Note: You may need to configure signing certificates in Xcode if building to a r The app is configured to connect to the LiveKit homepage agent by default, which you can also try at [livekit.com](https://www.livekit.com). To point the app at your own agent (see [Connect to your agent](#connect-to-your-agent)). > [!NOTE] -> To setup without the LiveKit CLI, clone the repository and then either create the `assets/.env` file manually from a copy of `.env.example`. The env file is optional: without any configuration, the app connects to a default agent — the same one featured on the [LiveKit homepage](https://livekit.io) — so you can try it out right away. +> To setup without the LiveKit CLI, clone the repository and then create the `assets/.env` file manually from a copy of `.env.example`. The env file is optional: without any configuration, the app connects to a default agent — the same one featured on the [LiveKit homepage](https://livekit.io) — so you can try it out right away. ## Connect to your agent 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](https://docs.livekit.io/frontends/authentication/tokens/sandbox-token-server/): enable it from your project's **Options** on the [Settings](https://cloud.livekit.io/projects/p_/settings/project) page in LiveKit Cloud and copy the `sandboxId`. +Second, you need a token server. For development, the easiest option is the [development token server](https://docs.livekit.io/frontends/build/authentication/development-token-server/): turn on the **Development token server** switch on the [Settings](https://cloud.livekit.io/projects/p_/settings/project) page in LiveKit Cloud and copy the **Token server ID**. -Then fill the `LIVEKIT_SANDBOX_ID` in your `assets/.env`: +Then fill the `LIVEKIT_TOKEN_SERVER_ID` in your `assets/.env`: -```swift -LIVEKIT_SANDBOX_ID= +```sh +LIVEKIT_TOKEN_SERVER_ID= ``` -or modify `lib/controllers/app_ctrl.dart` to replace the `SandboxTokenSource` with your own token source implementation (development-only hardcoded credentials are also supported there). +or modify `lib/controllers/app_ctrl.dart` to replace the `DevelopmentTokenSource` with your own token source implementation (development-only hardcoded credentials are also supported there). + +> [!NOTE] +> The development token server is for prototyping only — any client can request a token with any permissions. See [Token generation in production](#token-generation-in-production) before you ship. +> +> This setting was previously called the *sandbox token server*, and `LIVEKIT_SANDBOX_ID` is still accepted as a fallback for existing `.env` files. ## Feature overview @@ -85,7 +90,7 @@ If your agent publishes a video track (for example via a [virtual avatar](https: In a production environment, you will be responsible for developing a solution to [generate tokens for your users](https://docs.livekit.io/home/server/generating-tokens/) that integrates with your authentication system. -You should replace the `SandboxTokenSource` in `lib/controllers/app_ctrl.dart` with an `EndpointTokenSource` or your own `TokenSourceFixed` / `TokenSourceConfigurable` implementation. You can also use `.cached()` to cache valid tokens and avoid unnecessary token requests. +You should replace the `DevelopmentTokenSource` in `lib/controllers/app_ctrl.dart` with an `EndpointTokenSource` or your own `TokenSourceFixed` / `TokenSourceConfigurable` implementation. You can also use `.cached()` to cache valid tokens and avoid unnecessary token requests. ## Running on Simulator / Emulator diff --git a/lib/controllers/app_ctrl.dart b/lib/controllers/app_ctrl.dart index 47dcd5d..d12bab1 100644 --- a/lib/controllers/app_ctrl.dart +++ b/lib/controllers/app_ctrl.dart @@ -48,12 +48,17 @@ class AppCtrl extends ChangeNotifier { ); } - final sandboxId = dotenv.env['LIVEKIT_SANDBOX_ID']?.replaceAll('"', ''); + // The development token server ID from your LiveKit Cloud project's Settings page. + // LIVEKIT_SANDBOX_ID is the former name of this setting and is still accepted. + final tokenServerId = + (dotenv.env['LIVEKIT_TOKEN_SERVER_ID'] ?? dotenv.env['LIVEKIT_SANDBOX_ID'])?.replaceAll('"', ''); + const placeholderIds = {'', ''}; + sdk.EndpointTokenSource tokenSource; - if (sandboxId == null || sandboxId.isEmpty || sandboxId == '') { + if (tokenServerId == null || tokenServerId.isEmpty || placeholderIds.contains(tokenServerId)) { tokenSource = sdk.EndpointTokenSource(url: Uri.parse(homepageAgentTokenEndpoint)); } else { - tokenSource = sdk.SandboxTokenSource(sandboxId: sandboxId); + tokenSource = sdk.DevelopmentTokenSource(id: tokenServerId); } return sdk.Session.fromConfigurableTokenSource( diff --git a/lib/main.dart b/lib/main.dart index a540626..c85f80d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'app.dart'; // Load environment variables before starting the app -// This is used to configure the LiveKit sandbox ID for development +// This is used to configure the LiveKit development token server ID // The file is optional; without it the app connects to a default agent (see app_ctrl.dart) void main() async { await dotenv.load(fileName: 'assets/.env', isOptional: true); diff --git a/pubspec.yaml b/pubspec.yaml index c687ea0..846fb7a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 chat_bubbles: ^1.6.0 - livekit_client: ^2.10.0 + livekit_client: ^2.11.0 flutter_dotenv: ^6.0.0 http: ^1.3.0 provider: ^6.1.2 diff --git a/test/widget_test.dart b/test/widget_test.dart index 7858b3d..d22e6f4 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -16,7 +16,7 @@ void main() { fileName: 'assets/.env', isOptional: true, mergeWith: const { - 'LIVEKIT_SANDBOX_ID': 'test', + 'LIVEKIT_TOKEN_SERVER_ID': 'test', }, );