Skip to content

Commit

Permalink
rename extmap common shim
Browse files Browse the repository at this point in the history
and add units tests
  • Loading branch information
fippo committed Feb 14, 2021
1 parent 9d3f1c1 commit 27d724f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/js/adapter_factory.js
Expand Up @@ -66,7 +66,7 @@ export function adapterFactory({window} = {}, options = {
commonShim.shimConnectionState(window);
commonShim.shimMaxMessageSize(window);
commonShim.shimSendThrowTypeError(window);
commonShim.removeAllowExtmapMixed(window);
commonShim.removeExtmapAllowMixed(window, browserDetails);
break;
case 'firefox':
if (!firefoxShim || !firefoxShim.shimPeerConnection ||
Expand Down Expand Up @@ -141,7 +141,7 @@ export function adapterFactory({window} = {}, options = {
commonShim.shimRTCIceCandidate(window);
commonShim.shimMaxMessageSize(window);
commonShim.shimSendThrowTypeError(window);
commonShim.removeAllowExtmapMixed(window);
commonShim.removeExtmapAllowMixed(window, browserDetails);
break;
default:
logging('Unsupported browser!');
Expand Down
3 changes: 1 addition & 2 deletions src/js/common_shim.js
Expand Up @@ -317,12 +317,11 @@ export function shimConnectionState(window) {
});
}

export function removeAllowExtmapMixed(window) {
export function removeExtmapAllowMixed(window, browserDetails) {
/* remove a=extmap-allow-mixed for webrtc.org < M71 */
if (!window.RTCPeerConnection) {
return;
}
const browserDetails = utils.detectBrowser(window);
if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) {
return;
}
Expand Down
97 changes: 97 additions & 0 deletions test/unit/extmap-allow-mixed.js
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2021 The adapter.js project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/
/* eslint-env node */
const chai = require('chai');
const expect = chai.expect;
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);

describe('removal of extmap-allow-mixed', () => {
const shim = require('../../dist/common_shim');
let window;
let origSetRemoteDescription;
beforeEach(() => {
window = {
RTCPeerConnection: sinon.stub(),
};
origSetRemoteDescription = sinon.stub();
window.RTCPeerConnection.prototype.setRemoteDescription =
origSetRemoteDescription;
});

const sdp = 'a=extmap-allow-mixed\r\n';

describe('does nothing if', () => {
it('RTCPeerConnection is not defined', () => {
expect(() => shim.removeExtmapAllowMixed({}, {})).not.to.throw();
});
});

describe('Chrome behaviour', () => {
let browserDetails;
// Override addIceCandidate to simulate legacy behaviour.
beforeEach(() => {
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
return origSetRemoteDescription.apply(this, arguments);
};
browserDetails = {browser: 'chrome', version: '88'};
});

it('does not remove the extmap-allow-mixed line after Chrome 71', () => {
browserDetails.version = 71;
shim.removeExtmapAllowMixed(window, browserDetails);

const pc = new window.RTCPeerConnection();
pc.setRemoteDescription({sdp: '\n' + sdp});
expect(origSetRemoteDescription.firstCall.args[0].sdp)
.to.equal('\n' + sdp);
});

it('does remove the extmap-allow-mixed line before Chrome 71', () => {
browserDetails.version = 70;
shim.removeExtmapAllowMixed(window, browserDetails);

const pc = new window.RTCPeerConnection();
pc.setRemoteDescription({sdp: '\n' + sdp});
console.log(origSetRemoteDescription.firstCall.args);
expect(origSetRemoteDescription.firstCall.args[0].sdp).to.equal('\n');
});
});

describe('Safari behaviour', () => {
let browserDetails;
// Override addIceCandidate to simulate legacy behaviour.
beforeEach(() => {
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
return origSetRemoteDescription.apply(this, arguments);
};
browserDetails = {browser: 'safari', version: '605'};
});

it('does not remove the extmap-allow-mixed line after 605', () => {
browserDetails.version = 605;
shim.removeExtmapAllowMixed(window, browserDetails);

const pc = new window.RTCPeerConnection();
pc.setRemoteDescription({sdp: '\n' + sdp});
expect(origSetRemoteDescription.firstCall.args[0].sdp)
.to.equal('\n' + sdp);
});

it('does remove the extmap-allow-mixed line before 605', () => {
browserDetails.version = 604;
shim.removeExtmapAllowMixed(window, browserDetails);

const pc = new window.RTCPeerConnection();
pc.setRemoteDescription({sdp: '\n' + sdp});
console.log(origSetRemoteDescription.firstCall.args);
expect(origSetRemoteDescription.firstCall.args[0].sdp).to.equal('\n');
});
});
});

0 comments on commit 27d724f

Please sign in to comment.