fix: android prompt "Failed to stop voice call" on conn ended (#8434)

* fix: android prompt "Failed to stop voice call" on conn ended

Signed-off-by: fufesou <linlong1266@gmail.com>

* Remove invalid comment

Signed-off-by: fufesou <linlong1266@gmail.com>

* Better control of voice call status

Signed-off-by: fufesou <linlong1266@gmail.com>

* Better voice call status control

Signed-off-by: fufesou <linlong1266@gmail.com>

* better end conn for voice call

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-06-21 16:43:54 +08:00 committed by GitHub
parent 32c4712d5e
commit 74cc5abd09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 14 deletions

View File

@ -119,21 +119,17 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return false return false
} }
if (isVideoStart() || isAudioStart()) { // No need to check if video or audio is started here.
if (!switchToVoiceCall(mediaProjection)) { if (!switchToVoiceCall(mediaProjection)) {
return false return false
} }
} else {
if (!switchToVoiceCall(mediaProjection)) {
return false
}
}
return true return true
} }
fun onVoiceCallClosed(mediaProjection: MediaProjection?): Boolean { fun onVoiceCallClosed(mediaProjection: MediaProjection?): Boolean {
// Return true if `Build.VERSION.SDK_INT < Build.VERSION_CODES.R`, because is was not started.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return false return true
} }
if (isVideoStart()) { if (isVideoStart()) {
switchOutVoiceCall(mediaProjection) switchOutVoiceCall(mediaProjection)

View File

@ -105,11 +105,10 @@ class _RemotePageState extends State<RemotePage> {
} }
await keyboardSubscription.cancel(); await keyboardSubscription.cancel();
removeSharedStates(widget.id); removeSharedStates(widget.id);
if (isAndroid) { // `on_voice_call_closed` should be called when the connection is ended.
// The inner logic of `on_voice_call_closed` will check if the voice call is active.
// Only one client is considered here for now. // Only one client is considered here for now.
// TODO: take into account the case where there are multiple clients gFFI.chatModel.onVoiceCallClosed("End connetion");
gFFI.invokeMethod("on_voice_call_closed");
}
} }
// to-do: It should be better to use transparent color instead of the bgColor. // to-do: It should be better to use transparent color instead of the bgColor.

View File

@ -535,6 +535,8 @@ class ChatModel with ChangeNotifier {
void onVoiceCallClosed(String reason) { void onVoiceCallClosed(String reason) {
_voiceCallStatus.value = VoiceCallStatus.notStarted; _voiceCallStatus.value = VoiceCallStatus.notStarted;
if (isAndroid) { if (isAndroid) {
// We can always invoke "on_voice_call_closed"
// no matter if the `_voiceCallStatus` was `VoiceCallStatus.notStarted` or not.
parent.target?.invokeMethod("on_voice_call_closed"); parent.target?.invokeMethod("on_voice_call_closed");
} }
} }