Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create fallback turn server option #4391

Closed
wants to merge 13 commits into from

Conversation

CicadaCinema
Copy link

@CicadaCinema CicadaCinema commented Nov 1, 2021

PR Moved to #5781

Fixes #2329
Fixes #3063
You need to enable the fallback option in Settings > Voice & Video to use this feature:
Screenshot_20211106-215730_Element dbg.png

Pull Request Checklist

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
Please see my first remarks.
Also can you add a file for the changelog as per https://github.com/vector-im/element-android/blob/main/CONTRIBUTING.md#changelog ?

Thanks

@@ -269,17 +271,28 @@ class WebRtcCall(
private fun createPeerConnection(turnServerResponse: TurnServerResponse?) {
val peerConnectionFactory = peerConnectionFactoryProvider.get() ?: return
val iceServers = mutableListOf<PeerConnection.IceServer>().apply {
turnServerResponse?.let { server ->
server.uris?.forEach { uri ->
if (vectorPreferences.useFallbackTurnServer()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a specialist on this part of the code, but maybe use the fallback if and only if `turnServerResponse?.uris is null or empty, and the user has enable the fallback from the setting?

@CicadaCinema
Copy link
Author

Thank you for reviewing this! I actually don't know if this change fixes #2329 at all, I've asked people there to test out my builds. I'll finish up work on this PR if I get positive feedback on the changes.

@bmarty
Copy link
Member

bmarty commented Nov 2, 2021

Ok, thanks. I have enabled the CI for this PR so that APKs will be built and can be downloaded from here to be tested.

@CicadaCinema
Copy link
Author

Thank you!

@DoM1niC
Copy link

DoM1niC commented Nov 6, 2021

Nice PR @CicadaCinema but I prefer to use the TURN first from Homeserver instead of general Matrix to use.... I think, you can read this from API or you switch the Server URLs to gradle vars to find and setup faster the own TURN Server like me....

But anyway good work 👍🏻

@CicadaCinema
Copy link
Author

CicadaCinema commented Nov 6, 2021

Nice PR @CicadaCinema but I prefer to use the TURN first from Homeserver instead of general Matrix to use.... I think, you can read this from API or you switch the Server URLs to gradle vars to find and setup faster the own TURN Server like me....

But anyway good work 👍🏻

Thank you!

If this setting is enabled, I plan to only use turn.matrix.org when the user's homeserver does not have one that they can use (similarly to the way the setting in Element Web works).

@CicadaCinema CicadaCinema marked this pull request as ready for review November 6, 2021 22:00
@ouchadam
Copy link
Contributor

ouchadam commented Nov 8, 2021

awesome change! with the fallback only being used when no turn server uris are returned by the server and the preference is enabled this looks like it ticks everyone's boxes

server.uris?.forEach { uri ->
val useFallback = server.uris.isNullOrEmpty() && vectorPreferences.useFallbackTurnServer()
val serverList = if (useFallback) stringArrayProvider.getStringArray(R.array.fallback_ice_servers).toList() else server.uris
serverList?.forEach { uri ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a stupid question, but do we want to use the fallback if turnServerResponse is null? Here this will not be the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should only use the fallback if the home server does not define any ice servers (consitent with web).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the code turnServerResponse?.let { server -> has to be updated IIUC.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there, I've handled that now

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one question, but not blocking the merging

@BillCarsonFr
Copy link
Member

Notice that using a fallback while revealing your IP to the relay will also hide it to your contact.
In other app this option can be presented as always relay Calls (to avoid revealing your IP adress to your contact).
So the current text copy is maybe a bit too negative

@BillCarsonFr
Copy link
Member

Also the old android app was prompting the user to enable this option when you have a call that failed to connect and that your home server had no ice server config. Maybe a nice to have feature

add(
PeerConnection
.IceServer
.builder(uri)
.setUsername(server.username)
.setPassword(server.password)
.setUsername(if (useFallback) "xxxxx" else server.username)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback is stun, should do (from old sdk)

 if (!defaultIceServerUri.startsWith("stun:")) {
                    defaultIceServerUri = "stun:" + defaultIceServerUri;
                }
                defaultIceServer = PeerConnection.IceServer.builder(defaultIceServerUri).createIceServer();

@@ -7,6 +7,12 @@
<string name="matrix_org_server_url" translatable="false">https://matrix.org</string>
<string name="piwik_server_url" translatable="false">https://piwik.riot.im</string>
<string name="bug_report_url" translatable="false">https://riot.im/bugreports/submit</string>
<string name="fallback_stun_server_url" translatable="false">turn.matrix.org</string>
<string-array name="fallback_ice_servers" translatable="false">
<item>turn:turn.matrix.org:3478?transport=udp</item>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work, turn.matrix.org requires auth.
Just use stun: would work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback_ice_servers can just be removed now I think

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I've removed it

@@ -724,7 +724,7 @@
<!-- Note to translators: the translation MUST contain the string "${app_name}", which will be replaced by the application name -->
<string name="template_settings_call_ringtone_use_app_ringtone">Use default ${app_name} ringtone for incoming calls</string>
<string name="settings_call_ringtone_use_default_stun">Allow fallback call assist server</string>
<string name="settings_call_ringtone_use_default_stun_sum">Will use "%s" as assist when your homeserver does not offer one (your IP address will be shared during a call)</string>
<string name="settings_call_ringtone_use_default_stun_sum">Will use %s as assist when your homeserver does not offer one (your IP address will be shared during a call)</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this copy is missleading. IP will be shared with who? the peer yes, the stun yes.
Not using it will still share your IP with the peer.
So maybe your IP will be seen by the stun server? (not sure how valuable/actionable this information is for the user, given that not doing it will make calls fails depending on your network)

Copy link
Member

@BillCarsonFr BillCarsonFr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
The default server will only do stun, please see my comments.

@CicadaCinema
Copy link
Author

@BillCarsonFr

I adjusted the behaviour of the fallback to use the stun server instead, and I adjusted the option description.

Also the old android app was prompting the user to enable this option when you have a call that failed to connect and that your home server had no ice server config. Maybe a nice to have feature

I'm not sure how to even begin implementing this unfortunately - I only took a look at this issue because I noticed I couldn't make calls myself.

@bmarty bmarty added the Z-Community-PR Issue is solved by a community member's PR label Nov 30, 2021
@CicadaCinema
Copy link
Author

PR Moved to #5781

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
5 participants