From 3bfab87a8727e0f8081ddd3c8e8c569e9a5fab49 Mon Sep 17 00:00:00 2001 From: CicadaCinema <52425971+CicadaCinema@users.noreply.github.com> Date: Sun, 17 Apr 2022 01:42:31 +0100 Subject: [PATCH] create fallback turn server option --- changelog.d/2329.feature | 1 + vector-config/src/main/res/values/config.xml | 1 + .../vector/app/features/call/webrtc/WebRtcCall.kt | 15 ++++++++++++++- .../app/features/call/webrtc/WebRtcCallManager.kt | 10 ++++++++-- .../app/features/settings/VectorPreferences.kt | 8 ++++++++ .../settings/VectorSettingsVoiceVideoFragment.kt | 8 ++++++++ vector/src/main/res/values/strings.xml | 2 ++ .../main/res/xml/vector_settings_voice_video.xml | 6 ++++++ 8 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 changelog.d/2329.feature diff --git a/changelog.d/2329.feature b/changelog.d/2329.feature new file mode 100644 index 0000000000..a7df6304be --- /dev/null +++ b/changelog.d/2329.feature @@ -0,0 +1 @@ +Add setting to enable using turn.matrix.org as a fallback measure. \ No newline at end of file diff --git a/vector-config/src/main/res/values/config.xml b/vector-config/src/main/res/values/config.xml index 78b92cbfa4..7de918afd7 100755 --- a/vector-config/src/main/res/values/config.xml +++ b/vector-config/src/main/res/values/config.xml @@ -5,6 +5,7 @@ https://matrix.org + turn.matrix.org https://riot.im/bugreports/submit diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt index 90088c8475..5c954af011 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt @@ -19,6 +19,8 @@ package im.vector.app.features.call.webrtc import android.content.Context import android.hardware.camera2.CameraManager import androidx.core.content.getSystemService +import im.vector.app.R +import im.vector.app.core.resources.StringProvider import im.vector.app.core.services.CallService import im.vector.app.core.utils.PublishDataSource import im.vector.app.core.utils.TextUtils.formatDuration @@ -35,6 +37,7 @@ import im.vector.app.features.call.utils.awaitSetLocalDescription import im.vector.app.features.call.utils.awaitSetRemoteDescription import im.vector.app.features.call.utils.mapToCallCandidate import im.vector.app.features.session.coroutineScope +import im.vector.app.features.settings.VectorPreferences import im.vector.lib.core.utils.flow.chunk import im.vector.lib.core.utils.timer.CountUpTimer import kotlinx.coroutines.CoroutineScope @@ -111,7 +114,9 @@ class WebRtcCall( private val sessionProvider: Provider, private val peerConnectionFactoryProvider: Provider, private val onCallBecomeActive: (WebRtcCall) -> Unit, - private val onCallEnded: (String, EndCallReason, Boolean) -> Unit + private val onCallEnded: (String, EndCallReason, Boolean) -> Unit, + private var vectorPreferences: VectorPreferences, + private val stringProvider: StringProvider ) : MxCall.StateListener { interface Listener : MxCall.StateListener { @@ -295,6 +300,14 @@ class WebRtcCall( ) } } + if ((turnServerResponse == null || turnServerResponse.uris.isNullOrEmpty()) && vectorPreferences.useFallbackTurnServer()) { + add( + PeerConnection + .IceServer + .builder("stun:" + stringProvider.getString(R.string.fallback_stun_server_url)) + .createIceServer() + ) + } } Timber.tag(loggerTag.value).v("creating peer connection...with iceServers $iceServers ") val rtcConfig = PeerConnection.RTCConfiguration(iceServers).apply { diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt index fe12bf1ec7..e4a9249bb8 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt @@ -21,6 +21,7 @@ import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import im.vector.app.ActiveSessionDataSource import im.vector.app.BuildConfig +import im.vector.app.core.resources.StringProvider import im.vector.app.core.services.CallService import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.CallEnded @@ -32,6 +33,7 @@ import im.vector.app.features.call.lookup.CallUserMapper import im.vector.app.features.call.utils.EglUtils import im.vector.app.features.call.vectorCallService import im.vector.app.features.session.coroutineScope +import im.vector.app.features.settings.VectorPreferences import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.asCoroutineDispatcher @@ -72,7 +74,9 @@ private val loggerTag = LoggerTag("WebRtcCallManager", LoggerTag.VOIP) class WebRtcCallManager @Inject constructor( private val context: Context, private val activeSessionDataSource: ActiveSessionDataSource, - private val analyticsTracker: AnalyticsTracker + private val analyticsTracker: AnalyticsTracker, + private var vectorPreferences: VectorPreferences, + private val stringProvider: StringProvider ) : CallListener, DefaultLifecycleObserver { @@ -332,7 +336,9 @@ class WebRtcCallManager @Inject constructor( }, sessionProvider = { currentSession }, onCallBecomeActive = this::onCallActive, - onCallEnded = this::onCallEnded + onCallEnded = this::onCallEnded, + vectorPreferences = vectorPreferences, + stringProvider = stringProvider ) advertisedCalls.add(mxCall.callId) callsByCallId[mxCall.callId] = webRtcCall diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 195072465b..6affde2aad 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -138,6 +138,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { // Calls const val SETTINGS_CALL_PREVENT_ACCIDENTAL_CALL_KEY = "SETTINGS_CALL_PREVENT_ACCIDENTAL_CALL_KEY" + const val SETTINGS_CALL_USE_FALLBACK_CALL_ASSIST_SERVER_KEY = "SETTINGS_CALL_USE_FALLBACK_CALL_ASSIST_SERVER_KEY" const val SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_USE_RIOT_PREFERENCE_KEY" const val SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY = "SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY" @@ -721,6 +722,13 @@ class VectorPreferences @Inject constructor(private val context: Context) { return defaultPrefs.getBoolean(SETTINGS_CALL_PREVENT_ACCIDENTAL_CALL_KEY, false) } + /** + * Tells if turn.matrix should be used during calls as a fallback + */ + fun useFallbackTurnServer(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_CALL_USE_FALLBACK_CALL_ASSIST_SERVER_KEY, false) + } + /** * Tells if the read receipts should be shown * diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt index fbf54479fc..ce3bb7ae54 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt @@ -43,6 +43,9 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() { private val mCallRingtonePreference by lazy { findPreference(VectorPreferences.SETTINGS_CALL_RINGTONE_URI_PREFERENCE_KEY)!! } + private val useDefaultStunPreference by lazy { + findPreference(VectorPreferences.SETTINGS_CALL_USE_FALLBACK_CALL_ASSIST_SERVER_KEY)!! + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -56,6 +59,11 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() { false } + useDefaultStunPreference.let { + val stun = getString(R.string.fallback_stun_server_url) + it.summary = getString(R.string.settings_call_ringtone_use_default_stun_summary, stun) + } + mCallRingtonePreference.let { activity?.let { activity -> it.summary = getCallRingtoneName(activity) } it.onPreferenceClickListener = Preference.OnPreferenceClickListener { diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index ffd4333071..508cfdcf20 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -548,6 +548,8 @@ Calls Prevent accidental call Ask for confirmation before starting a call + Allow fallback call assist server + Will use %s as assist when your homeserver does not offer one (your IP address will be seen by the stun server during a call) Use default ${app_name} ringtone for incoming calls Incoming call ringtone diff --git a/vector/src/main/res/xml/vector_settings_voice_video.xml b/vector/src/main/res/xml/vector_settings_voice_video.xml index fc0c4b7bc2..99acc1f4ee 100644 --- a/vector/src/main/res/xml/vector_settings_voice_video.xml +++ b/vector/src/main/res/xml/vector_settings_voice_video.xml @@ -10,6 +10,12 @@ android:summary="@string/settings_call_show_confirmation_dialog_summary" android:title="@string/settings_call_show_confirmation_dialog_title" /> + +