'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!!
Solution 1:[1]
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.
Solution 2:[2]
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();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | emin deniz |