Skip to content
Merged
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
34 changes: 28 additions & 6 deletions lib/controllers/app_ctrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import 'package:livekit_client/livekit_client.dart' as sdk;
import 'package:livekit_components/livekit_components.dart' as components;
import 'package:logging/logging.dart';
import 'package:uuid/uuid.dart';

import '../services/token_service.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

enum AppScreenState { welcome, agent }

Expand All @@ -30,10 +29,33 @@ class AppCtrl extends ChangeNotifier {

late final sdk.Room room = sdk.Room(roomOptions: const sdk.RoomOptions(enableVisualizer: true));
late final roomContext = components.RoomContext(room: room);
late final sdk.Session session = sdk.Session.fromConfigurableTokenSource(
TokenServiceTokenSource(TokenService()),
options: sdk.SessionOptions(room: room),
);
late final sdk.Session session = _createSession(room: room);

static sdk.Session _createSession({required sdk.Room room}) {
// Development-only hardcoded credentials (optional).
const hardcodedServerUrl = null; // e.g. 'wss://your-host'
const hardcodedToken = null; // e.g. 'eyJ...'

if (hardcodedServerUrl != null && hardcodedToken != null) {
return sdk.Session.fromFixedTokenSource(
sdk.LiteralTokenSource(
serverUrl: hardcodedServerUrl,
participantToken: hardcodedToken,
),
options: sdk.SessionOptions(room: room),
);
}

final sandboxId = dotenv.env['LIVEKIT_SANDBOX_ID']?.replaceAll('"', '');
if (sandboxId == null || sandboxId.isEmpty) {
throw StateError('LIVEKIT_SANDBOX_ID is not set and no hardcoded token is configured.');
}

return sdk.Session.fromConfigurableTokenSource(
sdk.SandboxTokenSource(sandboxId: sandboxId).cached(),
options: sdk.SessionOptions(room: room),
);
}

bool isSendButtonEnabled = false;
bool isSessionStarting = false;
Expand Down
128 changes: 0 additions & 128 deletions lib/services/token_service.dart

This file was deleted.

9 changes: 9 additions & 0 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:voice_assistant/app.dart';

void main() {
testWidgets('App builds successfully', (WidgetTester tester) async {
await dotenv.load(
fileName: '.env',
isOptional: true,
mergeWith: const {
'LIVEKIT_SANDBOX_ID': 'test',
},
);

// Build our app and trigger a frame.
await tester.pumpWidget(const VoiceAssistantApp());
// Dispose resources started by the global controller to avoid pending timers.
Expand Down