### Installation: Bundle directory setup Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Sets up the installation prefix to create a relocatable bundle and starts with a clean directory. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Asset Installation Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Installs Flutter assets to the application bundle. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation: Target and file installation Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Installs the application executable, Flutter ICU data, Flutter library, and bundled plugin libraries. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### AOT Library Installation Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug builds. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### System-level dependencies Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Finds PkgConfig and checks for the gtk+-3.0 module. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Build configuration options Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Defines the build type (Debug, Profile, Release) if not already set. ```cmake # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Generated plugin build rules Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Includes the CMake file for managing generated plugin builds. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define the application target Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Defines the main executable target, including source files and dependencies. ```cmake # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Connecting to a room, publish video & audio Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Example of connecting to a LiveKit room, preparing the connection, and enabling local camera and microphone. ```dart final roomOptions = RoomOptions( adaptiveStream: true, dynacast: true, // ... your room options ) final room = Room(); // you can use `prepareConnection` to speed up connection. await room.prepareConnection(url, token); await room.connect(url, token, roomOptions: roomOptions); try { // video will fail when running in ios simulator await room.localParticipant.setCameraEnabled(true); } catch (error) { print('Could not publish video, error: $error'); } await room.localParticipant.setMicrophoneEnabled(true); ``` -------------------------------- ### Flutter library and tool build rules Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Sets the directory for Flutter managed files and adds it as a subdirectory. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Screen sharing Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Example of enabling screen sharing across all platforms. ```dart room.localParticipant.setScreenShareEnabled(true); ``` -------------------------------- ### Unit Test Setup Source: https://github.com/livekit/client-sdk-flutter/blob/main/linux/CMakeLists.txt Configures the build to include unit tests if the appropriate variable is set. ```cmake # === Tests === # These unit tests can be run from a terminal after building the example. # Only enable test builds when building the example (which sets this variable) # so that plugin clients aren't building the tests. if (${include_${PROJECT_NAME}_tests}) if(${CMAKE_VERSION} VERSION_LESS "3.11.0") message("Unit tests require CMake 3.11.0 or later") else() set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() # Add the Google Test dependency. include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/release-1.11.0.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) # The plugin's exported API is not very useful for unit testing, so build the # sources directly into the test binary rather than using the shared library. add_executable(${TEST_RUNNER} test/livekit_plugin_test.cc ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter) target_link_libraries(${TEST_RUNNER} PRIVATE PkgConfig::GTK) target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) # Enable automatic test discovery. include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() # CMake version check endif() # include_${PROJECT_NAME}_tests ``` -------------------------------- ### Apply standard compilation settings Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt A function to apply standard compilation features, options, and definitions to a target. ```cmake # Compilation settings that should be applied to most targets. # # Be cautious about adding new options here, as plugins use this function by # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Reacting to Room Events Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Example demonstrating how to use ChangeNotifier and EventsListener to react to room events in a Flutter application. ```dart class RoomWidget extends StatefulWidget { final Room room; RoomWidget(this.room); @override State createState() { return _RoomState(); } } class _RoomState extends State { late final EventsListener _listener = widget.room.createListener(); @override void initState() { super.initState(); // used for generic change updates widget.room.addListener(_onChange); // used for specific events _listener ..on((_) { // handle disconnect }) ..on((e) { print("participant joined: ${e.participant.identity}"); }) } @override void dispose() { // be sure to dispose listener to stop listening to further updates _listener.dispose(); widget.room.removeListener(_onChange); super.dispose(); } void _onChange() { // perform computations and then call setState // setState will trigger a build setState(() { // your updates here }); } @override Widget build(BuildContext context) { // your build function } } ``` -------------------------------- ### Runtime output directory Source: https://github.com/livekit/client-sdk-flutter/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to prevent running unbundled copies. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Reacting to Participant Changes Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Example showing how to use participant change listeners to update UI elements like video views. ```dart class VideoView extends StatefulWidget { final Participant participant; VideoView(this.participant); @override State createState() { return _VideoViewState(); } } class _VideoViewState extends State { TrackPublication? videoPub; @override void initState() { super.initState(); widget.participant.addListener(this._onParticipantChanged); // trigger initial change _onParticipantChanged(); } @override void dispose() { widget.participant.removeListener(_onParticipantChanged); super.dispose(); } @override void didUpdateWidget(covariant VideoView oldWidget) { oldWidget.participant.removeListener(_onParticipantChanged); widget.participant.addListener(_onParticipantChanged); _onParticipantChanged(); super.didUpdateWidget(oldWidget); } void _onParticipantChanged() { var subscribedVideos = widget.participant.videoTracks.values.where((pub) { return pub.kind == TrackType.VIDEO && !pub.isScreenShare && pub.subscribed; }); setState(() { if (subscribedVideos.length > 0) { var videoPub = subscribedVideos.first; // when muted, show placeholder if (!videoPub.muted) { this.videoPub = videoPub; return; } } this.videoPub = null; }); } @override Widget build(BuildContext context) { var videoPub = this.videoPub; if (videoPub != null) { return VideoTrackRenderer(videoPub.track as VideoTrack); } else { return Container( color: Colors.grey, ); } } } ``` -------------------------------- ### Android Audio Modes Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Example of initializing audio settings for Android, specifically setting the audio mode to 'media' for media playback oriented apps. ```dart import 'package:flutter_webrtc/flutter_webrtc.dart' as webrtc; Future _initializeAndroidAudioSettings() async { await webrtc.WebRTC.initialize(options: { 'androidAudioConfiguration': webrtc.AndroidAudioConfiguration.media.toMap() }); webrtc.Helper.setAndroidAudioConfiguration( webrtc.AndroidAudioConfiguration.media); } void main() async { await _initializeAudioSettings(); runApp(const MyApp()); } ``` -------------------------------- ### Bundled Libraries Source: https://github.com/livekit/client-sdk-flutter/blob/main/linux/CMakeLists.txt Lists libraries that should be bundled with the plugin. ```cmake # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an # external build triggered from this build file. set(livekit_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### iOS Podfile Minimum Deployment Target Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Set the minimum deployment target for iOS to 12.1 in your Podfile. ```ruby platform :ios, '12.1' ``` -------------------------------- ### Manually Creating and Publishing Video Track Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Dart code for manually creating a camera video track and publishing it to the room. ```dart var localVideo = await LocalVideoTrack.createCameraTrack(); await room.localParticipant.publishVideoTrack(localVideo); ``` -------------------------------- ### Desktop Screen Sharing Implementation Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Dart code for selecting a window or screen to share on desktop platforms using ScreenSelectDialog. ```dart try { final source = await showDialog( context: context, builder: (context) => ScreenSelectDialog(), ); if (source == null) { print('cancelled screenshare'); return; } print('DesktopCapturerSource: ${source.id}'); var track = await LocalVideoTrack.createScreenShareTrack( ScreenShareCaptureOptions( sourceId: source.id, maxFrameRate: 15.0, ), ); await room.localParticipant.publishVideoTrack(track); } catch (e) { print('could not publish screen sharing: $e'); } ``` -------------------------------- ### iOS Info.plist Camera and Microphone Usage Descriptions Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Declare camera and microphone usage in your iOS Info.plist file. ```xml ... NSCameraUsageDescription $(PRODUCT_NAME) uses your camera NSMicrophoneUsageDescription $(PRODUCT_NAME) uses your microphone ``` -------------------------------- ### AndroidManifest.xml for Android Screen Share Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Configuration for the AndroidManifest.xml file to enable media projection foreground service for screen sharing. ```xml ... ``` -------------------------------- ### End to End Encryption Worker Compilation Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Bash commands to compile the E2EE worker for Flutter web. ```bash # for example app dart compile js web/e2ee.worker.dart -o example/web/e2ee.worker.dart.js -m # for your project export YOUR_PROJECT_DIR=your_project_dir git clone https://github.com/livekit/client-sdk-flutter.git cd client-sdk-flutter && flutter pub get dart compile js web/e2ee.worker.dart -o ${YOUR_PROJECT_DIR}/web/e2ee.worker.dart.js -m ``` -------------------------------- ### Add livekit_client to pubspec.yaml Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Include the livekit_client package in your Flutter project's pubspec.yaml file. ```yaml dependencies: livekit_client: ^2.7.0 ``` -------------------------------- ### Bluetooth Permissions Request Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Code to request Bluetooth and Bluetooth Connect permissions after launching the app for the first time on Android. ```dart import 'package:permission_handler/permission_handler.dart'; Future _checkPermissions() async { var status = await Permission.bluetooth.request(); if (status.isPermanentlyDenied) { print('Bluetooth Permission disabled'); } status = await Permission.bluetoothConnect.request(); if (status.isPermanentlyDenied) { print('Bluetooth Connect Permission disabled'); } } void main() async { WidgetsFlutterBinding.ensureInitialized(); await _checkPermissions(); runApp(MyApp()); } ``` -------------------------------- ### iOS Podfile Workaround for 32-bit Build Issues Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Modify your iOS Podfile to include a workaround for 32-bit build issues, especially with Xcode 14 and newer Flutter versions. ```ruby post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| # Workaround for https://github.com/flutter/flutter/issues/64502 config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES' # <= this line end end end ``` -------------------------------- ### Android Manifest Permissions Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Required permissions for Android to be declared in AppManifest.xml for Flutter WebRTC. ```xml ... ``` -------------------------------- ### Rendering Video Track Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Flutter widget code for rendering a video track using VideoTrackRenderer. ```dart VideoTrack? track; @override Widget build(BuildContext context) { if (track != null) { return VideoTrackRenderer(track); } else { return Container( color: Colors.grey, ); } } ``` -------------------------------- ### iOS Info.plist Background Modes for Audio Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Enable background audio mode in your iOS Info.plist file for voice calls. ```xml ... UIBackgroundModes audio ``` -------------------------------- ### Mute/Unmute Local Tracks Source: https://github.com/livekit/client-sdk-flutter/blob/main/README.md Code snippets for muting and unmuting local tracks in LiveKit. ```dart // mute track trackPub.muted = true; // unmute track trackPub.muted = false; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.