WebRTC:强制对等方使用TURN服务器 [英] WebRTC: force peers to use TURN server
问题描述
我有一个webrtc应用程序,它工作正常,但出于测试目的,我需要测试我的TURN服务器是否工作,但因为两个测试设备都在同一个网络中,我无法测试,想到下面的代码会将候选人限制为只使用TURN服务器的人,
I have a webrtc application, it works fine, but for testing purposes, I need to test if my TURN server works, but because both the testing devices are within the same network, I am unable to test, thought below code would restrict candidates to only the ones using TURN server,
function onIceCandidate(event, targetSessionID, targetUserName) {
if (event.candidate) {
var candidate = event.candidate.candidate;
if(candidate.indexOf("relay")<0){ // if no relay address is found, assuming it means no TURN server
return;
}
sendMessage(candidate); // using socket.io to send to the otherside
...
但我注意到了那个(非常沮丧),这不起作用,因为当同伴创建答案描述时,
but I noticed that( with much frustration), this does not work, because when peer is creating answer description,
....
a=candidate:0 1 UDP 2128609535 13.198.98.221 58779 typ host
a=candidate:0 2 UDP 2128609534 13.198.98.221 58780 typ host
....
这意味着,通信是直接的,而不是通过TURN服务器,我假设这是正确的吗?现在,我如何强制webrtc使用TURN服务器?
this means, the communcation is direct and not through TURN server, am I correct in assuming this? Now, how do I force the webrtc to use the TURN server?
推荐答案
只需添加此项以关闭问题,
just adding this to close the question,
function onIceCandidate(event, targetSessionID, targetUserName) {
if (event.candidate) {
var candidate = event.candidate.candidate;
if(candidate.indexOf("relay")<0){ // if no relay address is found, assuming it means no TURN server
return;
}...
以上代码有效,检查到 wireshark
,
The above code works, checked to wireshark
,
添加 if(candidate.indexOf(relay)< 0)
条件,只能通过TURN服务器进行通信,如果服务器不存在/错误的详细信息,连接状态得到新
after adding the if(candidate.indexOf("relay")<0)
condition, communication takes place only through TURN server, if server is not present/ incorrect details, connection state get's struck at new
编辑: iceTransportPolicyrel =nofollow> w3 webrtc ,传递 relay
作为 iceTransportPolicy
应该有效,但我尚未检查它是否已在Firefox和Chrome中实现...
like cullen has said in his answer, according to w3 webrtc, passing relay
as iceTransportPolicy
should work, but I haven't checked if it is implemented in Firefox and Chrome yet...
这篇关于WebRTC:强制对等方使用TURN服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!