From ffe1946ab96ccb1251311d013e0c7b73003c6b73 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 9 Apr 2026 18:05:34 +0300 Subject: [PATCH] Pass bevent to "call update" event and use to stop bevent when call update is skipped Prevent other conference calls from closing when one participant hangs up --- app/src/main/cpp/baresip.c | 2 +- app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt | 5 +++-- .../main/kotlin/com/tutpro/baresip/ConnectionService.kt | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 80714900..0ea6110d 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -210,7 +210,7 @@ static void event_handler(enum bevent_ev ev, struct bevent *event, void *arg) break; case BEVENT_CALL_REMOTE_SDP: ardir = sdp_media_rdir(stream_sdpmedia(audio_strm(call_audio(call)))); - len = re_snprintf(event_buf, sizeof event_buf, "call update,%d", ardir); + len = re_snprintf(event_buf, sizeof event_buf, "call update,%d,%ld", ardir, (long)event); break; case BEVENT_CALL_MENC: if (prm[0] == '0') diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 243fb147..0704a936 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -802,7 +802,6 @@ class BaresipService: Service() { } "incoming call" -> { val peerUri = ev[1] - val bevent = ev[2].toLong() val toastMsg = if (Call.isAnyCallActive(applicationContext)) String.format(getString(R.string.call_auto_rejected), Utils.friendlyUri(this, peerUri, ua.account)) @@ -816,7 +815,7 @@ class BaresipService: Service() { if (toastMsg != "") { Log.d(TAG, "Auto-rejecting incoming call to $uap from $peerUri") Api.sip_treply(callp, 486, "Busy Here") - Api.bevent_stop(bevent) + Api.bevent_stop(ev[2].toLong()) toast(toastMsg) if (toastMsg.contains(getString(R.string.call_blocked))) { if (ua.account.callHistory) @@ -892,6 +891,7 @@ class BaresipService: Service() { "call update" -> { if (call!!.conferenceCall) { Log.d(TAG, "Refusing to update conference call ${call.callp}") + Api.bevent_stop(ev[2].toLong()) return } val newHeldState = when (ev[1].toInt()) {Api.SDP_INACTIVE, Api.SDP_RECVONLY -> true @@ -1002,6 +1002,7 @@ class BaresipService: Service() { } "call closed" -> { Log.d(TAG, "AoR $aor call $callp is closed prm: ${ev[1]}") + ConnectionService.lastDisconnectTime = System.currentTimeMillis() val connection = ConnectionService.connections[callp] if (connection != null) { val cause = when { diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt index 9d13b109..a33f2aa6 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt @@ -18,6 +18,7 @@ class ConnectionService : ConnectionService() { companion object { val connections = ConcurrentHashMap() var pendingOutgoingConnection: BaresipConnection? = null + var lastDisconnectTime = 0L fun promoteOutgoingConnection(callp: Long) { pendingOutgoingConnection?.let { @@ -159,8 +160,16 @@ class ConnectionService : ConnectionService() { override fun onDisconnect() { if (isDisconnecting) return + + if (System.currentTimeMillis() - lastDisconnectTime < 500) { + Log.d(TAG, "Ignoring cascaded onDisconnect for $callp") + return + } + Log.d(TAG, "Telecom Connection onDisconnect $callp") isDisconnecting = true + lastDisconnectTime = System.currentTimeMillis() + if (callp == 0L) { pendingOutgoingConnection = null setDisconnected(DisconnectCause(DisconnectCause.CANCELED))