Android WebRTC 和 STUN 问题
Android WebRTC and STUN issue
我尝试基于 webrtc 构建 Android 版本的 IOS 应用程序。我使用 STUN 服务器(不是 TURN,并且 IOS 应用仅使用 STUN 服务器)并且 android 应用无法在不同的网络上运行(但 IOS 工作正常)。
RTC配置:
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXCOMPAT;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.ALL;
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
PS :我尝试了许多不同的 STUN 服务器(例如:stun:stun.l.google.com:19302)但没有一个有效。
更新:
ICE SAMPLE of STUN(冰连接失败):
{"sdp":"candidate:1911153948 1 udp 2122260223 192.168.15.33 54469 typ host generation 0 ufrag Ucsk network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:4037141416 1 udp 1686052607 217.112.221.86 33341 typ srflx raddr 192.168.15.33 rport 54469 generation 0 ufrag Ucsk network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
ICE SAMPLE 工作回合:
{"sdp":"candidate:1911153948 1 udp 2122260223 192.168.15.33 53080 typ host generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:4037141416 1 udp 1686052607 217.112.221.86 47737 typ srflx raddr 192.168.15.33 rport 53080 generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:3433799847 1 udp 41885439 66.228.45.110 56124 typ relay raddr 217.112.221.86 rport 47737 generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
另外在日志中,我在 15 秒 ping 后出现连接超时错误:
I/libjingle: (port.cc:1413): Jingle:Conn[0xafe1c200:audio:ymVmyEYx:1:0:local:udp:192.168.15.x:59152->p7NE+tsC:1:1686052607:stun:udp:46.133.252.x:62179|C--I|0|0|7241540810645061118|-]: Sent STUN ping, id=597771634a2b427864497448, use_candidate=0, nomination=0
I/libjingle: (port.cc:1413): Jingle:Conn[0xafe1bd00:audio:ymVmyEYx:1:0:local:udp:192.168.15.x:59152->+xyFpztR:1:2122260223:local:udp:100.73.133.x:43879|C--I|0|0|9115038255631187454|-]: Sent STUN ping, id=345231714b49377a66633056, use_candidate=0, nomination=0
从评论链来看,Android 应用似乎在对称 NAT 之后。这通常是需要 TURN 服务器的原因;对称 NAT 后面的端点不能直接与另一个对称 NAT 或 port-restricted NAT 后面的端点通信。
因此,假设这是正在发生的事情,您无能为力;这是您需要 TURN 服务器的情况之一。
我尝试基于 webrtc 构建 Android 版本的 IOS 应用程序。我使用 STUN 服务器(不是 TURN,并且 IOS 应用仅使用 STUN 服务器)并且 android 应用无法在不同的网络上运行(但 IOS 工作正常)。
RTC配置:
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXCOMPAT;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.ALL;
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
PS :我尝试了许多不同的 STUN 服务器(例如:stun:stun.l.google.com:19302)但没有一个有效。
更新:
ICE SAMPLE of STUN(冰连接失败):
{"sdp":"candidate:1911153948 1 udp 2122260223 192.168.15.33 54469 typ host generation 0 ufrag Ucsk network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:4037141416 1 udp 1686052607 217.112.221.86 33341 typ srflx raddr 192.168.15.33 rport 54469 generation 0 ufrag Ucsk network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
ICE SAMPLE 工作回合:
{"sdp":"candidate:1911153948 1 udp 2122260223 192.168.15.33 53080 typ host generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:4037141416 1 udp 1686052607 217.112.221.86 47737 typ srflx raddr 192.168.15.33 rport 53080 generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
{"sdp":"candidate:3433799847 1 udp 41885439 66.228.45.110 56124 typ relay raddr 217.112.221.86 rport 47737 generation 0 ufrag u6i0 network-id 3 network-cost 10","sdpMLineIndex":0,"sdpMid":"audio"}
另外在日志中,我在 15 秒 ping 后出现连接超时错误:
I/libjingle: (port.cc:1413): Jingle:Conn[0xafe1c200:audio:ymVmyEYx:1:0:local:udp:192.168.15.x:59152->p7NE+tsC:1:1686052607:stun:udp:46.133.252.x:62179|C--I|0|0|7241540810645061118|-]: Sent STUN ping, id=597771634a2b427864497448, use_candidate=0, nomination=0
I/libjingle: (port.cc:1413): Jingle:Conn[0xafe1bd00:audio:ymVmyEYx:1:0:local:udp:192.168.15.x:59152->+xyFpztR:1:2122260223:local:udp:100.73.133.x:43879|C--I|0|0|9115038255631187454|-]: Sent STUN ping, id=345231714b49377a66633056, use_candidate=0, nomination=0
从评论链来看,Android 应用似乎在对称 NAT 之后。这通常是需要 TURN 服务器的原因;对称 NAT 后面的端点不能直接与另一个对称 NAT 或 port-restricted NAT 后面的端点通信。
因此,假设这是正在发生的事情,您无能为力;这是您需要 TURN 服务器的情况之一。