fix: clean up rejected peer's PeerSession to prevent stale sessions blocking hangup

When a peer rejects a group call, CallManager updated its state but never
notified CallController to dispose the peer's PeerSession. This caused two
issues:

1. The rejected peer's PeerConnection lingered in HAVE_LOCAL_OFFER state
   until the entire call ended (resource leak visible as "disposing 2 peer
   sessions" when only 1 should exist).

2. In onPeerDisconnected, the allDisconnected check required ALL sessions
   to be CLOSED. The stale session blocked this check, preventing automatic
   hangup when ICE failed — meaning the remote peer never received a hangup
   event and kept ringing.

Fix: invoke onPeerLeft when a peer rejects in Offering/Connecting/Connected
states, and make onPeerDisconnected treat sessions without a remote
description as inactive.

https://claude.ai/code/session_01UXaFKmHVPDyTzfHL8fkSw1
This commit is contained in:
Claude
2026-04-03 19:33:30 +00:00
parent 35a1a20bde
commit 303e68331a
2 changed files with 11 additions and 3 deletions
@@ -349,6 +349,7 @@ class CallManager(
transitionToEnded(current.callId, current.peerPubKeys, EndReason.PEER_REJECTED)
} else {
_state.value = current.copy(peerPubKeys = remaining)
onPeerLeft?.invoke(rejectingPeer)
}
}
@@ -356,12 +357,14 @@ class CallManager(
if (callId != current.callId) return
_state.value =
current.copy(pendingPeerPubKeys = current.pendingPeerPubKeys - rejectingPeer)
onPeerLeft?.invoke(rejectingPeer)
}
is CallState.Connected -> {
if (callId != current.callId) return
_state.value =
current.copy(pendingPeerPubKeys = current.pendingPeerPubKeys - rejectingPeer)
onPeerLeft?.invoke(rejectingPeer)
}
is CallState.IncomingCall -> {