broad-lamp-30178
09/11/2025, 9:31 PMtall-airline-16756
09/11/2025, 9:31 PMtall-airline-16756
09/11/2025, 9:31 PMbroad-lamp-30178
09/11/2025, 9:33 PMtall-airline-16756
09/11/2025, 9:34 PMlivekit_client
package to your pubspec.yaml
file like this:
dependencies:
livekit_client: <latest_version>
Don’t forget to set up the necessary permissions for your platform:
• iOS: Add camera and microphone permissions to your Info.plist
and make sure to enable background audio.
• Android: Include permissions for camera, microphone, and audio settings in your AndroidManifest.xml
.
2. Connect to a Room
Next, create a Room
instance and connect using your server URL and access token:
final room = Room();
await room.connect('<wss://your-server-url>', 'your-access-token');
Then, enable the microphone and camera for the local participant with these commands:
await room.localParticipant?.setMicrophoneEnabled(true);
await room.localParticipant?.setCameraEnabled(true);
3. Enable Real-Time Audio Communication
Good news—audio is enabled by default! But if you want to start audio playback explicitly, just do this:
await room.startAudio();
For Android, make sure to initialize audio settings like this:
import 'package:flutter_webrtc/flutter_webrtc.dart' as webrtc;
await webrtc.WebRTC.initialize(options: {
'androidAudioConfiguration': webrtc.AndroidAudioConfiguration.communication.toMap()
});
4. Enable Text Chat
To send chat messages, use sendText()
like so:
await room.localParticipant?.sendText('Hello!', options: SendTextOptions(topic: 'lk.chat'));
And to receive messages, listen for DataReceivedEvent
like this:
room.addListener((event) {
if (event is DataReceivedEvent) {
final text = utf8.decode(event.data);
print('Received message: $text');
}
});
5. Optional: Use Prebuilt UI Components
If you want to speed up your development, the livekit_components
package offers prebuilt widgets for chat and audio/video controls, which can be super handy.
For more detailed info, feel free to check out the LiveKit Flutter SDK GitHub and the LiveKit Documentation. If you have any questions along the way, I’m here to help!
Sources: lib/src/core/room.dart | lib/controllers/app_ctrl.dart | Docs::Agents | Web and mobile frontends | LiveKit Docs | example/lib/main.dart