我使用libjingle_peerconnection库进行WebRTC连接,
这是rtc连接的初始化,我在同一网络中工作, 不适用于其他网络
我需要做什么才能使转弯服务器正常工作?
func initalizeWebRTC() -> Void {
RTCPeerConnectionFactory.initializeSSL()
self.webRtcClient = RTCPeerConnectionFactory.init()
let stunServer = self.defaultStunServer()
let turnServer = self.getTurn()
let defaultConstraint = self.createDefaultConstraint()
let array = [turnServer, stunServer]
print(array)
self.peerConnection = self.webRtcClient?.peerConnection(withICEServers: array, constraints: defaultConstraint, delegate: self)
print(peerConnection)
self.localVideoView.delegate = self
self.remoteVideoView.delegate = self
// webrtc initalized local rendering of video on
self.addLocalMediaStrem()
}
func defaultStunServer() -> RTCICEServer {
let url = URL.init(string: "stun:stun.l.google.com:19302");
let iceServer = RTCICEServer.init(uri: url, username: "", password: "")
return iceServer!
}
func getTurn() -> RTCICEServer {
let url = URL.init(string: "turn:xxx.xxx.xx.xxx:xxxx");
let iceServer = RTCICEServer.init(uri: url, username: "xxxx", password: "xxxxxxxxxxxx")
return iceServer!
}