在您的 ubuntu 服务器机器上,设置、配置和运行coturn的打包版本 。对于基本设置,请执行
# set up
sudo apt-get install --assume-yes coturn
# configure & run
USERNAME="some-username"
PASSWORD="some-password"
PORT=3478
# -n: use only commandline parameters, no config file
sudo turnserver \
-n \
--verbose \
--lt-cred-mech \
--user $USERNAME:$PASSWORD \
--realm "someRealm" \
--no-dtls \
--no-tls \
--listening-port $PORT
添加--daemon
以使其在后台运行。有关选项列表,请参阅https://github.com/coturn/coturn/wiki/turnserver ,如果您想使用其中的一个而不是像我一样在命令行上使用和传递所有选项,请turnserver
查看他们的示例配置文件上面做了。-c CONFIGFILE
-n
要检查它是否有效,在 Google Chrome 中,在任何安全来源的页面(例如 stackoverflow.com)上,在开发者控制台中运行:
function checkTURNServer(turnConfig, timeout){
return new Promise(function(resolve, reject){
setTimeout(function(){
if(promiseResolved) return;
resolve(false);
promiseResolved = true;
}, timeout || 5000);
var promiseResolved = false
, myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection //compatibility for firefox and chrome
, pc = new myPeerConnection({iceServers:[turnConfig]})
, noop = function(){};
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(function(sdp){
if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
promiseResolved = true;
resolve(true);
}
pc.setLocalDescription(sdp, noop, noop);
}, noop); // create offer and set local description
pc.onicecandidate = function(ice){ //listen for candidate events
if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1)) return;
promiseResolved = true;
resolve(true);
};
});
}
const USERNAME="some-username"
const PASSWORD="some-password"
const PORT=3478
const IP="10.11.0.115" // you will have to change this
console.log('TURN server reachable on TCP?', await checkTURNServer( {
url: `turn:${IP}:${PORT}?transport=tcp`,
username: USERNAME,
credential: PASSWORD,
}))
console.log('TURN server reachable on UDP?', await checkTURNServer( {
url: `turn:${IP}:${PORT}?transport=udp`,
username: USERNAME,
credential: PASSWORD,
}))
你应该得到
TURN server reachable on TCP? true
TURN server reachable on UDP? true