diff --git a/library/ui-strings/src/main/res/values/strings_sc.xml b/library/ui-strings/src/main/res/values/strings_sc.xml index cfc39ee8b6..4362b07c01 100644 --- a/library/ui-strings/src/main/res/values/strings_sc.xml +++ b/library/ui-strings/src/main/res/values/strings_sc.xml @@ -229,4 +229,9 @@ Send as sticker + + 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 +) + diff --git a/vector-config/src/main/res/values/config.xml b/vector-config/src/main/res/values/config.xml index 810aab2273..f231ca5ab8 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://rageshake.schildi.chat/api/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 9c65d94a94..31b29e4bd4 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.CallAndroidService 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 @@ -114,7 +117,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 { @@ -299,6 +304,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 f229f30e7b..522a771808 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.core.pushers.UnifiedPushHelper +import im.vector.app.core.resources.StringProvider import im.vector.app.core.services.CallAndroidService 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 kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.asCoroutineDispatcher import org.matrix.android.sdk.api.extensions.orFalse @@ -74,6 +76,8 @@ class WebRtcCallManager @Inject constructor( private val analyticsTracker: AnalyticsTracker, private val unifiedPushHelper: UnifiedPushHelper, private val voipConfig: VoipConfig, + private var vectorPreferences: VectorPreferences, + private val stringProvider: StringProvider, ) : CallListener, DefaultLifecycleObserver { @@ -336,7 +340,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 072f15190e..6ad1b65006 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 @@ -176,6 +176,7 @@ class VectorPreferences @Inject constructor( // 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" @@ -859,6 +860,13 @@ class VectorPreferences @Inject constructor( return defaultPrefs.getBoolean(SETTINGS_CALL_PREVENT_ACCIDENTAL_CALL_KEY, true) } + /** + * 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 1cb7dcbf28..16752e10a5 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 @@ -46,6 +46,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) @@ -59,6 +62,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 { it.summary = ringtoneUtils.getCallRingtoneName() it.onPreferenceClickListener = Preference.OnPreferenceClickListener { 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 4ffa8d668a..020406e39e 100644 --- a/vector/src/main/res/xml/vector_settings_voice_video.xml +++ b/vector/src/main/res/xml/vector_settings_voice_video.xml @@ -18,6 +18,12 @@ android:title="@string/settings_hide_call_buttons" android:summary="@string/settings_hide_call_buttons_summary" /> + + - \ No newline at end of file +