Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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="test"
- const PASSWORD="test"
- const PORT=3478
- const IP="134.255.233.132" // 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,
- }))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement