fix: stop audio track on mute. (#207)

* fix: stop audio track on mute.

* chore: Let audioBitrate preset to music.

* update.

* update depends.

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