1

我正在使用 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();
}

如果有人想更好地查看代码,我将分享更多细节。请我需要帮助,因为我什至找不到这方面的文档。

4

1 回答 1

0

看起来您正在使用的转向服务器不再处于活动状态。请注意:几乎不可能找到免费的 TURN 服务器。据我所知,只有一个免费转服务器正在运行,它是:http://numb.viagenie.ca。请注意:这个回合服务器正在工作,但还不够好,您经常会断开连接。你应该用户如下:

private ArrayList<PeerConnection.IceServer> iceServer = new ArrayList<>(); iceServers.add(PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer()); iceServers.add(PeerConnection.IceServer.builder("stun:numb.viagenie.ca").createIceServer()); iceServers.add(PeerConnection.IceServer.builder("turn:numb.viagenie.ca").setUsername("YOUR_USER_NAME").setPassword("YOUR_PASSWORD").createIceServer());

并将其传递给 PeerConnection。

或者,您可以在 XIRSYS 上创建一个开发帐户,并获得免费的月度报价并使用它。

于 2020-07-11T11:02:42.133 回答