From 6f4bc290c5f6436cea9bc4458b75f82c3ead5688 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 20 Oct 2026 10:54:59 +0300 Subject: [PATCH] turn speaker on in video call. --- .../cx_module/chat/calling/call_provider.dart | 16 ++++++++++++++++ .../cx_module/chat/calling/webrtc_service.dart | 3 +++ 2 files changed, 19 insertions(+) diff --git a/lib/modules/cx_module/chat/calling/call_provider.dart b/lib/modules/cx_module/chat/calling/call_provider.dart index 6252e3fd..f069cc26 100644 --- a/lib/modules/cx_module/chat/calling/call_provider.dart +++ b/lib/modules/cx_module/chat/calling/call_provider.dart @@ -88,6 +88,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin { onSuccess = null; isMuted = false; isPeerMuted = false; + isSpeakerOn = false; // `CallProvider` is a long-lived singleton (registered once in main.dart), // so without resetting these here, toggling the camera off near the end // of one video call would leak into the *next* call, making it look like @@ -176,6 +177,9 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin { case RTCIceConnectionState.RTCIceConnectionStateConnected: case RTCIceConnectionState.RTCIceConnectionStateCompleted: if (currentStatus != "Connected") { + // The OS resets the audio route to the earpiece once media + // actually starts flowing, so re-apply it on connect. + _applyDefaultAudioRoute(); _setStatus("Connected"); _startCallDurationTimer(); } @@ -201,11 +205,23 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin { // on this singleton CallProvider (see endSession()). isCameraOn = true; isPeerCameraOn = true; + isSpeakerOn = true; await _webRTCService.initializeForVideoCall(); _webRTCService.setCameraEnabled(true); notifyListeners(); } else { + isSpeakerOn = false; await _webRTCService.initializeForAudioCall(); + notifyListeners(); + } + } + + void _applyDefaultAudioRoute() { + if (isVideo == true) { + isSpeakerOn = true; + _webRTCService.setSpeakerphoneEnabled(true); + } else { + _webRTCService.setSpeakerphoneEnabled(isSpeakerOn); } } diff --git a/lib/modules/cx_module/chat/calling/webrtc_service.dart b/lib/modules/cx_module/chat/calling/webrtc_service.dart index a764c0ff..2fffd1c5 100644 --- a/lib/modules/cx_module/chat/calling/webrtc_service.dart +++ b/lib/modules/cx_module/chat/calling/webrtc_service.dart @@ -269,6 +269,9 @@ class WebRTCService { ); } + // Video calls should use the loudspeaker, not the earpiece. + await setSpeakerphoneEnabled(true); + _isFullyInitialized = true; if (!_initializationCompleter!.isCompleted) {