WebRTC uses always TURN outside our LAN

我的未来我决定 提交于 2019-12-08 03:54:33

问题


My problem:

I wrote a video chat application based on WebRTC. When two clients connect inside our LAN, they always get a Peer-to-Peer connection. But when a client from our LAN connects with a client outside our LAN it's always a Peer-to-TURN connection. When mobile devices connect with each other it's often TURN-to-TURN.

What I expect:

I know of symmetric NAT problems and expect 20% to 30% of all connections to require a TURN connection. But so far I never found any two clients outside of our LAN to get a Peer-to-Peer connection - that seems wrong.

My setup:

I tested on Chrome, Firefox, Electron, Android and iOS devices.

I use a Coturn server as STUN/TURN server. The server is accessible via internet.

I check via peerConnection.getStats() for an item with item.type === 'googCandidatePair' && item.googActiveConnection === 'true' and look into its item.googLocalCandidateType and item.googRemoteCandidateType. If the type is something like relay, its a TURN connection.

My analysis:

When my system says the TURN server is involved and I stop Coturn, the video freezes - so I guess my applicatons feedback is true.

I see host, srflx and relay ICE candidates on both sides. So the STUN/TURN config of my app seems correct.

I even built a test setup into my application, which tries to connect to a designated robot peer, with video and audio disabled and try to send data via peerConnection data channel back and forth. Then I check the stats as stated above, but it behaves the same: Peer-to-Peer in our LAN. Always TURN involved outside.

During my tests I found peerConnection.oniceconnectionstatechange to take a long time (ca. 12 sec) to change from connected to completed. But again only with peers outside of LAN, not inside. However, the data channel opens earlier and works. Waiting for completed before calling getStats() does not change my result. AFAIK only the caller has a completed state.

My hope:

Has anyone any hints what I can change or how I can improve or extend my check? Which component might be the issue (app code, network, STUN server, TURN server)?

来源:https://stackoverflow.com/questions/52875054/webrtc-uses-always-turn-outside-our-lan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!