我正在使用 WebRTC 在我的 android 应用程序和 Web 应用程序之间进行媒体流通信。对于信号,我使用了 socket.io 并使用 socket,我已经建立了 android 应用程序和 Web 应用程序之间的连接。我可以在移动应用程序上发送报价和接收答案,理想情况下,流媒体应该开始,但在我的情况下,它会在网络上抛出这个错误。
WebRTC: ICE failed, your TURN server appears to be broken, see about:webrtc for more details
failed screen.js:835:25
Need to reconnect student screen.js:838:33
Ice Connecttion state Changed to disconnected|closed|failed
我认为这是因为无法与 TURN 服务器建立连接。有人可以帮我弄这个吗。我正在使用这段代码进行 TURN 服务器连接。另外请告诉我如何验证我与 TURN 的连接是否已建立。
try {
PeerConnection.IceServer peerIceServer1=PeerConnection.IceServer.builder("stun:stun.XXXXXX.com:3478")
.setUsername("XXXXXX")
.setPassword("XXXXXX")
.setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
.createIceServer();
String username1 = "XXXXX";
String credential1 = "XXXXXX/XXXXXXXX=";
String turnUrll = "turn:turn.XXXX.com:3478";
PeerConnection.IceServer peerIceServer = PeerConnection.IceServer.builder(turnUrll)
.setUsername(username1)
.setPassword(credential1)
.setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
.createIceServer();
peerIceServers.add(peerIceServer);
peerIceServers.add(peerIceServer1);
}
catch (Exception e){
e.printStackTrace();
}
这是我试图创建对等连接的一段代码。
private void createPeerConnection() {
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(peerIceServers);
// TCP candidates are only useful when connecting to a server that supports
// ICE-TCP.
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
// Use ECDSA encryption.
rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
localPeer = peerConnectionFactory.createPeerConnection(rtcConfig,
new CustomPeerConnectionObserver("localPeerCreation") {
@Override
public void onIceCandidate(IceCandidate iceCandidate) {
super.onIceCandidate(iceCandidate);
onIceCandidateReceived(iceCandidate);
}
@Override
public void onAddStream(MediaStream mediaStream) {
showToast("Received Remote stream");
super.onAddStream(mediaStream);
}
});
addStreamToLocalPeer();
}
如果有人想更好地查看代码,我将分享更多细节。请我需要帮助,因为我什至找不到这方面的文档。