Add turn server debug function
This commit is contained in:
parent
ddb54a28e2
commit
d00b1d825c
37
src/client/debug/index.js
Normal file
37
src/client/debug/index.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
const iceServers = require('./iceServers.js');
|
||||||
|
|
||||||
|
function checkTURNServer(turnConfig, timeout){
|
||||||
|
|
||||||
|
console.log('checking turn server', turnConfig);
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkTURNServer(iceServers[0], 10000)
|
||||||
|
.then(console.log.bind(console))
|
||||||
|
.catch(console.error.bind(console));
|
||||||
@ -1,8 +1,4 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
||||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const App = require('./components/app.js');
|
const App = require('./components/app.js');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactDom = require('react-dom');
|
const ReactDom = require('react-dom');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user