Fix linting errors

This commit is contained in:
Jerko Steiner 2017-05-30 20:31:35 -04:00
parent f376f579c0
commit d3d7fc3848
3 changed files with 32 additions and 17 deletions

View File

@ -29,7 +29,8 @@
"expect": true, "expect": true,
"localStorage": false, "localStorage": false,
"window": false, "window": false,
"jest": true "jest": true,
"jasmine": true
}, },
"rules": { "rules": {

View File

@ -1,31 +1,45 @@
const iceServers = require('./iceServers.js'); const iceServers = require('./iceServers.js');
function checkTURNServer(turnConfig, timeout){ function noop() {}
function checkTURNServer(turnConfig, timeout) {
console.log('checking turn server', turnConfig); console.log('checking turn server', turnConfig);
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject) {
setTimeout(function(){ setTimeout(function() {
if(promiseResolved) return; if (promiseResolved) return;
resolve(false); resolve(false);
promiseResolved = true; promiseResolved = true;
}, timeout || 5000); }, timeout || 5000);
var promiseResolved = false const promiseResolved = false;
, myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection //compatibility for firefox and chrome const PeerConnection = window.RTCPeerConnection ||
, pc = new myPeerConnection({iceServers:[turnConfig]}) window.mozRTCPeerConnection ||
, noop = function(){}; window.webkitRTCPeerConnection;
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(function(sdp){ const pc = new PeerConnection({ iceServers: [turnConfig] });
if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
// create a bogus data channel
pc.createDataChannel('');
pc.createOffer(function(sdp) {
// sometimes sdp contains the ice candidates...
if (sdp.sdp.indexOf('typ relay') > -1) {
promiseResolved = true; promiseResolved = true;
resolve(true); resolve(true);
} }
pc.setLocalDescription(sdp, noop, noop); pc.setLocalDescription(sdp, noop, noop);
}, noop); // create offer and set local description }, noop);
pc.onicecandidate = function(ice){ //listen for candidate events
if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1)) return; pc.onicecandidate = function(ice) {
if (promiseResolved ||
!ice ||
!ice.candidate ||
!ice.candidate.candidate ||
!(ice.candidate.candidate.indexOf('typ relay') > -1)) {
return;
}
promiseResolved = true; promiseResolved = true;
resolve(true); resolve(true);
}; };

View File

@ -27,7 +27,7 @@ describe('turn', () => {
username: 'c', username: 'c',
secret: 'd', secret: 'd',
auth: 'secret' auth: 'secret'
}] }];
it('does not expose secret', () => { it('does not expose secret', () => {
const s = turn.processServers(servers); const s = turn.processServers(servers);
@ -40,7 +40,7 @@ describe('turn', () => {
credential: jasmine.any(String) credential: jasmine.any(String)
}); });
expect(s[1].username).toMatch(/^[0-9]+:c$/); expect(s[1].username).toMatch(/^[0-9]+:c$/);
}) });
it('throws error when unknown auth type', () => { it('throws error when unknown auth type', () => {
expect(() => turn.processServers([{ auth: 'bla' }])) expect(() => turn.processServers([{ auth: 'bla' }]))