Skip to content

Commit

Permalink
edge: fix STUN/TURN filtering
Browse files Browse the repository at this point in the history
by filtering STUN ourselves again. Also adds logging.
Fixes #911
  • Loading branch information
fippo committed Dec 9, 2018
1 parent c507003 commit 45bb781
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/js/edge/edge_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export function shimPeerConnection(window) {
browserDetails.version);
window.RTCPeerConnection = function(config) {
if (config && config.iceServers) {
// TODO: pass browserDetails.version again. See #903 for
// why this is not done.
config.iceServers = filterIceServers(config.iceServers);
config.iceServers = filterIceServers(config.iceServers,
browserDetails.version);
utils.log('ICE servers after filtering:', config.iceServers);
}
return new RTCPeerConnectionShim(config);
};
Expand Down
13 changes: 8 additions & 5 deletions src/js/edge/filtericeservers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ export function filterIceServers(iceServers, edgeVersion) {
urls = [urls];
}
urls = urls.filter(url => {
// filter STUN unconditionally.
if (url.indexOf('stun:') === 0) {
return false;
}

const validTurn = url.startsWith('turn') &&
!url.startsWith('turn:[') &&
url.includes('transport=udp') &&
url.includes('transport=udp');
!hasTurn;

if (validTurn) {
if (validTurn && !hasTurn) {
hasTurn = true;
return true;
}
return url.indexOf('stun:') === 0 && edgeVersion >= 14393 &&
url.indexOf('?transport=udp') === -1;
return validTurn && !hasTurn;
});

delete server.url;
Expand Down
13 changes: 4 additions & 9 deletions test/unit/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe('Edge shim', () => {

it('converts legacy url member to urls', () => {
const result = filterIceServers([
{url: 'stun:stun.l.google.com'}
{url: 'turn:stun.l.google.com:19302?transport=udp'}
], edgeVersion);
expect(result).to.deep.equal([
{urls: 'stun:stun.l.google.com'}
{urls: 'turn:stun.l.google.com:19302?transport=udp'}
]);
});

Expand All @@ -63,13 +63,11 @@ describe('Edge shim', () => {
expect(result).to.deep.equal([]);
});

it('does not filter STUN without protocol after r14393', () => {
it('does filter STUN without protocol after r14393', () => {
const result = filterIceServers([
{urls: 'stun:stun.l.google.com'}
], edgeVersion);
expect(result).to.deep.equal([
{urls: 'stun:stun.l.google.com'}
]);
expect(result).to.deep.equal([]);
});

it('does filter STUN with protocol even after r14393', () => {
Expand Down Expand Up @@ -102,21 +100,18 @@ describe('Edge shim', () => {
{urls: 'turn:stun.l.google.com:19302?transport=udp'}
], edgeVersion);
expect(result).to.deep.equal([
{urls: 'stun:stun.l.google.com'},
{urls: 'turn:stun.l.google.com:19301?transport=udp'}
]);
});

it('in urls entries', () => {
const result = filterIceServers([
{urls: 'stun:stun.l.google.com'},
{urls: [
'turn:stun.l.google.com:19301?transport=udp',
'turn:stun.l.google.com:19302?transport=udp'
]}
], edgeVersion);
expect(result).to.deep.equal([
{urls: 'stun:stun.l.google.com'},
{urls: ['turn:stun.l.google.com:19301?transport=udp']}
]);
});
Expand Down

0 comments on commit 45bb781

Please sign in to comment.