diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8a5162a..ea7b84d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,20 +1,25 @@ PODS: + - connectivity_plus (0.0.1): + - Flutter + - ReachabilitySwift - device_info_plus (0.0.1): - Flutter - Flutter (1.0.0) - - flutter_webrtc (0.9.4): + - flutter_webrtc (0.9.13): - Flutter - - WebRTC-SDK (= 104.5112.02) - - livekit_client (1.1.0): + - WebRTC-SDK (= 104.5112.06) + - livekit_client (1.1.1): - Flutter - - WebRTC-SDK (~> 104.5112.02) + - WebRTC-SDK (~> 104.5112.06) - path_provider_ios (0.0.1): - Flutter + - ReachabilitySwift (5.0.0) - shared_preferences_ios (0.0.1): - Flutter - - WebRTC-SDK (104.5112.02) + - WebRTC-SDK (104.5112.06) DEPENDENCIES: + - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - Flutter (from `Flutter`) - flutter_webrtc (from `.symlinks/plugins/flutter_webrtc/ios`) @@ -24,9 +29,12 @@ DEPENDENCIES: SPEC REPOS: trunk: + - ReachabilitySwift - WebRTC-SDK EXTERNAL SOURCES: + connectivity_plus: + :path: ".symlinks/plugins/connectivity_plus/ios" device_info_plus: :path: ".symlinks/plugins/device_info_plus/ios" Flutter: @@ -41,13 +49,15 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/shared_preferences_ios/ios" SPEC CHECKSUMS: + connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed - Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a - flutter_webrtc: aa130dfe1eca6625c2e2e51ce830abb495bdb06e - livekit_client: f0343eef54a12a4b831d3ec1085760f13eca9ae3 + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + flutter_webrtc: 6e85da5004f21fd21255228a76c2d4867c3b8972 + livekit_client: 4240200323a2511f50ee17ce23436b043ac0dbc1 path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 + ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad - WebRTC-SDK: e0589abeb63db07a4ca1f45c82ba0f1a72e61622 + WebRTC-SDK: 85ee61404eb5698cf23a69a27008271db07159fc PODFILE CHECKSUM: 82aed1035f46bfa5b522f0d0dbf4730f17ec65ff diff --git a/example/lib/widgets/controls.dart b/example/lib/widgets/controls.dart index 2889898..7bbf910 100644 --- a/example/lib/widgets/controls.dart +++ b/example/lib/widgets/controls.dart @@ -75,6 +75,8 @@ class _ControlsWidgetState extends State { if (result == true) await participant.unpublishAllTracks(); } + bool get isMuted => participant.isMuted; + void _disableAudio() async { await participant.setMicrophoneEnabled(false); } @@ -270,7 +272,7 @@ class _ControlsWidgetState extends State { ), title: Text('Mute Microphone'), ), - onTap: _disableAudio, + onTap: isMuted ? _enableAudio : _disableAudio, ), if (_audioInputs != null) ..._audioInputs!.map((device) { diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 93beb01..9e97b9b 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -4,19 +4,19 @@ PODS: - ReachabilitySwift - device_info_plus_macos (0.0.1): - FlutterMacOS - - flutter_webrtc (0.9.4): + - flutter_webrtc (0.9.13): - FlutterMacOS - - WebRTC-SDK (= 104.5112.03) + - WebRTC-SDK (= 104.5112.06) - FlutterMacOS (1.0.0) - livekit_client (1.1.1): - FlutterMacOS - - WebRTC-SDK (~> 104.5112.03) + - WebRTC-SDK (~> 104.5112.06) - path_provider_macos (0.0.1): - FlutterMacOS - ReachabilitySwift (5.0.0) - shared_preferences_macos (0.0.1): - FlutterMacOS - - WebRTC-SDK (104.5112.03) + - WebRTC-SDK (104.5112.06) DEPENDENCIES: - connectivity_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos`) @@ -51,13 +51,13 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: connectivity_plus_macos: f6e86fd000e971d361e54b5afcadc8c8fa773308 device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7 - flutter_webrtc: 45cd8f5825bb32054e817708bf343ceff2c9cab8 - FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 - livekit_client: 42da9111e214db06de13279b12a70210294d03dc + flutter_webrtc: 4bb537cadddcfb5e5b24c96cbd6ff56f064b8faf + FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811 + livekit_client: b438747d15f01e3baaefa8036dd2feec5539387e path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19 ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727 - WebRTC-SDK: 9f50fb5a410edc38e6fbb865fe940e3010bc8e7e + WebRTC-SDK: 85ee61404eb5698cf23a69a27008271db07159fc PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c diff --git a/example/pubspec.lock b/example/pubspec.lock index acf29f6..9f98e18 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -70,7 +70,7 @@ packages: name: connectivity_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "1.2.3" connectivity_plus_web: dependency: transitive description: @@ -98,7 +98,7 @@ packages: name: dart_webrtc url: "https://pub.dartlang.org" source: hosted - version: "1.0.10" + version: "1.0.11" dbus: dependency: transitive description: @@ -208,7 +208,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.6" flutter_test: dependency: "direct dev" description: flutter @@ -225,7 +225,7 @@ packages: name: flutter_webrtc url: "https://pub.dartlang.org" source: hosted - version: "0.9.12" + version: "0.9.14" google_fonts: dependency: "direct main" description: @@ -351,7 +351,7 @@ packages: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.20" + version: "2.0.21" path_provider_ios: dependency: transitive description: @@ -393,7 +393,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "5.1.0" platform: dependency: transitive description: @@ -566,14 +566,14 @@ packages: name: webrtc_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "1.0.10" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.1.1" xdg_directories: dependency: transitive description: @@ -589,5 +589,5 @@ packages: source: hosted version: "6.1.0" sdks: - dart: ">=2.17.0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=3.0.0" diff --git a/ios/livekit_client.podspec b/ios/livekit_client.podspec index ba8dd59..62aa6e3 100644 --- a/ios/livekit_client.podspec +++ b/ios/livekit_client.podspec @@ -16,5 +16,5 @@ Pod::Spec.new do |s| s.static_framework = true s.dependency 'Flutter' - s.dependency 'WebRTC-SDK', '~> 104.5112.02' + s.dependency 'WebRTC-SDK', '~> 104.5112.06' end diff --git a/lib/src/options.dart b/lib/src/options.dart index 5c6f87f..4590fbb 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -130,6 +130,9 @@ class AudioPreset { static const telephone = 12000; static const speech = 20000; static const music = 32000; + static const musicStereo = 48000; + static const musicHighQuality = 64000; + static const musicHighQualityStereo = 96000; } /// Options used when publishing audio. @@ -142,9 +145,14 @@ class AudioPublishOptions { /// max audio bitrate final int audioBitrate; + /// Turn off the audio track when muted, to avoid the microphone + /// indicator light on. + final bool stopMicTrackOnMute; + const AudioPublishOptions({ this.dtx = true, - this.audioBitrate = AudioPreset.speech, + this.audioBitrate = AudioPreset.music, + this.stopMicTrackOnMute = true, }); @override diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index e4ce1e2..d59d2ac 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -25,6 +25,7 @@ import 'participant.dart'; /// Represents the current participant in the room. Instance of [LocalParticipant] is automatically /// created after successfully connecting to a [Room] and will be accessible from [Room.localParticipant]. class LocalParticipant extends Participant { + bool stopMicTrackOnMute = false; @internal LocalParticipant({ required Room room, @@ -53,6 +54,8 @@ class LocalParticipant extends Participant { publishOptions = publishOptions ?? room.roomOptions.defaultAudioPublishOptions; + stopMicTrackOnMute = publishOptions.stopMicTrackOnMute; + final trackInfo = await room.engine.addTrack( cid: track.getCid(), name: track.name, @@ -310,13 +313,24 @@ class LocalParticipant extends Participant { logger.fine('setSourceEnabled(source: $source, enabled: $enabled)'); final publication = getTrackPublicationBySource(source); if (publication != null) { + var track = publication.track; + var stopOnMute = stopMicTrackOnMute && track is LocalAudioTrack; if (enabled) { await publication.unmute(); + if (stopOnMute) { + await track.restartTrack(); + await track.onTrackStarted(); + } } else { if (source == TrackSource.screenShareVideo) { await unpublishTrack(publication.sid); } else { await publication.mute(); + if (stopOnMute) { + await track.sender?.setTrack(null); + await track.stop(); + await track.onTrackStopped(); + } } } return publication; diff --git a/lib/src/track/audio_management.dart b/lib/src/track/audio_management.dart index f303e37..935b5be 100644 --- a/lib/src/track/audio_management.dart +++ b/lib/src/track/audio_management.dart @@ -52,6 +52,20 @@ mixin LocalAudioManagementMixin on LocalTrack, AudioTrack { } return didUpdate; } + + Future onTrackStopped() async { + await _trackCounterLock.synchronized(() async { + _localTrackCount--; + await _onAudioTrackCountDidChange(); + }); + } + + Future onTrackStarted() async { + await _trackCounterLock.synchronized(() async { + _localTrackCount++; + await _onAudioTrackCountDidChange(); + }); + } } mixin RemoteAudioManagementMixin on RemoteTrack, AudioTrack { /// Start playing audio track. On web platform, create an audio element and diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 4151d64..3e88675 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -312,6 +312,10 @@ class Utils { case ConnectivityResult.ethernet: networkType = 'wired'; break; + case ConnectivityResult.vpn: + //TODO: will livekit-server handle vpn types correctly? + // networkType = 'vpn'; + break; case ConnectivityResult.none: networkType = 'empty'; break; diff --git a/macos/livekit_client.podspec b/macos/livekit_client.podspec index ebdaaaf..30e105e 100644 --- a/macos/livekit_client.podspec +++ b/macos/livekit_client.podspec @@ -16,5 +16,5 @@ Pod::Spec.new do |s| s.static_framework = true s.dependency 'FlutterMacOS' - s.dependency 'WebRTC-SDK', '~> 104.5112.03' + s.dependency 'WebRTC-SDK', '~> 104.5112.06' end diff --git a/pubspec.lock b/pubspec.lock index ac91303..7ce1c93 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "49.0.0" + version: "50.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "5.1.0" + version: "5.2.0" args: dependency: transitive description: @@ -56,7 +56,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: connectivity_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "1.2.3" connectivity_plus_web: dependency: transitive description: @@ -154,7 +154,7 @@ packages: name: dart_webrtc url: "https://pub.dartlang.org" source: hosted - version: "1.0.10" + version: "1.0.11" dbus: dependency: transitive description: @@ -260,14 +260,14 @@ packages: name: flutter_webrtc url: "https://pub.dartlang.org" source: hosted - version: "0.9.12" + version: "0.9.14" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" http: dependency: "direct main" description: @@ -302,7 +302,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: "direct main" description: @@ -372,7 +372,7 @@ packages: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.20" + version: "2.0.21" path_provider_ios: dependency: transitive description: @@ -414,7 +414,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "5.1.0" platform: dependency: transitive description: @@ -449,7 +449,7 @@ packages: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -552,14 +552,14 @@ packages: name: webrtc_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "1.0.10" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.1.1" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ea088fd..0d230ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,10 +23,10 @@ dependencies: uuid: ^3.0.6 synchronized: ^3.0.0+3 protobuf: ^2.1.0 - flutter_webrtc: 0.9.12 - dart_webrtc: 1.0.10 + flutter_webrtc: 0.9.14 + dart_webrtc: 1.0.11 device_info_plus: ^6.0.0 - webrtc_interface: 1.0.9 + webrtc_interface: 1.0.10 dev_dependencies: flutter_test: