Skip to content

Commit

Permalink
mobile: use TCP for ICE requests of WebRTC calls (#1888)
Browse files Browse the repository at this point in the history
* ios: support query string parameters in ICE server addresses

* android: support query params in ICE server address, add transport=TCP to default servers
  • Loading branch information
epoberezkin committed Feb 4, 2023
1 parent 86cc85b commit 3c493db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/android/app/src/main/assets/www/call.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package chat.simplex.app.views.call

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import chat.simplex.app.R
import chat.simplex.app.SimplexApp
import chat.simplex.app.*
import chat.simplex.app.model.Contact
import chat.simplex.app.model.User
import chat.simplex.app.views.helpers.generalGetString
Expand Down Expand Up @@ -159,8 +159,8 @@ data class ConnectionState(
)

// the servers are expected in this format:
// stun:stun.simplex.im:443
// turn:private:yleob6AVkiNI87hpR94Z@turn.simplex.im:443
// stun:stun.simplex.im:443?transport=tcp
// turn:private:yleob6AVkiNI87hpR94Z@turn.simplex.im:443?transport=tcp
fun parseRTCIceServer(str: String): RTCIceServer? {
var s = replaceScheme(str, "stun:")
s = replaceScheme(s, "turn:")
Expand All @@ -171,8 +171,9 @@ fun parseRTCIceServer(str: String): RTCIceServer? {
val port = u.port
if (u.path == "" && (scheme == "stun" || scheme == "turn")) {
val userInfo = u.userInfo?.split(":")
val query = if (u.query == null || u.query == "") "" else "?${u.query}"
return RTCIceServer(
urls = listOf("$scheme:$host:$port"),
urls = listOf("$scheme:$host:$port$query"),
username = userInfo?.getOrNull(0),
credential = userInfo?.getOrNull(1)
)
Expand Down
7 changes: 4 additions & 3 deletions apps/ios/Shared/Views/Call/WebRTC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ struct RTCIceServer: Codable, Equatable {
}

// the servers are expected in this format:
// stun:stun.simplex.im:443
// turn:private:yleob6AVkiNI87hpR94Z@turn.simplex.im:443
// stun:stun.simplex.im:443?transport=tcp
// turn:private:yleob6AVkiNI87hpR94Z@turn.simplex.im:443?transport=tcp
func parseRTCIceServer(_ str: String) -> RTCIceServer? {
var s = replaceScheme(str, "stun:")
s = replaceScheme(s, "turn:")
Expand All @@ -406,8 +406,9 @@ func parseRTCIceServer(_ str: String) -> RTCIceServer? {
let host = u.host,
let port = u.port,
u.path == "" && (scheme == "stun" || scheme == "turn") {
let query = u.query == nil || u.query == "" ? "" : "?" + (u.query ?? "")
return RTCIceServer(
urls: ["\(scheme):\(host):\(port)"],
urls: ["\(scheme):\(host):\(port)\(query)"],
username: u.user,
credential: u.password
)
Expand Down
4 changes: 2 additions & 2 deletions packages/simplex-chat-webrtc/src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ const processCommand = (function () {
}

const defaultIceServers: RTCIceServer[] = [
{urls: ["stun:stun.simplex.im:443"]},
{urls: ["turn:turn.simplex.im:443"], username: "private", credential: "yleob6AVkiNI87hpR94Z"},
{urls: ["stun:stun.simplex.im:443?transport=tcp"]},
{urls: ["turn:turn.simplex.im:443?transport=tcp"], username: "private", credential: "yleob6AVkiNI87hpR94Z"},
]

function getCallConfig(encodedInsertableStreams: boolean, iceServers?: RTCIceServer[], relay?: boolean): CallConfig {
Expand Down

0 comments on commit 3c493db

Please sign in to comment.