Android WebRTC application could not establish connection between peers

814 views Asked by At

A WebRTC application was developed with STUN servers alone. These servers work well when the devices are connected to the home network and peer connection is established between devices without any issues. And while testing the application with different ISP providers, peer connection could not be established between devices.

private List<PeerConnection.IceServer> getIceServers () {
        if (Objects.equals ( null, iceServers ) || iceServers.size () == 0) {
            iceServers = new ArrayList<> ();
            iceServers.add ( PeerConnection.IceServer.builder ( STUN_SERVER_1 ).createIceServer () );
            iceServers.add ( PeerConnection.IceServer.builder ( STUN_SERVER_2 ).createIceServer () );
        }
        return iceServers;
    }

To solve this issue, a TURN server (using coturn) was created in Ubuntu AWS Instance. After creation, this TURN server was tested with the help of WebRTC's Trickle ICE page. While clicking 'Gather candidates', the page returns 'Done' as a final result. So, got to know that the TURN server is running successfully.

Trickle ICE page result

Now, along with the existing STUN servers, this working TURN server credentials are added to the WebRTC application. So the application now has 3 ICE servers (2 Google STUN servers & 1 TURN server)

private List<PeerConnection.IceServer> getIceServers () {
        if (Objects.equals ( null, iceServers ) || iceServers.size () == 0) {
            iceServers = new ArrayList<> ();
            iceServers.add ( PeerConnection.IceServer.builder ( STUN_SERVER_1 ).createIceServer () );
            iceServers.add ( PeerConnection.IceServer.builder ( STUN_SERVER_2 ).createIceServer () );
            iceServers.add ( PeerConnection.IceServer.builder ( TURN_SERVER_1 )
              .setUsername ( "TURN_USER_NAME" ).setPassword ( "TURN_PASSWORD" ).createIceServer () );
        }
        return iceServers;
    }

Here the problem is, even after adding the TURN server, peer connection is not established between devices on some networks. Could not sort out what makes the iceConnectionState as FAILED. If anyone has provided a solution already, please help me find that. Thanks

1

There are 1 answers

1
niranj1997 On BEST ANSWER

Peer connection gets established between devices when the TCP transport method is added.

This is done by changing the TURN server URL from turn:<public-ip>:<port> to turn:<public-ip>:<port>?transport=tcp

Any other better working solution might be useful