mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 09:37:25 +00:00
fix: fixing call connect flows
This commit is contained in:
@@ -13,8 +13,6 @@ import android.telephony.PhoneStateListener
|
|||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.session.libsession.messaging.messages.control.CallMessage
|
|
||||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
|
||||||
import org.session.libsession.utilities.Address
|
import org.session.libsession.utilities.Address
|
||||||
import org.session.libsession.utilities.FutureTaskListener
|
import org.session.libsession.utilities.FutureTaskListener
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
@@ -113,13 +111,14 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
|
|||||||
.putExtra(EXTRA_CALL_ID, callId)
|
.putExtra(EXTRA_CALL_ID, callId)
|
||||||
.putExtra(EXTRA_REMOTE_DESCRIPTION, sdp)
|
.putExtra(EXTRA_REMOTE_DESCRIPTION, sdp)
|
||||||
|
|
||||||
fun iceCandidates(context: Context, iceCandidates: List<IceCandidate>, callId: UUID) =
|
fun iceCandidates(context: Context, address: Address, iceCandidates: List<IceCandidate>, callId: UUID) =
|
||||||
Intent(context, WebRtcCallService::class.java)
|
Intent(context, WebRtcCallService::class.java)
|
||||||
.setAction(ACTION_ICE_MESSAGE)
|
.setAction(ACTION_ICE_MESSAGE)
|
||||||
.putExtra(EXTRA_CALL_ID, callId)
|
.putExtra(EXTRA_CALL_ID, callId)
|
||||||
.putExtra(EXTRA_ICE_SDP, iceCandidates.map(IceCandidate::sdp).toTypedArray())
|
.putExtra(EXTRA_ICE_SDP, iceCandidates.map(IceCandidate::sdp).toTypedArray())
|
||||||
.putExtra(EXTRA_ICE_SDP_LINE_INDEX, iceCandidates.map(IceCandidate::sdpMLineIndex).toIntArray())
|
.putExtra(EXTRA_ICE_SDP_LINE_INDEX, iceCandidates.map(IceCandidate::sdpMLineIndex).toIntArray())
|
||||||
.putExtra(EXTRA_ICE_SDP_MID, iceCandidates.map(IceCandidate::sdpMid).toTypedArray())
|
.putExtra(EXTRA_ICE_SDP_MID, iceCandidates.map(IceCandidate::sdpMid).toTypedArray())
|
||||||
|
.putExtra(EXTRA_RECIPIENT_ADDRESS, address)
|
||||||
|
|
||||||
fun denyCallIntent(context: Context) = Intent(context, WebRtcCallService::class.java).setAction(ACTION_DENY_CALL)
|
fun denyCallIntent(context: Context) = Intent(context, WebRtcCallService::class.java).setAction(ACTION_DENY_CALL)
|
||||||
|
|
||||||
@@ -283,8 +282,8 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
setCallInProgressNotification(TYPE_INCOMING_RINGING, recipient)
|
setCallInProgressNotification(TYPE_INCOMING_RINGING, recipient)
|
||||||
}
|
}
|
||||||
callManager.onIncomingRing(offer, callId, recipient, timestamp)
|
|
||||||
callManager.clearPendingIceUpdates()
|
callManager.clearPendingIceUpdates()
|
||||||
|
callManager.onIncomingRing(offer, callId, recipient, timestamp)
|
||||||
callManager.postConnectionEvent(STATE_LOCAL_RINGING)
|
callManager.postConnectionEvent(STATE_LOCAL_RINGING)
|
||||||
if (TextSecurePreferences.isCallNotificationsEnabled(this)) {
|
if (TextSecurePreferences.isCallNotificationsEnabled(this)) {
|
||||||
callManager.startIncomingRinger()
|
callManager.startIncomingRinger()
|
||||||
@@ -481,7 +480,7 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
|
|||||||
|
|
||||||
private fun handleIceConnected(intent: Intent) {
|
private fun handleIceConnected(intent: Intent) {
|
||||||
val recipient = callManager.recipient ?: return
|
val recipient = callManager.recipient ?: return
|
||||||
if (callManager.currentConnectionState in arrayOf(STATE_ANSWERING, STATE_LOCAL_RINGING)) {
|
if (callManager.currentConnectionState in arrayOf(STATE_ANSWERING, STATE_DIALING)) {
|
||||||
callManager.postConnectionEvent(STATE_CONNECTED)
|
callManager.postConnectionEvent(STATE_CONNECTED)
|
||||||
callManager.postViewModelState(CallViewModel.State.CALL_CONNECTED)
|
callManager.postViewModelState(CallViewModel.State.CALL_CONNECTED)
|
||||||
} else {
|
} else {
|
||||||
@@ -646,7 +645,7 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
|
|||||||
startService(intent)
|
startService(intent)
|
||||||
} else if (newState == FAILED) {
|
} else if (newState == FAILED) {
|
||||||
val intent = Intent(this, WebRtcCallService::class.java)
|
val intent = Intent(this, WebRtcCallService::class.java)
|
||||||
.setAction(ACTION_REMOTE_HANGUP)
|
.setAction(ACTION_LOCAL_HANGUP)
|
||||||
.putExtra(EXTRA_CALL_ID, callManager.callId)
|
.putExtra(EXTRA_CALL_ID, callManager.callId)
|
||||||
|
|
||||||
startService(intent)
|
startService(intent)
|
||||||
|
@@ -108,7 +108,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
private val pendingOutgoingIceUpdates = ArrayDeque<IceCandidate>()
|
private val pendingOutgoingIceUpdates = ArrayDeque<IceCandidate>()
|
||||||
private val pendingIncomingIceUpdates = ArrayDeque<IceCandidate>()
|
private val pendingIncomingIceUpdates = ArrayDeque<IceCandidate>()
|
||||||
|
|
||||||
private val outgoingIceDebouncer = Debouncer(2_000L)
|
private val outgoingIceDebouncer = Debouncer(200L)
|
||||||
|
|
||||||
var localRenderer: SurfaceViewRenderer? = null
|
var localRenderer: SurfaceViewRenderer? = null
|
||||||
var remoteRenderer: SurfaceViewRenderer? = null
|
var remoteRenderer: SurfaceViewRenderer? = null
|
||||||
@@ -224,6 +224,13 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
val expectedCallId = this.callId ?: return
|
val expectedCallId = this.callId ?: return
|
||||||
val expectedRecipient = this.recipient ?: return
|
val expectedRecipient = this.recipient ?: return
|
||||||
pendingOutgoingIceUpdates.add(iceCandidate)
|
pendingOutgoingIceUpdates.add(iceCandidate)
|
||||||
|
|
||||||
|
if (peerConnection?.readyForIce != true) return
|
||||||
|
|
||||||
|
queueOutgoingIce(expectedCallId, expectedRecipient)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun queueOutgoingIce(expectedCallId: UUID, expectedRecipient: Recipient) {
|
||||||
outgoingIceDebouncer.publish {
|
outgoingIceDebouncer.publish {
|
||||||
val currentCallId = this.callId ?: return@publish
|
val currentCallId = this.callId ?: return@publish
|
||||||
val currentRecipient = this.recipient ?: return@publish
|
val currentRecipient = this.recipient ?: return@publish
|
||||||
@@ -331,10 +338,6 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
localCameraState = newCameraState
|
localCameraState = newCameraState
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enableLocalCamera() {
|
|
||||||
setVideoEnabled(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onIncomingRing(offer: String, callId: UUID, recipient: Recipient, callTime: Long) {
|
fun onIncomingRing(offer: String, callId: UUID, recipient: Recipient, callTime: Long) {
|
||||||
if (currentConnectionState != CallState.STATE_IDLE) return
|
if (currentConnectionState != CallState.STATE_IDLE) return
|
||||||
|
|
||||||
@@ -342,6 +345,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
this.recipient = recipient
|
this.recipient = recipient
|
||||||
this.pendingOffer = offer
|
this.pendingOffer = offer
|
||||||
this.pendingOfferTime = callTime
|
this.pendingOfferTime = callTime
|
||||||
|
startIncomingRinger()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onIncomingCall(context: Context, isAlwaysTurn: Boolean = false): Promise<Unit, Exception> {
|
fun onIncomingCall(context: Context, isAlwaysTurn: Boolean = false): Promise<Unit, Exception> {
|
||||||
@@ -523,6 +527,10 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
val connection = peerConnection ?: throw AssertionError("assert")
|
val connection = peerConnection ?: throw AssertionError("assert")
|
||||||
|
|
||||||
connection.setRemoteDescription(answer)
|
connection.setRemoteDescription(answer)
|
||||||
|
while (pendingIncomingIceUpdates.isNotEmpty()) {
|
||||||
|
connection.addIceCandidate(pendingIncomingIceUpdates.pop())
|
||||||
|
}
|
||||||
|
queueOutgoingIce(callId, recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleRemoteIceCandidate(iceCandidates: List<IceCandidate>, callId: UUID) {
|
fun handleRemoteIceCandidate(iceCandidates: List<IceCandidate>, callId: UUID) {
|
||||||
@@ -531,11 +539,12 @@ class CallManager(context: Context, audioManager: AudioManagerCompat): PeerConne
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConnection?.let { connection ->
|
val connection = peerConnection
|
||||||
|
if (connection != null && connection.readyForIce) {
|
||||||
iceCandidates.forEach { candidate ->
|
iceCandidates.forEach { candidate ->
|
||||||
connection.addIceCandidate(candidate)
|
connection.addIceCandidate(candidate)
|
||||||
}
|
}
|
||||||
} ?: run {
|
} else {
|
||||||
pendingIncomingIceUpdates.addAll(iceCandidates)
|
pendingIncomingIceUpdates.addAll(iceCandidates)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,6 +55,7 @@ class CallMessageProcessor(private val context: Context, lifecycle: Lifecycle) {
|
|||||||
|
|
||||||
private fun handleIceCandidates(callMessage: CallMessage) {
|
private fun handleIceCandidates(callMessage: CallMessage) {
|
||||||
val callId = callMessage.callId ?: return
|
val callId = callMessage.callId ?: return
|
||||||
|
val sender = callMessage.sender ?: return
|
||||||
|
|
||||||
val iceCandidates = callMessage.iceCandidates()
|
val iceCandidates = callMessage.iceCandidates()
|
||||||
if (iceCandidates.isEmpty()) return
|
if (iceCandidates.isEmpty()) return
|
||||||
@@ -62,7 +63,8 @@ class CallMessageProcessor(private val context: Context, lifecycle: Lifecycle) {
|
|||||||
val iceIntent = WebRtcCallService.iceCandidates(
|
val iceIntent = WebRtcCallService.iceCandidates(
|
||||||
context = context,
|
context = context,
|
||||||
iceCandidates = iceCandidates,
|
iceCandidates = iceCandidates,
|
||||||
callId = callId
|
callId = callId,
|
||||||
|
address = Address.fromSerialized(sender)
|
||||||
)
|
)
|
||||||
context.startService(iceIntent)
|
context.startService(iceIntent)
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,9 @@ class PeerConnectionWrapper(context: Context,
|
|||||||
private val videoSource: VideoSource?
|
private val videoSource: VideoSource?
|
||||||
private val videoTrack: VideoTrack?
|
private val videoTrack: VideoTrack?
|
||||||
|
|
||||||
|
val readyForIce
|
||||||
|
get() = peerConnection.localDescription != null && peerConnection.remoteDescription != null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val stun = PeerConnection.IceServer.builder("stun:freyr.getsession.org:5349").createIceServer()
|
val stun = PeerConnection.IceServer.builder("stun:freyr.getsession.org:5349").createIceServer()
|
||||||
val turn = PeerConnection.IceServer.builder("turn:freyr.getsession.org:5349").setUsername("webrtc").setPassword("webrtc").createIceServer()
|
val turn = PeerConnection.IceServer.builder("turn:freyr.getsession.org:5349").setUsername("webrtc").setPassword("webrtc").createIceServer()
|
||||||
|
Reference in New Issue
Block a user