diff --git a/CHANGELOG.md b/CHANGELOG.md index e3b478c2..c91f85ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.3.1 +* Fix: [Android] placing outgoing call then ending immediately results in no Flutter plugin not registering call ended. Thanks to [@RageshAntonyHM](https://github.com/RageshAntonyHM) & [@Erchil66](https://github.com/Erchil66) [Issue #275](https://github.com/cybex-dev/twilio_voice/issues/275) * Fix: [Android] Migrate to declarative plugins block from Flutter's `app_plugin_loader` Gradle plugin. (see: [Deprecated imperative apply of Flutter's Gradle plugins](https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply)) +* Docs: update CHANGELOG, TODO ## 0.3.0+1 diff --git a/TODO.md b/TODO.md index 907cd8d5..b3574a22 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,7 @@ # Project TODO ## Android Plugin - * [TwilioVoicePlugin] Update documentation (and Permission annotations) where necessary \ No newline at end of file + * [TwilioVoicePlugin] Update documentation (and Permission annotations) where necessary + +## Platform communication + * Improve message handling between Flutter and native platforms for event channels \ No newline at end of file diff --git a/android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt b/android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt index 4e48eadc..726d7a3e 100644 --- a/android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt +++ b/android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt @@ -1682,8 +1682,8 @@ class TwilioVoicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamH return } // callSid = null - Log.d(TAG, "handleBroadcastIntent: Call ended $callHandle") - logEvent("", "Call ended") + Log.d(TAG, "handleBroadcastIntent: Call Ended $callHandle") + logEvent("", "Call Ended") } TVBroadcastReceiver.ACTION_CALL_STATE -> { diff --git a/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnection.kt b/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnection.kt index 0abcceea..adeb7f75 100644 --- a/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnection.kt +++ b/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnection.kt @@ -494,9 +494,7 @@ open class TVCallConnection( rejectInvite() } else { Log.d(TAG, "onDisconnected: onDisconnected") - twilioCall.let { - it?.disconnect() - } + twilioCall?.disconnect() onEvent?.onChange(TVNativeCallEvents.EVENT_DISCONNECTED_LOCAL, null) setDisconnected(DisconnectCause(DisconnectCause.LOCAL)) onDisconnected?.withValue(DisconnectCause(DisconnectCause.LOCAL)) diff --git a/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt b/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt index 2751d1fd..0446b52e 100644 --- a/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt +++ b/android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt @@ -594,7 +594,36 @@ class TVConnectionService : ConnectionService() { } } } + + + // Set call disconnected listener, removes connection from active connections when call is disconnected + val onCallInitializingDisconnectedListener: CompletionHandler = CompletionHandler { + connection.twilioCall?.let { + if (activeConnections.containsKey(it.sid)) { + activeConnections.remove(it.sid) + } + sendBroadcastEvent(applicationContext, TVBroadcastReceiver.ACTION_CALL_ENDED, it.sid ?: "", connection.extras) + stopForegroundService() + stopSelfSafe() + } + } + + // NOTE(cybex-dev): This could be used as an alternative to the [onCallInitializingDisconnectedListener], + // however in the case of a call being initialized followed by a local disconnect - the call only has a temporary SID. + // The call SID is set in the [attachCallEventListeners] method when the call is in a RINGING or CONNECTED state. + // Thus, using [onEvent] will pass through a null call handle which may not be a good design. +// val onEvent: ValueBundleChanged = ValueBundleChanged { event: String?, extra: Bundle? -> +// if(event == TVBroadcastReceiver.ACTION_CALL_ENDED) { +// val callSid = connection.twilioCall?.sid; +// sendBroadcastEvent(applicationContext, event ?: "", callSid, extra) +// // This is a temporary solution since `isOnCall` returns true when there is an active ConnectionService, regardless of the source app. This also applies to SIM/Telecom calls. +// sendBroadcastCallHandle(applicationContext, extra?.getString(TVBroadcastReceiver.EXTRA_CALL_HANDLE)) +// } +// } + connection.setOnCallStateListener(onCallStateListener) + connection.setOnCallDisconnected(onCallInitializingDisconnectedListener) +// connection.setOnCallEventListener(onEvent) // Setup connection UI parameters connection.setInitializing()