Send sdp to remote party when answer is received.

This commit is contained in:
onurays 2020-05-26 17:42:44 +03:00 committed by Valere
parent 37c926d178
commit 54b154f85f
3 changed files with 48 additions and 15 deletions

View file

@ -17,10 +17,13 @@
package im.vector.riotx.features.call package im.vector.riotx.features.call
import android.app.KeyguardManager import android.app.KeyguardManager
import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.IBinder
import android.os.Parcelable import android.os.Parcelable
import android.view.View import android.view.View
import android.view.Window import android.view.Window
@ -35,6 +38,7 @@ import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.utils.PERMISSIONS_FOR_VIDEO_IP_CALL import im.vector.riotx.core.utils.PERMISSIONS_FOR_VIDEO_IP_CALL
import im.vector.riotx.core.utils.allGranted import im.vector.riotx.core.utils.allGranted
import im.vector.riotx.core.utils.checkPermissions import im.vector.riotx.core.utils.checkPermissions
import im.vector.riotx.features.call.service.CallHeadsUpService
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.PublishSubject
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -88,6 +92,19 @@ class VectorCallActivity : VectorBaseActivity(), WebRtcPeerConnectionManager.Lis
private val iceCandidateSource: PublishSubject<IceCandidate> = PublishSubject.create() private val iceCandidateSource: PublishSubject<IceCandidate> = PublishSubject.create()
var callHeadsUpService: CallHeadsUpService? = null
private val serviceConnection = object : ServiceConnection {
override fun onServiceDisconnected(name: ComponentName?) {
finish()
}
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
callHeadsUpService = (service as? CallHeadsUpService.CallHeadsUpServiceBinder)?.getService()
}
}
override fun doBeforeSetContentView() { override fun doBeforeSetContentView() {
// Set window styles for fullscreen-window size. Needs to be done before adding content. // Set window styles for fullscreen-window size. Needs to be done before adding content.
requestWindowFeature(Window.FEATURE_NO_TITLE) requestWindowFeature(Window.FEATURE_NO_TITLE)
@ -113,6 +130,8 @@ class VectorCallActivity : VectorBaseActivity(), WebRtcPeerConnectionManager.Lis
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
bindService(Intent(this, CallHeadsUpService::class.java), serviceConnection, 0)
if (intent.hasExtra(MvRx.KEY_ARG)) { if (intent.hasExtra(MvRx.KEY_ARG)) {
callArgs = intent.getParcelableExtra(MvRx.KEY_ARG)!! callArgs = intent.getParcelableExtra(MvRx.KEY_ARG)!!
} else { } else {
@ -340,8 +359,8 @@ class VectorCallActivity : VectorBaseActivity(), WebRtcPeerConnectionManager.Lis
private fun handleViewEvents(event: VectorCallViewEvents?) { private fun handleViewEvents(event: VectorCallViewEvents?) {
when (event) { when (event) {
is VectorCallViewEvents.CallAnswered -> { is VectorCallViewEvents.CallAnswered -> {
val sdp = SessionDescription(SessionDescription.Type.ANSWER, event.content.answer.sdp) //val sdp = SessionDescription(SessionDescription.Type.ANSWER, event.content.answer.sdp)
peerConnectionManager.answerReceived("", sdp) //peerConnectionManager.answerReceived("", sdp)
// peerConnection?.setRemoteDescription(object : SdpObserverAdapter() {}, sdp) // peerConnection?.setRemoteDescription(object : SdpObserverAdapter() {}, sdp)
} }
is VectorCallViewEvents.CallHangup -> { is VectorCallViewEvents.CallHangup -> {

View file

@ -103,8 +103,8 @@ class VectorCallViewModel @AssistedInject constructor(
} }
override fun initialState(viewModelContext: ViewModelContext): VectorCallViewState? { override fun initialState(viewModelContext: ViewModelContext): VectorCallViewState? {
val args: CallArgs = viewModelContext.args() //val args: CallArgs = viewModelContext.args()
return VectorCallViewState(roomId = args.roomId) return VectorCallViewState()
} }
} }
} }

View file

@ -94,6 +94,9 @@ class WebRtcPeerConnectionManager @Inject constructor(
private var peerConnection: PeerConnection? = null private var peerConnection: PeerConnection? = null
private var localViewRenderer: SurfaceViewRenderer? = null
private var remoteViewRenderer: SurfaceViewRenderer? = null
private var remoteVideoTrack: VideoTrack? = null private var remoteVideoTrack: VideoTrack? = null
private var localVideoTrack: VideoTrack? = null private var localVideoTrack: VideoTrack? = null
@ -185,7 +188,6 @@ class WebRtcPeerConnectionManager @Inject constructor(
localVideoTrack = peerConnectionFactory?.createVideoTrack("ARDAMSv0", videoSource)?.also { localVideoTrack = peerConnectionFactory?.createVideoTrack("ARDAMSv0", videoSource)?.also {
Timber.v("## VOIP Local video track created") Timber.v("## VOIP Local video track created")
listener?.addLocalVideoTrack(it)
// localSurfaceRenderer?.get()?.let { surface -> // localSurfaceRenderer?.get()?.let { surface ->
// // it.addSink(surface) // // it.addSink(surface)
// // } // // }
@ -226,15 +228,6 @@ class WebRtcPeerConnectionManager @Inject constructor(
} }
} }
fun answerReceived(callId: String, answerSdp: SessionDescription) {
this.callId = callId
executor.execute {
Timber.v("## answerReceived $callId")
peerConnection?.setRemoteDescription(object : SdpObserverAdapter() {}, answerSdp)
}
}
private fun startCall() { private fun startCall() {
createPeerConnectionFactory() createPeerConnectionFactory()
createPeerConnection(object : PeerConnectionObserverAdapter() { createPeerConnection(object : PeerConnectionObserverAdapter() {
@ -246,8 +239,16 @@ class WebRtcPeerConnectionManager @Inject constructor(
override fun onAddStream(mediaStream: MediaStream?) { override fun onAddStream(mediaStream: MediaStream?) {
Timber.v("## VOIP onAddStream remote $mediaStream") Timber.v("## VOIP onAddStream remote $mediaStream")
mediaStream?.videoTracks?.firstOrNull()?.let { mediaStream?.videoTracks?.firstOrNull()?.let {
listener?.addRemoteVideoTrack(it)
remoteVideoTrack = it remoteVideoTrack = it
remoteSurfaceRenderer?.get()?.let { surface ->
it.setEnabled(true)
it.addSink(surface)
}
mediaStream.videoTracks?.firstOrNull()?.let { videoTrack ->
remoteVideoTrack = videoTrack
remoteVideoTrack?.setEnabled(true)
remoteVideoTrack?.addSink(remoteViewRenderer)
}
} }
} }
@ -318,9 +319,14 @@ class WebRtcPeerConnectionManager @Inject constructor(
} }
fun attachViewRenderers(localViewRenderer: SurfaceViewRenderer, remoteViewRenderer: SurfaceViewRenderer) { fun attachViewRenderers(localViewRenderer: SurfaceViewRenderer, remoteViewRenderer: SurfaceViewRenderer) {
this.localViewRenderer = localViewRenderer
this.remoteViewRenderer = remoteViewRenderer
audioSource = peerConnectionFactory?.createAudioSource(DEFAULT_AUDIO_CONSTRAINTS) audioSource = peerConnectionFactory?.createAudioSource(DEFAULT_AUDIO_CONSTRAINTS)
audioTrack = peerConnectionFactory?.createAudioTrack(AUDIO_TRACK_ID, audioSource) audioTrack = peerConnectionFactory?.createAudioTrack(AUDIO_TRACK_ID, audioSource)
localViewRenderer.setMirror(true)
localVideoTrack?.addSink(localViewRenderer)
localMediaStream = peerConnectionFactory?.createLocalMediaStream("ARDAMS") // magic value? localMediaStream = peerConnectionFactory?.createLocalMediaStream("ARDAMS") // magic value?
if (isVideoCall == true) { if (isVideoCall == true) {
@ -429,6 +435,7 @@ class WebRtcPeerConnectionManager @Inject constructor(
this.isVideoCall = callInviteContent.isVideo() this.isVideoCall = callInviteContent.isVideo()
startHeadsUpService(signalingRoomId, participantUserId, true, callInviteContent.isVideo()) startHeadsUpService(signalingRoomId, participantUserId, true, callInviteContent.isVideo())
context.startActivity(VectorCallActivity.newIntent(context, signalingRoomId, participantUserId, false, callInviteContent.isVideo()))
startCall() startCall()
} }
@ -448,6 +455,13 @@ class WebRtcPeerConnectionManager @Inject constructor(
} }
override fun onCallAnswerReceived(callAnswerContent: CallAnswerContent) { override fun onCallAnswerReceived(callAnswerContent: CallAnswerContent) {
this.callId = callAnswerContent.callId
executor.execute {
Timber.v("## answerReceived $callId")
val sdp = SessionDescription(SessionDescription.Type.ANSWER, callAnswerContent.answer.sdp)
peerConnection?.setRemoteDescription(object : SdpObserverAdapter() {}, sdp)
}
} }
override fun onCallHangupReceived(callHangupContent: CallHangupContent) { override fun onCallHangupReceived(callHangupContent: CallHangupContent) {