lazy create and destroy peer connection factory

This commit is contained in:
Valere 2020-06-18 18:14:58 +02:00
parent 5dfa08ace6
commit 77a01f0cd4
1 changed files with 16 additions and 7 deletions

View File

@ -182,13 +182,6 @@ class WebRtcPeerConnectionManager @Inject constructor(
} }
} }
init {
// TODO do this lazyly
executor.execute {
createPeerConnectionFactory()
}
}
fun headSetButtonTapped() { fun headSetButtonTapped() {
Timber.v("## VOIP headSetButtonTapped") Timber.v("## VOIP headSetButtonTapped")
val call = currentCall?.mxCall ?: return val call = currentCall?.mxCall ?: return
@ -558,6 +551,12 @@ class WebRtcPeerConnectionManager @Inject constructor(
} }
fun startOutgoingCall(context: Context, signalingRoomId: String, otherUserId: String, isVideoCall: Boolean) { fun startOutgoingCall(context: Context, signalingRoomId: String, otherUserId: String, isVideoCall: Boolean) {
executor.execute {
if (peerConnectionFactory == null) {
createPeerConnectionFactory()
}
}
Timber.v("## VOIP startOutgoingCall in room $signalingRoomId to $otherUserId isVideo $isVideoCall") Timber.v("## VOIP startOutgoingCall in room $signalingRoomId to $otherUserId isVideo $isVideoCall")
val createdCall = sessionHolder.getSafeActiveSession()?.callSignalingService()?.createOutgoingCall(signalingRoomId, otherUserId, isVideoCall) ?: return val createdCall = sessionHolder.getSafeActiveSession()?.callSignalingService()?.createOutgoingCall(signalingRoomId, otherUserId, isVideoCall) ?: return
val callContext = CallContext(createdCall) val callContext = CallContext(createdCall)
@ -607,6 +606,11 @@ class WebRtcPeerConnectionManager @Inject constructor(
// Just ignore, maybe we could answer from other session? // Just ignore, maybe we could answer from other session?
return return
} }
executor.execute {
if (peerConnectionFactory == null) {
createPeerConnectionFactory()
}
}
val callContext = CallContext(mxCall) val callContext = CallContext(mxCall)
currentCall = callContext currentCall = callContext
@ -675,6 +679,11 @@ class WebRtcPeerConnectionManager @Inject constructor(
currentCall = null currentCall = null
audioManager.stop() audioManager.stop()
close() close()
executor.execute {
if (currentCall == null) {
peerConnectionFactory?.dispose()
}
}
} }
fun onWiredDeviceEvent(event: WiredHeadsetStateReceiver.HeadsetPlugEvent) { fun onWiredDeviceEvent(event: WiredHeadsetStateReceiver.HeadsetPlugEvent) {