Merge conflicts and implement answer function.

This commit is contained in:
onurays 2020-05-29 00:53:40 +03:00 committed by Valere
parent 03b9904b07
commit c0988ba6d9
4 changed files with 58 additions and 4 deletions

View File

@ -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) }
}

View File

@ -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))
}
}

View File

@ -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

View File

@ -49,5 +49,6 @@ class CallHeadsUpActionReceiver : BroadcastReceiver() {
private fun onCallAnswerClicked() {
Timber.d("onCallAnswerClicked")
peerConnectionManager.answerCall()
}
}