简体   繁体   中英

Using WebRTC for Video Streaming in android app

I am using WebRTC for communication for media streaming between my android app and web app. For signalling I have used socket.io and using socket I have established the connection between android app and web app. I am able to send offer and receive answer on Mobile app and ideally after that the streaming should start but in my case it is throwing this error on the 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

I think this is happening because connection can't be established with the TURN server. Can someone help me with this. I am using this piece of code for TURN server connection. Also please tell me how can i verify if my connection with TURN has been established.

 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();
    } 

This is the piece of code where i am trying to create peer connection.

  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();
}

If anyone wants to have more better view of code i will share more details. please i need help since i can't even find the documentation for this.

it looks like that the turn server you are using is not active anymore. Please note: it is almost impossible to find free TURN server. as far as i know, there is only one free turn server which is working and it is:http://numb.viagenie.ca. Please note: this turn server is working but it is not good enough and you are get disconnected very often. you should user is as follow:

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());

and pass it to the PeerConnection.

Alternatively, you can create a development account on XIRSYS and get free monthly quote and use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM