Skip to content

Commit

Permalink
fix: bug for speakerPhone switch. (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Dec 30, 2024
1 parent 5b94128 commit 27d7453
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 7 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ void main() async {
});
}

/// for livestreaming app, you can initialize the bypassVoiceProcessing = true
/// here to get better audio quality
///
/// await LiveKitClient.initialize(
/// bypassVoiceProcessing: lkPlatformIsMobile(),
/// );
runApp(const LiveKitExampleApp());
}

Expand Down
6 changes: 2 additions & 4 deletions example/lib/widgets/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {

StreamSubscription? _subscription;

bool _speakerphoneOn = Hardware.instance.preferSpeakerOutput;
bool _speakerphoneOn = Hardware.instance.speakerOn ?? false;

@override
void initState() {
Expand Down Expand Up @@ -396,9 +396,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {
if (!kIsWeb && lkPlatformIsMobile())
IconButton(
disabledColor: Colors.grey,
onPressed: Hardware.instance.canSwitchSpeakerphone
? _setSpeakerphoneOn
: null,
onPressed: _setSpeakerphoneOn,
icon: Icon(
_speakerphoneOn ? Icons.speaker_phone : Icons.phone_android),
tooltip: 'Switch SpeakerPhone',
Expand Down
5 changes: 2 additions & 3 deletions lib/src/hardware/hardware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Hardware {

bool? speakerOn;

bool _preferSpeakerOutput = true;
bool _preferSpeakerOutput = false;

Future<List<MediaDevice>> enumerateDevices({String? type}) async {
var infos = await rtc.navigator.mediaDevices.enumerateDevices();
Expand Down Expand Up @@ -146,8 +146,7 @@ class Hardware {
bool get preferSpeakerOutput => _preferSpeakerOutput;

bool get canSwitchSpeakerphone =>
((lkPlatformIs(PlatformType.iOS) && !_preferSpeakerOutput) ||
lkPlatformIs(PlatformType.android)) &&
(lkPlatformIsMobile()) &&
[AudioTrackState.localOnly, AudioTrackState.localAndRemote]
.contains(audioTrackState);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
uuid: '>=3.0.6'
synchronized: ^3.0.0+3
protobuf: ^3.0.0
flutter_webrtc: ^0.12.5+hotfix.1
flutter_webrtc: ^0.12.5+hotfix.2
device_info_plus: ^11.1.1
js: '>=0.6.4'
platform_detect: ^2.0.7
Expand Down

0 comments on commit 27d7453

Please sign in to comment.