diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/call/CallManager.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/call/CallManager.kt index 08a3ec779..7c10f9c9c 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/call/CallManager.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/call/CallManager.kt @@ -140,20 +140,10 @@ class CallManager( _state.value = CallState.Connecting(current.callId, current.peerPubKeys(), current.callType) cancelTimeout() - if (current.groupMembers.size > 2) { - // Group call: include all members in p-tags, sign once, wrap for each. - // Include self so other devices get notified too. - val allRecipients = current.groupMembers + signer.pubKey - 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) - } + // Include all group members + self so other devices get notified too. + val allRecipients = current.groupMembers + signer.pubKey + val result = factory.createGroupCallAnswer(sdpAnswer, allRecipients, current.callId, signer) + result.wraps.forEach { publishEvent(it) } } suspend fun rejectCall() { @@ -162,20 +152,10 @@ class CallManager( transitionToEnded(current.callId, current.peerPubKeys(), EndReason.REJECTED) - if (current.groupMembers.size > 2) { - // Group call: include all members in p-tags, sign once, wrap for each. - // Include self so other devices get notified too. - val allRecipients = current.groupMembers + signer.pubKey - 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) - } + // Include all group members + self so other devices get notified too. + val allRecipients = current.groupMembers + signer.pubKey + val result = factory.createGroupReject(allRecipients, current.callId, signer = signer) + result.wraps.forEach { publishEvent(it) } } fun onCallAnswered(event: CallAnswerEvent) { @@ -310,20 +290,14 @@ class CallManager( ) { val callId = currentCallId() ?: return val peerPubKeys = currentPeerPubKeys() ?: return - - val result = - if (peerPubKeys.size > 1) { - factory.createRenegotiate(sdpOffer, peerPubKey, peerPubKeys, callId, signer) - } else { - factory.createRenegotiate(sdpOffer, peerPubKey, callId, signer) - } + val result = factory.createRenegotiate(sdpOffer, peerPubKey, peerPubKeys, callId, signer) publishEvent(result.wrap) } /** * 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 - * event includes `p` tags for all members for group context. + * so this is always addressed to a single peer. The inner event includes + * `p` tags for all members for group context. */ suspend fun sendRenegotiationAnswer( sdpAnswer: String, @@ -331,13 +305,7 @@ class CallManager( ) { val callId = currentCallId() ?: return val peerPubKeys = currentPeerPubKeys() ?: return - - val result = - if (peerPubKeys.size > 1) { - factory.createCallAnswer(sdpAnswer, peerPubKey, peerPubKeys, callId, signer) - } else { - factory.createCallAnswer(sdpAnswer, peerPubKey, callId, signer) - } + val result = factory.createCallAnswer(sdpAnswer, peerPubKey, peerPubKeys, callId, signer) publishEvent(result.wrap) } @@ -418,13 +386,8 @@ class CallManager( } } - if (peerPubKeys.size == 1) { - val result = factory.createHangup(peerPubKeys.first(), callId, signer = signer) - publishEvent(result.wrap) - } else { - val result = factory.createGroupHangup(peerPubKeys, callId, signer = signer) - result.wraps.forEach { publishEvent(it) } - } + val result = factory.createGroupHangup(peerPubKeys, callId, signer = signer) + result.wraps.forEach { publishEvent(it) } transitionToEnded(callId, peerPubKeys, EndReason.HANGUP) }