How to Use LiveKit Flutter SDK for Real-time Audio, Video, and Data Features

Jan 22, 2024 | Programming

If you’re looking to enhance your Flutter application with real-time audio, video, and data capabilities, look no further! The LiveKit Flutter SDK is here to make it easy for you. This SDK allows you to connect to LiveKit Cloud or a self-hosted server to build applications such as multi-modal AI, live streaming, or video calls all with minimal code. In this guide, we’ll walk you through the steps to get started!

Supported Platforms

The LiveKit client SDK works across all platforms supported by Flutter:

  • Android
  • iOS
  • Web
  • macOS
  • Windows
  • Linux

Installation Steps

To begin using the LiveKit Flutter SDK, include the package in your pubspec.yaml file:

dependencies:
  livekit_client: version

Special Configuration for iOS

For iOS apps, you need to declare camera and microphone usage in your Info.plist:

key NSCameraUsageDescription
string $(PRODUCT_NAME) uses your camera
key NSMicrophoneUsageDescription
string $(PRODUCT_NAME) uses your microphone

Also, if your application requires background modes for voice calls, enable it in your Xcode project settings.

Configuration for Android

For Android, you must declare necessary permissions in your AppManifest.xml:

uses-permission android:name="android.permission.CAMERA"
uses-permission android:name="android.permission.RECORD_AUDIO"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"

Code Analogy: Connecting to a Room

Think of your app as a party. The LiveKit SDK is your invitation that allows your app to enter the party (the LiveKit room). You need two things for your invitation: an invite link (URL) and a special code (token). Once you have your invitation sorted, you can freely communicate with other guests (participants) in the party, as follows:

final roomOptions = RoomOptions(
  adaptiveStream: true,
  dynacast: true,
);
final room = Room();
await room.prepareConnection(url, token);
await room.connect(url, token, roomOptions: roomOptions);

Once connected, you can enable local video and audio just like sharing your own voice and face at the party:

await room.localParticipant.setCameraEnabled(true);
await room.localParticipant.setMicrophoneEnabled(true);

Screen Sharing

Screen sharing is beneficial for collaborative work. You can enable it with the simple command:

room.localParticipant.setScreenShareEnabled(true);

Remember, the capabilities of screen sharing might differ across platforms, so ensure you follow the specific instructions for each one.

Troubleshooting

If you encounter any issues, here are a few tips to debug:

  • Ensure all permissions are correctly declared in your configuration files.
  • Make sure you are using a compatible Flutter version (3.3.0 or higher is recommended).
  • If on iOS, double-check that your Info.plist is properly configured for camera and microphone usage.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Your Feedback Matters

As you integrate the LiveKit Flutter SDK, make sure to monitor for any unexpected behaviors. LiveKit client incorporates events to notify you of changes, which can enhance the responsiveness of your app.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Conclusion

You now have the foundational knowledge to begin using the LiveKit Flutter SDK in your application. Dive into the world of real-time communication and unlock powerful possibilities!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox