Alexander
Alexander

Reputation: 333

Add TURN server to android webRtc native

I'm working on WebRtc native android application. Im also compiling io.pristine lib. Im able to establish calls between two devices only if both of them are connected to the wifi. In case when one of the devices is connected to the cellular network im not able to establish call. I read any possible forum out there and its look like I need TURN server. I already run my own TURN server but idk how I can force the app to use this server. Any help is welcome. Thank you!!

Upvotes: 9

Views: 7366

Answers (2)

emin deniz
emin deniz

Reputation: 439

WebRTC deprecated old API to create ICE servers. (Answer which uses old API)

To create ICE server you need to use IceServer builder pattern.

 PeerConnection.IceServer stun =  PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer();
 PeerConnection.IceServer turn =  PeerConnection.IceServer.builder("turn:numb.viagenie.ca").setUsername("[email protected]").setPassword("muazkh").createIceServer();

Upvotes: 18

Mikko
Mikko

Reputation: 1947

You need to set the TURN server when creating the PeerConnection.

It will go something like this:

    // Set ICE servers
    List<PeerConnection.IceServer> iceServers = new ArrayList<>();
    iceServers.add(new org.webrtc.PeerConnection.IceServer("stun:xxx.xxx.xxx.xxx"));
    iceServers.add(new org.webrtc.PeerConnection.IceServer("turn:xxx.xxx.xxx.xxx:3478", "username", "credential"));

    // Create peer connection
    final PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
    PeerConnectionFactory factory = new PeerConnectionFactory(new PeerConnectionFactory.Options());
    MediaConstraints constraints = new MediaConstraints();
    PeerConnection peerConnection = factory.createPeerConnection(iceServers, constraints, new YourPeerConnectionObserver());

I have not run this code, but you should get the idea.

Upvotes: 11

Related Questions