remove redundant turn servers and reduce turn servers connections to 2

pull/562/head
Ryan Zhao 4 years ago
parent f7af8141c0
commit 83c7283a76

@ -8,7 +8,7 @@ struct TurnServerInfo {
let username: String let username: String
let urls: [String] let urls: [String]
init?(attributes: JSON) { init?(attributes: JSON, random: Int? = nil) {
if let passwordAttribute = (attributes["password"] as? String) { if let passwordAttribute = (attributes["password"] as? String) {
password = passwordAttribute password = passwordAttribute
} else { } else {
@ -22,7 +22,12 @@ struct TurnServerInfo {
} }
if let urlsAttribute = attributes["urls"] as? [String] { if let urlsAttribute = attributes["urls"] as? [String] {
if let random = random {
urls = Array(urlsAttribute.shuffled()[0..<random])
} else {
urls = urlsAttribute urls = urlsAttribute
}
} else { } else {
return nil return nil
} }

@ -22,7 +22,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
let url = Bundle.main.url(forResource: "Session-Turn-Server", withExtension: nil)! let url = Bundle.main.url(forResource: "Session-Turn-Server", withExtension: nil)!
let data = try! Data(contentsOf: url) let data = try! Data(contentsOf: url)
let json = try! JSONSerialization.jsonObject(with: data, options: [ .fragmentsAllowed ]) as! JSON let json = try! JSONSerialization.jsonObject(with: data, options: [ .fragmentsAllowed ]) as! JSON
return TurnServerInfo(attributes: json) return TurnServerInfo(attributes: json, random: 2)
}() }()
internal lazy var factory: RTCPeerConnectionFactory = { internal lazy var factory: RTCPeerConnectionFactory = {
@ -36,9 +36,8 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
/// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed. /// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed.
internal lazy var peerConnection: RTCPeerConnection = { internal lazy var peerConnection: RTCPeerConnection = {
let configuration = RTCConfiguration() let configuration = RTCConfiguration()
configuration.iceServers = [ RTCIceServer(urlStrings: ["stun:freyr.getsession.org:5349"]), RTCIceServer(urlStrings: ["turn:freyr.getsession.org"], username: "session", credential: "session") ]
if let defaultICEServer = defaultICEServer { if let defaultICEServer = defaultICEServer {
configuration.iceServers.append(RTCIceServer(urlStrings: defaultICEServer.urls, username: defaultICEServer.username, credential: defaultICEServer.password)) configuration.iceServers = [ RTCIceServer(urlStrings: defaultICEServer.urls, username: defaultICEServer.username, credential: defaultICEServer.password) ]
} }
configuration.sdpSemantics = .unifiedPlan configuration.sdpSemantics = .unifiedPlan
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:]) let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:])

Loading…
Cancel
Save