将STUN服务器集成到XSockets.NET WebRTC中
我对这个很陌生。 我将如何向现有的XSockets.NET WebRTC Javascript代码中添加STUN功能 这个JS创建了我的连接。我在运行mono的linux机器上单独运行信令服务器将STUN服务器集成到XSockets.NET WebRTC中,webrtc,xsockets.net,Webrtc,Xsockets.net,我对这个很陌生。 我将如何向现有的XSockets.NET WebRTC Javascript代码中添加STUN功能 这个JS创建了我的连接。我在运行mono的linux机器上单独运行信令服务器 <script type="text/javascript"> $(document).ready(function() { var rtc, ws, currentContext, change; var roomName = '<?
<script type="text/javascript">
$(document).ready(function()
{
var rtc, ws, currentContext, change;
var roomName = '<?php echo $roomName; ?>';
var myCtx = '<?php echo $roomHash; ?>';
var XSocketsServerIP = '<?php echo $XSocketsServerIP; ?>';
var startofurl = "/";
var myCtxURLVersion = startofurl.concat(roomName);
window.history.pushState("", "title", myCtxURLVersion);
//Create new XSockets WebSocket.
ws = new XSockets.WebSocket(XSocketsServerIP);
ws.onopen = function (connection)
{
console.log("Connection", connection);
rtc = new XSockets.WebRTC(ws);
rtc.oncontextcreated = function(ctx)
{
console.log("ctx", ctx);
};
rtc.oncontextchanged = function(change)
{
console.log("change of context", change);
};
rtc.getUserMedia({audio:true,video:false}, function(result)
{
rtc.changeContext(myCtx);
console.log("getUserMedia() success.", result);
});
rtc.onremotestream = function(event) {
var randhash = Math.floor((Math.random() * 9999) + 1);
randhash = hex_md5(randhash);
var videoTag = document.createElement('video');
videoTag.setAttribute("id",randhash);
videoTag.setAttribute("autoplay", "true");
videoTag.setAttribute("poster", "images/user.png");
document.getElementById('othersarea').appendChild(videoTag);
attachMediaStream(videoTag, event.stream);
}
rtc.onlocalstream = function(stream)
{
console.log("attach okay!");
attachMediaStream(document.querySelector("#localVideo"), stream);
};
ws.subscribe("onChangeContextFailed", function(data)
{
console.log(data);
});
rtc.bind(XSockets.WebRTC.Events.onPeerConnectionLost, function(peer)
{
console.log('OnPeerConnectionLost', peer);
$('video').last().remove();
});
};
var root = "<?php echo $root; ?>";
fullURL = root.concat(myCtxURLVersion);
function urlIntoBox(myCtxURLVersion) {
var textbox = document.getElementById('txtSelect');
textbox.value = fullURL;
}
function getNumVidsOnPage()
{
var videos = document.getElementsByTagName('video'),
numVideos = videos.length;
}
urlIntoBox();
var currVideos = getNumVidsOnPage();
if (currVideos > 10)
{
window.location.href = "http://voice.gg?msg=That%20room%20has%20too%20many%users.";
}
});
</script>
$(文档).ready(函数()
{
var rtc、ws、currentContext、变更;
var roomName='';
var myCtx='';
var XSocketsServerIP='';
var startofull=“/”;
var myCtxURLVersion=startofull.concat(roomName);
window.history.pushState(“,“title”,myctxurversion);
//创建新的XSockets WebSocket。
ws=新的XSockets.WebSocket(XSocketsServerIP);
ws.onopen=函数(连接)
{
日志(“连接”,连接);
rtc=新的XSockets.WebRTC(ws);
rtc.oncontextcreated=函数(ctx)
{
控制台日志(“ctx”,ctx);
};
rtc.oncontextchanged=函数(更改)
{
日志(“上下文更改”,更改);
};
getUserMedia({audio:true,video:false},函数(结果)
{
rtc.changeContext(myCtx);
log(“getUserMedia()success.”,result);
});
rtc.onremotestream=函数(事件){
var randhash=Math.floor((Math.random()*9999)+1);
randhash=hex_md5(randhash);
var videoTag=document.createElement('video');
videoTag.setAttribute(“id”,randhash);
setAttribute(“自动播放”、“真”);
setAttribute(“poster”、“images/user.png”);
document.getElementById('othersarea').appendChild(videoTag);
attachMediaStream(视频标签、事件流);
}
rtc.onlocalstream=函数(流)
{
日志(“连接好!”);
attachMediaStream(document.querySelector(“本地视频”),流);
};
订阅(“onChangeContextFailed”,函数(数据)
{
控制台日志(数据);
});
绑定(XSockets.WebRTC.Events.onPeerConnectionLost,函数(对等)
{
log('OnPeerConnectionLost',peer);
$('video').last().remove();
});
};
var root=“”;
fullURL=root.concat(myCtxURLVersion);
函数urlIntoBox(myCtxURLVersion){
var textbox=document.getElementById('txtSelect');
textbox.value=fullURL;
}
函数getNumVidsOnPage()
{
var videos=document.getElementsByTagName(“视频”),
numVideos=videos.length;
}
urlIntoBox();
var currvides=getNumVidsOnPage();
如果(视频>10)
{
window.location.href=”http://voice.gg?msg=That%20room%20has%20too%20many%users.";
}
});
我如何才能继续添加STUN功能以确保NAT用户也可以连接,因为目前他们在连接方面遇到了问题。。
谢谢 不知道您使用的是XSockets版本3还是版本4,但如果您查看一下,就会发现有一节介绍了如何更改stun服务器的配置 github的示例:
var rtc = new XSockets.WebRTC(broker, {
iceServers: [{
url: 'stun:404.idonotexist.net'
}],
streamConstraints: {
optional: [{
'bandwidth': 500
}]
}});
谢谢您有推荐的STUN服务器吗?默认为STUN.google.com,但您可以添加任何STUN服务器。如果你需要打开服务器,你可以咨询xsockets开发者论坛。看起来我运行的是3.0版。是的,当我仔细看的时候,我可以看到这一点。带有WebRTC的版本3非常适合业余爱好/私人爱好,但版本4速度更快,并且解决了一些问题,如连接故障。您也可以将stun添加到版本3中,这样您仍然可以实现您的要求。是否可以使用上述代码将stun添加到v3中?