remove redundant turn servers and reduce turn servers connections to 2
This commit is contained in:
parent
f7af8141c0
commit
83c7283a76
|
@ -8,7 +8,7 @@ struct TurnServerInfo {
|
|||
let username: String
|
||||
let urls: [String]
|
||||
|
||||
init?(attributes: JSON) {
|
||||
init?(attributes: JSON, random: Int? = nil) {
|
||||
if let passwordAttribute = (attributes["password"] as? String) {
|
||||
password = passwordAttribute
|
||||
} else {
|
||||
|
@ -22,7 +22,12 @@ struct TurnServerInfo {
|
|||
}
|
||||
|
||||
if let urlsAttribute = attributes["urls"] as? [String] {
|
||||
urls = urlsAttribute
|
||||
if let random = random {
|
||||
urls = Array(urlsAttribute.shuffled()[0..<random])
|
||||
} else {
|
||||
urls = urlsAttribute
|
||||
}
|
||||
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
|
|||
let url = Bundle.main.url(forResource: "Session-Turn-Server", withExtension: nil)!
|
||||
let data = try! Data(contentsOf: url)
|
||||
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 = {
|
||||
|
@ -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.
|
||||
internal lazy var peerConnection: RTCPeerConnection = {
|
||||
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 {
|
||||
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
|
||||
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:])
|
||||
|
|
Loading…
Reference in New Issue