2017-06-16 65 views
1

我正在使用WebRtc native android应用程序。我也编译io.pristine库。我只能在两个设备连接到无线网络时才能建立呼叫。如果其中一个设备连接到蜂窝网络,则无法建立呼叫。我读了任何可能的论坛,看起来像我需要TURN服务器。我已经运行了我自己的TURN服务器,但idk我如何强制应用程序使用此服务器。欢迎任何帮助。谢谢!!将TURN服务器添加到android webRtc本地

+0

你能指导我如何构建io.pristine库。 –

+0

严格来说,只需一个STUN服务器就足够了,但如果客户端无法建立点对点连接,TURN也会提供回退。在那里有免费的公共STUN服务器,例如stun.l.google.com:19302。 – jamix

回答

1

创建PeerConnection时需要设置TURN服务器。

它会是这样的:

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

我还没有运行此代码,但你应该明白我的意思。

+1

只需在第二行和第三行末尾添加括号即可。 –