Skip to content

Commit 64d9ebe

Browse files
authored
Merge pull request #156 from cybex-dev/feat_android_connection_service
Fix call not disconnecting immediately after answering
2 parents 23567cc + 3e1fbca commit 64d9ebe

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TVCallInviteConnection(
4242
}
4343

4444
override fun onAnswer() {
45+
Log.d(TAG, "onAnswer: onAnswer")
4546
super.onAnswer()
4647
twilioCall = callInvite.accept(context, this)
4748
onAction?.onChange(TVNativeCallActions.ACTION_ANSWERED, Bundle().apply {
@@ -51,16 +52,24 @@ class TVCallInviteConnection(
5152
}
5253

5354
fun acceptInvite() {
55+
Log.d(TAG, "acceptInvite: acceptInvite")
5456
onAnswer()
5557
}
5658

5759
fun rejectInvite() {
60+
Log.d(TAG, "rejectInvite: rejectInvite")
5861
onReject()
5962
}
6063

6164
override fun onReject() {
65+
Log.d(TAG, "onReject: onReject")
6266
super.onReject()
6367
callInvite.reject(context)
68+
// if the call was answered, then immediately rejected/ended, we need to disconnect the call also
69+
twilioCall?.let {
70+
Log.d(TAG, "onReject: disconnecting call")
71+
it.disconnect()
72+
}
6473
onEvent?.onChange(TVNativeCallEvents.EVENT_DISCONNECTED_LOCAL, null)
6574
onDisconnected?.withValue(DisconnectCause(DisconnectCause.REJECTED))
6675
onAction?.onChange(TVNativeCallActions.ACTION_REJECTED, null)
@@ -308,12 +317,14 @@ open class TVCallConnection(
308317
override fun onReject(rejectReason: Int) {
309318
Log.d(TAG, "onReject: onReject $rejectReason")
310319
super.onReject(rejectReason)
320+
twilioCall?.disconnect()
311321
onAction?.onChange(TVNativeCallActions.ACTION_REJECTED, null)
312322
}
313323

314324
override fun onReject(replyMessage: String?) {
315325
Log.d(TAG, "onReject: onReject $replyMessage")
316326
super.onReject(replyMessage)
327+
twilioCall?.disconnect()
317328
onAction?.onChange(TVNativeCallActions.ACTION_REJECTED, Bundle().apply {
318329
putString(TVNativeCallActions.EXTRA_REJECT_REASON, replyMessage)
319330
})
@@ -456,6 +467,7 @@ open class TVCallConnection(
456467
* Otherwise, disconnect the call using [Call.disconnect] with [DisconnectCause.LOCAL]
457468
*/
458469
fun disconnect() {
470+
Log.d(TAG, "disconnect: disconnect")
459471
if (this is TVCallInviteConnection && state == STATE_RINGING) {
460472
rejectInvite()
461473
} else {

0 commit comments

Comments
 (0)