From 77a01f0cd466208097a8a99a3c02d62e1fb1b3fc Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 18 Jun 2020 18:14:58 +0200 Subject: [PATCH] lazy create and destroy peer connection factory --- .../call/WebRtcPeerConnectionManager.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 57c3f75f55..f75bbede19 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 @@ -182,13 +182,6 @@ class WebRtcPeerConnectionManager @Inject constructor( } } - init { - // TODO do this lazyly - executor.execute { - createPeerConnectionFactory() - } - } - fun headSetButtonTapped() { Timber.v("## VOIP headSetButtonTapped") val call = currentCall?.mxCall ?: return @@ -558,6 +551,12 @@ class WebRtcPeerConnectionManager @Inject constructor( } 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") val createdCall = sessionHolder.getSafeActiveSession()?.callSignalingService()?.createOutgoingCall(signalingRoomId, otherUserId, isVideoCall) ?: return val callContext = CallContext(createdCall) @@ -607,6 +606,11 @@ class WebRtcPeerConnectionManager @Inject constructor( // Just ignore, maybe we could answer from other session? return } + executor.execute { + if (peerConnectionFactory == null) { + createPeerConnectionFactory() + } + } val callContext = CallContext(mxCall) currentCall = callContext @@ -675,6 +679,11 @@ class WebRtcPeerConnectionManager @Inject constructor( currentCall = null audioManager.stop() close() + executor.execute { + if (currentCall == null) { + peerConnectionFactory?.dispose() + } + } } fun onWiredDeviceEvent(event: WiredHeadsetStateReceiver.HeadsetPlugEvent) {