Skip to content

Commit 65b69bb

Browse files
authored
Merge pull request #277 from cybex-dev/275-twiliocallplatformhangup-does-not-hang-up
275 TwilioCallPlatform.hangUp() does not hang up the call—the call still continues.
2 parents 2485e49 + 6227722 commit 65b69bb

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 0.3.1
22

3+
* 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)
34
* 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))
5+
* Docs: update CHANGELOG, TODO
46

57
## 0.3.0+1
68

TODO.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Project TODO
22

33
## Android Plugin
4-
* [TwilioVoicePlugin] Update documentation (and Permission annotations) where necessary
4+
* [TwilioVoicePlugin] Update documentation (and Permission annotations) where necessary
5+
6+
## Platform communication
7+
* Improve message handling between Flutter and native platforms for event channels

android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,8 +1682,8 @@ class TwilioVoicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamH
16821682
return
16831683
}
16841684
// callSid = null
1685-
Log.d(TAG, "handleBroadcastIntent: Call ended $callHandle")
1686-
logEvent("", "Call ended")
1685+
Log.d(TAG, "handleBroadcastIntent: Call Ended $callHandle")
1686+
logEvent("", "Call Ended")
16871687
}
16881688

16891689
TVBroadcastReceiver.ACTION_CALL_STATE -> {

android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnection.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ open class TVCallConnection(
494494
rejectInvite()
495495
} else {
496496
Log.d(TAG, "onDisconnected: onDisconnected")
497-
twilioCall.let {
498-
it?.disconnect()
499-
}
497+
twilioCall?.disconnect()
500498
onEvent?.onChange(TVNativeCallEvents.EVENT_DISCONNECTED_LOCAL, null)
501499
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
502500
onDisconnected?.withValue(DisconnectCause(DisconnectCause.LOCAL))

android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,36 @@ class TVConnectionService : ConnectionService() {
594594
}
595595
}
596596
}
597+
598+
599+
// Set call disconnected listener, removes connection from active connections when call is disconnected
600+
val onCallInitializingDisconnectedListener: CompletionHandler<DisconnectCause> = CompletionHandler {
601+
connection.twilioCall?.let {
602+
if (activeConnections.containsKey(it.sid)) {
603+
activeConnections.remove(it.sid)
604+
}
605+
sendBroadcastEvent(applicationContext, TVBroadcastReceiver.ACTION_CALL_ENDED, it.sid ?: "", connection.extras)
606+
stopForegroundService()
607+
stopSelfSafe()
608+
}
609+
}
610+
611+
// NOTE(cybex-dev): This could be used as an alternative to the [onCallInitializingDisconnectedListener],
612+
// however in the case of a call being initialized followed by a local disconnect - the call only has a temporary SID.
613+
// The call SID is set in the [attachCallEventListeners] method when the call is in a RINGING or CONNECTED state.
614+
// Thus, using [onEvent] will pass through a null call handle which may not be a good design.
615+
// val onEvent: ValueBundleChanged<String> = ValueBundleChanged { event: String?, extra: Bundle? ->
616+
// if(event == TVBroadcastReceiver.ACTION_CALL_ENDED) {
617+
// val callSid = connection.twilioCall?.sid;
618+
// sendBroadcastEvent(applicationContext, event ?: "", callSid, extra)
619+
// // 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.
620+
// sendBroadcastCallHandle(applicationContext, extra?.getString(TVBroadcastReceiver.EXTRA_CALL_HANDLE))
621+
// }
622+
// }
623+
597624
connection.setOnCallStateListener(onCallStateListener)
625+
connection.setOnCallDisconnected(onCallInitializingDisconnectedListener)
626+
// connection.setOnCallEventListener(onEvent)
598627

599628
// Setup connection UI parameters
600629
connection.setInitializing()

0 commit comments

Comments
 (0)