Skip to content

Commit 68363e9

Browse files
committed
Merge branch 'fix_android_on_call_decline'
2 parents e850ecf + 9dc423a commit 68363e9

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Next Release
2+
3+
* Fix: [Android] `call.isOnCall()` returns true when call is declined
4+
* Fix: [Android] handle reject vs error disconnect cause with message.
5+
* Logging: [Android] Added error code fallback
6+
17
## 0.2.2
28

39
* Fix: [Android] Fix cancelling call when app is in background throws [BackgroundServiceStartNotAllowedException](https://developer.android.com/reference/android/app/BackgroundServiceStartNotAllowedException). [Issue #204](https://github.com/cybex-dev/twilio_voice/issues/204)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,11 @@ class TwilioVoicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamH
18271827
}
18281828

18291829
TVNativeCallEvents.EVENT_CONNECT_FAILURE -> {
1830-
val code = intent.getIntExtra(CallExceptionExtension.EXTRA_CODE, -1)
1830+
var code = intent.getIntExtra(CallExceptionExtension.EXTRA_CODE, -1)
1831+
if(code == -1) {
1832+
// Fallback to the old code
1833+
code = intent.getIntExtra("code", -1)
1834+
}
18311835
val message = intent.getStringExtra(CallExceptionExtension.EXTRA_MESSAGE) ?: run {
18321836
Log.e(TAG, "No 'EXTRA_MESSAGE' provided or invalid type")
18331837
return

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,17 @@ open class TVCallConnection(
146146
override fun onConnectFailure(call: Call, callException: CallException) {
147147
Log.d(TAG, "onConnectFailure: onConnectFailure")
148148
twilioCall = null
149-
[email protected](DisconnectCause(DisconnectCause.ERROR, callException.message))
149+
val rejectedErrorCodeList = listOf(
150+
31600, // Call invite rejected
151+
)
152+
val disconnectCauseCode = if (rejectedErrorCodeList.contains(callException.errorCode)) {
153+
DisconnectCause.REJECTED
154+
} else {
155+
DisconnectCause.ERROR
156+
}
157+
val disconnectCause = DisconnectCause(disconnectCauseCode, callException.message);
158+
[email protected](disconnectCause)
159+
onDisconnected?.withValue(disconnectCause)
150160
onEvent?.onChange(TVNativeCallEvents.EVENT_CONNECT_FAILURE, callException.toBundle())
151161
onCallStateListener?.withValue(call.state)
152162
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@ class TVConnectionService : ConnectionService() {
630630
stopForegroundService()
631631
stopSelfSafe()
632632
}
633+
val onCallState: CompletionHandler<Call.State> = CompletionHandler { state ->
634+
if (state == Call.State.DISCONNECTED) {
635+
if (activeConnections.containsKey(callSid)) {
636+
activeConnections.remove(callSid)
637+
}
638+
stopForegroundService()
639+
stopSelfSafe()
640+
}
641+
}
633642

634643
// Add to local connection cache
635644
activeConnections[callSid] = connection
@@ -638,6 +647,7 @@ class TVConnectionService : ConnectionService() {
638647
connection.setOnCallActionListener(onAction)
639648
connection.setOnCallEventListener(onEvent)
640649
connection.setOnCallDisconnected(onDisconnect)
650+
connection.setOnCallStateListener(onCallState);
641651
}
642652

643653
/**

0 commit comments

Comments
 (0)