refactor: remove P2P vs group branching in CallManager
The group factory methods work correctly with any number of members, including single-peer calls. Remove the if/else branches that duplicated P2P vs group logic in acceptCall, rejectCall, hangup, sendRenegotiation, and sendRenegotiationAnswer. https://claude.ai/code/session_013h2E7spwHDgSjunqumsYgp
This commit is contained in:
+14
-51
@@ -140,20 +140,10 @@ class CallManager(
|
|||||||
_state.value = CallState.Connecting(current.callId, current.peerPubKeys(), current.callType)
|
_state.value = CallState.Connecting(current.callId, current.peerPubKeys(), current.callType)
|
||||||
cancelTimeout()
|
cancelTimeout()
|
||||||
|
|
||||||
if (current.groupMembers.size > 2) {
|
// Include all group members + self so other devices get notified too.
|
||||||
// Group call: include all members in p-tags, sign once, wrap for each.
|
val allRecipients = current.groupMembers + signer.pubKey
|
||||||
// Include self so other devices get notified too.
|
val result = factory.createGroupCallAnswer(sdpAnswer, allRecipients, current.callId, signer)
|
||||||
val allRecipients = current.groupMembers + signer.pubKey
|
result.wraps.forEach { publishEvent(it) }
|
||||||
val result = factory.createGroupCallAnswer(sdpAnswer, allRecipients, current.callId, signer)
|
|
||||||
result.wraps.forEach { publishEvent(it) }
|
|
||||||
} else {
|
|
||||||
val result = factory.createCallAnswer(sdpAnswer, current.callerPubKey, current.callId, signer)
|
|
||||||
publishEvent(result.wrap)
|
|
||||||
|
|
||||||
// Notify other devices of this user that the call was answered here.
|
|
||||||
val selfNotify = factory.createCallAnswer(sdpAnswer, signer.pubKey, current.callId, signer)
|
|
||||||
publishEvent(selfNotify.wrap)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun rejectCall() {
|
suspend fun rejectCall() {
|
||||||
@@ -162,20 +152,10 @@ class CallManager(
|
|||||||
|
|
||||||
transitionToEnded(current.callId, current.peerPubKeys(), EndReason.REJECTED)
|
transitionToEnded(current.callId, current.peerPubKeys(), EndReason.REJECTED)
|
||||||
|
|
||||||
if (current.groupMembers.size > 2) {
|
// Include all group members + self so other devices get notified too.
|
||||||
// Group call: include all members in p-tags, sign once, wrap for each.
|
val allRecipients = current.groupMembers + signer.pubKey
|
||||||
// Include self so other devices get notified too.
|
val result = factory.createGroupReject(allRecipients, current.callId, signer = signer)
|
||||||
val allRecipients = current.groupMembers + signer.pubKey
|
result.wraps.forEach { publishEvent(it) }
|
||||||
val result = factory.createGroupReject(allRecipients, current.callId, signer = signer)
|
|
||||||
result.wraps.forEach { publishEvent(it) }
|
|
||||||
} else {
|
|
||||||
val result = factory.createReject(current.callerPubKey, current.callId, signer = signer)
|
|
||||||
publishEvent(result.wrap)
|
|
||||||
|
|
||||||
// Notify other devices of this user that the call was rejected here.
|
|
||||||
val selfNotify = factory.createReject(signer.pubKey, current.callId, signer = signer)
|
|
||||||
publishEvent(selfNotify.wrap)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCallAnswered(event: CallAnswerEvent) {
|
fun onCallAnswered(event: CallAnswerEvent) {
|
||||||
@@ -310,20 +290,14 @@ class CallManager(
|
|||||||
) {
|
) {
|
||||||
val callId = currentCallId() ?: return
|
val callId = currentCallId() ?: return
|
||||||
val peerPubKeys = currentPeerPubKeys() ?: return
|
val peerPubKeys = currentPeerPubKeys() ?: return
|
||||||
|
val result = factory.createRenegotiate(sdpOffer, peerPubKey, peerPubKeys, callId, signer)
|
||||||
val result =
|
|
||||||
if (peerPubKeys.size > 1) {
|
|
||||||
factory.createRenegotiate(sdpOffer, peerPubKey, peerPubKeys, callId, signer)
|
|
||||||
} else {
|
|
||||||
factory.createRenegotiate(sdpOffer, peerPubKey, callId, signer)
|
|
||||||
}
|
|
||||||
publishEvent(result.wrap)
|
publishEvent(result.wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a renegotiation answer to a specific peer. SDP is per-PeerConnection
|
* Sends a renegotiation answer to a specific peer. SDP is per-PeerConnection
|
||||||
* so this is always addressed to a single peer. In group calls the inner
|
* so this is always addressed to a single peer. The inner event includes
|
||||||
* event includes `p` tags for all members for group context.
|
* `p` tags for all members for group context.
|
||||||
*/
|
*/
|
||||||
suspend fun sendRenegotiationAnswer(
|
suspend fun sendRenegotiationAnswer(
|
||||||
sdpAnswer: String,
|
sdpAnswer: String,
|
||||||
@@ -331,13 +305,7 @@ class CallManager(
|
|||||||
) {
|
) {
|
||||||
val callId = currentCallId() ?: return
|
val callId = currentCallId() ?: return
|
||||||
val peerPubKeys = currentPeerPubKeys() ?: return
|
val peerPubKeys = currentPeerPubKeys() ?: return
|
||||||
|
val result = factory.createCallAnswer(sdpAnswer, peerPubKey, peerPubKeys, callId, signer)
|
||||||
val result =
|
|
||||||
if (peerPubKeys.size > 1) {
|
|
||||||
factory.createCallAnswer(sdpAnswer, peerPubKey, peerPubKeys, callId, signer)
|
|
||||||
} else {
|
|
||||||
factory.createCallAnswer(sdpAnswer, peerPubKey, callId, signer)
|
|
||||||
}
|
|
||||||
publishEvent(result.wrap)
|
publishEvent(result.wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,13 +386,8 @@ class CallManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peerPubKeys.size == 1) {
|
val result = factory.createGroupHangup(peerPubKeys, callId, signer = signer)
|
||||||
val result = factory.createHangup(peerPubKeys.first(), callId, signer = signer)
|
result.wraps.forEach { publishEvent(it) }
|
||||||
publishEvent(result.wrap)
|
|
||||||
} else {
|
|
||||||
val result = factory.createGroupHangup(peerPubKeys, callId, signer = signer)
|
|
||||||
result.wraps.forEach { publishEvent(it) }
|
|
||||||
}
|
|
||||||
transitionToEnded(callId, peerPubKeys, EndReason.HANGUP)
|
transitionToEnded(callId, peerPubKeys, EndReason.HANGUP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user