diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/model/MxCallImpl.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/model/MxCallImpl.kt index 82537b2e5b..fdee9c295b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/model/MxCallImpl.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/model/MxCallImpl.kt @@ -89,7 +89,7 @@ internal class MxCallImpl( callId = callId, answer = CallAnswerContent.Answer(sdp = sdp.description) ) - .let { createEventAndLocalEcho(type = EventType.CALL_INVITE, roomId = roomId, content = it.toContent()) } + .let { createEventAndLocalEcho(type = EventType.CALL_ANSWER, roomId = roomId, content = it.toContent()) } .also { roomEventSender.sendEvent(it) } } diff --git a/vector/src/main/java/im/vector/riotx/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/riotx/features/call/VectorCallActivity.kt index af1bea1d6c..c21251c9ed 100644 --- a/vector/src/main/java/im/vector/riotx/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/call/VectorCallActivity.kt @@ -417,6 +417,7 @@ class VectorCallActivity : VectorBaseActivity(), WebRtcPeerConnectionManager.Lis fun newIntent(context: Context, mxCall: MxCallDetail): Intent { return Intent(context, VectorCallActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK putExtra(MvRx.KEY_ARG, CallArgs(mxCall.roomId, mxCall.otherUserId, !mxCall.isOutgoing, mxCall.isVideoCall)) } } diff --git a/vector/src/main/java/im/vector/riotx/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/riotx/features/call/WebRtcPeerConnectionManager.kt index a283414310..ec5f6f2048 100644 --- a/vector/src/main/java/im/vector/riotx/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/call/WebRtcPeerConnectionManager.kt @@ -281,7 +281,7 @@ class WebRtcPeerConnectionManager @Inject constructor( private fun sendSdpOffer() { val constraints = MediaConstraints() constraints.mandatory.add(MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")) - constraints.mandatory.add(MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")) + constraints.mandatory.add(MediaConstraints.KeyValuePair("OfferToReceiveVideo", if (currentCall?.isVideoCall == true) "true" else "false")) Timber.v("## VOIP creating offer...") peerConnection?.createOffer(object : SdpObserver { @@ -429,9 +429,10 @@ class WebRtcPeerConnectionManager @Inject constructor( currentCall = mxCall startHeadsUpService(mxCall) - context.startActivity(VectorCallActivity.newIntent(context, mxCall)) - startCall() + + val sdp = SessionDescription(SessionDescription.Type.OFFER, callInviteContent.offer?.sdp) + peerConnection?.setRemoteDescription(object : SdpObserverAdapter() {}, sdp) } private fun startHeadsUpService(mxCall: MxCallDetail) { @@ -441,6 +442,57 @@ class WebRtcPeerConnectionManager @Inject constructor( context.bindService(Intent(context, CallHeadsUpService::class.java), serviceConnection, 0) } + fun answerCall() { + if (currentCall != null) { + val constraints = MediaConstraints().apply { + mandatory.add(MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")) + mandatory.add(MediaConstraints.KeyValuePair("OfferToReceiveVideo", if (currentCall?.isVideoCall == true) "true" else "false")) + } + + peerConnection?.createAnswer(object : SdpObserver { + override fun onCreateSuccess(sessionDescription: SessionDescription) { + Timber.v("## createAnswer onCreateSuccess") + + val sdp = SessionDescription(sessionDescription.type, sessionDescription.description) + + peerConnection?.setLocalDescription(object : SdpObserver { + override fun onSetSuccess() { + currentCall?.accept(sdp) + + currentCall?.let { + context.startActivity(VectorCallActivity.newIntent(context, it)) + } + } + + override fun onCreateSuccess(localSdp: SessionDescription) {} + + override fun onSetFailure(p0: String?) { + endCall() + } + + override fun onCreateFailure(p0: String?) { + endCall() + } + }, sdp) + } + + override fun onSetSuccess() { + Timber.v("## createAnswer onSetSuccess") + } + + override fun onSetFailure(error: String) { + Timber.v("answerCall.onSetFailure failed: $error") + endCall() + } + + override fun onCreateFailure(error: String) { + Timber.v("answerCall.onCreateFailure failed: $error") + endCall() + } + }, constraints) + } + } + fun endCall() { currentCall?.hangUp() currentCall = null diff --git a/vector/src/main/java/im/vector/riotx/features/call/service/CallHeadsUpActionReceiver.kt b/vector/src/main/java/im/vector/riotx/features/call/service/CallHeadsUpActionReceiver.kt index aee51ff422..4671217312 100644 --- a/vector/src/main/java/im/vector/riotx/features/call/service/CallHeadsUpActionReceiver.kt +++ b/vector/src/main/java/im/vector/riotx/features/call/service/CallHeadsUpActionReceiver.kt @@ -49,5 +49,6 @@ class CallHeadsUpActionReceiver : BroadcastReceiver() { private fun onCallAnswerClicked() { Timber.d("onCallAnswerClicked") + peerConnectionManager.answerCall() } }