先说以下如何获得REST API编写的ICE Servers获取方法:
curl -d "key=AIzaSyA2WoxRAjLTwrD7upuk9N2qdlcOch3D2wU" https://networktraversal.googleapis.com/v1alpha/iceconfig --referer https://appr.tc/
返回一个json:
{
"lifetimeDuration": "86400s",
"iceServers": [
{
"urls": [
"stun:172.217.211.127:19302",
"stun:[2404:6800:400a:1001::7f]:19302"
]
},
{
"urls": [
"turn:74.125.203.127:19305?transport=udp",
"turn:[2404:6800:4008:c03::7f]:19305?transport=udp",
"turn:74.125.203.127:19305?transport=tcp",
"turn:[2404:6800:4008:c03::7f]:19305?transport=tcp"
],
"username": "CMSGwvYFEgYIbyyLcjcYzc/s6OMTIICjBQ",
"credential": "GdxhGuNTskLoyMMzXmDRJU3jiRI=",
"maxRateKbps": "8000"
}
],
"blockStatus": "NOT_BLOCKED",
"iceTransportPolicy": "all"
}
下面把这个里面的stun和tun服务的url在一个小工具“Trickle ICE”里的做验证。
Trickle ICE地址:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
1. 测试turn
返回的结果为:
该工具的使用说明部分有一句话:If you test just a single TURN/UDP server, this page even allows you to detect when you are using the wrong credential to authenticated.
意思是说,turn/udp可以使用错误的凭据,但turn/tcp不行。我验证一下,这似乎只对google自己的turn/udp不验证凭据,其他的turn/udp还是需要验证的。
出现“relay”表明成功,之前出现的“srflx”表明turn服务中已经包含了stun。
2. 测试stun
返回的结果为:
还是看该工具的使用说明部分有一句话:If you test a STUN server, it works if you can gather a candidate with type "srflx". If you test a TURN server, it works if you can gather a candidate with type "relay".
出现“srflx”表明成功。