diff --git a/.eslintrc b/.eslintrc index f569a0c..43899d2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -29,7 +29,8 @@ "expect": true, "localStorage": false, "window": false, - "jest": true + "jest": true, + "jasmine": true }, "rules": { diff --git a/src/client/debug/index.js b/src/client/debug/index.js index 6e2ed31..53ae0cc 100644 --- a/src/client/debug/index.js +++ b/src/client/debug/index.js @@ -1,31 +1,45 @@ const iceServers = require('./iceServers.js'); -function checkTURNServer(turnConfig, timeout){ +function noop() {} + +function checkTURNServer(turnConfig, timeout) { console.log('checking turn server', turnConfig); - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { - setTimeout(function(){ - if(promiseResolved) return; + 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... + const promiseResolved = false; + const PeerConnection = window.RTCPeerConnection || + window.mozRTCPeerConnection || + window.webkitRTCPeerConnection; + + const pc = new PeerConnection({ iceServers: [turnConfig] }); + + // 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; 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; + }, noop); + + pc.onicecandidate = function(ice) { + if (promiseResolved || + !ice || + !ice.candidate || + !ice.candidate.candidate || + !(ice.candidate.candidate.indexOf('typ relay') > -1)) { + return; + } promiseResolved = true; resolve(true); }; diff --git a/src/server/__tests__/turn-test.js b/src/server/__tests__/turn-test.js index 3497fd6..196b4b9 100644 --- a/src/server/__tests__/turn-test.js +++ b/src/server/__tests__/turn-test.js @@ -27,7 +27,7 @@ describe('turn', () => { username: 'c', secret: 'd', auth: 'secret' - }] + }]; it('does not expose secret', () => { const s = turn.processServers(servers); @@ -40,7 +40,7 @@ describe('turn', () => { credential: jasmine.any(String) }); expect(s[1].username).toMatch(/^[0-9]+:c$/); - }) + }); it('throws error when unknown auth type', () => { expect(() => turn.processServers([{ auth: 'bla' }]))