broad-lamp-30178
08/21/2025, 9:23 PMtall-airline-16756
08/21/2025, 9:23 PMtall-airline-16756
08/21/2025, 9:25 PMnpm install livekit-server-sdk
◦ Go: go get github.com/livekit/server-sdk-go/v2
1. Make sure to keep your API keys safe by putting them in a secure environment file.
2. Create an endpoint to generate tokens. Here’s a simple example in Node.js:`import express from 'express';
import { AccessToken } from 'livekit-server-sdk';
const app = express();
const port = 3000;
app.post('/token', async (req, res) => {
const { roomName, participantName } = req.body;
const at = new AccessToken('your-api-key', 'your-api-secret', {
identity: participantName,
ttl: '10m',
});
at.addGrant({ roomJoin: true, room: roomName });
res.send(at.toJwt());
});
app.listen(port, () => console.log(Server running on port ${port}));`
Integrating with Your Flutter App
1. Create a service in your Flutter app that fetches tokens from your server. Here’s a quick example:import 'dart:convert';
import 'package:http/http.dart' as http;
class TokenService {
final String tokenServerUrl = <YOUR_TOKEN_SERVER_URL>;
Future<String> fetchToken(String roomName, String participantName) async {
final response = await http.post(
Uri.parse(tokenServerUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'roomName': roomName, 'participantName': participantName}),
);
if (response.statusCode == 200) {
return response.body;
} else {
throw Exception('Failed to fetch token');
}
}
}
2. Then, use that token to connect your Flutter app to LiveKit.
When you’re ready for production, just double-check that your token server is secure and hooked up to your authentication system. If you have any questions or want me to walk you through anything, just let me know — I’m here to help!broad-lamp-30178
08/21/2025, 9:27 PMtall-airline-16756
08/21/2025, 9:27 PMlib/services/token_service.dart
• Support for iOS, macOS, Android, and web platforms
• Easy integration with LiveKit Cloud Sandbox for quick prototyping
Getting Started
1. Create a Sandbox Token Server for your LiveKit Cloud project.
2. Clone and connect the template using the LiveKit CLI:
lk app create --template agent-starter-flutter --sandbox <token_server_sandbox_id>
1. Install dependencies and run:
flutter pub get
flutter run
Alternative Setup
If you’d rather skip the CLI, no worries! You can manually clone the repo and set things up by:
• Adding a LIVEKIT_SANDBOX_ID to your .env file for sandbox use
• Updating token_service.dart with your own token server URL and manually generated tokens
Feel free to reach out if you want a hand with setting up the example project—I’m here to help!
Sources: lib/services/token_service.dart | README.mdbroad-lamp-30178
08/22/2025, 3:02 AMtall-airline-16756
08/22/2025, 3:03 AMimport os
from livekit import api
def generate_token(room_name, identity):
token = (
api.AccessToken(os.getenv('LIVEKIT_API_KEY'), os.getenv('LIVEKIT_API_SECRET'))
.with_identity(identity)
.with_grants(api.VideoGrants(room_join=True, room=room_name))
.to_jwt()
)
return token
2. Flask-Based Token Server
Here’s an example using Flask to create an endpoint for token generation:
from flask import Flask, request, jsonify
from livekit import api
app = Flask(__name__)
@app.route('/generate-token', methods=['POST'])
def generate_token():
data = request.json
room_name = data.get('room_name')
identity = data.get('identity')
token = (
api.AccessToken(os.getenv('LIVEKIT_API_KEY'), os.getenv('LIVEKIT_API_SECRET'))
.with_identity(identity)
.with_grants(api.VideoGrants(room_join=True, room=room_name))
.to_jwt()
)
return jsonify({'token': token})
3. Repository Links
• Standalone Token Function
• Flask-Based Token Server
If you have any questions or want to dive deeper into these examples, just let me know—I’m here to help!
Sources: templates.yaml | complex-agents/ivr-agent/flask_livekit/extension.py | ivr-nagivator/flask_livekit/extension.py | examples/rpc.py | auth.pybroad-lamp-30178
08/22/2025, 3:09 AMtall-airline-16756
08/22/2025, 3:09 AMbroad-lamp-30178
08/24/2025, 11:40 PMtall-airline-16756
08/24/2025, 11:41 PMimport express from 'express';
import { AccessToken } from 'livekit-server-sdk';
const app = express();
app.post('/token', async (req, res) => {
const { roomName, participantName } = req.body;
const token = new AccessToken('your-api-key', 'your-api-secret', {
identity: participantName,
ttl: '10m',
}).addGrant({ roomJoin: true, room: roomName }).toJwt();
res.send(token);
});
app.listen(3000, () => console.log('Token server running on port 3000'));
2. Environment Configuration
• Next up, set your environment variables on Render.com like this:
LIVEKIT_URL=wss://your-livekit-url.livekit.cloud
LIVEKIT_API_KEY=your-livekit-api-key
LIVEKIT_API_SECRET=your-livekit-api-secret
3. Client-Side Integration
• Then, in your app, you’ll want to fetch tokens from your token server. Here’s how you might do it in Flutter:
class TokenService {
final String tokenServerUrl = <YOUR_TOKEN_SERVER_URL>;
Future<String> fetchToken(String roomName, String participantName) async {
final response = await http.post(
Uri.parse(tokenServerUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'roomName': roomName, 'participantName': participantName}),
);
if (response.statusCode == 200) {
return response.body;
} else {
throw Exception('Failed to fetch token');
}
}
}
4. Development vs Production
• For development, feel free to use LiveKit Cloud Sandbox or even hardcoded tokens to get started quickly.
• When you’re ready for production, make sure your token server is secure and properly integrated with your authentication system.
If you hit any bumps or want to chat more about this setup, just let me know—I’m here to help!
Sources: render.com/README.md | Authentication Examples | livekit/livekit_composite | DeepWiki | lib/services/token_service.dart | Next.js quickstart | LiveKit Docs | TEMPLATE.md